Skip to content

Commit 7a1a710

Browse files
test(tools): name the abort listener the cancelled-stream release must drop
The getState() cancellation case asserted that task.off() was called with expect.any(Function). A function-shaped matcher cannot fail: it passes when the release deregisters a different callback, and it passes when the listener was never registered at all, which is the half of the contract this case exists for. The state the case seeds is also the state the listener is attached to, so the reference is available - capture it, pin the registration before the release, and assert the release against the same value. Measured with git grep -n -e expect.any(Function) over src at this head: 57 occurrences in 27 files, one of them on an off() call (this line) and none on a once() call; at the merge base 37 occurrences in 18 files. The matcher is common in this tree, the listener-removal shape was not, so this settles the row rather than generalising it. Gates (node v22.23.4): vitest.core.config.ts writeToFileTool-partial-state-cleanup.spec.ts 10 passed. Negative control with task.once(RooCodeEventName.TaskAborted, state.abortCleanup) deleted from WriteToFileTool.ts (git show HEAD of the file, written back and compared byte-for-byte): 4 failed | 6 passed - this case fails on both halves of the pairing, which the class matcher passed silently.
1 parent 7dd3077 commit 7a1a710

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/core/tools/__tests__/writeToFileTool-partial-state-cleanup.spec.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,19 @@ describe("WriteToFileTool partial-delta cancellation", () => {
226226
// suppressed-focus branch release the state and return on its own, which proves nothing
227227
// about the check under test.)
228228
task.diffViewProvider.editType = undefined
229-
seedStablePath(task as unknown as Task)
229+
// The release assertion below needs the listener identity, not a function-shaped matcher.
230+
// Seeding through the call the case already makes is enough: it returns the per-task state
231+
// the abort listener is attached to, so no extra registration is invented here.
232+
const state = seedStablePath(task as unknown as Task)
233+
const releasedAbortCleanup = state.abortCleanup
234+
// The registration side of the pairing, asserted before the release. This is the only
235+
// listener-removal assertion in the tree that used a class matcher (measured with
236+
// git grep -n -e expect.any(Function) over src: 57 occurrences in 27 files, one of them on
237+
// an off() call, and zero on a once() call). The class version passes when nothing was ever
238+
// registered, which is the half of the contract this case exists for: the per-task state
239+
// binds its abortCleanup callback, handlePartial registers that reference through task.once,
240+
// and this early-exit path has to deregister the same one.
241+
expect(task.once).toHaveBeenCalledWith(RooCodeEventName.TaskAborted, releasedAbortCleanup)
230242
task.providerRef.deref = () => ({
231243
getState: async () => {
232244
task.abort = true
@@ -238,7 +250,7 @@ describe("WriteToFileTool partial-delta cancellation", () => {
238250

239251
expect(vi.mocked(fileExistsAtPath)).not.toHaveBeenCalled()
240252
expect(writeToFileTool["taskPartialStreamState"].size).toBe(0)
241-
expect(task.off).toHaveBeenCalledWith(RooCodeEventName.TaskAborted, expect.any(Function))
253+
expect(task.off).toHaveBeenCalledWith(RooCodeEventName.TaskAborted, releasedAbortCleanup)
242254
expect(task.ask).not.toHaveBeenCalled()
243255
})
244256

0 commit comments

Comments
 (0)