@@ -195,3 +195,88 @@ it("clears named plugin runtime slots between files", async () => {
195195 await fs . rm ( root , { recursive : true , force : true } ) ;
196196 }
197197} ) ;
198+
199+ it ( "clears session suspension state between files" , async ( ) => {
200+ const root = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-session-suspension-runner-" ) ) ;
201+ try {
202+ const write = ( name : string , content : string ) =>
203+ fs . writeFile ( path . join ( root , name ) , content , "utf-8" ) ;
204+ const sessionSuspensionPath = JSON . stringify (
205+ path . join ( repoRoot , "src" , "agents" , "session-suspension.ts" ) ,
206+ ) ;
207+ const sessionSuspensionTestSupportPath = JSON . stringify (
208+ path . join ( repoRoot , "src" , "agents" , "session-suspension.test-support.ts" ) ,
209+ ) ;
210+ const sharedVitestConfigPath = JSON . stringify (
211+ path . join ( repoRoot , "test" , "vitest" , "vitest.shared.config.ts" ) ,
212+ ) ;
213+ await fs . symlink (
214+ path . join ( repoRoot , "node_modules" ) ,
215+ path . join ( root , "node_modules" ) ,
216+ "junction" ,
217+ ) ;
218+ await write (
219+ "a-seed.test.ts" ,
220+ [
221+ `import { getSuspendedLaneIdsForGatewayPublication } from ${ sessionSuspensionPath } ;` ,
222+ `import { seedClearedLaneResumeForTest } from ${ sessionSuspensionTestSupportPath } ;` ,
223+ 'import { expect, it } from "vitest";' ,
224+ 'const laneId = "plugin:test:session-suspension";' ,
225+ 'it("seeds real process-global suspension state", () => {' ,
226+ " seedClearedLaneResumeForTest(laneId, {" ,
227+ " resumeConcurrency: 1," ,
228+ " resumeAtMs: Date.now() + 10_000," ,
229+ " });" ,
230+ " expect(getSuspendedLaneIdsForGatewayPublication()).toContain(laneId);" ,
231+ "});" ,
232+ "" ,
233+ ] . join ( "\n" ) ,
234+ ) ;
235+ await write (
236+ "b-observe.test.ts" ,
237+ [
238+ `import { getSuspendedLaneIdsForGatewayPublication } from ${ sessionSuspensionPath } ;` ,
239+ 'import { expect, it } from "vitest";' ,
240+ 'it("starts without real suspension state from the previous file", () => {' ,
241+ " expect(getSuspendedLaneIdsForGatewayPublication()).toEqual(new Set());" ,
242+ "});" ,
243+ "" ,
244+ ] . join ( "\n" ) ,
245+ ) ;
246+ await write (
247+ "vitest.config.ts" ,
248+ [
249+ `import { sharedVitestConfig } from ${ sharedVitestConfigPath } ;` ,
250+ 'import { defineConfig } from "vitest/config";' ,
251+ 'import { BaseSequencer } from "vitest/node";' ,
252+ "class AlphabeticalSequencer extends BaseSequencer {" ,
253+ ' override async sort(files: Parameters<BaseSequencer["sort"]>[0]) {' ,
254+ " return [...files].sort((a, b) => a.moduleId.localeCompare(b.moduleId));" ,
255+ " }" ,
256+ "}" ,
257+ "export default defineConfig({" ,
258+ ` cacheDir: ${ JSON . stringify ( path . join ( root , ".vite" ) ) } ,` ,
259+ " resolve: sharedVitestConfig.resolve," ,
260+ " test: {" ,
261+ " isolate: false," ,
262+ " fileParallelism: false," ,
263+ " maxWorkers: 1," ,
264+ " sequence: { sequencer: AlphabeticalSequencer }," ,
265+ ` runner: ${ JSON . stringify ( path . join ( repoRoot , "test" , "non-isolated-runner.ts" ) ) } ,` ,
266+ " }," ,
267+ "});" ,
268+ "" ,
269+ ] . join ( "\n" ) ,
270+ ) ;
271+
272+ const vitestEntry = path . join ( repoRoot , "node_modules" , "vitest" , "vitest.mjs" ) ;
273+ const result = await execFileAsync (
274+ process . execPath ,
275+ [ vitestEntry , "run" , "--root" , root , "--config" , path . join ( root , "vitest.config.ts" ) ] ,
276+ { cwd : repoRoot , env : childEnv ( ) , maxBuffer : 16 * 1024 * 1024 } ,
277+ ) ;
278+ expect ( `${ result . stdout } \n${ result . stderr } ` ) . toContain ( "2 passed" ) ;
279+ } finally {
280+ await fs . rm ( root , { recursive : true , force : true } ) ;
281+ }
282+ } ) ;
0 commit comments