@@ -368,65 +368,110 @@ func TestCompact2_Off_NoOp(t *testing.T) {
368368 c := NewCompactor (stubSummarizerCM ("LLM" ))
369369 msgs := []session.Message {{Role : "system" , Content : "sys" }, {Role : "user" , Content : "u1" }, {Role : "assistant" , Content : "a1" }}
370370 r , _ := c .Compact2 (context .Background (), CompactInput {Messages : msgs , Mode : ContextCompactionOff , MaxTokens : 100 })
371- if len (r .Kept ) != len (msgs ) { t .Errorf ("off no-op; got %d want %d" , len (r .Kept ), len (msgs )) }
371+ if len (r .Kept ) != len (msgs ) {
372+ t .Errorf ("off no-op; got %d want %d" , len (r .Kept ), len (msgs ))
373+ }
372374}
373375
374376func TestCompact2_Deterministic_EvidencePreserved (t * testing.T ) {
375377 c := NewCompactor (stubSummarizerCM ("LLM" ))
376378 c .Configure (CompactorConfig {Mode : ContextCompactionDeterministic , Trigger : CompactionTriggerTokens , Threshold : 0.8 , MaxTokens : 8000 , PreserveEvidence : true , RecentTurns : 4 })
377379 msgs := make ([]session.Message , 30 )
378- for i := range msgs { msgs [i ] = session.Message {Role : "user" , Content : "noise" }; if i % 2 == 1 { msgs [i ].Role = "assistant" } }
380+ for i := range msgs {
381+ msgs [i ] = session.Message {Role : "user" , Content : "noise" }
382+ if i % 2 == 1 {
383+ msgs [i ].Role = "assistant"
384+ }
385+ }
379386 msgs [0 ] = session.Message {Role : "system" , Content : "SYSTEM" }
380387 msgs [15 ] = session.Message {Role : "assistant" , Content : "VERIFY: VERIFICATION PASSED" }
381388 r , _ := c .Compact2 (context .Background (), CompactInput {Messages : msgs , Mode : ContextCompactionDeterministic , MaxTokens : 8000 })
382- if len (r .Kept ) >= len (msgs ) { t .Errorf ("deterministic reduce; got %d from %d" , len (r .Kept ), len (msgs )) }
383- found := false ; for _ , m := range r .Kept { if m .Content == "VERIFY: VERIFICATION PASSED" { found = true } }
384- if ! found { t .Error ("missing VERIFICATION PASSED" ) }
385- if r .Summary != "" { t .Errorf ("deterministic summary non-empty: %q" , r .Summary ) }
389+ if len (r .Kept ) >= len (msgs ) {
390+ t .Errorf ("deterministic reduce; got %d from %d" , len (r .Kept ), len (msgs ))
391+ }
392+ found := false
393+ for _ , m := range r .Kept {
394+ if m .Content == "VERIFY: VERIFICATION PASSED" {
395+ found = true
396+ }
397+ }
398+ if ! found {
399+ t .Error ("missing VERIFICATION PASSED" )
400+ }
401+ if r .Summary != "" {
402+ t .Errorf ("deterministic summary non-empty: %q" , r .Summary )
403+ }
386404}
387405
388406func TestCompact2_LLM_SingleSummary (t * testing.T ) {
389407 c := NewCompactor (stubSummarizerCM ("LLM-SUMMARY" ))
390408 c .Configure (CompactorConfig {Mode : ContextCompactionLLM , MaxTokens : 8000 , PreserveEvidence : true , RecentTurns : 4 })
391409 msgs := []session.Message {{Role : "system" , Content : "S" }, {Role : "user" , Content : "g" }, {Role : "assistant" , Content : "p" }}
392410 r , _ := c .Compact2 (context .Background (), CompactInput {Messages : msgs , Mode : ContextCompactionLLM , MaxTokens : 8000 })
393- if len (r .Kept ) != 1 || r .Kept [0 ].Role != "system" { t .Error ("llm single system message expected" ) }
394- if ! strings .Contains (r .Summary , "LLM-SUMMARY" ) { t .Errorf ("summary missing tag: %q" , r .Summary ) }
395- if ! r .Mode .IsLossy () { t .Error ("llm should be lossy" ) }
411+ if len (r .Kept ) != 1 || r .Kept [0 ].Role != "system" {
412+ t .Error ("llm single system message expected" )
413+ }
414+ if ! strings .Contains (r .Summary , "LLM-SUMMARY" ) {
415+ t .Errorf ("summary missing tag: %q" , r .Summary )
416+ }
417+ if ! r .Mode .IsLossy () {
418+ t .Error ("llm should be lossy" )
419+ }
396420}
397421
398422func TestCompact2_Hybrid_EvidencePlusSummary (t * testing.T ) {
399423 c := NewCompactor (stubSummarizerCM ("LLM-HYBRID" ))
400424 c .Configure (CompactorConfig {Mode : ContextCompactionHybrid , RecentTurns : 2 , PreserveEvidence : true , MaxTokens : 8000 })
401425 msgs := make ([]session.Message , 20 )
402- for i := range msgs { msgs [i ] = session.Message {Role : "user" , Content : "m" + strconv .Itoa (i )}; if i % 2 == 1 { msgs [i ].Role = "assistant" } }
426+ for i := range msgs {
427+ msgs [i ] = session.Message {Role : "user" , Content : "m" + strconv .Itoa (i )}
428+ if i % 2 == 1 {
429+ msgs [i ].Role = "assistant"
430+ }
431+ }
403432 msgs [0 ].Role = "system"
404433 msgs [15 ].Content = "VERIFICATION PASSED"
405434 r , _ := c .Compact2 (context .Background (), CompactInput {Messages : msgs , Mode : ContextCompactionHybrid , MaxTokens : 8000 })
406- if ! strings .Contains (r .Summary , "LLM-HYBRID" ) { t .Errorf ("hybrid summary missing tag: %q" , r .Summary ) }
407- if len (r .Kept ) == 0 || r .Kept [0 ].Role != "system" { t .Error ("hybrid Kept[0] should be system" ) }
435+ if ! strings .Contains (r .Summary , "LLM-HYBRID" ) {
436+ t .Errorf ("hybrid summary missing tag: %q" , r .Summary )
437+ }
438+ if len (r .Kept ) == 0 || r .Kept [0 ].Role != "system" {
439+ t .Error ("hybrid Kept[0] should be system" )
440+ }
408441}
409442
410443func TestCompact2_LegacyStrategy_Unchanged (t * testing.T ) {
411444 c := NewCompactor (stubSummarizerCM ("LLM" ))
412445 msgs := makeTestMessages (20 )
413446 r , _ := c .Compact2 (context .Background (), CompactInput {Messages : msgs , Strategy : CompactionTruncate , MaxTokens : 3000 })
414- if len (r .Kept ) >= len (msgs ) { t .Error ("legacy truncate should reduce" ) }
447+ if len (r .Kept ) >= len (msgs ) {
448+ t .Error ("legacy truncate should reduce" )
449+ }
415450}
416451
417452func TestCompact2_ByteStableDeterministic (t * testing.T ) {
418453 cfg := CompactorConfig {Mode : ContextCompactionDeterministic , RecentTurns : 4 , PreserveEvidence : true , MaxTokens : 8000 }
419454 msgs := []session.Message {{Role : "system" , Content : "S" }, {Role : "user" , Content : "U1" }, {Role : "assistant" , Content : "A1" }, {Role : "tool" , Content : "T1" , ToolCallID : "tc1" }, {Role : "assistant" , Content : "VERIFICATION PASSED" }}
420- c1 := NewCompactor (stubSummarizerCM ("FIXED" )); c1 .Configure (cfg )
421- c2 := NewCompactor (stubSummarizerCM ("FIXED" )); c2 .Configure (cfg )
455+ c1 := NewCompactor (stubSummarizerCM ("FIXED" ))
456+ c1 .Configure (cfg )
457+ c2 := NewCompactor (stubSummarizerCM ("FIXED" ))
458+ c2 .Configure (cfg )
422459 r1 , _ := c1 .Compact2 (context .Background (), CompactInput {Messages : msgs , Mode : cfg .Mode , MaxTokens : cfg .MaxTokens })
423460 r2 , _ := c2 .Compact2 (context .Background (), CompactInput {Messages : msgs , Mode : cfg .Mode , MaxTokens : cfg .MaxTokens })
424- if len (r1 .Kept ) != len (r2 .Kept ) { t .Errorf ("byte-stable r1=%d r2=%d" , len (r1 .Kept ), len (r2 .Kept )) }
425- for i := range r1 .Kept { if r1 .Kept [i ].Role != r2 .Kept [i ].Role || r1 .Kept [i ].Content != r2 .Kept [i ].Content { t .Errorf ("Kept[%d] differs" , i ) } }
461+ if len (r1 .Kept ) != len (r2 .Kept ) {
462+ t .Errorf ("byte-stable r1=%d r2=%d" , len (r1 .Kept ), len (r2 .Kept ))
463+ }
464+ for i := range r1 .Kept {
465+ if r1 .Kept [i ].Role != r2 .Kept [i ].Role || r1 .Kept [i ].Content != r2 .Kept [i ].Content {
466+ t .Errorf ("Kept[%d] differs" , i )
467+ }
468+ }
426469}
427470
428471func TestIdentifyEvidence_FindsMarkers (t * testing.T ) {
429472 msgs := []session.Message {{Role : "system" , Content : "s" }, {Role : "user" , Content : "u" }, {Role : "assistant" , Content : "VERIFICATION PASSED" }, {Role : "user" , Content : "m" }, {Role : "assistant" , Content : "Open acceptance criteria: yes" }}
430473 idx := evidenceIndices (msgs )
431- if len (idx ) != 2 { t .Errorf ("evidenceIndices size: got %d want 2 (idx=%v)" , len (idx ), idx ) }
474+ if len (idx ) != 2 {
475+ t .Errorf ("evidenceIndices size: got %d want 2 (idx=%v)" , len (idx ), idx )
476+ }
432477}
0 commit comments