import { describe, expect, it } from "vitest"; import { evaluateSourceHealth, SOURCE_HEALTH_ALLOWLIST, SOURCE_HEALTH_RULES } from "./verify-source-health.mjs"; describe("verify-source-health", () => { it("keeps API app composition and route module budgets explicit", () => { expect(SOURCE_HEALTH_RULES).toEqual([ { id: "api-app-composition", path: "apps/api/src/app.ts", maxLines: 450 }, { id: "api-route-modules", path: "apps/api/src/routes", maxLines: 500, glob: /\.ts$/ }, ]); expect(SOURCE_HEALTH_ALLOWLIST).toEqual([]); }); it("fails oversized files unless they are allowlisted with a reason", async () => { const rules = [{ id: "fixture", path: "scripts/fixtures/source-health/oversized.ts", maxLines: 2 }]; const [failure] = await evaluateSourceHealth({ rules, allowlist: [] }); const [allowed] = await evaluateSourceHealth({ rules, allowlist: [{ path: "scripts/fixtures/source-health/oversized.ts", reason: "Fixture proves allowlist handling." }], }); expect(failure.pass).toBe(false); expect(failure.lines).toBeGreaterThan(2); expect(allowed.pass).toBe(true); expect(allowed.allowed).toBe(true); expect(allowed.reason).toBe("Fixture proves allowlist handling."); }); it("fails stale source health allowlist entries", async () => { const results = await evaluateSourceHealth({ rules: [{ id: "fixture", path: "scripts/fixtures/source-health/oversized.ts", maxLines: 2 }], allowlist: [{ path: "scripts/fixtures/source-health/deleted.ts", reason: "Simulates a removed exception." }], }); expect(results).toContainEqual( expect.objectContaining({ ruleId: "source-health-allowlist", path: "scripts/fixtures/source-health/deleted.ts", problem: "stale allowlist entry", pass: false, }), ); }); it("fails allowlist entries without an explicit reason", async () => { const [result] = await evaluateSourceHealth({ rules: [{ id: "fixture", path: "scripts/fixtures/source-health/oversized.ts", maxLines: 2 }], allowlist: [{ path: "scripts/fixtures/source-health/oversized.ts", reason: " " }], }); expect(result).toEqual( expect.objectContaining({ allowed: false, problem: "allowlist entry requires a reason", pass: false, }), ); }); });