Skip to content

Commit e4b3151

Browse files
test(webview): pin the tab panel's listener tracking as well
The case added for the sidebar leaves the tab branch's onDidChangeViewState subscription unobserved, so dropping the push that records it in the provider's disposable list changes nothing any test can see: the subscription then leaks on panel close, and no assertion notices. Same shape as the sidebar registrations that the mutation run already caught. The panel-shaped case resolves a WebviewPanel stand-in, asserts its view-state subscription lands in the same list every other registration uses and is not disposed while the panel is live, and asserts the provider's disposal releases it exactly once and empties the list. Measured control: replacing the push with a bare reference leaves the subscription untracked and the case fails with "expected [ { dispose: [Function Mock] }, ...(2) ] to include { dispose: [Function Mock] }"; restored byte-identically -> green. Unit-shaped mutation run over the three commits on this branch (base 2860e2b, 7 changed executable lines, test paths excluded): 5 mutants, 5 killed, 0 surviving, 0 uncovered.
1 parent 5e44ab0 commit e4b3151

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,30 @@ describe("ClineProvider", () => {
29522952
expect(mockWebviewPanel.webview.html).toBe(html)
29532953
})
29542954

2955+
test("tracks the tab view-state subscription in the same list the sidebar uses", async () => {
2956+
const viewStateDisposable = { dispose: vi.fn() }
2957+
vi.mocked(mockWebviewPanel.onDidChangeViewState).mockReturnValue(viewStateDisposable)
2958+
const messageDisposable = { dispose: vi.fn() }
2959+
vi.mocked(mockWebviewPanel.webview.onDidReceiveMessage).mockReturnValue(messageDisposable)
2960+
const focusDisposable = { dispose: vi.fn() }
2961+
provider.webviewFocusTracker.init = vi.fn().mockReturnValue(focusDisposable)
2962+
const configDisposable = { dispose: vi.fn() }
2963+
vi.mocked(vscode.workspace.onDidChangeConfiguration).mockReturnValue(configDisposable)
2964+
2965+
await provider.resolveWebviewView(mockWebviewPanel)
2966+
2967+
// The tab branch records its onDidChangeViewState subscription in the provider's one
2968+
// disposable list, like every other registration; there is no second per-surface bookkeeping
2969+
// left to keep it alive.
2970+
expect(provider["webviewDisposables"]).toContain(viewStateDisposable)
2971+
expect(viewStateDisposable.dispose).not.toHaveBeenCalled()
2972+
2973+
await provider.dispose()
2974+
2975+
expect(viewStateDisposable.dispose).toHaveBeenCalledOnce()
2976+
expect(provider["webviewDisposables"]).toEqual([])
2977+
})
2978+
29552979
test.each([false, true])(
29562980
"replaces the tab host without disposing its provider or task (interrupted: %s)",
29572981
async (interrupted) => {

0 commit comments

Comments
 (0)