import { describe, expect, it } from "vitest"; import { failureCount, gates, notificationInventoryPatterns, notificationInventoryScanRoots, renderReport, reportPath, } from "./verify-notification-boundary-baseline.mjs"; const requiredNotificationTargets = [ "packages/queue/src/producers.test.ts", "packages/mail/src/queue.test.ts", "apps/web/app/modules/emails/services/TransactionalEmailQueue.server.test.ts", "apps/web/app/modules/notifications/services/.server/NotificationService.test.ts", ]; const requiredInventoryPatternIds = [ "novu-reference", "notification-queue-job", "mail-transactional-reference", "preference-opt-marker", "tenant-user-workspace-marker", "sse-stream-marker", "direct-notification-model", ]; function notificationBoundaryArgs(gateInventory = gates) { const gate = gateInventory.find((candidate) => candidate.id === "vitest-notification-boundary"); return gate?.args ?? []; } describe("verify-notification-boundary-baseline", () => { it("defines the Notification Boundary non-E2E baseline gates and report path", () => { expect(reportPath).toMatch(/\.tc\/baselines\/notification-boundary\/baseline-health\.md$/); expect(gates.map((gate) => gate.id)).toEqual(["typecheck", "lint", "vitest-notification-boundary", "notification-inventory"]); expect(notificationBoundaryArgs().join(" ")).toBe( "exec vitest run packages/queue/src/producers.test.ts packages/mail/src/queue.test.ts apps/web/app/modules/emails/services/TransactionalEmailQueue.server.test.ts apps/web/app/modules/notifications/services/.server/NotificationService.test.ts", ); expect(notificationBoundaryArgs()).toEqual(expect.arrayContaining(requiredNotificationTargets)); expect(gates.some((gate) => gate.args?.some((arg) => /playwright|cypress|browser|e2e/i.test(arg)))).toBe(false); }); it("protects focused notification tests from being dropped from the Vitest boundary gate", () => { for (const target of requiredNotificationTargets) { const inventoryWithoutTarget = gates.map((gate) => gate.id === "vitest-notification-boundary" ? { ...gate, args: gate.args.filter((arg) => arg !== target) } : gate, ); expect(notificationBoundaryArgs(inventoryWithoutTarget)).not.toEqual(expect.arrayContaining([target])); } expect(notificationBoundaryArgs()).toEqual(expect.arrayContaining(requiredNotificationTargets)); }); it("wires read-only notification inventory roots and required pattern families", () => { expect(notificationInventoryScanRoots).toEqual(["apps/web/app", "apps/api/src", "packages", "prisma"]); expect(notificationInventoryPatterns.map((pattern) => pattern.id)).toEqual(requiredInventoryPatternIds); }); it("does not count successful gate output as failures", () => { expect(failureCount("lint", "warning only", "", 0)).toBe(0); expect(failureCount("vitest-notification-boundary", "Tests 30 passed", "", 0)).toBe(0); expect(failureCount("notification-inventory", "total matches: 12", "", 0)).toBe(0); }); it("counts failed TypeScript diagnostics conservatively", () => { const output = "src/a.ts(1,1): error TS2307: Cannot find module\nsrc/b.ts(2,2): error TS2322: Type mismatch"; expect(failureCount("typecheck", output, "", 1)).toBe(2); expect(failureCount("typecheck", "Build failed", "", 1)).toBe(1); }); it("counts failed ESLint diagnostics conservatively", () => { expect(failureCount("lint", "✖ 4 problems (3 errors, 1 warning)", "", 1)).toBe(3); expect(failureCount("lint", "2 errors and 0 warnings", "", 1)).toBe(2); expect(failureCount("lint", "Lint crashed", "", 1)).toBe(1); }); it("counts failed Vitest diagnostics conservatively", () => { expect(failureCount("vitest-notification-boundary", "Tests 2 failed | 8 passed", "", 1)).toBe(2); expect(failureCount("vitest-notification-boundary", "Test Files 1 failed | 2 passed", "", 1)).toBe(1); expect(failureCount("vitest-notification-boundary", "Vitest crashed", "", 1)).toBe(1); }); it("renders required Notification Boundary report sections", () => { const report = renderReport([ { id: "notification-inventory", command: "read-only notification inventory", exitCode: 0, durationMs: 10, failureCount: 0, fingerprint: { hash: "abc123", excerpt: "Notification inventory scanned roots: apps/web/app, apps/api/src, packages, prisma" }, }, ]); expect(report).toContain("# Notification Boundary Baseline Health"); expect(report).toContain("non-E2E baseline gates for Notification Boundary baseline"); expect(report).toContain("Novu references, notification queue jobs, transactional mail references"); expect(report).toContain("preference opt-in/opt-out markers, tenant/user/workspace markers, SSE/EventSource/stream markers"); expect(report).toContain("## notification-inventory"); expect(report).toContain("Command: `read-only notification inventory`"); expect(report).toContain("Exitcode: 0"); expect(report).toContain("Failure Count: 0"); expect(report).toContain("Output Fingerprint: abc123"); }); });