@@ -564,65 +564,13 @@ describe("session.compaction.create", () => {
564564describe ( "session.compaction.prune" , ( ) => {
565565 it . live (
566566 "compacts old completed tool output" ,
567- provideTmpdirInstance ( ( dir ) =>
568- Effect . gen ( function * ( ) {
569- const compact = yield * SessionCompaction . Service
570- const ssn = yield * SessionNs . Service
571- const info = yield * ssn . create ( { } )
572- const a = yield * ssn . updateMessage ( {
573- id : MessageID . ascending ( ) ,
574- role : "user" ,
575- sessionID : info . id ,
576- agent : "build" ,
577- model : ref ,
578- time : { created : Date . now ( ) } ,
579- } )
580- yield * ssn . updatePart ( {
581- id : PartID . ascending ( ) ,
582- messageID : a . id ,
583- sessionID : info . id ,
584- type : "text" ,
585- text : "first" ,
586- } )
587- const b : MessageV2 . Assistant = {
588- id : MessageID . ascending ( ) ,
589- role : "assistant" ,
590- sessionID : info . id ,
591- mode : "build" ,
592- agent : "build" ,
593- path : { cwd : dir , root : dir } ,
594- cost : 0 ,
595- tokens : {
596- output : 0 ,
597- input : 0 ,
598- reasoning : 0 ,
599- cache : { read : 0 , write : 0 } ,
600- } ,
601- modelID : ref . modelID ,
602- providerID : ref . providerID ,
603- parentID : a . id ,
604- time : { created : Date . now ( ) } ,
605- finish : "end_turn" ,
606- }
607- yield * ssn . updateMessage ( b )
608- yield * ssn . updatePart ( {
609- id : PartID . ascending ( ) ,
610- messageID : b . id ,
611- sessionID : info . id ,
612- type : "tool" ,
613- callID : crypto . randomUUID ( ) ,
614- tool : "bash" ,
615- state : {
616- status : "completed" ,
617- input : { } ,
618- output : "x" . repeat ( 200_000 ) ,
619- title : "done" ,
620- metadata : { } ,
621- time : { start : Date . now ( ) , end : Date . now ( ) } ,
622- } ,
623- } )
624- for ( const text of [ "second" , "third" ] ) {
625- const msg = yield * ssn . updateMessage ( {
567+ provideTmpdirInstance (
568+ ( dir ) =>
569+ Effect . gen ( function * ( ) {
570+ const compact = yield * SessionCompaction . Service
571+ const ssn = yield * SessionNs . Service
572+ const info = yield * ssn . create ( { } )
573+ const a = yield * ssn . updateMessage ( {
626574 id : MessageID . ascending ( ) ,
627575 role : "user" ,
628576 sessionID : info . id ,
@@ -632,23 +580,82 @@ describe("session.compaction.prune", () => {
632580 } )
633581 yield * ssn . updatePart ( {
634582 id : PartID . ascending ( ) ,
635- messageID : msg . id ,
583+ messageID : a . id ,
636584 sessionID : info . id ,
637585 type : "text" ,
638- text,
586+ text : "first" ,
639587 } )
640- }
588+ const b : MessageV2 . Assistant = {
589+ id : MessageID . ascending ( ) ,
590+ role : "assistant" ,
591+ sessionID : info . id ,
592+ mode : "build" ,
593+ agent : "build" ,
594+ path : { cwd : dir , root : dir } ,
595+ cost : 0 ,
596+ tokens : {
597+ output : 0 ,
598+ input : 0 ,
599+ reasoning : 0 ,
600+ cache : { read : 0 , write : 0 } ,
601+ } ,
602+ modelID : ref . modelID ,
603+ providerID : ref . providerID ,
604+ parentID : a . id ,
605+ time : { created : Date . now ( ) } ,
606+ finish : "end_turn" ,
607+ }
608+ yield * ssn . updateMessage ( b )
609+ yield * ssn . updatePart ( {
610+ id : PartID . ascending ( ) ,
611+ messageID : b . id ,
612+ sessionID : info . id ,
613+ type : "tool" ,
614+ callID : crypto . randomUUID ( ) ,
615+ tool : "bash" ,
616+ state : {
617+ status : "completed" ,
618+ input : { } ,
619+ output : "x" . repeat ( 200_000 ) ,
620+ title : "done" ,
621+ metadata : { } ,
622+ time : { start : Date . now ( ) , end : Date . now ( ) } ,
623+ } ,
624+ } )
625+ for ( const text of [ "second" , "third" ] ) {
626+ const msg = yield * ssn . updateMessage ( {
627+ id : MessageID . ascending ( ) ,
628+ role : "user" ,
629+ sessionID : info . id ,
630+ agent : "build" ,
631+ model : ref ,
632+ time : { created : Date . now ( ) } ,
633+ } )
634+ yield * ssn . updatePart ( {
635+ id : PartID . ascending ( ) ,
636+ messageID : msg . id ,
637+ sessionID : info . id ,
638+ type : "text" ,
639+ text,
640+ } )
641+ }
641642
642- yield * compact . prune ( { sessionID : info . id } )
643+ yield * compact . prune ( { sessionID : info . id } )
643644
644- const msgs = yield * ssn . messages ( { sessionID : info . id } )
645- const part = msgs . flatMap ( ( msg ) => msg . parts ) . find ( ( part ) => part . type === "tool" )
646- expect ( part ?. type ) . toBe ( "tool" )
647- expect ( part ?. state . status ) . toBe ( "completed" )
648- if ( part ?. type === "tool" && part . state . status === "completed" ) {
649- expect ( part . state . time . compacted ) . toBeNumber ( )
650- }
651- } ) ,
645+ const msgs = yield * ssn . messages ( { sessionID : info . id } )
646+ const part = msgs . flatMap ( ( msg ) => msg . parts ) . find ( ( part ) => part . type === "tool" )
647+ expect ( part ?. type ) . toBe ( "tool" )
648+ expect ( part ?. state . status ) . toBe ( "completed" )
649+ if ( part ?. type === "tool" && part . state . status === "completed" ) {
650+ expect ( part . state . time . compacted ) . toBeNumber ( )
651+ }
652+ } ) ,
653+
654+ {
655+ config : {
656+ compaction : { prune : true } ,
657+ } ,
658+ } ,
652659 ) ,
653660 )
654661
0 commit comments