@@ -1527,4 +1527,104 @@ describe("handoff arming (/handoff)", () => {
15271527 reason : "context-threshold" ,
15281528 } ) ;
15291529 } ) ;
1530+
1531+ test ( "cancelManual after an idle fold keeps extras and does not re-arm" , ( ) => {
1532+ const governor = createCompactionGovernor ( undefined ) ;
1533+ governor . syncFromTurns ( tenTurns ) ;
1534+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1535+ expect (
1536+ governor . interceptIdleContinuation (
1537+ pivot ( "keep the UI audit" ) ,
1538+ capabilities ,
1539+ ) ,
1540+ ) . not . toBeNull ( ) ;
1541+ governor . cancelManual ( ) ;
1542+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1543+ expect (
1544+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1545+ ) . toBeNull ( ) ;
1546+ } ) ;
1547+
1548+ test ( "cancelManual after a tool-pause fold keeps extras and does not re-arm" , ( ) => {
1549+ const governor = createCompactionGovernor ( undefined ) ;
1550+ governor . syncFromTurns ( tenTurns ) ;
1551+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1552+ expect (
1553+ governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
1554+ ) . not . toBeNull ( ) ;
1555+ governor . cancelManual ( ) ;
1556+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1557+ expect (
1558+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1559+ ) . toBeNull ( ) ;
1560+ } ) ;
1561+
1562+ test ( "cancelManual after a fired idle fold does not restore a second idle compact" , ( ) => {
1563+ const governor = createCompactionGovernor ( undefined ) ;
1564+ governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
1565+ expect (
1566+ governor . noteIdleTurn ( inferenceDone ( overThreshold ) , [
1567+ { type : "reply" , content : "done" } ,
1568+ ] ) ,
1569+ ) . toBe ( true ) ;
1570+ expect ( governor . requestHandoff ( "now do the UI audit" ) ) . toBe ( "armed" ) ;
1571+ expect (
1572+ governor . interceptIdleContinuation (
1573+ pivot ( "now do the UI audit" ) ,
1574+ capabilities ,
1575+ ) ,
1576+ ) . not . toBeNull ( ) ;
1577+ governor . cancelManual ( ) ;
1578+ expect (
1579+ governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
1580+ ) . toBeNull ( ) ;
1581+ } ) ;
1582+
1583+ test ( "noop then cancelManual does not wipe extras from a prior fold" , ( ) => {
1584+ const governor = createCompactionGovernor ( undefined ) ;
1585+ governor . syncFromTurns ( tenTurns ) ;
1586+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1587+ governor . interceptIdleContinuation (
1588+ pivot ( "keep the UI audit" ) ,
1589+ capabilities ,
1590+ ) ;
1591+ governor . syncFromTurns ( threeTurns ) ;
1592+ expect ( governor . requestHandoff ( "wipe this" ) ) . toBe ( "noop" ) ;
1593+ governor . cancelManual ( ) ;
1594+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1595+ } ) ;
1596+
1597+ test ( "double requestHandoff then cancel restores committed extras, not the first uncommitted" , ( ) => {
1598+ const governor = createCompactionGovernor ( undefined ) ;
1599+ governor . syncFromTurns ( tenTurns ) ;
1600+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1601+ governor . interceptIdleContinuation (
1602+ pivot ( "keep the UI audit" ) ,
1603+ capabilities ,
1604+ ) ;
1605+ expect ( governor . requestHandoff ( "first uncommitted" ) ) . toBe ( "armed" ) ;
1606+ expect ( governor . requestHandoff ( "second uncommitted" ) ) . toBe ( "armed" ) ;
1607+ governor . cancelManual ( ) ;
1608+ expect ( governor . extraInstructions ) . toBe ( "keep the UI audit" ) ;
1609+ } ) ;
1610+
1611+ test ( "empty trailing after a successful fold uses the default structured summary" , ( ) => {
1612+ const governor = createCompactionGovernor ( undefined ) ;
1613+ governor . syncFromTurns ( tenTurns ) ;
1614+ expect ( governor . requestHandoff ( "keep the UI audit" ) ) . toBe ( "armed" ) ;
1615+ governor . interceptIdleContinuation (
1616+ pivot ( "keep the UI audit" ) ,
1617+ capabilities ,
1618+ ) ;
1619+ expect ( governor . requestHandoff ( " " ) ) . toBe ( "armed" ) ;
1620+ expect ( governor . extraInstructions ) . toBeUndefined ( ) ;
1621+ const prompt = buildSummaryPrompt (
1622+ tenTurns ,
1623+ governor . extraInstructions !== undefined
1624+ ? { extraInstructions : governor . extraInstructions }
1625+ : undefined ,
1626+ ) ;
1627+ expect ( prompt ) . not . toContain ( "keep the UI audit" ) ;
1628+ expect ( prompt ) . not . toContain ( "Operator compact instructions" ) ;
1629+ } ) ;
15301630} ) ;
0 commit comments