test(root): share temp dir helper across root tests

This commit is contained in:
Vincent Koc
2026-04-06 05:42:40 +01:00
parent d4c443bc1e
commit ce50b97c86
3 changed files with 44 additions and 21 deletions

View File

@@ -1,9 +1,9 @@
import { execFileSync } from "node:child_process";
import { chmodSync } from "node:fs";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import { mkdir, writeFile } from "node:fs/promises";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
const SCRIPT = path.join(process.cwd(), "scripts", "ios-team-id.sh");
const BASH_BIN = process.platform === "win32" ? "bash" : "/bin/bash";
@@ -15,6 +15,7 @@ let sharedBinDir = "";
let sharedHomeDir = "";
let sharedHomeBinDir = "";
let sharedFakePythonPath = "";
const tempDirs: string[] = [];
const runScriptCache = new Map<string, { ok: boolean; stdout: string; stderr: string }>();
type TeamCandidate = {
teamId: string;
@@ -110,12 +111,19 @@ function runScript(
runScriptCache.set(cacheKey, result);
return result;
} catch (error) {
const e = error as {
stdout?: string | Buffer;
stderr?: string | Buffer;
};
const stdout = typeof e.stdout === "string" ? e.stdout : (e.stdout?.toString("utf8") ?? "");
const stderr = typeof e.stderr === "string" ? e.stderr : (e.stderr?.toString("utf8") ?? "");
const e = error as { stdout?: unknown; stderr?: unknown };
const stdout =
typeof e.stdout === "string"
? e.stdout
: Buffer.isBuffer(e.stdout)
? e.stdout.toString("utf8")
: "";
const stderr =
typeof e.stderr === "string"
? e.stderr
: Buffer.isBuffer(e.stderr)
? e.stderr.toString("utf8")
: "";
const result = { ok: false, stdout: stdout.trim(), stderr: stderr.trim() };
runScriptCache.set(cacheKey, result);
return result;
@@ -124,7 +132,7 @@ function runScript(
describe("scripts/ios-team-id.sh", () => {
beforeAll(async () => {
fixtureRoot = await mkdtemp(path.join(os.tmpdir(), "openclaw-ios-team-id-"));
fixtureRoot = makeTempDir(tempDirs, "openclaw-ios-team-id-");
sharedBinDir = path.join(fixtureRoot, "shared-bin");
await mkdir(sharedBinDir, { recursive: true });
sharedHomeDir = path.join(fixtureRoot, "home");
@@ -182,10 +190,7 @@ printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`,
});
afterAll(async () => {
if (!fixtureRoot) {
return;
}
await rm(fixtureRoot, { recursive: true, force: true });
cleanupTempDirs(tempDirs);
});
it("parses team listings and prioritizes preferred IDs without shelling out", () => {