@@ -216,7 +216,7 @@ describe("todo-continuation-enforcer", () => {
216216 expect ( promptCalls . length ) . toBe ( 1 )
217217 } )
218218
219- test ( "should cancel countdown on user message" , async ( ) => {
219+ test ( "should cancel countdown on user message after grace period " , async ( ) => {
220220 // #given - session starting countdown
221221 const sessionID = "main-cancel"
222222 setMainSession ( sessionID )
@@ -228,19 +228,46 @@ describe("todo-continuation-enforcer", () => {
228228 event : { type : "session.idle" , properties : { sessionID } } ,
229229 } )
230230
231- // #when - user sends message immediately (before 2s countdown)
231+ // #when - wait past grace period (500ms), then user sends message
232+ await new Promise ( r => setTimeout ( r , 600 ) )
232233 await hook . handler ( {
233234 event : {
234235 type : "message.updated" ,
235236 properties : { info : { sessionID, role : "user" } }
236237 } ,
237238 } )
238239
239- // #then - wait past countdown time and verify no injection
240+ // #then - wait past countdown time and verify no injection (countdown was cancelled)
240241 await new Promise ( r => setTimeout ( r , 2500 ) )
241242 expect ( promptCalls ) . toHaveLength ( 0 )
242243 } )
243244
245+ test ( "should ignore user message within grace period" , async ( ) => {
246+ // #given - session starting countdown
247+ const sessionID = "main-grace"
248+ setMainSession ( sessionID )
249+
250+ const hook = createTodoContinuationEnforcer ( createMockPluginInput ( ) , { } )
251+
252+ // #when - session goes idle
253+ await hook . handler ( {
254+ event : { type : "session.idle" , properties : { sessionID } } ,
255+ } )
256+
257+ // #when - user message arrives within grace period (immediately)
258+ await hook . handler ( {
259+ event : {
260+ type : "message.updated" ,
261+ properties : { info : { sessionID, role : "user" } }
262+ } ,
263+ } )
264+
265+ // #then - countdown should continue (message was ignored)
266+ // wait past 2s countdown and verify injection happens
267+ await new Promise ( r => setTimeout ( r , 2500 ) )
268+ expect ( promptCalls ) . toHaveLength ( 1 )
269+ } )
270+
244271 test ( "should cancel countdown on assistant activity" , async ( ) => {
245272 // #given - session starting countdown
246273 const sessionID = "main-assistant"
0 commit comments