문제: fanout 검사의 실패 줄은 `FAIL <file>:<line> <call> inside <context>`뿐이라, 제품 팀은 메시지만 보고 커서 runtime이나 검토 주석이라는 두 방법을 알 수 없었다. `// fanout-reviewed:` 주석으로 넘긴 호출 수도 출력하지 않았고, 허용 fixture는 bulk 읽기 하나였다(0929 결정 (가)를 하지 않았다). 고친 것: 실패 줄이 기능 `adapters/`의 `createCursorPaginationRuntime`과 같은 줄의 `// fanout-reviewed: <이유>`를 함께 적는다. 결과 줄과 fixture 줄이 검토된 예외의 수와 위치·이유를 적는다. 허용 fixture에 주석 달린 커서 루프를 더하고, fixture 실행은 그것이 예외로 세어져야 통과한다. 머리 주석과 `docs/operations/ci-quality-gates.md`에 미탐 범위를 적었다. 위험·한계: 휴리스틱 자체(receiver 이름)는 그대로다(1105의 재설계 (나)는 하지 않았다). 검증: desktop `node scripts/run-vitest.ts run tests/architecture/request-fanout.test.ts` 통과. 검사기를 기준 커밋으로 되돌리면 새 시험 셋이 실패한다. Refs: 0929/12-01
73 lines
3.3 KiB
TypeScript
73 lines
3.3 KiB
TypeScript
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
checkRequestFanoutFixtures,
|
|
findRequestFanout,
|
|
formatFanoutViolation,
|
|
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([]);
|
|
expect(allowed.reviewed).toEqual([
|
|
expect.objectContaining({
|
|
file: "tests/fixtures/architecture/request-fanout/allowed/reviewed-cursor-loop.ts",
|
|
call: "gateway.page()",
|
|
reason: "cursor pages, bounded by maxPages",
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("names the dispatch and the repeating construct", async () => {
|
|
const violations = await findRequestFanout(
|
|
"inline.ts",
|
|
"export const load = (api: { get(id: string): Promise<unknown> }, 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<void> }) {\n for (let i = 0; i < 2; i += 1) await http.execute(); // fanout-reviewed: bounded 2-step handshake\n}\n",
|
|
);
|
|
expect(violations).toEqual([]);
|
|
});
|
|
|
|
// 0929/12-01. The failure line named only the call, so a product team saw
|
|
// neither the cursor runtime nor the reviewed-exception comment, and the
|
|
// result line hid how many calls a comment let through.
|
|
it("tells the author both ways out on the failure line", async () => {
|
|
const [violation] = await findRequestFanout(
|
|
"inline.ts",
|
|
"export const load = (api: { get(id: string): Promise<unknown> }, ids: string[]) =>\n Promise.all(ids.map((id) => api.get(id)));\n",
|
|
);
|
|
const line = formatFanoutViolation(violation!);
|
|
expect(line).toMatch(/^FAIL inline\.ts:2 api\.get\(\) inside \.map\(\) callback: /u);
|
|
expect(line).toContain("createCursorPaginationRuntime (src/adapters/query-cache)");
|
|
expect(line).toContain("`// fanout-reviewed: <reason>` on the call's line");
|
|
});
|
|
|
|
it("counts and lists the reviewed exceptions in the fixture result line", async () => {
|
|
const result = await checkRequestFanoutFixtures(path.resolve("."));
|
|
expect(result.ok).toBe(true);
|
|
expect(result.line).toMatch(/allowed 0 violations and 1 reviewed exception \(tests\/fixtures\/architecture\/request-fanout\/allowed\/reviewed-cursor-loop\.ts:\d+ cursor pages, bounded by maxPages\) PASS/u);
|
|
});
|
|
});
|