import path from "node:path"; import { describe, expect, it } from "vitest"; import { findRequestFanout, scanRequestFanout, } from "../../scripts/check-request-fanout.ts"; describe("no per-row transport loop (frontend N+1 source gate)", () => { it("finds no per-row dispatch in feature code or application use cases", async () => { const result = await scanRequestFanout(path.resolve(".")); expect(result.files).toBeGreaterThan(0); expect(result.violations).toEqual([]); }); it("rejects every forbidden fixture and accepts the bulk-read fixture", async () => { const root = path.resolve("."); const forbidden = await scanRequestFanout(root, ["tests/fixtures/architecture/request-fanout/forbidden"]); const allowed = await scanRequestFanout(root, ["tests/fixtures/architecture/request-fanout/allowed"]); expect(new Set(forbidden.violations.map((violation) => violation.file)).size).toBe(forbidden.files); expect(forbidden.files).toBe(3); expect(allowed.violations).toEqual([]); }); it("names the dispatch and the repeating construct", async () => { const violations = await findRequestFanout( "inline.ts", "export const load = (api: { get(id: string): Promise }, ids: string[]) =>\n Promise.all(ids.map((id) => api.get(id)));\n", ); expect(violations).toEqual([ { file: "inline.ts", line: 2, call: "api.get()", context: ".map() callback" }, ]); }); it("honours an explicit reviewed exception on the call line", async () => { const violations = await findRequestFanout( "reviewed.ts", "export async function f(http: { execute(): Promise }) {\n for (let i = 0; i < 2; i += 1) await http.execute(); // fanout-reviewed: bounded 2-step handshake\n}\n", ); expect(violations).toEqual([]); }); });