@@ -902,4 +902,35 @@ describe("handoff arming (/handoff)", () => {
902902 ) ,
903903 ) . toBeNull ( ) ;
904904 } ) ;
905+
906+ test ( "cancelManual clears sticky extraInstructions from a failed pivot" , ( ) => {
907+ const governor = createCompactionGovernor ( undefined ) ;
908+ governor . syncFromTurns ( tenTurns ) ;
909+ expect ( governor . requestHandoff ( "now do the UI audit" ) ) . toBe ( "armed" ) ;
910+ governor . cancelManual ( ) ;
911+ expect ( governor . extraInstructions ) . toBeUndefined ( ) ;
912+ } ) ;
913+
914+ test ( "threshold pending survives cancelManual so a tool pause still folds" , ( ) => {
915+ const governor = createCompactionGovernor ( undefined ) ;
916+ governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
917+ expect (
918+ governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
919+ ) . not . toBeNull ( ) ;
920+
921+ const cancelled = createCompactionGovernor ( undefined ) ;
922+ cancelled . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
923+ expect ( cancelled . requestHandoff ( "now do the UI audit" ) ) . toBe ( "armed" ) ;
924+ cancelled . cancelManual ( ) ;
925+ const actions = cancelled . interceptActions (
926+ toolDone ( ) ,
927+ inferAction ,
928+ capabilities ,
929+ ) ;
930+ expect ( actions ) . not . toBeNull ( ) ;
931+ expect ( actions ?. some ( ( a ) => a . type === "compact" ) ) . toBe ( true ) ;
932+ expect ( actions ?. find ( ( a ) => a . type === "compact" ) ) . toMatchObject ( {
933+ reason : "context-threshold" ,
934+ } ) ;
935+ } ) ;
905936} ) ;
0 commit comments