Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132import { spawn } from "node:child_process";import { readdir } from "node:fs/promises";import { availableParallelism, totalmem } from "node:os";import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("../", import.meta.url));const args = process.argv.slice(2);if ( args.length > 1 || args.some((arg) => !["--quick", "--execution", "--full"].includes(arg))) throw new Error("Usage: pnpm test [--quick|--execution|--full]");const concurrency = Number( process.env.FLAREBOT_TEST_CONCURRENCY ?? Math.min( 4, availableParallelism(), Math.max(1, Math.floor(totalmem() / (2 * 1024 ** 3))), ),);if (!Number.isSafeInteger(concurrency) || concurrency < 1) throw new Error("FLAREBOT_TEST_CONCURRENCY must be a positive integer");
// These suites need neither packaged assets, a browser nor a container runtime.const quick = [ "artifact-loading", "attachment-storage", "configuration", "control-plane-effect", "deployment-effect", "diagnostics", "domain-auth", "domain-effect", "gateway-provisioning", "installation-metadata", "model-provider", "publish-release-artifacts", "test-runner", "worker-bundle-boundaries", "update-on-visit",].map((name) => `tests/${name}.test.mjs`);
async function run(command, args) { console.log(`\n> ${command} ${args.join(" ")}`); const child = spawn(command, args, { cwd: root, stdio: "inherit" }); let interrupted; const stop = (signal) => { interrupted = signal; child.kill(signal); }; const interrupt = () => stop("SIGINT"); const terminate = () => stop("SIGTERM"); process.on("SIGINT", interrupt); process.on("SIGTERM", terminate); try { await new Promise((resolve, reject) => { child.once("error", reject); child.once("exit", (code, signal) => { if (code === 0 && !interrupted) resolve(); else reject( new Error(`${command} failed (${interrupted ?? signal ?? code})`), ); }); }); } finally { process.off("SIGINT", interrupt); process.off("SIGTERM", terminate); }}
const started = performance.now();try { let files = quick; if (args.length === 0 || args.includes("--full")) await run("pnpm", ["typecheck"]); if (args.includes("--execution")) { files = [ "execution", "execution-cron", "execution-recovery", "execution-cleanup", ].map((name) => `tests/${name}.test.mjs`); } else if (args.includes("--full")) { await run("pnpm", ["build:release"]); // Catalog tests replace dist/catalog. Finish all writers before readers start. await run(process.execPath, [ "--max-old-space-size=512", "--test", "tests/catalog.test.mjs", ]); await run("pnpm", ["build:control-plane:fixture"]); // This short restart suite hit ECONNRESET under load but passed alone. // Preserve its serial execution until its HTTP lifecycle is made robust. await run(process.execPath, [ "--max-old-space-size=512", "--test", "tests/ownership.test.mjs", ]); files = (await readdir(new URL("../tests/", import.meta.url))) .filter( (name) => name.endsWith(".test.mjs") && !["catalog.test.mjs", "ownership.test.mjs"].includes(name), ) .sort() .map((name) => `tests/${name}`); } if (args.length === 0) files = [ ...quick, ...["attachments", "deployment-network", "customer-runtime-effect"].map( (name) => `tests/${name}.test.mjs`, ), ]; await run(process.execPath, [ // Bound retained JavaScript memory while several native fixtures are alive. "--max-old-space-size=512", "--test", `--test-concurrency=${concurrency}`, ...(args.includes("--execution") ? ["--test-reporter=tap"] : []), ...files, ]);} catch (error) { console.error(error.message); process.exitCode = 1;} finally { console.log( `\nLocal tests finished in ${((performance.now() - started) / 1000).toFixed(1)}s`, );}