-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(acp-bridge): map Windows-shaped workspace paths to their sandbox mount #7228
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1dd5393
fix(acp-bridge): map Windows-shaped workspace paths to their sandbox …
zjunothing 4ab9f67
test(serve): document the SANDBOX env read in the process-env guard
zjunothing 3046e3b
fix(serve): translate Windows-shaped workspace paths before the absol…
zjunothing 59f11f0
fix(serve): import the sandbox path translation via the workspacePath…
zjunothing b646a41
test(serve): update the import-boundary pin for the merged workspaceP…
zjunothing 60705e1
fix(acp-bridge,serve): refuse ..-escapes in the sandbox translation; …
zjunothing e9c3b00
fix(serve): bound cwd length before the sandbox translation; cover th…
zjunothing 3675d96
refactor(serve): share the translate-then-check ordering across inges…
zjunothing 88a5fc9
fix(serve): echo the raw --workspace input in the absolute-path rejec…
zjunothing 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,61 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import { makeBridge, makeChannel } from './internal/testUtils.js'; | ||
| import { _setSandboxMountExistsForTest } from './workspacePaths.js'; | ||
|
|
||
| // #7139 wiring for the bridge ingestion site: `resolveWorkspaceKey` guards | ||
| // with `path.isAbsolute` before canonicalizing, so a Windows-shaped | ||
| // `workspaceCwd` arriving via spawnOrAttach (clients, persisted | ||
| // registrations) must be translated to its bind mount first — the sibling | ||
| // of the dispatch/request-helpers/route/boot-validator wiring tests. | ||
| describe('bridge spawnOrAttach inside a POSIX container sandbox (#7139)', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| _setSandboxMountExistsForTest(undefined); | ||
| }); | ||
|
|
||
| it.skipIf(process.platform === 'win32')( | ||
| 'accepts a Windows-shaped workspaceCwd bound to its mount location', | ||
| async () => { | ||
| vi.stubEnv('SANDBOX', 'qwen-code-sandbox-0'); | ||
| _setSandboxMountExistsForTest((p) => p === '/c/qwen-repro'); | ||
| const handle = makeChannel(); | ||
| const bridge = makeBridge({ | ||
| boundWorkspace: '/c/qwen-repro', | ||
| channelFactory: vi.fn().mockResolvedValue(handle.channel), | ||
| }); | ||
| try { | ||
| const session = await bridge.spawnOrAttach({ | ||
| workspaceCwd: 'C:\\qwen-repro', | ||
| }); | ||
| expect(session.sessionId).toBeTruthy(); | ||
| } finally { | ||
| await bridge.shutdown(); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| it.skipIf(process.platform === 'win32')( | ||
| 'still rejects a Windows-shaped workspaceCwd outside a sandbox', | ||
| async () => { | ||
| vi.stubEnv('SANDBOX', ''); | ||
| const handle = makeChannel(); | ||
| const bridge = makeBridge({ | ||
| boundWorkspace: '/c/qwen-repro', | ||
| channelFactory: vi.fn().mockResolvedValue(handle.channel), | ||
| }); | ||
| try { | ||
| await expect( | ||
| bridge.spawnOrAttach({ workspaceCwd: 'C:\\qwen-repro' }), | ||
| ).rejects.toThrow('workspaceCwd must be an absolute path'); | ||
| } finally { | ||
| await bridge.shutdown(); | ||
| } | ||
| }, | ||
| ); | ||
| }); |
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,52 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import { canonicalizeWorkspace } from './workspacePaths.js'; | ||
|
|
||
| // Isolated from workspacePaths.test.ts because it mocks node:fs — the other | ||
| // file drives real filesystem fixtures. | ||
| vi.mock('node:fs', async (importOriginal) => { | ||
| const actual = (await importOriginal()) as typeof import('node:fs'); | ||
| return { | ||
| ...actual, | ||
| existsSync: (p: unknown) => | ||
| p === '/c/qwen-repro' ? true : actual.existsSync(p as never), | ||
| }; | ||
| }); | ||
|
|
||
| describe('canonicalizeWorkspace inside a POSIX container sandbox (#7139)', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| it.skipIf(process.platform === 'win32')( | ||
| 'resolves a Windows-shaped workspace to its bind-mount location', | ||
| () => { | ||
| vi.stubEnv('SANDBOX', 'qwen-code-sandbox-0'); | ||
| // The mount exists (mocked), realpath on it ENOENTs on this host, so | ||
| // the fallback returns the translated absolute path — NOT the cwd | ||
| // concatenation `path.resolve` alone would produce. | ||
| expect(canonicalizeWorkspace('C:\\qwen-repro')).toBe('/c/qwen-repro'); | ||
| }, | ||
| ); | ||
|
|
||
| it.skipIf(process.platform === 'win32')( | ||
| 'keeps Windows-shaped input untouched outside a sandbox', | ||
| () => { | ||
| // Explicitly clear SANDBOX: when this suite itself runs inside the | ||
| // project's Docker sandbox the launcher sets it, and unstubAllEnvs | ||
| // would not remove a genuinely inherited value. | ||
| vi.stubEnv('SANDBOX', ''); | ||
| const result = canonicalizeWorkspace('C:\\qwen-repro'); | ||
| // Unsandboxed POSIX behavior is unchanged: the string resolves | ||
| // relative to the cwd (and stays broken — which is what the | ||
| // pre-#7139 sandbox path produced too). | ||
| expect(result.endsWith('C:\\qwen-repro')).toBe(true); | ||
| expect(result.startsWith('/')).toBe(true); | ||
| }, | ||
| ); | ||
| }); | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] This "outside a sandbox" test never stubs
SANDBOX, but the file-levelvi.mock('node:fs')makesexistsSync('/c/qwen-repro')returntruefor every test in the file. IfSANDBOXhappens to be set in the environment — e.g. running this suite inside the project's Docker sandbox container, where the launcher setsSANDBOX=qwen-code-sandbox-0— the translation fires (truthysandboxEnv, regex match, mocked-true mount probe) and returns/c/qwen-repro, soresult.endsWith('C:\\qwen-repro')isfalseand the test fails spuriously.afterEach(vi.unstubAllEnvs)only restores variables a prior test stubbed; it does not unset a real inheritedSANDBOX. — Concrete cost: a flaky, misleading failure that looks like a translation bug but is a test-isolation gap.— qwen3.8-max-preview via Qwen Code /review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 60705e1 — the outside-a-sandbox tests (both this file and the REST-helper sibling) now stub
SANDBOXto '' explicitly, exactly for the inherited-env case you describe. 中文:两处 outside-a-sandbox 测试都显式 stubEnv('SANDBOX',''),覆盖套件本身跑在项目 Docker 沙箱内继承真实 SANDBOX 的情形。