@@ -3,9 +3,19 @@ import os from "node:os";
33import path from "node:path" ;
44import { afterEach , describe , expect , it } from "vitest" ;
55import { SessionManager } from "../../agents/sessions/session-manager.js" ;
6- import { closeOpenClawAgentDatabasesForTest } from "../../state/openclaw-agent-db.js" ;
6+ import {
7+ closeOpenClawAgentDatabasesForTest ,
8+ resolveIncognitoOpenClawAgentSqlitePath ,
9+ } from "../../state/openclaw-agent-db.js" ;
710import { resolveStorePath } from "./paths.js" ;
8- import { createSessionEntryWithTranscript , loadSessionEntry } from "./session-accessor.js" ;
11+ import {
12+ createSessionEntryWithTranscript ,
13+ listSessionEntries ,
14+ loadSessionEntry ,
15+ loadTranscriptEvents ,
16+ patchSessionEntry ,
17+ } from "./session-accessor.js" ;
18+ import { replaceSqliteTranscriptEvents } from "./session-accessor.sqlite.js" ;
919
1020const sessionKey = "agent:main:dashboard:incognito-round-trip" ;
1121
@@ -81,4 +91,83 @@ describe("incognito transcript access", () => {
8191 fs . rmSync ( cwd , { force : true , recursive : true } ) ;
8292 }
8393 } ) ;
94+
95+ it ( "prunes incognito transcripts in process without publishing a disk archive" , async ( ) => {
96+ const stateDir = fs . realpathSync (
97+ fs . mkdtempSync ( path . join ( fs . realpathSync ( os . tmpdir ( ) ) , "incognito-maintenance-" ) ) ,
98+ ) ;
99+ const env = { ...process . env , OPENCLAW_STATE_DIR : stateDir } ;
100+ const storePath = resolveIncognitoOpenClawAgentSqlitePath ( { agentId : "main" , env } ) ;
101+ const archiveDirectory = path . join ( path . dirname ( path . dirname ( storePath ) ) , "sessions" ) ;
102+ const staleScope = {
103+ agentId : "main" ,
104+ env,
105+ sessionKey : "agent:main:dashboard:incognito-stale" ,
106+ storePath,
107+ } ;
108+ const activeScope = {
109+ agentId : "main" ,
110+ env,
111+ sessionKey : "agent:main:dashboard:incognito-active" ,
112+ storePath,
113+ } ;
114+ const now = Date . now ( ) ;
115+
116+ try {
117+ await patchSessionEntry (
118+ staleScope ,
119+ ( ) => ( { sessionId : "incognito-stale-session" , updatedAt : now } ) ,
120+ {
121+ fallbackEntry : { sessionId : "incognito-stale-session" , updatedAt : now } ,
122+ replaceEntry : true ,
123+ skipMaintenance : true ,
124+ } ,
125+ ) ;
126+ await replaceSqliteTranscriptEvents ( { ...staleScope , sessionId : "incognito-stale-session" } , [
127+ {
128+ id : "incognito-stale-event" ,
129+ timestamp : new Date ( now ) . toISOString ( ) ,
130+ type : "metadata" ,
131+ } ,
132+ ] ) ;
133+ await patchSessionEntry (
134+ activeScope ,
135+ ( ) => ( { sessionId : "incognito-active-session" , updatedAt : now + 1 } ) ,
136+ {
137+ fallbackEntry : { sessionId : "incognito-active-session" , updatedAt : now + 1 } ,
138+ replaceEntry : true ,
139+ skipMaintenance : true ,
140+ } ,
141+ ) ;
142+
143+ await patchSessionEntry ( activeScope , ( ) => ( { model : "gpt-test" } ) , {
144+ maintenanceConfig : {
145+ highWaterBytes : null ,
146+ maxDiskBytes : null ,
147+ maxEntries : 1 ,
148+ mode : "enforce" ,
149+ modelRunPruneAfterMs : 24 * 60 * 60 * 1000 ,
150+ pruneAfterMs : 365 * 24 * 60 * 60 * 1000 ,
151+ resetArchiveRetentionMs : null ,
152+ } ,
153+ } ) ;
154+
155+ expect (
156+ listSessionEntries ( { agentId : "main" , env, storePath } ) . map (
157+ ( summary ) => summary . sessionKey ,
158+ ) ,
159+ ) . toEqual ( [ activeScope . sessionKey ] ) ;
160+ await expect (
161+ loadTranscriptEvents ( {
162+ ...staleScope ,
163+ sessionId : "incognito-stale-session" ,
164+ } ) ,
165+ ) . resolves . toEqual ( [ ] ) ;
166+ expect ( fs . existsSync ( storePath ) ) . toBe ( false ) ;
167+ expect ( fs . existsSync ( archiveDirectory ) ) . toBe ( false ) ;
168+ } finally {
169+ closeOpenClawAgentDatabasesForTest ( ) ;
170+ fs . rmSync ( stateDir , { force : true , recursive : true } ) ;
171+ }
172+ } ) ;
84173} ) ;
0 commit comments