test(e2e): reuse suite temp root tracker in docker setup tests

This commit is contained in:
Vincent Koc
2026-04-06 06:27:48 +01:00
parent 6f2c258011
commit e7de00c363

View File

@@ -1,10 +1,10 @@
import { spawnSync } from "node:child_process";
import { chmod, copyFile, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
import { chmod, copyFile, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
import { createServer } from "node:net";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { createSuiteTempRootTracker } from "./test-helpers/temp-dir.js";
const repoRoot = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
@@ -49,7 +49,7 @@ exit 0
}
async function createDockerSetupSandbox(): Promise<DockerSetupSandbox> {
const rootDir = await mkdtemp(join(tmpdir(), "openclaw-docker-setup-"));
const rootDir = await sandboxRootTracker.make("suite");
const scriptPath = join(rootDir, "scripts", "docker", "setup.sh");
const dockerfilePath = join(rootDir, "Dockerfile");
const composePath = join(rootDir, "docker-compose.yml");
@@ -69,6 +69,8 @@ async function createDockerSetupSandbox(): Promise<DockerSetupSandbox> {
return { rootDir, scriptPath, logPath, binDir };
}
const sandboxRootTracker = createSuiteTempRootTracker({ prefix: "openclaw-docker-setup-" });
function createEnv(
sandbox: DockerSetupSandbox,
overrides: Record<string, string | undefined> = {},
@@ -193,14 +195,17 @@ describe("scripts/docker/setup.sh", () => {
let sandbox: DockerSetupSandbox | null = null;
beforeAll(async () => {
await sandboxRootTracker.setup();
sandbox = await createDockerSetupSandbox();
});
afterAll(async () => {
if (!sandbox) {
await sandboxRootTracker.cleanup();
return;
}
await rm(sandbox.rootDir, { recursive: true, force: true });
await sandboxRootTracker.cleanup();
sandbox = null;
});