Files
HiveGrid-Wireframes/hivegrid-cloud/scripts/verify-storage-boundary-baseline.test.mjs
T

111 lines
4.4 KiB
JavaScript

import { describe, expect, it } from "vitest";
import {
failureCount,
gates,
renderReport,
reportPath,
storageInventoryPatterns,
storageInventoryScanRoots,
} from "./verify-storage-boundary-baseline.mjs";
describe("Storage Boundary baseline gate contract", () => {
it("writes the baseline report to the Storage Boundary health artifact path", () => {
expect(reportPath.replaceAll("\\", "/")).toMatch(/\.tc\/baselines\/storage-boundary\/baseline-health\.md$/);
});
it("keeps the expected non-E2E gate IDs in order", () => {
expect(gates.map((gate) => gate.id)).toEqual(["typecheck", "lint", "vitest-storage-package", "storage-inventory"]);
});
it("pins the storage package Vitest gate to the package unit test only", () => {
const gate = gates.find((candidate) => candidate.id === "vitest-storage-package");
expect(gate).toMatchObject({ command: "pnpm" });
expect(gate?.args).toEqual(["exec", "vitest", "run", "packages/storage/src/index.test.ts"]);
expect(gate?.args.join(" ")).not.toMatch(/\b(?:playwright|cypress|browser|e2e|test:e2e)\b/i);
});
it("covers current storage inventory scan roots and pattern metadata", () => {
expect(storageInventoryScanRoots).toEqual([
"apps/web/app/modules/storage",
"apps/web/app/utils/integrations",
"packages",
"prisma",
]);
expect(storageInventoryPatterns.map(({ id }) => id)).toEqual([
"supabase-storage",
"legacy-file-model",
"file-base64",
"bucket-reference",
"avatar-reference",
"attachment-reference",
"tenant-marker",
"mime-type-size",
"scan-quarantine",
]);
const patternSources = Object.fromEntries(storageInventoryPatterns.map(({ id, pattern }) => [id, pattern.source]));
expect(patternSources["supabase-storage"]).toMatch(/supabase/);
expect(patternSources["legacy-file-model"]).not.toMatch(/removed form file model/i);
expect(patternSources["file-base64"]).toMatch(/fileBase64|base64/);
expect(patternSources["tenant-marker"]).toMatch(/tenant/);
expect(patternSources["mime-type-size"]).toMatch(/mimeType|fileSize/);
expect(patternSources["scan-quarantine"]).toMatch(/quarantine|malware/);
});
it("counts no failures for successful command output and inventory findings", () => {
expect(failureCount("typecheck", "", "", 0)).toBe(0);
expect(failureCount("lint", "", "", 0)).toBe(0);
expect(failureCount("vitest-storage-package", "", "", 0)).toBe(0);
expect(failureCount("storage-inventory", "legacy storage matches", "", 1)).toBe(0);
});
it("counts TypeScript diagnostics and falls back conservatively on crashes", () => {
expect(failureCount("typecheck", "src/a.ts(1,1): error TS2322: wrong\nsrc/b.ts(2,2): error TS7006: wrong", "", 2)).toBe(2);
expect(failureCount("typecheck", "", "tsc crashed before diagnostics", 1)).toBe(1);
expect(failureCount("unknown-gate", "", "process terminated", 1)).toBe(1);
});
it("counts ESLint error summaries", () => {
expect(failureCount("lint", "✖ 5 problems (3 errors, 2 warnings)", "", 1)).toBe(3);
expect(failureCount("lint", "3 errors and 0 warnings", "", 1)).toBe(3);
expect(failureCount("lint", "eslint crashed", "", 1)).toBe(1);
});
it("counts Vitest failed tests or failed files", () => {
expect(failureCount("vitest-storage-package", "Tests 2 failed | 4 passed", "", 1)).toBe(2);
expect(failureCount("vitest-storage-package", "Test Files 1 failed | 2 passed", "", 1)).toBe(1);
expect(failureCount("vitest-storage-package", "vitest crashed", "", 1)).toBe(1);
});
it("renders baseline report diagnostics without snapshots", () => {
const report = renderReport([
{
id: "storage-inventory",
command: "read-only storage inventory",
exitCode: 0,
durationMs: 42,
failureCount: 0,
fingerprint: { hash: "abc123def456", excerpt: "supabase-storage: 7" },
},
{
id: "typecheck",
command: "pnpm run typecheck",
exitCode: 2,
durationMs: 99,
failureCount: 3,
fingerprint: { hash: "badc0ffee123", excerpt: "error TS2322" },
},
]);
expect(report).toContain("# Storage Boundary Baseline Health");
expect(report).toContain("non-E2E baseline gates");
expect(report).toContain("## storage-inventory");
expect(report).toContain("- Exitcode: 2");
expect(report).toContain("- Failure Count: 3");
expect(report).toContain("- Output Fingerprint: badc0ffee123");
});
});