113 lines
5.5 KiB
JavaScript
113 lines
5.5 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
failureCount,
|
|
gates,
|
|
realtimeInventoryPatterns,
|
|
realtimeInventoryScanRoots,
|
|
renderReport,
|
|
reportPath,
|
|
} from "./verify-realtime-boundary-baseline.mjs";
|
|
|
|
const requiredRealtimeTargets = [
|
|
"packages/queue/src/producers.test.ts",
|
|
"packages/queue/src/connection.test.ts",
|
|
"apps/web/app/components/notifications/NotificationCenter.test.tsx",
|
|
"apps/api/src/app.test.ts",
|
|
"apps/api/src/openapi.test.ts",
|
|
];
|
|
|
|
const requiredInventoryPatternIds = [
|
|
"sse-eventsource-stream",
|
|
"notification-queue-novu",
|
|
"tenant-user-workspace-marker",
|
|
"auth-permission-marker",
|
|
"cursor-reconnect-last-event-id",
|
|
"streaming-error-backpressure",
|
|
];
|
|
|
|
function realtimeBoundaryArgs(gateInventory = gates) {
|
|
const gate = gateInventory.find((candidate) => candidate.id === "vitest-realtime-boundary");
|
|
return gate?.args ?? [];
|
|
}
|
|
|
|
describe("verify-realtime-boundary-baseline", () => {
|
|
it("defines the Realtime Boundary non-E2E realtime baseline gates and report path", () => {
|
|
expect(reportPath.replaceAll("\\", "/")).toMatch(/\.tc\/baselines\/realtime-boundary\/baseline-health\.md$/);
|
|
expect(gates.map((gate) => gate.id)).toEqual(["typecheck", "lint", "vitest-realtime-boundary", "realtime-inventory"]);
|
|
expect(realtimeBoundaryArgs()).toEqual(["exec", "vitest", "run", ...requiredRealtimeTargets]);
|
|
expect(realtimeBoundaryArgs().join(" ")).not.toMatch(/\b(?:playwright|cypress|browser|e2e|test:e2e)\b/i);
|
|
});
|
|
|
|
it("protects focused realtime and notification boundary tests from being dropped", () => {
|
|
for (const target of requiredRealtimeTargets) {
|
|
const inventoryWithoutTarget = gates.map((gate) =>
|
|
gate.id === "vitest-realtime-boundary" ? { ...gate, args: gate.args.filter((arg) => arg !== target) } : gate,
|
|
);
|
|
|
|
expect(realtimeBoundaryArgs(inventoryWithoutTarget)).not.toEqual(expect.arrayContaining([target]));
|
|
}
|
|
|
|
expect(realtimeBoundaryArgs()).toEqual(expect.arrayContaining(requiredRealtimeTargets));
|
|
});
|
|
|
|
it("wires read-only realtime inventory roots and required pattern families", () => {
|
|
expect(realtimeInventoryScanRoots).toEqual(["apps/web/app", "apps/api/src", "packages", "prisma"]);
|
|
expect(realtimeInventoryPatterns.map((pattern) => pattern.id)).toEqual(requiredInventoryPatternIds);
|
|
|
|
const patternSources = Object.fromEntries(realtimeInventoryPatterns.map(({ id, pattern }) => [id, pattern.source]));
|
|
expect(patternSources["sse-eventsource-stream"]).toMatch(/EventSource|ReadableStream|text\\\/event-stream/);
|
|
expect(patternSources["notification-queue-novu"]).toMatch(/Novu|notificationQueue/);
|
|
expect(patternSources["tenant-user-workspace-marker"]).toMatch(/tenant|workspace|user/);
|
|
expect(patternSources["auth-permission-marker"]).toMatch(/auth|permission/);
|
|
expect(patternSources["cursor-reconnect-last-event-id"]).toMatch(/Last-Event-ID|reconnect|cursor/);
|
|
expect(patternSources["streaming-error-backpressure"]).toMatch(/backpressure|AbortSignal|enqueue/);
|
|
});
|
|
|
|
it("does not count successful command output or legacy inventory findings as failures", () => {
|
|
expect(failureCount("typecheck", "", "", 0)).toBe(0);
|
|
expect(failureCount("lint", "warning only", "", 0)).toBe(0);
|
|
expect(failureCount("vitest-realtime-boundary", "Tests 173 passed", "", 0)).toBe(0);
|
|
expect(failureCount("realtime-inventory", "total matches: 42", "", 1)).toBe(0);
|
|
});
|
|
|
|
it("counts failed TypeScript, ESLint, and Vitest diagnostics conservatively", () => {
|
|
expect(failureCount("typecheck", "src/a.ts(1,1): error TS2307: Cannot find module\nsrc/b.ts(2,2): error TS2322: Type mismatch", "", 1)).toBe(2);
|
|
expect(failureCount("typecheck", "Build failed", "", 1)).toBe(1);
|
|
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("vitest-realtime-boundary", "Tests 2 failed | 8 passed", "", 1)).toBe(2);
|
|
expect(failureCount("vitest-realtime-boundary", "Test Files 1 failed | 2 passed", "", 1)).toBe(1);
|
|
expect(failureCount("unknown-gate", "", "process terminated", 1)).toBe(1);
|
|
});
|
|
|
|
it("renders required Realtime Boundary report sections and non-E2E inventory language", () => {
|
|
const report = renderReport([
|
|
{
|
|
id: "realtime-inventory",
|
|
command: "read-only realtime inventory",
|
|
exitCode: 0,
|
|
durationMs: 10,
|
|
failureCount: 0,
|
|
fingerprint: { hash: "abc123", excerpt: "Realtime inventory scanned roots: apps/web/app, apps/api/src, packages, prisma" },
|
|
},
|
|
]);
|
|
|
|
expect(report).toContain("# Realtime Boundary Baseline Health");
|
|
expect(report).toContain("non-E2E baseline gates for Realtime Boundary baseline");
|
|
expect(report).toContain("executes no E2E/browser gates");
|
|
expect(report).toContain("legacy inventory findings");
|
|
expect(report).toContain("SSE/EventSource/ReadableStream/text-event-stream markers");
|
|
expect(report).toContain("notification service/queue/Novu references");
|
|
expect(report).toContain("tenant/user/workspace identifiers");
|
|
expect(report).toContain("auth/permission markers");
|
|
expect(report).toContain("reconnect/cursor/Last-Event-ID markers");
|
|
expect(report).toContain("streaming error/backpressure markers");
|
|
expect(report).toContain("## realtime-inventory");
|
|
expect(report).toContain("Command: `read-only realtime inventory`");
|
|
expect(report).toContain("Exitcode: 0");
|
|
expect(report).toContain("Failure Count: 0");
|
|
expect(report).toContain("Output Fingerprint: abc123");
|
|
});
|
|
});
|