repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

scripts/run_leaks_fuzz.mjs

Raw
File outline
import { spawnSync } from "node:child_process";
import process from "node:process";
import { fileURLToPath } from "node:url";

export function runProcess(command, args, timeout) {
	const result = spawnSync(command, args, {
		stdio: "inherit",
		timeout,
		killSignal: "SIGKILL",
	});
	return result.error?.code === "ETIMEDOUT" ? 124 : (result.status ?? 1);
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
	const testing = process.env.LEAKS_FUZZ_TEST_HANG === "1";
	const requested = Number(process.env.LEAKS_FUZZ_TIMEOUT_MS ?? 120_000);
	const timeout = testing
		? Math.max(
				1,
				Math.min(Number.isFinite(requested) ? requested : 120_000, 120_000),
			)
		: 120_000;
	const args = testing
		? ["-e", "setInterval(() => {}, 1000)"]
		: [
				"node_modules/vitest/vitest.mjs",
				"run",
				"--config",
				"extensions/leaks/vitest.fuzz.config.ts",
			];
	process.exit(runProcess(process.execPath, args, timeout));
}