test(todo-continuation-enforcer): cover isContinuationStopped race during countdown
Adds a regression test for the race where /stop-continuation fires after handleSessionIdle passes the flag check but before injectContinuation runs. Verifies no injection occurs when the flag becomes true mid-countdown.
This commit is contained in:
@@ -1608,6 +1608,31 @@ describe("todo-continuation-enforcer", () => {
|
||||
expect(promptCalls).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("should not inject when isContinuationStopped becomes true during countdown", async () => {
|
||||
// given - session where continuation is not stopped at idle time but stops during countdown
|
||||
const sessionID = "main-race-condition"
|
||||
setMainSession(sessionID)
|
||||
let stopped = false
|
||||
|
||||
const hook = createTodoContinuationEnforcer(createMockPluginInput(), {
|
||||
isContinuationStopped: () => stopped,
|
||||
})
|
||||
|
||||
// when - session goes idle with continuation not yet stopped
|
||||
await hook.handler({
|
||||
event: { type: "session.idle", properties: { sessionID } },
|
||||
})
|
||||
|
||||
// when - stop-continuation fires during the 2s countdown window
|
||||
stopped = true
|
||||
|
||||
// when - countdown elapses and injectContinuation fires
|
||||
await fakeTimers.advanceBy(3000)
|
||||
|
||||
// then - no injection because isContinuationStopped became true before injectContinuation ran
|
||||
expect(promptCalls).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("should inject when isContinuationStopped returns false", async () => {
|
||||
fakeTimers.restore()
|
||||
// given - session with continuation not stopped
|
||||
|
||||
Reference in New Issue
Block a user