@@ -8410,6 +8410,9 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
84108410 "early-reset" ,
84118411 "early-reset-snooze-only" ,
84128412 "early-reset-manual-snooze" ,
8413+ "early-reset-then-snooze" ,
8414+ "early-reset-then-cancel" ,
8415+ "early-reset-then-stop" ,
84138416 ] as const ) ( "guards a scheduled usage-limit continuation against %s" , ( scenario ) =>
84148417 Effect . gen ( function * ( ) {
84158418 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
@@ -8637,13 +8640,12 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
86378640 } ) ;
86388641 if ( snooze )
86398642 assert . equal ( DateTime . toEpochMillis ( armedShell . snoozedUntil ! ) , Date . parse ( resetAt ) ) ;
8640- if (
8641- scenario === "early-reset" ||
8642- scenario === "early-reset-snooze-only" ||
8643- scenario === "early-reset-manual-snooze"
8644- ) {
8643+ if ( scenario . startsWith ( "early-reset" ) ) {
86458644 const manualWakeAt = DateTime . add ( now , { seconds : 30 } ) ;
8646- if ( scenario === "early-reset-manual-snooze" )
8645+ // Until a snooze the user set ends, the early reset is recorded and nothing continues.
8646+ const manualSnooze =
8647+ scenario === "early-reset-manual-snooze" || scenario . startsWith ( "early-reset-then" ) ;
8648+ if ( manualSnooze )
86478649 yield * orchestrator . dispatch ( {
86488650 type : "thread.snooze" ,
86498651 commandId : CommandId . make ( `recovery:manual-snooze:${ scenario } ` ) ,
@@ -8687,9 +8689,11 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
86878689 resetBefore : DateTime . add ( DateTime . makeUnsafe ( resetAt ) , { seconds : 1 } ) ,
86888690 } ) ;
86898691 const reset = ( yield * orchestrator . getThreadProjection ( threadId ) ) . thread ;
8690- assert . deepInclude ( reset . limitRecovery , { autoResume, snooze : false , resetEarly : true } ) ;
8692+ assert . deepInclude ( reset . limitRecovery , { autoResume, snooze : false } ) ;
8693+ // Without a scheduled continuation there is nothing to bring forward.
8694+ assert . equal ( reset . limitRecovery ?. resetEarly , autoResume ? true : undefined ) ;
86918695 // The reset ends the snooze the recovery set, never one the user chose.
8692- if ( scenario === "early-reset-manual-snooze" )
8696+ if ( manualSnooze )
86938697 assert . equal (
86948698 DateTime . toEpochMillis ( reset . snoozedUntil ! ) ,
86958699 DateTime . toEpochMillis ( manualWakeAt ) ,
@@ -8707,17 +8711,39 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
87078711 ? null
87088712 : limitRecoveryCommand ( candidate , false , DateTime . toEpochMillis ( sweptAt ) ) ;
87098713 } ) ;
8710- if ( scenario !== "early-reset" ) {
8711- assert . isNull ( yield * sweep ) ;
8712- if ( scenario === "early-reset-manual-snooze" ) yield * TestClock . adjust ( "30 seconds" ) ;
8713- else
8714+ const choose = (
8715+ choice : string ,
8716+ limitRecovery : { autoResume ?: boolean ; snooze ?: boolean } ,
8717+ ) =>
8718+ orchestrator . dispatch ( {
8719+ type : "thread.metadata.update" ,
8720+ commandId : CommandId . make ( `recovery:${ choice } :${ scenario } ` ) ,
8721+ threadId,
8722+ limitRecovery : { runId : run . id , resetAt, ...limitRecovery } ,
8723+ } ) ;
8724+ if ( scenario !== "early-reset" ) assert . isNull ( yield * sweep ) ;
8725+ if ( scenario !== "early-reset" && scenario !== "early-reset-manual-snooze" ) {
8726+ // A choice made after the reset goes by the reset time the thread still shows.
8727+ if ( scenario === "early-reset-then-snooze" ) yield * choose ( "snooze" , { snooze : true } ) ;
8728+ if ( scenario === "early-reset-then-cancel" )
8729+ yield * choose ( "cancel" , { autoResume : false } ) ;
8730+ if ( scenario === "early-reset-then-stop" )
87148731 yield * orchestrator . dispatch ( {
8715- type : "thread.metadata.update " ,
8716- commandId : CommandId . make ( `recovery:resume-after-reset :${ scenario } ` ) ,
8732+ type : "thread.stop " ,
8733+ commandId : CommandId . make ( `recovery:stop :${ scenario } ` ) ,
87178734 threadId,
8718- limitRecovery : { runId : run . id , resetAt, autoResume : true } ,
87198735 } ) ;
8736+ if ( scenario !== "early-reset-then-snooze" ) yield * choose ( "resume" , { autoResume : true } ) ;
8737+ const chosen = ( yield * orchestrator . getThreadProjection ( threadId ) ) . thread ;
8738+ assert . deepInclude ( chosen . limitRecovery , { autoResume : true } ) ;
8739+ assert . isUndefined ( chosen . limitRecovery ?. resetEarly ) ;
8740+ if ( scenario === "early-reset-then-snooze" )
8741+ assert . equal ( DateTime . toEpochMillis ( chosen . snoozedUntil ! ) , Date . parse ( resetAt ) ) ;
8742+ yield * TestClock . adjust ( "30 seconds" ) ;
8743+ assert . isNull ( yield * sweep ) ;
8744+ return ;
87208745 }
8746+ if ( manualSnooze ) yield * TestClock . adjust ( "30 seconds" ) ;
87218747 const resume = yield * sweep ;
87228748 assert ( resume ?. type === "message.dispatch" ) ;
87238749 assert . isBelow ( DateTime . toEpochMillis ( yield * DateTime . now ) , Date . parse ( resetAt ) ) ;
0 commit comments