@@ -10,7 +10,12 @@ import {
1010 sessionStoreEntry ,
1111} from "./test/server-sessions.test-helpers.js" ;
1212
13- const { createSessionStoreDir, openClient } = setupGatewaySessionsTestHarness ( ) ;
13+ const {
14+ createConfiguredGlobalAgentSessionStore,
15+ createSessionStoreDir,
16+ openClient,
17+ resetConfiguredGlobalAgentSessionStore,
18+ } = setupGatewaySessionsTestHarness ( ) ;
1419
1520type MockCalls = {
1621 mock : { calls : unknown [ ] [ ] } ;
@@ -178,114 +183,6 @@ function expectMainPatchBroadcast(
178183 } ) ;
179184}
180185
181- async function setupGlobalAgentSessionStores ( {
182- writePrimeStore = false ,
183- withTranscripts = false ,
184- } : {
185- writePrimeStore ?: boolean ;
186- withTranscripts ?: boolean ;
187- } = { } ) {
188- const { dir } = await createSessionStoreDir ( ) ;
189- const storeTemplate = path . join ( dir , "{agentId}" , "sessions.json" ) ;
190- testState . sessionStorePath = storeTemplate ;
191- testState . sessionConfig = { scope : "global" } ;
192- if ( writePrimeStore ) {
193- await writeSessionStore ( {
194- entries : { } ,
195- storePath : path . join ( dir , "prime-sessions.json" ) ,
196- } ) ;
197- }
198-
199- const mainStorePath = storeTemplate . replace ( "{agentId}" , "main" ) ;
200- const workStorePath = storeTemplate . replace ( "{agentId}" , "work" ) ;
201- const mainTranscript = path . join ( path . dirname ( mainStorePath ) , "sess-main-global.jsonl" ) ;
202- const workTranscript = path . join ( path . dirname ( workStorePath ) , "sess-work-global.jsonl" ) ;
203- await fs . mkdir ( path . dirname ( mainStorePath ) , { recursive : true } ) ;
204- await fs . mkdir ( path . dirname ( workStorePath ) , { recursive : true } ) ;
205- if ( withTranscripts ) {
206- await fs . writeFile ( mainTranscript , "main one\nmain two\n" , "utf-8" ) ;
207- await fs . writeFile ( workTranscript , "work one\nwork two\n" , "utf-8" ) ;
208- }
209- await fs . writeFile (
210- mainStorePath ,
211- JSON . stringify (
212- {
213- global : sessionStoreEntry (
214- "sess-main-global" ,
215- withTranscripts ? { sessionFile : mainTranscript } : undefined ,
216- ) ,
217- } ,
218- null ,
219- 2 ,
220- ) ,
221- "utf-8" ,
222- ) ;
223- await fs . writeFile (
224- workStorePath ,
225- JSON . stringify (
226- {
227- global : sessionStoreEntry (
228- "sess-work-global" ,
229- withTranscripts
230- ? { authProfileOverride : "github-copilot:work" , sessionFile : workTranscript }
231- : undefined ,
232- ) ,
233- } ,
234- null ,
235- 2 ,
236- ) ,
237- "utf-8" ,
238- ) ;
239-
240- const configPath = process . env . OPENCLAW_CONFIG_PATH ;
241- if ( ! configPath ) {
242- throw new Error ( "OPENCLAW_CONFIG_PATH is required" ) ;
243- }
244- await fs . writeFile (
245- configPath ,
246- `${ JSON . stringify (
247- {
248- agents : { list : [ { id : "main" , default : true } , { id : "work" } ] } ,
249- session : { scope : "global" , store : storeTemplate } ,
250- } ,
251- null ,
252- 2 ,
253- ) } \n`,
254- "utf-8" ,
255- ) ;
256- const { clearConfigCache, clearRuntimeConfigSnapshot, getRuntimeConfig } =
257- await getGatewayConfigModule ( ) ;
258- clearRuntimeConfigSnapshot ( ) ;
259- clearConfigCache ( ) ;
260-
261- return {
262- clearConfigCache,
263- clearRuntimeConfigSnapshot,
264- configPath,
265- getRuntimeConfig,
266- mainStorePath,
267- mainTranscript,
268- workStorePath,
269- workTranscript,
270- } ;
271- }
272-
273- async function resetGlobalAgentSessionStores ( {
274- clearConfigCache,
275- clearRuntimeConfigSnapshot,
276- configPath,
277- } : {
278- clearConfigCache : ( ) => void ;
279- clearRuntimeConfigSnapshot : ( ) => void ;
280- configPath : string ;
281- } ) {
282- testState . sessionStorePath = undefined ;
283- testState . sessionConfig = undefined ;
284- await fs . writeFile ( configPath , "{}\n" , "utf-8" ) ;
285- clearRuntimeConfigSnapshot ( ) ;
286- clearConfigCache ( ) ;
287- }
288-
289186async function invokeSessionsCompact ( {
290187 getRuntimeConfig,
291188 params,
@@ -629,7 +526,7 @@ test("sessions.changed mutation events include sendPolicy metadata", async () =>
629526} ) ;
630527
631528test ( "sessions.patch scopes selected global mutations and events to the requested agent" , async ( ) => {
632- const globalStores = await setupGlobalAgentSessionStores ( { writePrimeStore : true } ) ;
529+ const globalStores = await createConfiguredGlobalAgentSessionStore ( { writePrimeStore : true } ) ;
633530
634531 const { broadcastToConnIds, responsePayload } = await invokeSessionsPatch ( {
635532 key : "global" ,
@@ -652,11 +549,11 @@ test("sessions.patch scopes selected global mutations and events to the requeste
652549 } ;
653550 expect ( mainStore . global ?. label ) . toBeUndefined ( ) ;
654551 expect ( workStore . global ?. label ) . toBe ( "Work global" ) ;
655- await resetGlobalAgentSessionStores ( globalStores ) ;
552+ await resetConfiguredGlobalAgentSessionStore ( globalStores ) ;
656553} ) ;
657554
658555test ( "sessions.compact scopes selected global truncation to the requested agent" , async ( ) => {
659- const globalStores = await setupGlobalAgentSessionStores ( { withTranscripts : true } ) ;
556+ const globalStores = await createConfiguredGlobalAgentSessionStore ( { withTranscripts : true } ) ;
660557 const { broadcastToConnIds, responsePayload } = await invokeSessionsCompact ( {
661558 getRuntimeConfig : globalStores . getRuntimeConfig ,
662559 params : {
@@ -677,11 +574,11 @@ test("sessions.compact scopes selected global truncation to the requested agent"
677574 "main one\nmain two\n" ,
678575 ) ;
679576 await expect ( fs . readFile ( globalStores . workTranscript , "utf-8" ) ) . resolves . toBe ( "work two\n" ) ;
680- await resetGlobalAgentSessionStores ( globalStores ) ;
577+ await resetConfiguredGlobalAgentSessionStore ( globalStores ) ;
681578} ) ;
682579
683580test ( "sessions.compact passes the selected global agent into embedded compaction" , async ( ) => {
684- const globalStores = await setupGlobalAgentSessionStores ( { withTranscripts : true } ) ;
581+ const globalStores = await createConfiguredGlobalAgentSessionStore ( { withTranscripts : true } ) ;
685582 const { responsePayload } = await invokeSessionsCompact ( {
686583 getRuntimeConfig : globalStores . getRuntimeConfig ,
687584 params : {
@@ -699,7 +596,7 @@ test("sessions.compact passes the selected global agent into embedded compaction
699596 agentId : "work" ,
700597 authProfileId : "github-copilot:work" ,
701598 } ) ;
702- await resetGlobalAgentSessionStores ( globalStores ) ;
599+ await resetConfiguredGlobalAgentSessionStore ( globalStores ) ;
703600} ) ;
704601
705602test ( "sessions.changed mutation events include subagent ownership metadata" , async ( ) => {
0 commit comments