Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0e1bada
fix(vscode): restore native diff approval flow
yiliang114 Aug 30, 2026
f1f45f2
fix(vscode): only accept host-delivered web-shell permission decisions
yiliang114 Aug 30, 2026
1be6b2d
fix(vscode): open web-shell permission diffs read-only
yiliang114 Aug 30, 2026
f9a6d9b
fix(vscode): align showDiff overload signatures with options argument
yiliang114 Aug 30, 2026
2317625
fix(vscode): only vote web-shell approvals from the permission diff
yiliang114 Aug 30, 2026
1744245
fix(web-shell): lowercase tool names inside isEditToolName
yiliang114 Aug 30, 2026
5071a73
docs(web-shell): note pending-edit-approval exception in expand invar…
yiliang114 Aug 30, 2026
eb6ff92
test(web-shell): pin allow_once-first ladder for native edit approvals
yiliang114 Aug 30, 2026
8bac3fd
test(vscode): expect the readOnly options argument in showDiff comman…
yiliang114 Aug 30, 2026
868ade9
fix(vscode): accept host-relayed permission decisions by their source…
yiliang114 Aug 30, 2026
48cafd6
fix(vscode): only accept diff votes targeting a pending permission diff
yiliang114 Aug 30, 2026
59f8a6b
test(vscode): pin web-shell diff source to readOnly showDiff mapping
yiliang114 Aug 30, 2026
ee902f1
fix(vscode): keep read-only approval diffs from reusing writable twins
yiliang114 Aug 30, 2026
01546cf
fix(vscode): clear web-shell permission flag when the chat view disposes
yiliang114 Aug 30, 2026
446610c
test(vscode): pin the command-level diff vote gate chain
yiliang114 Aug 30, 2026
3e86689
test(vscode): expect pending:false when permission diffs are torn down
yiliang114 Aug 30, 2026
d8cefb2
fix(vscode): complete WebShell host interaction parity
yiliang114 Aug 30, 2026
4b408eb
merge: integrate concurrent VS Code diff safeguards
yiliang114 Aug 30, 2026
b546b30
fix(vscode): surface a notice when a diff vote is not applied
yiliang114 Aug 30, 2026
44b9d08
fix(vscode): complete native diff follow-ups
yiliang114 Aug 30, 2026
3a0824a
Merge branch 'main' into codex/vscode-webshell-diff-approval
yiliang114 Aug 30, 2026
258acf9
fix(vscode): address native diff verification findings
yiliang114 Aug 30, 2026
7ecdea9
test(vscode): cover legacy diff permission fallback
yiliang114 Aug 30, 2026
4fee90a
fix(web-shell): accept native votes for structured edits
yiliang114 Aug 31, 2026
427dc2e
Merge branch 'main' into codex/vscode-webshell-diff-approval
yiliang114 Aug 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/cli/src/acp-integration/session/permissionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ describe('permissionUtils', () => {
}),
);
});

it('keeps one-shot and always-allow options on edit approvals', () => {
const options = toPermissionOptions({
type: 'edit',
title: 'Confirm edit',
fileName: 'a.txt',
filePath: '/tmp/a.txt',
fileDiff: 'diff',
originalContent: 'a',
newContent: 'b',
onConfirm: async () => undefined,
});

// Both kinds must stay present and in this wire order: the web-shell
// native Accept path selects by kind preference (allow_once first), so
// a missing allow_once would escalate a single Accept into
// "Allow All Edits".
expect(options).toEqual([
expect.objectContaining({
optionId: ToolConfirmationOutcome.ProceedAlways,
name: 'Allow All Edits',
kind: 'allow_always',
}),
expect.objectContaining({
optionId: ToolConfirmationOutcome.ProceedOnce,
kind: 'allow_once',
}),
expect.objectContaining({
optionId: ToolConfirmationOutcome.Cancel,
kind: 'reject_once',
}),
]);
});
});

describe('interactionMetaFields', () => {
Expand Down
42 changes: 40 additions & 2 deletions packages/vscode-ide-companion/src/commands/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ describe('registerNewCommands', () => {
'/workspace/src/app.ts',
'old',
'new',
{ readOnly: false, permissionRequestId: undefined },
);
});

Expand All @@ -196,7 +197,11 @@ describe('registerNewCommands', () => {
{ fsPath: '/workspace' },
'src/foo.ts',
);
expect(closeDiff).toHaveBeenCalledWith('/workspace/src/foo.ts', true);
expect(closeDiff).toHaveBeenCalledWith(
'/workspace/src/foo.ts',
true,
undefined,
);
});

it('closeDiff keeps absolute paths unchanged', async () => {
Expand All @@ -216,7 +221,11 @@ describe('registerNewCommands', () => {
await getRegisteredHandler(closeDiffCommand)('/workspace/src/foo.ts');

expect(joinPath).not.toHaveBeenCalled();
expect(closeDiff).toHaveBeenCalledWith('/workspace/src/foo.ts', true);
expect(closeDiff).toHaveBeenCalledWith(
'/workspace/src/foo.ts',
true,
undefined,
);
});

it('showDiff keeps UNC paths absolute', async () => {
Expand All @@ -243,6 +252,35 @@ describe('registerNewCommands', () => {
'\\\\server\\share\\app.ts',
'old',
'new',
{ readOnly: false, permissionRequestId: undefined },
);
});

it('showDiff forwards the readOnly flag', async () => {
workspaceMock.workspaceFolders = [
{ uri: { fsPath: '/workspace' }, name: 'workspace', index: 0 },
];

registerNewCommands(
context as never,
log,
diffManager as never,
() => [],
vi.fn() as never,
);

await getRegisteredHandler(showDiffCommand)({
path: '/workspace/src/app.ts',
oldText: 'old',
newText: 'new',
readOnly: true,
});

expect(diffManager.showDiff).toHaveBeenCalledWith(
'/workspace/src/app.ts',
'old',
'new',
{ readOnly: true, permissionRequestId: undefined },
);
});
});
21 changes: 17 additions & 4 deletions packages/vscode-ide-companion/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,20 @@ export function registerNewCommands(
disposables.push(
vscode.commands.registerCommand(
showDiffCommand,
async (args: { path: string; oldText: string; newText: string }) => {
async (args: {
path: string;
oldText: string;
newText: string;
readOnly?: boolean;
permissionRequestId?: string;
}) => {
try {
const absolutePath = resolveWorkspaceRelativePath(args.path);
log(`[Command] Showing diff for ${absolutePath}`);
await diffManager.showDiff(absolutePath, args.oldText, args.newText);
await diffManager.showDiff(absolutePath, args.oldText, args.newText, {
readOnly: args.readOnly === true,
permissionRequestId: args.permissionRequestId,
});
Comment thread
yiliang114 marked this conversation as resolved.
Comment thread
yiliang114 marked this conversation as resolved.
} catch (error) {
const errorMsg = getErrorMessage(error);
log(`[Command] Error showing diff: ${errorMsg}`);
Expand All @@ -95,8 +104,12 @@ export function registerNewCommands(
disposables.push(
vscode.commands.registerCommand(
closeDiffCommand,
async (filePath: string) =>
diffManager.closeDiff(resolveWorkspaceRelativePath(filePath), true),
async (filePath: string, permissionRequestId?: string) =>
diffManager.closeDiff(
resolveWorkspaceRelativePath(filePath),
true,
permissionRequestId,
),
Comment thread
yiliang114 marked this conversation as resolved.
),
);

Expand Down
179 changes: 179 additions & 0 deletions packages/vscode-ide-companion/src/diff-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

const executeCommand = vi.fn().mockResolvedValue(undefined);

vi.mock('vscode', () => {
class EventEmitter<T> {
private listeners = new Set<(event: T) => void>();
event = (listener: (event: T) => void) => {
this.listeners.add(listener);
return { dispose: () => this.listeners.delete(listener) };
};
fire(event: T): void {
for (const listener of [...this.listeners]) listener(event);
}
dispose(): void {
this.listeners.clear();
}
}

return {
EventEmitter,
Uri: {
file: (filePath: string) => {
const uri: {
fsPath: string;
scheme: string;
query: string;
with: (change: Record<string, unknown>) => unknown;
toString: () => string;
} = {
fsPath: filePath,
scheme: 'file',
query: '',
with(change: Record<string, unknown>) {
return { ...uri, ...change };
},
toString() {
return `${uri.scheme}://${uri.fsPath}?${uri.query}`;
},
};
return uri;
},
},
ViewColumn: { Active: -1, Beside: -2 },
commands: { executeCommand },
window: {
activeTextEditor: undefined,
onDidChangeActiveTextEditor: vi.fn(() => ({ dispose: vi.fn() })),
tabGroups: { all: [] },
},
};
});

// Avoid pulling the full extension module graph; only the scheme constant is
// needed by the diff manager.
vi.mock('./extension.js', () => ({ DIFF_SCHEME: 'qwen-diff' }));

vi.mock('@qwen-code/qwen-code-core', () => ({
IdeDiffAcceptedNotificationSchema: { parse: (value: unknown) => value },
IdeDiffClosedNotificationSchema: { parse: (value: unknown) => value },
}));

const { DiffContentProvider, DiffManager } = await import('./diff-manager.js');

const WRITABLE_COMMAND =
'workbench.action.files.setActiveEditorWriteableInSession';

describe('DiffManager.showDiff writability', () => {
beforeEach(() => {
executeCommand.mockClear();
});

function createManager(): InstanceType<typeof DiffManager> {
return new DiffManager(() => {}, new DiffContentProvider());
}

it('makes regular diffs editable so IDE-mode approvals can round-trip edits', async () => {
const manager = createManager();

await manager.showDiff('/workspace/foo.ts', 'old', 'new');

expect(executeCommand).toHaveBeenCalledWith(WRITABLE_COMMAND);
});

it('keeps read-only diffs locked for flows that cannot round-trip edits', async () => {
const manager = createManager();

await manager.showDiff('/workspace/foo.ts', 'old', 'new', {
readOnly: true,
});

expect(executeCommand).not.toHaveBeenCalledWith(WRITABLE_COMMAND);
// The diff itself still opens.
expect(executeCommand).toHaveBeenCalledWith(
'vscode.diff',
expect.anything(),
expect.anything(),
expect.stringContaining('foo.ts'),
expect.anything(),
);
});
});

describe('DiffManager.showDiff reuse', () => {
beforeEach(() => {
executeCommand.mockClear();
});

function createManager(): InstanceType<typeof DiffManager> {
return new DiffManager(() => {}, new DiffContentProvider());
}

function diffOpenCount(): number {
return executeCommand.mock.calls.filter(
([command]) => command === 'vscode.diff',
).length;
}

it('opens a fresh diff instead of reusing a writable twin for a read-only request', async () => {
const manager = createManager();

// IDE-mode flow opens a writable diff for this (path, old, new) triple.
await manager.showDiff('/workspace/foo.ts', 'old', 'new');
executeCommand.mockClear();

// A web-shell approval for the same triple must get its own read-only
// diff; reusing the writable one would invite hand-edits that the
// approving tool then silently discards (and inside the dedupe window
// the request would otherwise be suppressed outright).
await manager.showDiff('/workspace/foo.ts', 'old', 'new', {
readOnly: true,
});

expect(diffOpenCount()).toBe(1);
expect(executeCommand).not.toHaveBeenCalledWith(WRITABLE_COMMAND);
});

it('opens a fresh diff instead of reusing a read-only twin for a writable request', async () => {
const manager = createManager();

await manager.showDiff('/workspace/foo.ts', 'old', 'new', {
readOnly: true,
});
executeCommand.mockClear();

// The IDE-mode flow needs an editable right side to round-trip edits;
// refocusing the locked diff would take that away.
await manager.showDiff('/workspace/foo.ts', 'old', 'new');

expect(diffOpenCount()).toBe(1);
expect(executeCommand).toHaveBeenCalledWith(WRITABLE_COMMAND);
});

it('still dedupes repeat requests with matching writability', async () => {
const manager = createManager();

await manager.showDiff('/workspace/foo.ts', 'old', 'new');
executeCommand.mockClear();

// Same writability inside the dedupe window: suppressed entirely.
await manager.showDiff('/workspace/foo.ts', 'old', 'new');
expect(diffOpenCount()).toBe(0);

await manager.showDiff('/workspace/foo.ts', 'old', 'new', {
readOnly: true,
});
executeCommand.mockClear();
await manager.showDiff('/workspace/foo.ts', 'old', 'new', {
readOnly: true,
});
expect(diffOpenCount()).toBe(0);
});
});
Loading
Loading