Skip to content

Commit e27b693

Browse files
Re-adopt two upstream cases and replace the fixed 50 ms readiness waits with a verified signal
The .each-inclusive survivor audit of this tree against e943530 flagged 11 rows: 4 declarations absent and 7 rewrites. Of the absent ones, 1 is re-adopted verbatim, 2 are superseded by stronger coverage already on this head, and 1 is re-adopted here: - registerCommands.spec.ts: main's 'creates diagnostics from all provider instances without requiring a visible provider' (exact-argument pinning of { context, outputChannel, providers }); the head already had a looser ObjectContaining version of the same fan-out, so this adds the exact shape and the no-visible-provider condition. 54 -> 55 declarations. - ExtensionStateContext.spec.tsx: main's 'does not intern messages from stale sequenced state updates' (41 lines, harness already present). 40 -> 41 declarations. Superseded, reported rather than re-adopted: main's 'plusButtonClicked is a no-op when no visible provider' (this head asserts 5 things about the registered sidebar provider where main asserted 1, and the handler resolves the registered provider through postActions()), and main's 'should handle invalid mode gracefully' in ClineProvider.sticky-mode.spec.ts - that case assumed 'the provider actually does switch to invalid modes', while this head rejects invalid modes at ClineProvider.ts:5026/5078 and asserts it in ClineProvider.spec.ts (Ignoring invalid mode logs), switchModeTool.spec.ts:105 and CustomModesSettings.spec.ts:61 - lower, stronger layers. Review thread PRRT_kwDOSK-bwM6z6_R2 (api-task-control.spec.ts, coderabbitai 2026-11-05T04:20:41Z): the two wall-clock 'await new Promise(setTimeout 50ms)' waits at lines 302 and 648 are replaced with the fake-clock readiness signal the reviewer described: the bound in src/extension/api.ts:299- 310 arms exactly one setTimeout when the wait is entered, so both cases now advance the clock to the first tick, assert vi.getTimerCount() === 1 as proof the wait started, and restore real timers in a finally. Assertions per case: 1 -> 2 and 2 -> 3; no fixed delay remains in the file. Controls, each reverted to a byte-identical production blob afterwards: - providers: ClineProvider.getAllInstances() -> [] : catches the re-adopted fan-out case and the existing looser one, nothing else. - seq guard '<=' -> '<' (equal sequence treated as fresh): catches the re-adopted stale-sequenced case. - api.ts disposal-after-wait throw removed : catches exactly the disposal case. - api.ts readiness block never entered : catches 4 cases including both rewritten ones via 'expected +0 to be 1' on the timer count. Gates: prettier --check clean, eslint --prune-suppressions count-neutral (3293, reverted), check-types clean across 13 packages, misc lane 115 files 2106 pass + 13 skip, webview-ui lane 188 files 2506 pass, and the two touched src specs green per-file (92 cases).
1 parent 64ce56b commit e27b693

3 files changed

Lines changed: 84 additions & 12 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ describe("registerCommands handlers", () => {
306306

307307
// The sidebar title-bar handlers target the registered provider (the
308308
// sidebar click origin) directly, not the visible-instance heuristic.
309+
it("creates diagnostics from all provider instances without requiring a visible provider", async () => {
310+
const { createDiagnosticsReport } = await import("../../services/diagnostics")
311+
const providers = [{}, {}]
312+
;(ClineProvider.getAllInstances as Mock).mockReturnValue(providers)
313+
;(ClineProvider.getVisibleInstance as Mock).mockReturnValue(undefined)
314+
315+
await handlers["zoo-code.createDiagnosticsReport"]()
316+
317+
expect(createDiagnosticsReport).toHaveBeenCalledWith({
318+
context: mockContext,
319+
outputChannel: mockOutputChannel,
320+
providers,
321+
})
322+
})
323+
309324
it("settingsButtonClicked posts both settingsButtonClicked and didBecomeVisible actions on the registered provider", () => {
310325
handlers["zoo-code.settingsButtonClicked"]()
311326

‎src/extension/__tests__/api-task-control.spec.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,28 @@ describe("API task controls", () => {
293293
// Disposal resolves viewStateReadiness to release waiters (see ClineProvider.dispose)
294294
// and marks the provider disposed first: the wait must then fail instead of
295295
// creating a task against the disposed view.
296+
vi.useFakeTimers()
296297
let resolveReady!: () => void
297298
sidebarProvider.viewStateReadiness = new Promise<void>((resolve) => {
298299
resolveReady = resolve
299300
})
300301

301302
const started = api.startNewTask({ configuration, text: "new task" })
302-
await new Promise((resolve) => setTimeout(resolve, 50))
303-
sidebarProvider.isDisposed = true
304-
resolveReady()
305-
306-
await expect(started).rejects.toThrow(
303+
const settled = expect(started).rejects.toThrow(
307304
"The provider was disposed while waiting for the view state to become ready",
308305
)
309-
expect(sidebarProvider.createTask).not.toHaveBeenCalled()
306+
try {
307+
// The readiness bound arms exactly one timer when the wait is entered, so an
308+
// armed timer proves the wait started; elapsed wall-clock time does not.
309+
await vi.advanceTimersByTimeAsync(0)
310+
expect(vi.getTimerCount()).toBe(1)
311+
sidebarProvider.isDisposed = true
312+
resolveReady()
313+
await settled
314+
expect(sidebarProvider.createTask).not.toHaveBeenCalled()
315+
} finally {
316+
vi.useRealTimers()
317+
}
310318
})
311319
})
312320

@@ -642,16 +650,23 @@ describe("API task controls - per-view review fixes", () => {
642650
newTabProvider.viewStateReadiness = readiness
643651
openClineInNewTabMock.mockResolvedValue(newTabProvider)
644652

653+
vi.useFakeTimers()
645654
const started = api.startNewTask({ configuration, text: "wait for view state", newTab: true })
646655

647-
// The task must not start while the view persisted state is still loading.
648-
await new Promise((resolve) => setTimeout(resolve, 50))
649-
expect(newTabProvider.createTask).not.toHaveBeenCalled()
656+
try {
657+
// The task must not start while the view persisted state is still loading, and
658+
// the bound's armed timer is what proves the wait was entered.
659+
await vi.advanceTimersByTimeAsync(0)
660+
expect(vi.getTimerCount()).toBe(1)
661+
expect(newTabProvider.createTask).not.toHaveBeenCalled()
650662

651-
resolveReadiness()
663+
resolveReadiness()
652664

653-
await expect(started).resolves.toBe("new-tab-task")
654-
expect(newTabProvider.createTask).toHaveBeenCalled()
665+
await expect(started).resolves.toBe("new-tab-task")
666+
expect(newTabProvider.createTask).toHaveBeenCalled()
667+
} finally {
668+
vi.useRealTimers()
669+
}
655670
})
656671
})
657672

‎webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,48 @@ describe("ExtensionStateContext", () => {
618618
expect(historyCache?.size).toBe(historySize)
619619
})
620620

621+
it("does not intern messages from stale sequenced state updates", () => {
622+
const internSpy = vi.spyOn(StringCache.prototype, "intern")
623+
render(
624+
<ExtensionStateContextProvider initialState={{ clineMessagesSeq: 5 }}>
625+
<TestComponent />
626+
</ExtensionStateContextProvider>,
627+
)
628+
internSpy.mockClear()
629+
const staleMessage = { ts: 1, type: "say", say: "text", text: "stale" } as ClineMessage
630+
const currentMessage = { ts: 2, type: "say", say: "text", text: "current" } as ClineMessage
631+
632+
act(() => {
633+
window.dispatchEvent(
634+
new MessageEvent("message", {
635+
data: { type: "state", state: { clineMessages: [staleMessage], clineMessagesSeq: 5 } },
636+
}),
637+
)
638+
})
639+
expect(internSpy).not.toHaveBeenCalledWith(staleMessage)
640+
expectMessages([])
641+
642+
act(() => {
643+
window.dispatchEvent(
644+
new MessageEvent("message", {
645+
data: { type: "state", state: { clineMessages: [currentMessage], clineMessagesSeq: 6 } },
646+
}),
647+
)
648+
})
649+
expect(internSpy).toHaveBeenCalledWith(currentMessage)
650+
expectMessages([currentMessage])
651+
internSpy.mockClear()
652+
act(() => {
653+
window.dispatchEvent(
654+
new MessageEvent("message", {
655+
data: { type: "state", state: { clineMessages: [staleMessage], clineMessagesSeq: 6 } },
656+
}),
657+
)
658+
})
659+
expect(internSpy).not.toHaveBeenCalledWith(staleMessage)
660+
expectMessages([currentMessage])
661+
})
662+
621663
it("does not intern an update for a message outside the current task", () => {
622664
const currentMessage = { ts: 1, type: "say", say: "text", text: "current" } as ClineMessage
623665
const unknownMessage = { ts: 2, type: "say", say: "text", text: "late" } as ClineMessage

0 commit comments

Comments
 (0)