@@ -1627,4 +1627,57 @@ describe("handoff arming (/handoff)", () => {
16271627 expect ( prompt ) . not . toContain ( "keep the UI audit" ) ;
16281628 expect ( prompt ) . not . toContain ( "Operator compact instructions" ) ;
16291629 } ) ;
1630+
1631+ test ( "empty trailing then cancel restores committed extras" , ( ) => {
1632+ const governor = createCompactionGovernor ( undefined ) ;
1633+ governor . syncFromTurns ( tenTurns ) ;
1634+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1635+ governor . interceptIdleContinuation (
1636+ pivot ( "keep the UI audit" ) ,
1637+ capabilities ,
1638+ ) ;
1639+ expect ( governor . requestHandoff ( " " ) ) . toBe ( "armed" ) ;
1640+ expect ( governor . extraInstructions ) . toBeUndefined ( ) ;
1641+ governor . cancelManual ( ) ;
1642+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1643+ } ) ;
1644+
1645+ test ( "noop then cancel after a restored idle fold has already fired does not re-arm idle" , ( ) => {
1646+ const governor = createCompactionGovernor ( undefined ) ;
1647+ governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
1648+ expect (
1649+ governor . noteIdleTurn ( inferenceDone ( overThreshold ) , [
1650+ { type : "reply" , content : "done" } ,
1651+ ] ) ,
1652+ ) . toBe ( true ) ;
1653+ expect ( governor . requestHandoff ( "now do the UI audit" ) ) . toBe ( "armed" ) ;
1654+ governor . cancelManual ( ) ;
1655+ expect (
1656+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1657+ ) . not . toBeNull ( ) ;
1658+ governor . syncFromTurns ( threeTurns ) ;
1659+ expect ( governor . requestHandoff ( "wipe this" ) ) . toBe ( "noop" ) ;
1660+ governor . cancelManual ( ) ;
1661+ expect (
1662+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1663+ ) . toBeNull ( ) ;
1664+ } ) ;
1665+
1666+ test ( "overflow then handoff does not double-fold" , ( ) => {
1667+ const governor = createCompactionGovernor ( undefined ) ;
1668+ governor . syncFromTurns ( tenTurns ) ;
1669+ expect ( governor . requestHandoff ( "now do the UI audit" ) ) . toBe ( "armed" ) ;
1670+ const overflow = governor . interceptOverflow ( overflowError ( ) , capabilities ) ;
1671+ expect ( overflow ) . not . toBeNull ( ) ;
1672+ expect ( overflow ?. find ( ( a ) => a . type === "compact" ) ) . toMatchObject ( {
1673+ reason : "context-overflow" ,
1674+ } ) ;
1675+ expect (
1676+ governor . interceptIdleContinuation (
1677+ pivot ( "now do the UI audit" ) ,
1678+ capabilities ,
1679+ ) ,
1680+ ) . toBeNull ( ) ;
1681+ expect ( governor . extraInstructions ) . toBe ( "now do the UI audit" ) ;
1682+ } ) ;
16301683} ) ;
0 commit comments