116 lines
6.6 KiB
JavaScript
116 lines
6.6 KiB
JavaScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
import { mkdtemp } from "node:fs/promises";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
exportInventoryPatterns,
|
|
exportInventoryScanRoots,
|
|
failureCount,
|
|
gates,
|
|
renderReport,
|
|
reportPath,
|
|
runExportInventory,
|
|
} from "./verify-export-boundary-baseline.mjs";
|
|
|
|
describe("Export Boundary baseline gate contract", () => {
|
|
it("writes the baseline report to the Export Boundary health artifact path", () => {
|
|
expect(reportPath.replaceAll("\\", "/")).toMatch(/\.tc\/baselines\/export-boundary\/baseline-health\.md$/);
|
|
});
|
|
|
|
it("keeps the expected non-E2E gate IDs in order", () => {
|
|
expect(gates.map((gate) => gate.id)).toEqual(["typecheck", "lint", "vitest-export-boundary", "vitest-export-infrastructure", "export-inventory"]);
|
|
expect(gates.some((gate) => gate.args?.some((arg) => /playwright|cypress|browser|e2e|test:e2e/i.test(arg)))).toBe(false);
|
|
});
|
|
|
|
it("pins export boundary and infrastructure Vitest gates to explicit unit tests", () => {
|
|
expect(gates.find((gate) => gate.id === "vitest-export-boundary")?.args).toEqual([
|
|
"exec",
|
|
"vitest",
|
|
"run",
|
|
"packages/db/src/file-object-schema.test.ts",
|
|
"packages/storage/src/index.test.ts",
|
|
"packages/storage/src/signed/index.test.ts",
|
|
]);
|
|
expect(gates.find((gate) => gate.id === "vitest-export-infrastructure")?.args).toEqual([
|
|
"exec",
|
|
"vitest",
|
|
"run",
|
|
"packages/queue/src/producers.test.ts",
|
|
"apps/worker/src/handlers.test.ts",
|
|
"apps/worker/src/runtime.test.ts",
|
|
]);
|
|
});
|
|
|
|
it("covers export inventory roots and fingerprint pattern metadata", () => {
|
|
expect(exportInventoryScanRoots).toEqual(["apps/web/app/routes", "apps/api/src", "apps/worker/src", "packages/db/src", "packages/queue/src", "packages/storage/src", "prisma/schema"]);
|
|
expect(exportInventoryPatterns.map(({ id }) => id)).toEqual([
|
|
"export-route-reference",
|
|
"export-format-term",
|
|
"queue-worker-export-wiring",
|
|
"signed-download-storage-reference",
|
|
"retention-expiry-marker",
|
|
"permission-audit-marker",
|
|
"generated-client-reference",
|
|
]);
|
|
const patternSources = Object.fromEntries(exportInventoryPatterns.map(({ id, pattern }) => [id, pattern.source]));
|
|
expect(patternSources["export-route-reference"]).toMatch(/export|download/);
|
|
expect(patternSources["export-format-term"]).toMatch(/csv|json|xlsx|pdf/);
|
|
expect(patternSources["queue-worker-export-wiring"]).toMatch(/queue|worker|exportJob/);
|
|
expect(patternSources["signed-download-storage-reference"]).toMatch(/signedUrl|storage|FileObject/);
|
|
expect(patternSources["retention-expiry-marker"]).toMatch(/retention|expiresAt|ttl/);
|
|
expect(patternSources["permission-audit-marker"]).toMatch(/permission|audit|tenantId/);
|
|
expect(patternSources["generated-client-reference"]).toContain("packages\\/db\\/generated");
|
|
expect(patternSources["generated-client-reference"]).toContain("client\\/models\\/FileObject");
|
|
});
|
|
|
|
it("counts command failures while treating read-only inventory findings as non-failing", () => {
|
|
expect(failureCount("typecheck", "src/a.ts(1,1): error TS2322: wrong\nerror TS7006", "", 2)).toBe(2);
|
|
expect(failureCount("lint", "✖ 5 problems (3 errors, 2 warnings)", "", 1)).toBe(3);
|
|
expect(failureCount("vitest-export-boundary", "Tests 2 failed | 4 passed", "", 1)).toBe(2);
|
|
expect(failureCount("vitest-export-infrastructure", "Test Files 1 failed | 2 passed", "", 1)).toBe(1);
|
|
expect(failureCount("export-inventory", "generated-client-reference: 4", "", 1)).toBe(0);
|
|
});
|
|
|
|
it("renders baseline report diagnostics without snapshots", () => {
|
|
const report = renderReport([
|
|
{ id: "export-inventory", command: "read-only export inventory", exitCode: 0, durationMs: 42, failureCount: 0, fingerprint: { hash: "abc123def456", excerpt: "export-format-term: 7" } },
|
|
{ id: "typecheck", command: "pnpm run typecheck", exitCode: 2, durationMs: 99, failureCount: 3, fingerprint: { hash: "badc0ffee123", excerpt: "error TS2322" } },
|
|
]);
|
|
|
|
expect(report).toContain("# Export Boundary Baseline Health");
|
|
expect(report).toContain("non-E2E baseline gates for Export Boundary baseline");
|
|
expect(report).toContain("## export-inventory");
|
|
expect(report).toContain("- Exitcode: 2");
|
|
expect(report).toContain("- Failure Count: 3");
|
|
expect(report).toContain("- Output Fingerprint: badc0ffee123");
|
|
});
|
|
|
|
it("scans export roots while excluding generated Prisma client noise", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "exportBoundary-export-inventory-"));
|
|
await mkdir(join(root, "apps", "web", "app", "routes"), { recursive: true });
|
|
await mkdir(join(root, "apps", "worker", "src"), { recursive: true });
|
|
await mkdir(join(root, "packages", "db", "src"), { recursive: true });
|
|
await mkdir(join(root, "packages", "db", "generated", "prisma", "client", "models"), { recursive: true });
|
|
await mkdir(join(root, "prisma", "schema"), { recursive: true });
|
|
|
|
await writeFile(join(root, "apps", "web", "app", "routes", "exports.ts"), "export async function loader() { return json({ csv: true, pdf: true }); }\n", "utf8");
|
|
await writeFile(join(root, "apps", "worker", "src", "export-worker.ts"), "const exportJob = queue.add('export', { expiresAt: new Date(), audit: true });\n", "utf8");
|
|
await writeFile(join(root, "packages", "db", "src", "file-object.ts"), "const key = 'FileObject signedUrl tenantId';\n", "utf8");
|
|
await writeFile(join(root, "packages", "db", "generated", "prisma", "client", "models", "FileObject.ts"), "PrismaClient FileObject generated/prisma should be ignored\n", "utf8");
|
|
await writeFile(join(root, "prisma", "schema", "schema.prisma"), "model ExportAudit { id String @id }\n", "utf8");
|
|
|
|
const inventory = await runExportInventory(root);
|
|
|
|
expect(inventory.roots).toEqual(expect.arrayContaining(["apps/web/app/routes", "apps/worker/src", "packages/db/src", "prisma/schema"]));
|
|
expect(inventory.counts["export-route-reference"]).toBeGreaterThan(0);
|
|
expect(inventory.counts["export-format-term"]).toBeGreaterThan(0);
|
|
expect(inventory.counts["queue-worker-export-wiring"]).toBeGreaterThan(0);
|
|
expect(inventory.counts["signed-download-storage-reference"]).toBeGreaterThan(0);
|
|
expect(inventory.counts["retention-expiry-marker"]).toBeGreaterThan(0);
|
|
expect(inventory.counts["permission-audit-marker"]).toBeGreaterThan(0);
|
|
expect(inventory.matches.join("\n")).not.toContain("packages/db/generated/prisma/client/models/FileObject.ts");
|
|
});
|
|
});
|