11import { spawn , type ChildProcessByStdio } from "node:child_process" ;
22import { existsSync , readFileSync } from "node:fs" ;
3- import fs from "node:fs/promises" ;
4- import os from "node:os" ;
53import path from "node:path" ;
64import type { Readable } from "node:stream" ;
75import { setTimeout as delay } from "node:timers/promises" ;
86import { afterEach , describe , expect , it } from "vitest" ;
7+ import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js" ;
98import type { RuntimeEnv } from "../runtime.js" ;
109import { searchSkillsFromClawHub } from "../skills/lifecycle/clawhub.js" ;
1110import { runPluginsSearchCommand } from "./plugins-search-command.js" ;
1211
1312const SCRIPT_PATH = "scripts/e2e/lib/clawhub-fixture-server.cjs" ;
1413const servers : Array < ChildProcessByStdio < null , Readable , Readable > > = [ ] ;
15- const tempDirs : string [ ] = [ ] ;
14+ const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
1615const previousClawHubUrl = process . env . OPENCLAW_CLAWHUB_URL ;
1716const previousClawHubConfigPath = process . env . CLAWHUB_CONFIG_PATH ;
1817const previousClawHubToken = process . env . CLAWHUB_TOKEN ;
1918const previousClawHubAuthToken = process . env . CLAWHUB_AUTH_TOKEN ;
2019
2120afterEach ( async ( ) => {
2221 await Promise . all ( servers . splice ( 0 ) . map ( stopServer ) ) ;
23- await Promise . all ( tempDirs . splice ( 0 ) . map ( ( dir ) => fs . rm ( dir , { recursive : true , force : true } ) ) ) ;
2422 if ( previousClawHubUrl === undefined ) {
2523 delete process . env . OPENCLAW_CLAWHUB_URL ;
2624 } else {
@@ -59,8 +57,7 @@ async function stopServer(child: ChildProcessByStdio<null, Readable, Readable>)
5957}
6058
6159async function startFixtureServer ( ) {
62- const root = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "clawhub-search-e2e-" ) ) ;
63- tempDirs . push ( root ) ;
60+ const root = tempDirs . make ( "clawhub-search-e2e-" ) ;
6461 const portFile = path . join ( root , "port" ) ;
6562 const child = spawn ( process . execPath , [ SCRIPT_PATH , "catalog-search" , portFile ] , {
6663 cwd : process . cwd ( ) ,
@@ -78,7 +75,7 @@ async function startFixtureServer() {
7875 if ( existsSync ( portFile ) ) {
7976 const port = Number ( readFileSync ( portFile , "utf8" ) ) ;
8077 if ( Number . isInteger ( port ) && port > 0 ) {
81- return `http://127.0.0.1:${ port } ` ;
78+ return { baseUrl : `http://127.0.0.1:${ port } ` , root } ;
8279 }
8380 }
8481 if ( child . exitCode !== null ) {
@@ -119,9 +116,9 @@ async function readRequestLog(baseUrl: string): Promise<string[]> {
119116
120117describe ( "openclaw plugins search ClawHub E2E" , ( ) => {
121118 it ( "keeps plugin discovery separate from skills and surfaces empty and failed lookups" , async ( ) => {
122- const baseUrl = await startFixtureServer ( ) ;
119+ const { baseUrl, root } = await startFixtureServer ( ) ;
123120 process . env . OPENCLAW_CLAWHUB_URL = baseUrl ;
124- process . env . CLAWHUB_CONFIG_PATH = path . join ( tempDirs [ 0 ] ?? os . tmpdir ( ) , "missing-config.json" ) ;
121+ process . env . CLAWHUB_CONFIG_PATH = path . join ( root , "missing-config.json" ) ;
125122 delete process . env . CLAWHUB_TOKEN ;
126123 delete process . env . CLAWHUB_AUTH_TOKEN ;
127124
0 commit comments