import assert from "node:assert/strict"; import { describe, it } from "vitest"; import { failureCount, gates, renderReport, reportPath } from "./verify-db-boundary-baseline.mjs"; describe("verify-db-boundary-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-db-boundary", "pnpm", [ "exec", "vitest", "run", "packages/db/src/index.test.ts", "packages/db/src/client.server.test.ts", "packages/db/src/prisma-browser.test.ts", ], ], ["prisma-ownership", "node", ["scripts/verify-prisma-ownership.mjs"]], ], ); const commandText = gates.map((gate) => [gate.command, ...gate.args].join(" ")).join("\n"); assert.doesNotMatch(commandText, /playwright|cypress|test:e2e|(?:^|[\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-db-boundary", "Tests 4 failed | 10 passed", ""), 4); assert.equal(failureCount("vitest-db-boundary", "Test Files 3 failed | 20 passed", ""), 3); assert.equal(failureCount("vitest-db-boundary", "Unhandled error between tests", ""), 1); 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 DB Boundary 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, /# DB Boundary Baseline Health/); assert.match(report, /DB Boundary\ baseline/); assert.doesNotMatch(report, /Transactional Mail Provider 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\/db-boundary\/baseline-health\.md$/); }); });