@@ -82,7 +82,6 @@ const {
8282 formatToolFailuresSection,
8383 splitPreservedRecentTurns,
8484 formatPreservedTurnsSection,
85- formatSplitTurnContextSection,
8685 buildCompactionStructureInstructions,
8786 buildStructuredFallbackSummary,
8887 prependPreviousSummaryForRedistill,
@@ -105,7 +104,6 @@ const {
105104 SUMMARY_TRUNCATED_MARKER ,
106105 CONTEXT_TRUNCATED_MARKER ,
107106 MAX_SPLIT_TURN_CONTEXT_CHARS ,
108- SPLIT_TURN_TRUNCATED_MARKER ,
109107} = testing ;
110108
111109function auditSummaryQuality (
@@ -498,43 +496,6 @@ describe("compaction-safeguard tool failures", () => {
498496} ) ;
499497
500498describe ( "compaction-safeguard summary budgets" , ( ) => {
501- it . each ( [
502- { bodyLength : 60 , suffixLength : 0 , maxChars : 100 , overflows : false } ,
503- { bodyLength : 60 , suffixLength : 40 , maxChars : 100 , overflows : false } ,
504- { bodyLength : 80 , suffixLength : 10 , maxChars : 100 , overflows : false } ,
505- { bodyLength : 80 , suffixLength : 21 , maxChars : 100 , overflows : true } ,
506- { bodyLength : 20 , suffixLength : 100 , maxChars : 100 , overflows : true } ,
507- ] ) (
508- "uses the slack-aware body allocation at body=$bodyLength suffix=$suffixLength cap=$maxChars" ,
509- ( { bodyLength, suffixLength, maxChars, overflows } ) => {
510- const body = "b" . repeat ( bodyLength ) ;
511- const suffix = "s" . repeat ( suffixLength ) ;
512-
513- const capped = capCompactionSummaryPreservingSuffix ( body , suffix , maxChars ) ;
514-
515- expect ( capped . length ) . toBeLessThanOrEqual ( maxChars ) ;
516- if ( ! overflows ) {
517- expect ( capped ) . toBe ( `${ body } ${ suffix } ` ) ;
518- return ;
519- }
520- const bodyFloor = Math . min ( bodyLength , Math . max ( 1 , Math . ceil ( maxChars / 2 ) ) ) ;
521- const bodySlot = Math . min (
522- bodyLength ,
523- Math . max ( bodyFloor , maxChars - Math . min ( suffixLength , maxChars ) ) ,
524- ) ;
525- if ( bodyLength > bodySlot && bodySlot >= SUMMARY_TRUNCATED_MARKER . length ) {
526- expect ( capped ) . toContain ( SUMMARY_TRUNCATED_MARKER ) ;
527- }
528- if ( suffixLength > maxChars - Math . min ( bodyLength , bodySlot ) ) {
529- expect ( capped ) . toContain (
530- maxChars - Math . min ( bodyLength , bodySlot ) > CONTEXT_TRUNCATED_MARKER . length
531- ? CONTEXT_TRUNCATED_MARKER
532- : "s" ,
533- ) ;
534- }
535- } ,
536- ) ;
537-
538499 it ( "caps file operations summary and reports omitted entries" , ( ) => {
539500 const readFiles = Array . from (
540501 { length : 200 } ,
@@ -655,40 +616,6 @@ describe("compaction-safeguard summary budgets", () => {
655616 expect ( capped ) . toContain ( "<read-files>" ) ;
656617 expect ( capped ) . toContain ( "## Session Startup" ) ;
657618 } ) ;
658-
659- it ( "keeps generated summary content when an oversized suffix exhausts the artifact budget" , ( ) => {
660- const body = "BODY-START\nBODY-MIDDLE\nBODY-END" ;
661- const oversizedSuffix = `${ "old context\n" . repeat ( MAX_COMPACTION_SUMMARY_CHARS ) } CRITICAL-TAIL` ;
662-
663- const capped = capCompactionSummaryPreservingSuffix ( body , oversizedSuffix ) ;
664-
665- expect ( capped . length ) . toBeLessThanOrEqual ( MAX_COMPACTION_SUMMARY_CHARS ) ;
666- expect ( capped ) . toContain ( "BODY-START" ) ;
667- expect ( capped ) . toContain ( "BODY-MIDDLE" ) ;
668- expect ( capped ) . toContain ( "BODY-END" ) ;
669- expect ( capped ) . toContain ( "CRITICAL-TAIL" ) ;
670- expect ( capped ) . toContain ( "truncated" ) ;
671- } ) ;
672-
673- it ( "keeps an oversized preserved suffix UTF-16 safe at its leading edge" , ( ) => {
674- expect ( capCompactionSummaryPreservingSuffix ( "body" , "A🚀tail" , 5 ) ) . toBe ( "bodil" ) ;
675- } ) ;
676-
677- it ( "bounds raw split-turn context on whole-message boundaries and retains the newest end" , ( ) => {
678- const messages = Array . from ( { length : 20 } , ( _ , index ) => ( {
679- role : "user" as const ,
680- content : `message-${ String ( index ) . padStart ( 2 , "0" ) } -${ "x" . repeat ( 700 ) } ` ,
681- timestamp : index ,
682- } ) ) ;
683-
684- const section = formatSplitTurnContextSection ( messages ) as string ;
685-
686- expect ( section . length ) . toBeLessThanOrEqual ( MAX_SPLIT_TURN_CONTEXT_CHARS ) ;
687- expect ( section ) . toContain ( SPLIT_TURN_TRUNCATED_MARKER . trim ( ) ) ;
688- expect ( section ) . not . toContain ( "message-00-" ) ;
689- expect ( section ) . toContain ( "message-19-" ) ;
690- expect ( section . split ( "\n" ) . some ( ( line ) => line . startsWith ( "x" ) ) ) . toBe ( false ) ;
691- } ) ;
692619} ) ;
693620
694621describe ( "computeAdaptiveChunkRatio" , ( ) => {
@@ -3123,6 +3050,7 @@ describe("compaction-safeguard recent-turn preservation", () => {
31233050 const retainedSuffix = summary . split ( CONTEXT_TRUNCATED_MARKER ) [ 1 ] ?? "" ;
31243051 const firstRetainedLine = retainedSuffix . split ( "\n" ) . find ( ( line ) => line . length > 0 ) ;
31253052 expect ( firstRetainedLine ) . toMatch ( / ^ - U s e r : r a w - p r e f i x - \d { 2 } - / ) ;
3053+ expect ( summary ) . toContain ( "raw-prefix-19-" ) ;
31263054 expect ( summary . length ) . toBeLessThanOrEqual ( MAX_COMPACTION_SUMMARY_CHARS ) ;
31273055 expect ( summary ) . toContain ( "## Recent turns preserved verbatim" ) ;
31283056 } ) ;
0 commit comments