77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/* eslint-disable no-console */
|
|
import { spawn } from "node:child_process";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const repoRoot = path.resolve(__dirname, "..");
|
|
|
|
export const gates = [
|
|
{
|
|
label: "TypeScript/static health",
|
|
command: "pnpm",
|
|
args: ["run", "typecheck"],
|
|
},
|
|
{
|
|
label: "Focused auth/API/body-limit Vitest surfaces",
|
|
command: "pnpm",
|
|
args: [
|
|
"exec",
|
|
"vitest",
|
|
"run",
|
|
"apps/api/src/auth.test.ts",
|
|
"apps/api/src/app.test.ts",
|
|
"apps/api/src/middleware/body-limit.test.ts",
|
|
"apps/api/src/middleware/request-id.test.ts",
|
|
"apps/web/app/routes/session-entry.host-aware.test.ts",
|
|
"root.theme-preference.test.tsx",
|
|
],
|
|
},
|
|
];
|
|
|
|
export function shellCommand({ command, args }) {
|
|
return [command, ...args].join(" ");
|
|
}
|
|
|
|
export function runGate(gate) {
|
|
return new Promise((resolve) => {
|
|
console.log(`\n[Auth API Body baseline] ${gate.label}`);
|
|
console.log(`[Auth API Body baseline] $ ${shellCommand(gate)}`);
|
|
|
|
const child = spawn(gate.command, gate.args, {
|
|
cwd: repoRoot,
|
|
env: { ...process.env, CI: "1" },
|
|
shell: false,
|
|
stdio: "inherit",
|
|
});
|
|
|
|
child.on("error", (error) => {
|
|
console.error(`[Auth API Body baseline] ${gate.label} failed to start: ${error.message}`);
|
|
resolve(1);
|
|
});
|
|
|
|
child.on("close", (code) => {
|
|
resolve(code ?? 1);
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function runGates(commandInventory = gates) {
|
|
for (const gate of commandInventory) {
|
|
const exitCode = await runGate(gate);
|
|
if (exitCode !== 0) {
|
|
console.error(`[Auth API Body baseline] Failing gate: ${gate.label} (exit code ${exitCode})`);
|
|
return exitCode;
|
|
}
|
|
}
|
|
|
|
console.log("\n[Auth API Body baseline] All baseline gates passed.");
|
|
return 0;
|
|
}
|
|
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
const exitCode = await runGates();
|
|
process.exitCode = exitCode;
|
|
}
|