@@ -27,7 +27,6 @@ import {
2727 deliveryContextFromSession ,
2828 sessionDeliveryRoute ,
2929} from "../../utils/delivery-context.shared.js" ;
30- import { readSessionArchiveContentSync } from "./archive-compression.js" ;
3130import {
3231 applySessionEntryReplacements ,
3332 applySessionPatchProjections ,
@@ -2815,17 +2814,6 @@ describe("session accessor seam", () => {
28152814
28162815 unsubscribe ( ) ;
28172816 expect ( result ) . toMatchObject ( { compacted : true , kept : 3 } ) ;
2818- const archived = result . compacted ? result . archived : "" ;
2819- expect ( path . basename ( archived ) ) . toMatch (
2820- new RegExp ( `^${ sessionId } \\.jsonl\\.bak\\.\\d{4}-\\d{2}-\\d{2}T` ) ,
2821- ) ;
2822- expect ( fs . realpathSync ( path . dirname ( archived ) ) ) . toBe ( fs . realpathSync ( tempDir ) ) ;
2823- expect ( fs . existsSync ( archived ) ) . toBe ( true ) ;
2824- const archivedRecords = readSessionArchiveContentSync ( archived )
2825- . split ( "\n" )
2826- . filter ( ( line ) => line . length > 0 )
2827- . map ( ( line ) => JSON . parse ( line ) as Record < string , unknown > ) ;
2828- expect ( archivedRecords ) . toEqual ( transcriptRecords ) ;
28292817 const trimmedRecords = ( await loadTranscriptEvents ( scope ) ) as Array < Record < string , unknown > > ;
28302818 expect ( trimmedRecords ) . toMatchObject ( [
28312819 { type : "session" , id : sessionId } ,
@@ -2845,27 +2833,6 @@ describe("session accessor seam", () => {
28452833 expect ( updates ) . toEqual ( [ ] ) ;
28462834 } ) ;
28472835
2848- it ( "keeps every transcript row when the manual compact backup cannot be written" , async ( ) => {
2849- const sessionId = "44444444-4444-4444-8444-444444444444" ;
2850- const stateDir = path . join ( tempDir , "state-root" ) ;
2851- const scope = {
2852- agentId : "main" ,
2853- env : { ...process . env , OPENCLAW_STATE_DIR : stateDir } ,
2854- sessionId,
2855- sessionKey : "agent:main:main" ,
2856- } ;
2857- const records = createManualCompactRecords ( sessionId ) ;
2858- await upsertSessionEntryCore ( scope , { sessionId, updatedAt : 1 } ) ;
2859- await replaceTranscriptEvents ( scope , records as Parameters < typeof replaceTranscriptEvents > [ 1 ] ) ;
2860- const archiveDirPath = path . join ( stateDir , "agents" , "main" , "sessions" ) ;
2861- fs . writeFileSync ( archiveDirPath , "not a directory" ) ;
2862-
2863- await expect ( trimSessionTranscriptForManualCompact ( scope , { maxLines : 3 } ) ) . rejects . toThrow ( ) ;
2864-
2865- expect ( ( await loadTranscriptEvents ( scope ) ) . length ) . toBe ( 5 ) ;
2866- expect ( await loadTranscriptEvents ( scope ) ) . toEqual ( records ) ;
2867- } ) ;
2868-
28692836 it ( "keeps no-op manual compaction tolerant of a missing current session entry" , async ( ) => {
28702837 await expect (
28712838 trimTranscriptForManualCompact (
@@ -2921,49 +2888,29 @@ describe("session accessor seam", () => {
29212888
29222889 expect ( await loadTranscriptEvents ( scope ) ) . toEqual ( records ) ;
29232890 expect ( loadSessionEntry ( scope ) ) . toEqual ( entryBeforeCompact ) ;
2924- const archiveNames = fs . readdirSync ( tempDir ) . filter ( ( name ) => name . includes ( ".bak." ) ) ;
2925- expect ( archiveNames ) . toHaveLength ( 1 ) ;
2926- expect (
2927- readSessionArchiveContentSync (
2928- path . join ( tempDir , expectDefined ( archiveNames [ 0 ] , "manual compact archive name" ) ) ,
2929- ) ,
2930- ) . toBe ( `${ records . map ( ( record ) => JSON . stringify ( record ) ) . join ( "\n" ) } \n` ) ;
29312891 } ) ;
29322892
29332893 it . each ( [
29342894 {
29352895 name : "rejects a manual compact when session metadata changes after its snapshot" ,
29362896 sessionId : "88888888-8888-4888-8888-888888888888" ,
29372897 conflict : "metadata" ,
2938- reuseArchive : false ,
29392898 } ,
29402899 {
2941- name : "preserves the backup and rows written after the manual compact snapshot" ,
2900+ name : "preserves rows written after the manual compact snapshot" ,
29422901 sessionId : "55555555-5555-4555-8555-555555555555" ,
29432902 conflict : "transcript" ,
2944- reuseArchive : false ,
2945- } ,
2946- {
2947- name : "preserves a reused manual compact backup when the rewrite conflicts" ,
2948- sessionId : "66666666-6666-4666-8666-666666666666" ,
2949- conflict : "transcript" ,
2950- reuseArchive : true ,
29512903 } ,
2952- ] as const ) ( "$name" , async ( { sessionId, conflict, reuseArchive } ) => {
2904+ ] as const ) ( "$name" , async ( { sessionId, conflict } ) => {
29532905 const scope = { agentId : "main" , sessionId, sessionKey : "agent:main:main" , storePath } ;
29542906 const records = createManualCompactRecords ( sessionId ) ;
2955- const archiveContent = `${ records . map ( ( record ) => JSON . stringify ( record ) ) . join ( "\n" ) } \n` ;
29562907 await upsertSessionEntryCore (
29572908 scope ,
29582909 conflict === "metadata"
29592910 ? { sessionId, totalTokens : 30 , totalTokensFresh : true , updatedAt : 100 }
29602911 : { sessionId, updatedAt : 1 } ,
29612912 ) ;
29622913 await replaceTranscriptEvents ( scope , records as Parameters < typeof replaceTranscriptEvents > [ 1 ] ) ;
2963- const existingArchive = path . join ( tempDir , `${ sessionId } .jsonl.bak.preexisting` ) ;
2964- if ( reuseArchive ) {
2965- fs . writeFileSync ( existingArchive , archiveContent ) ;
2966- }
29672914
29682915 const expectedError =
29692916 conflict === "metadata"
@@ -3008,18 +2955,6 @@ describe("session accessor seam", () => {
30082955 expect ( remaining . slice ( 0 , 5 ) ) . toEqual ( records ) ;
30092956 expect ( remaining [ 5 ] ) . toMatchObject ( { id : "late-append" } ) ;
30102957 }
3011- if ( reuseArchive ) {
3012- expect ( fs . existsSync ( existingArchive ) ) . toBe ( true ) ;
3013- expect ( readSessionArchiveContentSync ( existingArchive ) ) . toBe ( archiveContent ) ;
3014- } else {
3015- const archiveNames = fs . readdirSync ( tempDir ) . filter ( ( name ) => name . includes ( ".bak." ) ) ;
3016- expect ( archiveNames ) . toHaveLength ( 1 ) ;
3017- expect (
3018- readSessionArchiveContentSync (
3019- path . join ( tempDir , expectDefined ( archiveNames [ 0 ] , "manual compact archive name" ) ) ,
3020- ) ,
3021- ) . toBe ( archiveContent ) ;
3022- }
30232958 } ) ;
30242959
30252960 it ( "repairs a retained compaction boundary when its first kept entry was trimmed" , async ( ) => {
0 commit comments