Adds parameterized test cases to the worktree-liveness test to exercise different configured `worktreesDir` paths, improving coverage of the worktree escape/isolation path. Fusion-Task-Id: FN-4737 Fusion-Task-Lineage: 40e262ea-2507-461e-b9f5-940b3b4490f9
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { spawn } from "node:child_process";
|
|
import { dirname, resolve } from "node:path";
|
|
import { existsSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
export const packageRoot = resolve(__dirname, "..");
|
|
export const workspaceRoot = resolve(packageRoot, "..", "..");
|
|
|
|
function resolveBin(command: string, cwd: string): string {
|
|
const suffix = process.platform === "win32" ? ".cmd" : "";
|
|
const localBin = resolve(cwd, "node_modules", ".bin", `${command}${suffix}`);
|
|
if (existsSync(localBin)) {
|
|
return localBin;
|
|
}
|
|
|
|
return resolve(workspaceRoot, "node_modules", ".bin", `${command}${suffix}`);
|
|
}
|
|
|
|
export function runWorkspaceBin(command: string, args: string[], cwd: string): Promise<void> {
|
|
return new Promise((resolvePromise, rejectPromise) => {
|
|
const child = spawn(resolveBin(command, cwd), args, {
|
|
cwd,
|
|
stdio: "inherit",
|
|
env: process.env,
|
|
});
|
|
|
|
child.on("error", rejectPromise);
|
|
child.on("exit", (code) => {
|
|
if (code === 0) {
|
|
resolvePromise();
|
|
return;
|
|
}
|
|
|
|
rejectPromise(new Error(`${command} ${args.join(" ")} exited with code ${code ?? "unknown"}`));
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function buildCore(): Promise<void> {
|
|
await runWorkspaceBin("tsc", [], resolve(workspaceRoot, "packages", "core"));
|
|
}
|
|
|
|
export async function buildDashboard(): Promise<void> {
|
|
const dashboardRoot = resolve(workspaceRoot, "packages", "dashboard");
|
|
await runWorkspaceBin("vite", ["build"], dashboardRoot);
|
|
await runWorkspaceBin("tsc", [], dashboardRoot);
|
|
}
|
|
|
|
export async function buildDashboardClient(): Promise<void> {
|
|
await runWorkspaceBin("vite", ["build"], resolve(workspaceRoot, "packages", "dashboard"));
|
|
}
|