-
Notifications
You must be signed in to change notification settings - Fork 46
fix workspace bug #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix workspace bug #289
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c29926
fix workspace bug
whoiskatrin 3f74569
fallback to tmp
whoiskatrin b515c00
fallbac to homedir instead of /tmp
whoiskatrin 09f238e
Fix workspace bug in sandbox container
whoiskatrin da8fb50
clear tests
whoiskatrin 732b2b8
minor nits
whoiskatrin d639183
Delete tests/e2e/workspace-deletion-workflow.test.ts
whoiskatrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@cloudflare/sandbox": patch | ||
| --- | ||
|
|
||
whoiskatrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fix workspace bug | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * Workspace Deletion Workflow Tests (Issue #288) | ||
| * | ||
| * Tests that new sessions fall back to the home directory when /workspace | ||
| * doesn't exist, preventing "Unknown Error, TODO" failures. | ||
| * | ||
| * @see https://github.com/cloudflare/sandbox-sdk/issues/288 | ||
| */ | ||
whoiskatrin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import { describe, test, expect, beforeAll } from 'vitest'; | ||
| import { | ||
| getSharedSandbox, | ||
| createUniqueSession | ||
| } from './helpers/global-sandbox'; | ||
| import type { ExecResult } from '@repo/shared'; | ||
|
|
||
| describe('Workspace Deletion Workflow (Issue #288)', () => { | ||
| let workerUrl: string; | ||
| let sandbox: Awaited<ReturnType<typeof getSharedSandbox>>; | ||
|
|
||
| beforeAll(async () => { | ||
| sandbox = await getSharedSandbox(); | ||
| workerUrl = sandbox.workerUrl; | ||
| }, 120000); | ||
|
|
||
| /** | ||
| * Core test for issue #288: new session creation after /workspace is deleted. | ||
| * | ||
| * The bug was that creating a NEW session after /workspace was deleted would | ||
| * fail with "Unknown Error, TODO". The fix makes session initialization fall | ||
| * back to the home directory if /workspace doesn't exist. | ||
| */ | ||
| test('new session falls back to home directory when /workspace is deleted', async () => { | ||
| const setupHeaders = sandbox.createHeaders(createUniqueSession()); | ||
|
|
||
| // Delete /workspace | ||
| const deleteResponse = await fetch(`${workerUrl}/api/execute`, { | ||
| method: 'POST', | ||
| headers: setupHeaders, | ||
| body: JSON.stringify({ command: 'rm -rf /workspace' }) | ||
| }); | ||
| expect(deleteResponse.status).toBe(200); | ||
|
|
||
| // Create a NEW session - this is where the bug occurred | ||
| const newHeaders = sandbox.createHeaders(createUniqueSession()); | ||
|
|
||
| const execResponse = await fetch(`${workerUrl}/api/execute`, { | ||
| method: 'POST', | ||
| headers: newHeaders, | ||
| body: JSON.stringify({ command: 'pwd' }) | ||
| }); | ||
|
|
||
| expect(execResponse.status).toBe(200); | ||
| const execData = (await execResponse.json()) as ExecResult; | ||
| expect(execData.success).toBe(true); | ||
| expect(execData.stdout?.trim()).toBe('/root'); | ||
|
|
||
| // Restore /workspace for other tests | ||
| await fetch(`${workerUrl}/api/execute`, { | ||
| method: 'POST', | ||
| headers: setupHeaders, | ||
| body: JSON.stringify({ command: 'mkdir -p /workspace' }) | ||
| }); | ||
| }, 90000); | ||
|
|
||
| /** | ||
| * Tests that new sessions work when /workspace is a symlink to a valid directory. | ||
| */ | ||
| test('new session works when /workspace is a symlink', async () => { | ||
| const setupHeaders = sandbox.createHeaders(createUniqueSession()); | ||
| const backupDir = `/tmp/workspace-backup-${Date.now()}`; | ||
|
|
||
| // Replace /workspace with a symlink | ||
| await fetch(`${workerUrl}/api/execute`, { | ||
| method: 'POST', | ||
| headers: setupHeaders, | ||
| body: JSON.stringify({ | ||
| command: `mkdir -p ${backupDir} && rm -rf /workspace && ln -sf ${backupDir} /workspace` | ||
| }) | ||
| }); | ||
|
|
||
| // Create a NEW session - should work with the symlink | ||
| const newHeaders = sandbox.createHeaders(createUniqueSession()); | ||
|
|
||
| const execResponse = await fetch(`${workerUrl}/api/execute`, { | ||
| method: 'POST', | ||
| headers: newHeaders, | ||
| body: JSON.stringify({ command: 'pwd -P' }) // -P resolves symlinks | ||
| }); | ||
|
|
||
| expect(execResponse.status).toBe(200); | ||
| const execData = (await execResponse.json()) as ExecResult; | ||
| expect(execData.success).toBe(true); | ||
| expect(execData.stdout?.trim()).toBe(backupDir); | ||
|
|
||
| // Restore /workspace as a real directory | ||
| await fetch(`${workerUrl}/api/execute`, { | ||
| method: 'POST', | ||
| headers: setupHeaders, | ||
| body: JSON.stringify({ | ||
| command: `rm -f /workspace && mkdir -p /workspace && rm -rf ${backupDir}` | ||
| }) | ||
| }); | ||
| }, 90000); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.