@@ -6,20 +6,19 @@ import path from "node:path";
66import type { Readable } from "node:stream" ;
77import { setTimeout as delay } from "node:timers/promises" ;
88import { afterEach , describe , expect , it } from "vitest" ;
9- import { cleanupTempDirs , makeTempDir } from "../helpers/temp-dir.js" ;
9+ import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js" ;
1010
11- const SCRIPT_PATH = "scripts/e2e/lib/clawhub-fixture-server.cjs" ;
11+ const SCRIPT_PATH = path . resolve ( "scripts/e2e/lib/clawhub-fixture-server.cjs" ) ;
1212const PACKAGE_NAME = "@openclaw/kitchen-sink" ;
1313const PACKAGE_PATH = `/api/v1/packages/${ encodeURIComponent ( PACKAGE_NAME ) } ` ;
1414const KITCHEN_SINK_VERSION = "0.2.5" ;
15- const tempDirs : string [ ] = [ ] ;
1615type FixtureServerChild = ChildProcessByStdio < null , Readable , Readable > ;
1716const servers : FixtureServerChild [ ] = [ ] ;
1817
1918afterEach ( async ( ) => {
2019 await Promise . all ( servers . splice ( 0 ) . map ( stopServer ) ) ;
21- cleanupTempDirs ( tempDirs ) ;
2220} ) ;
21+ const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
2322
2423function collectStream ( stream : NodeJS . ReadableStream ) {
2524 let text = "" ;
@@ -45,11 +44,11 @@ async function stopServer(child: FixtureServerChild) {
4544 }
4645}
4746
48- async function startFixtureServer ( profile : string , args : string [ ] = [ ] ) {
49- const root = makeTempDir ( tempDirs , "openclaw-clawhub-fixture-server-" ) ;
47+ async function startFixtureServer ( profile : string , args : string [ ] = [ ] , cwd = process . cwd ( ) ) {
48+ const root = tempDirs . make ( "openclaw-clawhub-fixture-server-" ) ;
5049 const portFile = path . join ( root , "port" ) ;
5150 const child = spawn ( process . execPath , [ SCRIPT_PATH , profile , portFile , ...args ] , {
52- cwd : process . cwd ( ) ,
51+ cwd,
5352 env : { ...process . env } ,
5453 stdio : [ "ignore" , "pipe" , "pipe" ] ,
5554 } ) ;
@@ -80,11 +79,16 @@ async function fetchJson(baseUrl: string, requestPath: string) {
8079 return response . json ( ) ;
8180}
8281
83- function runPrepublishAssertion ( baseUrl ?: string , packageName ?: string , version ?: string ) {
82+ function runPrepublishAssertion (
83+ baseUrl ?: string ,
84+ packageName ?: string ,
85+ version ?: string ,
86+ cwd = process . cwd ( ) ,
87+ ) {
8488 return spawnSync (
8589 process . execPath ,
8690 [ SCRIPT_PATH , "assert-prepublish-requests" , baseUrl ?? "" , packageName ?? "" , version ?? "" ] ,
87- { cwd : process . cwd ( ) , encoding : "utf8" , env : { ...process . env } } ,
91+ { cwd, encoding : "utf8" , env : { ...process . env } } ,
8892 ) ;
8993}
9094
@@ -141,7 +145,8 @@ describe("ClawHub fixture server", () => {
141145 } ) ;
142146
143147 it ( "serves exact prepublish tarballs through the ClawHub artifact contract" , async ( ) => {
144- const root = makeTempDir ( tempDirs , "openclaw-clawhub-prepublish-" ) ;
148+ const root = tempDirs . make ( "openclaw-clawhub-prepublish-" ) ;
149+ const isolatedCwd = tempDirs . make ( "openclaw-clawhub-isolated-" ) ;
145150 const packageDir = path . join ( root , "package" ) ;
146151 const tarball = "openclaw-whatsapp-2026.8.1-beta.1.tgz" ;
147152 const tarballPath = path . join ( root , tarball ) ;
@@ -166,7 +171,11 @@ describe("ClawHub fixture server", () => {
166171 } ) } \n`,
167172 ) ;
168173
169- const { baseUrl } = await startFixtureServer ( "prepublish-artifacts" , [ manifestPath ] ) ;
174+ const { baseUrl } = await startFixtureServer (
175+ "prepublish-artifacts" ,
176+ [ manifestPath ] ,
177+ isolatedCwd ,
178+ ) ;
170179 const whatsappPath = `/api/v1/packages/${ encodeURIComponent ( "@openclaw/whatsapp" ) } ` ;
171180 const detail = await fetchJson ( baseUrl , whatsappPath ) ;
172181 expect ( detail . package ) . toMatchObject ( {
@@ -190,7 +199,9 @@ describe("ClawHub fixture server", () => {
190199 `GET ${ whatsappPath } /versions/${ version } /security` ,
191200 `GET ${ whatsappPath } /versions/${ version } /artifact/download` ,
192201 ] ) ;
193- expect ( runPrepublishAssertion ( baseUrl , "@openclaw/whatsapp" , version ) . status ) . toBe ( 0 ) ;
202+ expect ( runPrepublishAssertion ( baseUrl , "@openclaw/whatsapp" , version , isolatedCwd ) . status ) . toBe (
203+ 0 ,
204+ ) ;
194205 expect ( ( await fetch ( `${ baseUrl } ${ whatsappPath } /versions/0.0.0/artifact` ) ) . status ) . toBe ( 404 ) ;
195206 const mismatch = runPrepublishAssertion ( baseUrl , "@openclaw/whatsapp" , version ) ;
196207 expect ( mismatch . status ) . toBe ( 1 ) ;
0 commit comments