Skip to content

Commit 8c4a0ec

Browse files
Re-adopt 14 upstream test declarations lost in the vps2 chain and pin the abort path
The .each-inclusive survivor audit of the merged tree against e943530 flagged 22 rows in three specs. All 22 exist at the merge base 3ee042d and all three files are ours-only paths, so nothing here was lost by the merge: 15 declarations were dropped by our chain when it reworked these files, 7 rows are the rewrites themselves. Re-adopted from main, bodies verbatim, harness lines included: - webview-ui ExtensionStateContext.spec.tsx: the 13-declaration interning suite (main 145-581) plus its expectMessages/InternSpy/cacheFor helpers, the StringCache import, the ExtensionMessage type and afterEach(() => vi.restoreAllMocks()). 28 -> 41 declarations. - registerCommands.spec.ts: 'creates diagnostics from all provider instances without requiring a visible provider' plus the services/diagnostics module mock it needs. 50 -> 51. One main case is superseded rather than re-adopted: plusButtonClicked 'no-op when no visible provider' - our handler resolves the registered sidebar provider through postActions() and the replacement case asserts 5 things where main asserted 1. One real gap the audit surfaced: our chain moved all four enqueueProviderProfileMutation call sites to runToCompletion, which left production's abort branch (ClineProvider.ts:445-446, 'aborting in-flight mutation') emitted but unasserted. Added a case that drives the non-runToCompletion path through the private helper directly and pins the cancelled signal, the log and the queue advance; three mutants (log text, removed abort, queue no longer advancing on timeout) each kill it. Controls: no-oping all 9 interning call sites fails 12 of the 13 re-adopted cases; emptying the providers fan-out fails exactly the re-adopted diagnostics case; production was restored byte-identical after every mutation. eslint --prune-suppressions stayed count-neutral (3298 total, no file above max(base, ours, main)), prettier --check clean, tsc clean for src, webview-ui and packages/types, core/misc/api/webview-ui/packages-types lanes green.
1 parent 3f99274 commit 8c4a0ec

3 files changed

Lines changed: 506 additions & 0 deletions

File tree

‎src/activate/__tests__/registerCommands.spec.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ vi.mock("../../services/ripgrep/diagnostic", () => ({
107107
registerRipgrepDiagnosticCommand: vi.fn().mockReturnValue({ dispose: vi.fn() }),
108108
}))
109109

110+
vi.mock("../../services/diagnostics", () => ({
111+
createDiagnosticsReport: vi.fn().mockResolvedValue(undefined),
112+
}))
113+
110114
describe("getVisibleProviderOrLog", () => {
111115
let mockOutputChannel: vscode.OutputChannel
112116

@@ -279,6 +283,21 @@ describe("registerCommands handlers", () => {
279283

280284
// The sidebar title-bar handlers target the registered provider (the
281285
// sidebar click origin) directly, not the visible-instance heuristic.
286+
it("creates diagnostics from all provider instances without requiring a visible provider", async () => {
287+
const { createDiagnosticsReport } = await import("../../services/diagnostics")
288+
const providers = [{}, {}]
289+
;(ClineProvider.getAllInstances as Mock).mockReturnValue(providers)
290+
;(ClineProvider.getVisibleInstance as Mock).mockReturnValue(undefined)
291+
292+
await handlers["zoo-code.createDiagnosticsReport"]()
293+
294+
expect(createDiagnosticsReport).toHaveBeenCalledWith({
295+
context: mockContext,
296+
outputChannel: mockOutputChannel,
297+
providers,
298+
})
299+
})
300+
282301
it("settingsButtonClicked posts both settingsButtonClicked and didBecomeVisible actions on the registered provider", () => {
283302
handlers["zoo-code.settingsButtonClicked"]()
284303

‎src/core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,38 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
996996
}
997997
})
998998

999+
test("a mutation queued without runToCompletion aborts its in-flight callback and advances the queue", async () => {
1000+
vi.useFakeTimers()
1001+
const logSpy = vi.spyOn(provider, "log")
1002+
let mutationSignal: AbortSignal | undefined
1003+
let started = 0
1004+
const runMutation = (work: (signal: AbortSignal) => Promise<void>) =>
1005+
provider["enqueueProviderProfileMutation"]((signal) => {
1006+
mutationSignal = signal
1007+
started += 1
1008+
return work(signal)
1009+
})
1010+
1011+
try {
1012+
const hanging = runMutation(() => new Promise<void>(() => undefined))
1013+
const rejected = expect(hanging).rejects.toThrow("Provider profile mutation timed out")
1014+
await vi.advanceTimersByTimeAsync(ClineProvider.PENDING_OPERATION_TIMEOUT_MS)
1015+
await rejected
1016+
1017+
// The default path aborts the mutation the caller stopped waiting for, so the
1018+
// callback sees a cancelled signal and the log names the abort.
1019+
expect(started).toBe(1)
1020+
expect(mutationSignal?.aborted).toBe(true)
1021+
expect(logSpy).toHaveBeenCalledWith("Provider profile mutation timed out; aborting in-flight mutation")
1022+
1023+
// The queue advanced on the timeout instead of waiting for the aborted run.
1024+
await runMutation(() => Promise.resolve())
1025+
expect(started).toBe(2)
1026+
} finally {
1027+
vi.useRealTimers()
1028+
}
1029+
})
1030+
9991031
test("mode switch preserves its default task when queued behind a profile mutation", async () => {
10001032
let releaseProfileActivation!: () => void
10011033
const profileActivation = new Promise<void>((resolve) => {

0 commit comments

Comments
 (0)