@@ -997,4 +997,104 @@ describe("handoff arming (/handoff)", () => {
997997 reason : "context-threshold" ,
998998 } ) ;
999999 } ) ;
1000+
1001+ test ( "cancelManual after an idle fold keeps extras and does not re-arm" , ( ) => {
1002+ const governor = createCompactionGovernor ( undefined ) ;
1003+ governor . syncFromTurns ( tenTurns ) ;
1004+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1005+ expect (
1006+ governor . interceptIdleContinuation (
1007+ pivot ( "keep the UI audit" ) ,
1008+ capabilities ,
1009+ ) ,
1010+ ) . not . toBeNull ( ) ;
1011+ governor . cancelManual ( ) ;
1012+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1013+ expect (
1014+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1015+ ) . toBeNull ( ) ;
1016+ } ) ;
1017+
1018+ test ( "cancelManual after a tool-pause fold keeps extras and does not re-arm" , ( ) => {
1019+ const governor = createCompactionGovernor ( undefined ) ;
1020+ governor . syncFromTurns ( tenTurns ) ;
1021+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1022+ expect (
1023+ governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
1024+ ) . not . toBeNull ( ) ;
1025+ governor . cancelManual ( ) ;
1026+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1027+ expect (
1028+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1029+ ) . toBeNull ( ) ;
1030+ } ) ;
1031+
1032+ test ( "cancelManual after a fired idle fold does not restore a second idle compact" , ( ) => {
1033+ const governor = createCompactionGovernor ( undefined ) ;
1034+ governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
1035+ expect (
1036+ governor . noteIdleTurn ( inferenceDone ( overThreshold ) , [
1037+ { type : "reply" , content : "done" } ,
1038+ ] ) ,
1039+ ) . toBe ( true ) ;
1040+ expect ( governor . requestHandoff ( "now do the UI audit" ) ) . toBe ( "armed" ) ;
1041+ expect (
1042+ governor . interceptIdleContinuation (
1043+ pivot ( "now do the UI audit" ) ,
1044+ capabilities ,
1045+ ) ,
1046+ ) . not . toBeNull ( ) ;
1047+ governor . cancelManual ( ) ;
1048+ expect (
1049+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1050+ ) . toBeNull ( ) ;
1051+ } ) ;
1052+
1053+ test ( "noop then cancelManual does not wipe extras from a prior fold" , ( ) => {
1054+ const governor = createCompactionGovernor ( undefined ) ;
1055+ governor . syncFromTurns ( tenTurns ) ;
1056+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1057+ governor . interceptIdleContinuation (
1058+ pivot ( "keep the UI audit" ) ,
1059+ capabilities ,
1060+ ) ;
1061+ governor . syncFromTurns ( threeTurns ) ;
1062+ expect ( governor . requestHandoff ( "wipe this" ) ) . toBe ( "noop" ) ;
1063+ governor . cancelManual ( ) ;
1064+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1065+ } ) ;
1066+
1067+ test ( "double requestHandoff then cancel restores committed extras, not the first uncommitted" , ( ) => {
1068+ const governor = createCompactionGovernor ( undefined ) ;
1069+ governor . syncFromTurns ( tenTurns ) ;
1070+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1071+ governor . interceptIdleContinuation (
1072+ pivot ( "keep the UI audit" ) ,
1073+ capabilities ,
1074+ ) ;
1075+ expect ( governor . requestHandoff ( "first uncommitted" ) ) . toBe ( "armed" ) ;
1076+ expect ( governor . requestHandoff ( "second uncommitted" ) ) . toBe ( "armed" ) ;
1077+ governor . cancelManual ( ) ;
1078+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1079+ } ) ;
1080+
1081+ test ( "empty trailing after a successful fold uses the default structured summary" , ( ) => {
1082+ const governor = createCompactionGovernor ( undefined ) ;
1083+ governor . syncFromTurns ( tenTurns ) ;
1084+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1085+ governor . interceptIdleContinuation (
1086+ pivot ( "keep the UI audit" ) ,
1087+ capabilities ,
1088+ ) ;
1089+ expect ( governor . requestHandoff ( " " ) ) . toBe ( "armed" ) ;
1090+ expect ( governor . extraInstructions ) . toBeUndefined ( ) ;
1091+ const prompt = buildSummaryPrompt (
1092+ tenTurns ,
1093+ governor . extraInstructions !== undefined
1094+ ? { extraInstructions : governor . extraInstructions }
1095+ : undefined ,
1096+ ) ;
1097+ expect ( prompt ) . not . toContain ( "keep the UI audit" ) ;
1098+ expect ( prompt ) . not . toContain ( "Operator compact instructions" ) ;
1099+ } ) ;
10001100} ) ;
0 commit comments