Skip to content

Commit a3c6f86

Browse files
committed
feat(experiments): make chat-diff the default approval path (L2, #1375)
Flips the PREVENT_FOCUS_DISRUPTION experiment default from false to true so the chat-diff approval path (approve in chat, save directly, no diff-editor focus) is the default. The diff-editor path remains available by toggling the experiment off; the storage key is unchanged so saved values are preserved. Production call sites already route through experiments.isEnabled(... ?? {}), so the flip applies automatically. Test-only changes pin the legacy path explicitly where base mocks relied on the old default.
1 parent 78c712a commit a3c6f86

8 files changed

Lines changed: 60 additions & 14 deletions

File tree

‎src/core/tools/__tests__/editFileTool.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ describe("editFileTool", () => {
115115
getState: vi.fn().mockResolvedValue({
116116
diagnosticsEnabled: true,
117117
writeDelayMs: 1000,
118-
experiments: {},
118+
// Pin the legacy diff-editor path explicitly: the PREVENT_FOCUS_DISRUPTION default
119+
// flipped to true (L2, plan #33), so these tests must opt out.
120+
experiments: { preventFocusDisruption: false } as Record<string, boolean>,
119121
}),
120122
}),
121123
}

‎src/core/tools/__tests__/editTool.spec.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ describe("editTool", () => {
111111
getState: vi.fn().mockResolvedValue({
112112
diagnosticsEnabled: true,
113113
writeDelayMs: 1000,
114-
experiments: {},
114+
// Pin the legacy diff-editor path explicitly: the PREVENT_FOCUS_DISRUPTION default
115+
// flipped to true (L2, plan #33), so these tests must opt out.
116+
experiments: { preventFocusDisruption: false } as Record<string, boolean>,
115117
}),
116118
}),
117119
}
@@ -361,6 +363,39 @@ describe("editTool", () => {
361363
})
362364
})
363365

366+
describe("focus disruption default (L2: chat-diff is the default approval path)", () => {
367+
it("saves via saveDirectly without opening the diff editor when no experiment value is stored", async () => {
368+
mockAskApproval.mockResolvedValue(true)
369+
// No stored experiment value: the default (flipped to true in L2) resolves
370+
// to the chat-diff path.
371+
mockTask.providerRef.deref.mockReturnValue({
372+
getState: vi.fn().mockResolvedValue({
373+
diagnosticsEnabled: true,
374+
writeDelayMs: 1000,
375+
experiments: {},
376+
}),
377+
})
378+
379+
await executeEditTool()
380+
381+
expect(mockTask.diffViewProvider.saveDirectly).toHaveBeenCalled()
382+
expect(mockTask.diffViewProvider.open).not.toHaveBeenCalled()
383+
expect(mockTask.diffViewProvider.saveChanges).not.toHaveBeenCalled()
384+
expect(mockTask.didEditFile).toBe(true)
385+
})
386+
387+
it("still uses the diff-editor path when the user has opted out (stored false)", async () => {
388+
mockAskApproval.mockResolvedValue(true)
389+
// Base mock pins experiments: { preventFocusDisruption: false } (legacy path).
390+
391+
await executeEditTool()
392+
393+
expect(mockTask.diffViewProvider.open).toHaveBeenCalled()
394+
expect(mockTask.diffViewProvider.saveChanges).toHaveBeenCalled()
395+
expect(mockTask.diffViewProvider.saveDirectly).not.toHaveBeenCalled()
396+
})
397+
})
398+
364399
describe("partial block handling", () => {
365400
it("handles partial block without errors after path stabilizes", async () => {
366401
// Path stabilization requires two consecutive calls with the same path

‎src/core/tools/__tests__/searchReplaceTool.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ describe("searchReplaceTool", () => {
113113
getState: vi.fn().mockResolvedValue({
114114
diagnosticsEnabled: true,
115115
writeDelayMs: 1000,
116-
experiments: {},
116+
// Pin the legacy diff-editor path explicitly: the PREVENT_FOCUS_DISRUPTION default
117+
// flipped to true (L2, plan #33), so these tests must opt out.
118+
experiments: { preventFocusDisruption: false } as Record<string, boolean>,
117119
}),
118120
}),
119121
}

‎src/core/tools/__tests__/writeToFileTool.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ describe("writeToFileTool", () => {
137137
getState: vi.fn().mockResolvedValue({
138138
diagnosticsEnabled: true,
139139
writeDelayMs: 1000,
140+
// Pin the legacy diff-editor path explicitly: the PREVENT_FOCUS_DISRUPTION default
141+
// flipped to true (L2, plan #33), so these tests must opt out.
142+
experiments: { preventFocusDisruption: false },
140143
}),
141144
}),
142145
}

‎src/integrations/editor/__tests__/DiffViewProvider.spec.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,15 +811,16 @@ describe("DiffViewProvider", () => {
811811
expect(result.finalContent).toBe("new content")
812812
})
813813

814-
it("should not open file when openWithoutFocus is false", async () => {
814+
it("should not open file when openWithoutFocus is false (focus not stolen: in-memory document only)", async () => {
815815
await diffViewProvider.saveDirectly("test.ts", "new content", false, true, 1000)
816816

817817
// Verify file was written
818818
const fs = await import("fs/promises")
819819
expect(fs.writeFile).toHaveBeenCalledWith(`${mockCwd}/test.ts`, "new content", "utf-8")
820820

821-
// Verify file was NOT opened
821+
// Verify file was NOT opened in the editor, and the document is loaded in memory only
822822
expect(vscode.window.showTextDocument).not.toHaveBeenCalled()
823+
expect(vscode.workspace.openTextDocument).toHaveBeenCalled()
823824
})
824825

825826
it("should skip diagnostics when diagnosticsEnabled is false", async () => {

‎src/shared/__tests__/experiments-preventFocusDisruption.spec.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ describe("PREVENT_FOCUS_DISRUPTION experiment", () => {
55
expect(EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION).toBe("preventFocusDisruption")
66
})
77

8-
it("should have PREVENT_FOCUS_DISRUPTION in experimentConfigsMap", () => {
8+
it("should have PREVENT_FOCUS_DISRUPTION enabled by default (chat-diff is the default approval path)", () => {
99
expect(experimentConfigsMap.PREVENT_FOCUS_DISRUPTION).toBeDefined()
10-
expect(experimentConfigsMap.PREVENT_FOCUS_DISRUPTION.enabled).toBe(false)
10+
expect(experimentConfigsMap.PREVENT_FOCUS_DISRUPTION.enabled).toBe(true)
1111
})
1212

13-
it("should have PREVENT_FOCUS_DISRUPTION in experimentDefault", () => {
14-
expect(experimentDefault.preventFocusDisruption).toBe(false)
13+
it("should have PREVENT_FOCUS_DISRUPTION enabled in experimentDefault", () => {
14+
expect(experimentDefault.preventFocusDisruption).toBe(true)
1515
})
1616

1717
it("should correctly check if PREVENT_FOCUS_DISRUPTION is enabled", () => {
@@ -23,8 +23,8 @@ describe("PREVENT_FOCUS_DISRUPTION experiment", () => {
2323
const enabledConfig = { preventFocusDisruption: true }
2424
expect(experiments.isEnabled(enabledConfig, EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION)).toBe(true)
2525

26-
// Test when experiment is not in config (should use default)
26+
// Test when experiment is not in config (should use default — now enabled)
2727
const emptyConfig = {}
28-
expect(experiments.isEnabled(emptyConfig, EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION)).toBe(false)
28+
expect(experiments.isEnabled(emptyConfig, EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION)).toBe(true)
2929
})
3030
})

‎src/shared/__tests__/experiments.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { EXPERIMENT_IDS, experimentConfigsMap, experiments as Experiments } from
66

77
describe("experiments", () => {
88
describe("PREVENT_FOCUS_DISRUPTION", () => {
9-
it("is configured correctly", () => {
9+
it("is configured correctly (chat-diff is the default approval path)", () => {
1010
expect(EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION).toBe("preventFocusDisruption")
1111
expect(experimentConfigsMap.PREVENT_FOCUS_DISRUPTION).toMatchObject({
12-
enabled: false,
12+
enabled: true,
1313
})
1414
})
1515
})

‎src/shared/experiments.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ interface ExperimentConfig {
1919
}
2020

2121
export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
22-
PREVENT_FOCUS_DISRUPTION: { enabled: false },
22+
// Chat-diff is the default approval path (plan issue #33, L2): writes are saved
23+
// without opening/refocusing the diff editor. The diff-editor path remains
24+
// available by toggling this experiment off (storage key unchanged).
25+
PREVENT_FOCUS_DISRUPTION: { enabled: true },
2326
IMAGE_GENERATION: { enabled: false },
2427
RUN_SLASH_COMMAND: { enabled: false },
2528
CUSTOM_TOOLS: { enabled: false },

0 commit comments

Comments
 (0)