Skip to content

Commit 0c4fc13

Browse files
test(api): pin the abort-bridge listener identity in the cleanup assertion
The initialization-abort test only counted removeEventListener calls. Spy on addEventListener too and assert the removed listener is the exact callback the bridge registered, so a wrong-listener cleanup cannot pass.
1 parent fcb0461 commit 0c4fc13

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/api/providers/__tests__/vscode-lm.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,7 @@ describe("VsCodeLmHandler", () => {
25562556
handler["client"] = null
25572557

25582558
const controller = new AbortController()
2559+
const addEventListenerSpy = vi.spyOn(controller.signal, "addEventListener")
25592560
const removeEventListenerSpy = vi.spyOn(controller.signal, "removeEventListener")
25602561
const meta = makeCreateMessageMetadata({ abortSignal: controller.signal })
25612562
const stream = handler.createMessage(systemPrompt, messages, meta)
@@ -2584,6 +2585,13 @@ describe("VsCodeLmHandler", () => {
25842585
// initialization window.
25852586
expect(tokenSourceInstance().cancel).toHaveBeenCalled()
25862587
expect(removeEventListenerSpy).toHaveBeenCalledTimes(1)
2588+
2589+
// The cleanup must detach the exact callback the bridge registered: a
2590+
// wrong listener identity would leave the bridge attached to a dead
2591+
// request and leak it into later ones.
2592+
const abortRegistrations = addEventListenerSpy.mock.calls.filter(([event]) => event === "abort")
2593+
expect(abortRegistrations).toHaveLength(1)
2594+
expect(removeEventListenerSpy).toHaveBeenCalledWith("abort", abortRegistrations[0][1])
25872595
})
25882596

25892597
it("should bridge a mid-flight external abort to the request cancellation token", async () => {

0 commit comments

Comments
 (0)