test(scripts): reuse temp dir helpers in runtime tests

This commit is contained in:
Vincent Koc
2026-04-06 05:35:38 +01:00
parent d77dbd699c
commit b1ae35d602
2 changed files with 10 additions and 33 deletions

View File

@@ -1,26 +1,14 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { describe, expect, it, vi } from "vitest";
import {
copyStaticExtensionAssets,
listStaticExtensionAssetOutputs,
writeStableRootRuntimeAliases,
} from "../../scripts/runtime-postbuild.mjs";
import { createScriptTestHarness } from "./test-helpers.js";
const cleanupDirs: string[] = [];
afterEach(async () => {
await Promise.all(
cleanupDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })),
);
});
async function createTempRoot() {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-runtime-postbuild-"));
cleanupDirs.push(dir);
return dir;
}
const { createTempDir } = createScriptTestHarness();
describe("runtime postbuild static assets", () => {
it("tracks plugin-owned static assets that release packaging must ship", () => {
@@ -30,7 +18,7 @@ describe("runtime postbuild static assets", () => {
});
it("copies declared static assets into dist", async () => {
const rootDir = await createTempRoot();
const rootDir = createTempDir("openclaw-runtime-postbuild-");
const src = "extensions/acpx/src/runtime-internals/mcp-proxy.mjs";
const dest = "dist/extensions/acpx/mcp-proxy.mjs";
const sourcePath = path.join(rootDir, src);
@@ -47,7 +35,7 @@ describe("runtime postbuild static assets", () => {
});
it("warns when a declared static asset is missing", async () => {
const rootDir = await createTempRoot();
const rootDir = createTempDir("openclaw-runtime-postbuild-");
const warn = vi.fn();
copyStaticExtensionAssets({
@@ -62,7 +50,7 @@ describe("runtime postbuild static assets", () => {
});
it("writes stable aliases for hashed root runtime modules", async () => {
const rootDir = await createTempRoot();
const rootDir = createTempDir("openclaw-runtime-postbuild-");
const distDir = path.join(rootDir, "dist");
await fs.mkdir(distDir, { recursive: true });
await fs.writeFile(

View File

@@ -1,24 +1,14 @@
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os";
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { describe, expect, it } from "vitest";
import {
renderBundledRootHelpText,
writeCliStartupMetadata,
} from "../../scripts/write-cli-startup-metadata.ts";
function createTempDir(prefix: string): string {
return mkdtempSync(path.join(os.tmpdir(), prefix));
}
import { createScriptTestHarness } from "./test-helpers.js";
describe("write-cli-startup-metadata", () => {
const tempDirs: string[] = [];
afterEach(() => {
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true });
}
});
const { createTempDir } = createScriptTestHarness();
it("captures bundled root help text from the CLI program", async () => {
const rootHelpText = await renderBundledRootHelpText();
@@ -29,7 +19,6 @@ describe("write-cli-startup-metadata", () => {
it("writes startup metadata with populated root help text", async () => {
const tempRoot = createTempDir("openclaw-startup-metadata-");
tempDirs.push(tempRoot);
const distDir = path.join(tempRoot, "dist");
const extensionsDir = path.join(tempRoot, "extensions");
const outputPath = path.join(distDir, "cli-startup-metadata.json");