Files
HiveGrid-Wireframes/hivegrid-cloud/scripts/verify-api-auth-enforced-baseline.test.mjs
T

65 lines
2.5 KiB
JavaScript

import assert from "node:assert/strict";
import { describe, it } from "vitest";
import { failureCount, gates, renderReport } from "./verify-api-auth-enforced-baseline.mjs";
describe("verify-api-auth-enforced-baseline", () => {
it("defines the expected non-E2E gate commands", () => {
assert.deepEqual(
gates.map((gate) => [gate.id, gate.command, gate.args]),
[
["typecheck", "pnpm", ["run", "typecheck"]],
["lint", "pnpm", ["run", "lint"]],
["vitest-app", "pnpm", ["exec", "vitest", "run", "apps/web/app/"]],
["api-auth-surface", "node", ["scripts/verify-api-auth-surface.mjs", "--json"]],
],
);
const commandText = gates.map((gate) => [gate.command, ...gate.args].join(" ")).join("\n");
assert.doesNotMatch(commandText, /playwright|cypress|browser|test:e2e/i);
});
it("derives failure counts from non-zero gate output", () => {
assert.equal(failureCount("typecheck", "src/a.ts(1,1): error TS2322: wrong\nerror TS7006", ""), 2);
assert.equal(failureCount("lint", "✖ 3 problems (2 errors, 1 warning)", ""), 2);
assert.equal(failureCount("lint", "2 errors and 0 warnings potentially fixable", ""), 2);
assert.equal(failureCount("vitest-app", "Tests 4 failed | 10 passed", ""), 4);
assert.equal(failureCount("vitest-app", "Test Files 3 failed | 20 passed", ""), 3);
assert.equal(
failureCount(
"api-auth-surface",
JSON.stringify({
directValidateApiKeyCallsites: [
{ file: "apps/api/src/app.ts" },
{ file: "apps/web/app/utils/services/apiService.ts" },
],
}),
"",
),
1,
);
assert.equal(failureCount("api-auth-surface", "not json", ""), 1);
});
it("renders API Auth Enforcement report sections with exitcodes, failure counts and fingerprints", () => {
const report = renderReport([
{
id: "typecheck",
command: "pnpm run typecheck",
exitCode: 2,
durationMs: 123,
failureCount: 5,
fingerprint: { hash: "abc123", excerpt: "error TS2322" },
},
]);
assert.match(report, /# API Auth Enforcement Baseline Health/);
assert.match(report, /API Auth Enforcement\ baseline/);
assert.doesNotMatch(report, /API Auth Routing Baseline Health/);
assert.match(report, /## typecheck/);
assert.match(report, /Exitcode: 2/);
assert.match(report, /Failure Count: 5/);
assert.match(report, /Output Fingerprint: abc123/);
});
});