@@ -1326,7 +1326,11 @@ describe("compactEmbeddedPiSession hooks (ownsCompaction engine)", () => {
13261326 } ) ;
13271327 } ) ;
13281328
1329- it ( "rotates the active transcript after harness compaction without a delegated successor" , async ( ) => {
1329+ it ( "rotates the active transcript after harness compaction without a delegated successor and emits side effects" , async ( ) => {
1330+ const listener = vi . fn ( ) ;
1331+ const cleanup = onSessionTranscriptUpdate ( listener ) ;
1332+ const sync = vi . fn ( async ( ) => { } ) ;
1333+ getMemorySearchManagerMock . mockResolvedValue ( { manager : { sync } } ) ;
13301334 maybeCompactAgentHarnessSessionMock . mockResolvedValueOnce ( {
13311335 ok : true ,
13321336 compacted : true ,
@@ -1344,31 +1348,46 @@ describe("compactEmbeddedPiSession hooks (ownsCompaction engine)", () => {
13441348 leafId : "leaf-1" ,
13451349 } ) ;
13461350
1347- const result = await compactEmbeddedPiSession (
1348- wrappedCompactionArgs ( {
1349- currentTokenCount : 333 ,
1350- config : {
1351- agents : {
1352- defaults : {
1353- compaction : {
1354- truncateAfterCompaction : true ,
1351+ try {
1352+ const result = await compactEmbeddedPiSession (
1353+ wrappedCompactionArgs ( {
1354+ currentTokenCount : 333 ,
1355+ config : {
1356+ agents : {
1357+ defaults : {
1358+ compaction : {
1359+ truncateAfterCompaction : true ,
1360+ postIndexSync : "await" ,
1361+ } ,
13551362 } ,
13561363 } ,
1357- } ,
1358- } ,
1359- } ) ,
1360- ) ;
1364+ } as never ,
1365+ } ) ,
1366+ ) ;
13611367
1362- expect ( result . ok ) . toBe ( true ) ;
1363- expect ( result . compacted ) . toBe ( true ) ;
1364- expect ( rotateTranscriptFileAfterCompactionMock ) . toHaveBeenCalledWith ( {
1365- sessionFile : TEST_SESSION_FILE ,
1366- synthesizeMissingBoundary : true ,
1367- } ) ;
1368- expect ( result . result ?. sessionId ) . toBe ( "rotated-session" ) ;
1369- expect ( result . result ?. sessionFile ) . toBe ( "/tmp/rotated-session.jsonl" ) ;
1370- expect ( result . result ?. tokensBefore ) . toBe ( 333 ) ;
1371- expect ( result . result ?. details ) . toEqual ( { backend : "codex-app-server" } ) ;
1368+ expect ( result . ok ) . toBe ( true ) ;
1369+ expect ( result . compacted ) . toBe ( true ) ;
1370+ expect ( rotateTranscriptFileAfterCompactionMock ) . toHaveBeenCalledWith ( {
1371+ sessionFile : TEST_SESSION_FILE ,
1372+ synthesizeMissingBoundary : true ,
1373+ } ) ;
1374+ expect ( result . result ?. sessionId ) . toBe ( "rotated-session" ) ;
1375+ expect ( result . result ?. sessionFile ) . toBe ( "/tmp/rotated-session.jsonl" ) ;
1376+ expect ( result . result ?. tokensBefore ) . toBe ( 333 ) ;
1377+ expect ( result . result ?. details ) . toEqual ( { backend : "codex-app-server" } ) ;
1378+ expect ( listener ) . toHaveBeenCalledTimes ( 1 ) ;
1379+ expect ( listener ) . toHaveBeenCalledWith ( {
1380+ sessionFile : "/tmp/rotated-session.jsonl" ,
1381+ sessionKey : TEST_SESSION_KEY ,
1382+ } ) ;
1383+ expect ( sync ) . toHaveBeenCalledTimes ( 1 ) ;
1384+ expect ( sync ) . toHaveBeenCalledWith ( {
1385+ reason : "post-compaction" ,
1386+ sessionFiles : [ "/tmp/rotated-session.jsonl" ] ,
1387+ } ) ;
1388+ } finally {
1389+ cleanup ( ) ;
1390+ }
13721391 } ) ;
13731392
13741393 it ( "does not fire after_compaction when compaction fails" , async ( ) => {
0 commit comments