110 lines
4.4 KiB
JavaScript
110 lines
4.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "vitest";
|
|
|
|
import { failureCount, gates, renderReport, reportPath } from "./verify-permissions-audit-baseline.mjs";
|
|
|
|
describe("verify-permissions-audit-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-audit-log-persistence",
|
|
"pnpm",
|
|
[
|
|
"exec",
|
|
"vitest",
|
|
"run",
|
|
"packages/db/src/impersonation-audit.server.test.ts",
|
|
"packages/db/src/logs.server.test.ts",
|
|
],
|
|
],
|
|
["impersonation-audit-cascade-guard", "pnpm", ["run", "verify:audit-cascade-guard"]],
|
|
["prisma-ownership", "node", ["scripts/verify-prisma-ownership.mjs"]],
|
|
],
|
|
);
|
|
|
|
const commandText = gates.map((gate) => [gate.command, ...gate.args].join(" ")).join("\n");
|
|
assert.doesNotMatch(commandText, /playwright/i);
|
|
assert.doesNotMatch(commandText, /cypress/i);
|
|
assert.doesNotMatch(commandText, /test:e2e/i);
|
|
assert.doesNotMatch(commandText, /(?:^|[\s/])e2e(?:$|[\s/])/i);
|
|
});
|
|
|
|
it("derives failure counts from TypeScript, ESLint, Vitest, and Prisma ownership output", () => {
|
|
assert.equal(failureCount("typecheck", "src/a.ts(1,1): error TS2322: wrong\nerror TS7006", ""), 2);
|
|
assert.equal(failureCount("typecheck", "Build failed without a TS code", ""), 1);
|
|
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("lint", "Parsing error: unexpected token", ""), 1);
|
|
assert.equal(failureCount("vitest-audit-log-persistence", "Tests 4 failed | 10 passed", ""), 4);
|
|
assert.equal(failureCount("vitest-audit-log-persistence", "Test Files 3 failed | 20 passed", ""), 3);
|
|
assert.equal(failureCount("vitest-audit-log-persistence", "Unhandled error between tests", ""), 1);
|
|
assert.equal(
|
|
failureCount(
|
|
"impersonation-audit-cascade-guard",
|
|
"",
|
|
"FAIL impersonation audit cascade guard\n- schema.actor.optional-set-null: relation must use SetNull\n- migration.actorUserId.set-null: foreign key must use SET NULL",
|
|
),
|
|
2,
|
|
);
|
|
assert.equal(
|
|
failureCount("impersonation-audit-cascade-guard", "PASS impersonation audit cascade guard: schema and migration retain audit rows", ""),
|
|
0,
|
|
);
|
|
assert.equal(
|
|
failureCount(
|
|
"prisma-ownership",
|
|
"",
|
|
[
|
|
"FAIL Prisma ownership verification",
|
|
"- apps/web/app/routes/_index.tsx: forbidden app-local generated Prisma client import",
|
|
"- apps/web/app/routes/projects.tsx: forbidden root/app Prisma generated-client path",
|
|
"Summary: 4 passed, 2 failed",
|
|
].join("\n"),
|
|
),
|
|
2,
|
|
);
|
|
assert.equal(
|
|
failureCount(
|
|
"prisma-ownership",
|
|
"",
|
|
[
|
|
"FAIL Prisma ownership verification",
|
|
"- apps/web/app/routes/_index.tsx: forbidden app-local generated Prisma client import",
|
|
"- apps/web/app/routes/projects.tsx: forbidden root/app Prisma generated-client path",
|
|
].join("\n"),
|
|
),
|
|
2,
|
|
);
|
|
assert.equal(failureCount("prisma-ownership", "", ""), 0);
|
|
});
|
|
|
|
it("renders Permissions Audit report sections with commands, exitcodes, failure counts, durations, fingerprints, and report path text", () => {
|
|
const report = renderReport([
|
|
{
|
|
id: "typecheck",
|
|
command: "pnpm run typecheck",
|
|
exitCode: 2,
|
|
durationMs: 123,
|
|
failureCount: 5,
|
|
fingerprint: { hash: "abc123", excerpt: "error TS2322" },
|
|
},
|
|
]);
|
|
|
|
assert.match(report, /# Permissions Audit Baseline Health/);
|
|
assert.match(report, /Permissions Audit\ baseline/);
|
|
assert.doesNotMatch(report, /Observability Console Baseline Health/);
|
|
assert.match(report, /## typecheck/);
|
|
assert.match(report, /Command: `pnpm run typecheck`/);
|
|
assert.match(report, /Exitcode: 2/);
|
|
assert.match(report, /Failure Count: 5/);
|
|
assert.match(report, /Duration: 123ms/);
|
|
assert.match(report, /Output Fingerprint: abc123/);
|
|
assert.match(report, /error TS2322/);
|
|
assert.match(reportPath, /\.tc\/baselines\/permissions-audit\/baseline-health\.md$/);
|
|
});
|
|
});
|