import { spawnSync } from "node:child_process"; import { access, rm } from "node:fs/promises"; import { createBoundedPnpmScriptInvocation, formatPnpmScriptFailure, } from "./lib/bounded-pnpm-script.ts"; const receiptPath = "artifacts/tests/http-scenario-executions.json"; const expectedNegativeDiagnostic = "[TEST-EVIDENCE-EXECUTION-ID-MISSING]"; const pnpmCli = process.env.npm_execpath; if (!pnpmCli) throw new Error("npm_execpath is required"); await rm(receiptPath, { force: true }); try { await access(receiptPath); throw new Error(`stale scenario receipt remains: ${receiptPath}`); } catch (error) { if ( typeof error !== "object" || error === null || !("code" in error) || error.code !== "ENOENT" ) { throw error; } } runExpectedPass("test:http-scenario-catalog"); runExpectedPass("check:http-scenario-evidence"); const negative = run("check:http-scenario-evidence:fixture"); if ( negative.status !== 1 || !`${negative.stdout}\n${negative.stderr}`.includes(expectedNegativeDiagnostic) ) { process.stderr.write(negative.stdout); process.stderr.write(negative.stderr); throw new Error( `scenario negative fixture identity mismatch: ${formatPnpmScriptFailure( "check:http-scenario-evidence:fixture", negative, )}`, ); } process.stdout.write( "HTTP scenario evidence: PASS (stale receipt removed, 54 executed, missing-ID fixture rejected)\n", ); function run(script: string) { const invocation = createBoundedPnpmScriptInvocation({ nodePath: process.execPath, pnpmCli: pnpmCli!, script, environment: process.env, }); return spawnSync( invocation.command, [...invocation.arguments], invocation.options, ); } function runExpectedPass(script: string): void { const result = run(script); process.stdout.write(result.stdout); process.stderr.write(result.stderr); if (result.status !== 0 || result.error !== undefined) { throw new Error(formatPnpmScriptFailure(script, result)); } }