// One-shot driver: start the shared static host on web/dist, run the workbench // surface audit against it, then shut the host down. Keeps the origin ephemeral // (loopback, COOP/COEP via tools/static-host.mjs) so the audit never reuses a // stale long-running preview server. import path from "node:path"; import { spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; import { startStaticHost } from "./static-host.mjs"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const host = await startStaticHost(path.join(root, "web/dist")); try { console.log(JSON.stringify({ origin: host.origin })); const code = await new Promise((resolve) => { const child = spawn(process.execPath, [path.join(root, "tools", "ui-workbench-surface-audit.mjs")], { cwd: root, env: { ...process.env, FREECAD_BROWSER_ORIGIN: host.origin }, stdio: ["ignore", "inherit", "inherit"], }); child.once("error", () => resolve(1)); child.once("close", (exitCode) => resolve(exitCode ?? 1)); }); process.exitCode = code; } finally { // server.close() is callback-style; await it properly and drop keep-alive // sockets so this driver exits instead of holding the event loop open. await new Promise((resolve) => { host.server.closeAllConnections?.(); host.server.close(() => resolve()); }); }