Skip to content

Commit 98979d2

Browse files
committed
test(qa): use shared temp cleanup
1 parent b0ae803 commit 98979d2

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

‎src/cli/plugins-search-command.clawhub.e2e.test.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { spawn, type ChildProcessByStdio } from "node:child_process";
22
import { existsSync, readFileSync } from "node:fs";
3-
import fs from "node:fs/promises";
4-
import os from "node:os";
53
import path from "node:path";
64
import type { Readable } from "node:stream";
75
import { setTimeout as delay } from "node:timers/promises";
86
import { afterEach, describe, expect, it } from "vitest";
7+
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
98
import type { RuntimeEnv } from "../runtime.js";
109
import { searchSkillsFromClawHub } from "../skills/lifecycle/clawhub.js";
1110
import { runPluginsSearchCommand } from "./plugins-search-command.js";
1211

1312
const SCRIPT_PATH = "scripts/e2e/lib/clawhub-fixture-server.cjs";
1413
const servers: Array<ChildProcessByStdio<null, Readable, Readable>> = [];
15-
const tempDirs: string[] = [];
14+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1615
const previousClawHubUrl = process.env.OPENCLAW_CLAWHUB_URL;
1716
const previousClawHubConfigPath = process.env.CLAWHUB_CONFIG_PATH;
1817
const previousClawHubToken = process.env.CLAWHUB_TOKEN;
1918
const previousClawHubAuthToken = process.env.CLAWHUB_AUTH_TOKEN;
2019

2120
afterEach(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

6159
async 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

120117
describe("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

Comments
 (0)