FE-GATE-029는 check:design-system:fixture와 check:diagnostics:fixture가 exit 1과 머리말을 내면 통과로 센다. 거절된 파일이 하나만 있어도 그 조건이 채워진다. 그래서 검사기에서 진짜 규칙(TSX의 raw palette·hue mix·inline style, direct console·민감 context)을 지워도 029가 초록이었다. fixture 폴더에서만 도는 표식 규칙(TOOLTIP_ONLY_REQUIRED_INFORMATION, UNKNOWN_DIAGNOSTIC_EVENT)이 자기 파일을 늘 거절했기 때문이다. check-i18n.ts가 하던 파일별 판정을 scripts/lib/fixture-rejection.ts로 옮기고 세 검사기가 같이 쓴다. fixture 모드에서 어느 failure도 이름을 대지 않는 fixture 파일이 있거나 fixture 파일이 하나도 없으면, 그 목록을 찍고 exit 2로 끝난다. 029는 exit 1을 기대하므로 실패한다. 파일 이름은 경로 경계로 맞춘다(a.ts가 a.tsx·b/a.ts에 맞지 않는다). i18n 판정은 endsWith에서 이 판정으로 바뀌어 조금 엄격해진다. 표식 규칙 둘을 지운다. tooltip-only.tsx는 그 표식 말고 거절할 규칙이 없어 지운다. headless-vendor-import.tsx·hue-mix.tsx를 더하고, raw-palette.tsx는 inline style 없이 SVG fill로 바꿔 fixture 하나가 규칙 하나에 걸리게 한다. direct-console.ts에서는 표식 문자열을 뺀다. fe-design-system 스킬이 지운 tooltip 규칙을 있는 것처럼 적던 줄도 고친다. 버린 안: gates.json의 expectedDiagnosticId를 규칙 문구로 좁히기. 항목 범위가 029 정의를 바꾸지 말라고 하고, 규칙이 여럿이라 문구 하나로는 다 못 본다. 한계: 파일마다 「failure가 하나라도 있는지」를 본다. fixture 하나에 서로 다른 규칙 둘이 걸리면 하나를 지워도 다른 하나가 거절한다. 지금 fixture는 규칙 하나씩이고 시험이 failure 목록을 그대로 단언하지만, 새 fixture에 그것을 강제하지는 않는다. check-i18n.ts가 helper를 부르는지 단언하는 시험은 없다(main에도 없다). 시험: design-system-rules.test.ts·fixture-rejection.test.ts가 임시 root에서 검사기를 돌려, fixture마다 기대한 failure만 나오는지와 거절되지 않는 파일을 더하면 exit 2와 그 파일이 찍히는지 본다. helper는 경로 경계· 빈 폴더를 단위로 본다. timeout은 desktop에서 잰 가장 긴 값(test:unit 1,038 ms)이다. design-system 쪽 두 시험(가장 긴 719 ms)은 기존 describe의 3,540 ms 안이다. RED·GREEN은 PR 본문에 적는다. Refs: REV-FE-0002
103 lines
4.4 KiB
TypeScript
103 lines
4.4 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { cp, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
failureNamesFile,
|
|
fixtureRejectionFailure,
|
|
unrejectedFixtureFiles,
|
|
} from "../../scripts/lib/fixture-rejection.ts";
|
|
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
|
|
|
|
// REV-FE-0002. A `*:fixture` command passes on exit 1 and the header, which
|
|
// one rejected file gives; check-i18n, check-design-system and
|
|
// check-diagnostics ask that every fixture file is rejected on its own.
|
|
describe("negative fixture rejection", { timeout: childProcessTimeout(1_038) }, () => {
|
|
describe("failureNamesFile", () => {
|
|
it.each([
|
|
["raw palette value in tests/a.tsx", true],
|
|
["tests/a.tsx mixes colours in hsl; use oklab", true],
|
|
["tests/a.tsx:2 z-index: 50 writes 50 by hand", true],
|
|
["eslint 1:1 message in tests/a.tsx", true],
|
|
["raw palette value in tests/a.tsx.bak", false],
|
|
["raw palette value in other/tests/a.tsx", false],
|
|
["raw palette value in tests/a.tsxx", false],
|
|
["direct console diagnostics bypass", false],
|
|
])("%s names tests/a.tsx: %s", (failure, named) => {
|
|
expect(failureNamesFile(failure, "tests/a.tsx")).toBe(named);
|
|
});
|
|
|
|
it("does not take a file for the longer path it starts", () => {
|
|
expect(failureNamesFile("raw palette value in tests/a.tsx", "tests/a.ts")).toBe(false);
|
|
});
|
|
|
|
it("finds the file after an earlier partial match", () => {
|
|
expect(failureNamesFile("tests/a.tsx.bak and tests/a.tsx", "tests/a.tsx")).toBe(true);
|
|
});
|
|
});
|
|
|
|
it("lists the fixture files no failure names", () => {
|
|
expect(
|
|
unrejectedFixtureFiles(["tests/a.ts", "tests/b.ts", "tests/c.ts"], ["rule one in tests/a.ts", "tests/c.ts:1 rule two"]),
|
|
).toEqual(["tests/b.ts"]);
|
|
});
|
|
|
|
it("passes only when every fixture file is rejected", () => {
|
|
expect(fixtureRejectionFailure("Probe", ["tests/a.ts"], ["rule in tests/a.ts"])).toBeUndefined();
|
|
expect(fixtureRejectionFailure("Probe", ["tests/a.ts", "tests/b.ts"], ["rule in tests/a.ts"])).toBe(
|
|
"Probe fixture was not rejected:\ntests/b.ts\n",
|
|
);
|
|
});
|
|
|
|
it("refuses a fixture folder with no files", () => {
|
|
expect(fixtureRejectionFailure("Probe", [], ["rule in tests/a.ts"])).toBe(
|
|
"Probe fixture was not rejected:\n(no fixture files found)\n",
|
|
);
|
|
});
|
|
|
|
// A rule dropped from check-diagnostics.ts leaves its fixture unrejected:
|
|
// the script exits 2 and FE-GATE-029, which expects exit 1, fails.
|
|
describe("check-diagnostics.ts --fixture", () => {
|
|
const fixtures = "tests/fixtures/diagnostics/forbidden";
|
|
const runFixtureMode = async (extra?: { file: string; source: string }) => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "diagnostics-fixture-"));
|
|
try {
|
|
await cp(fixtures, path.join(root, fixtures), { recursive: true });
|
|
if (extra) await writeFile(path.join(root, fixtures, extra.file), extra.source);
|
|
const result = spawnSync(process.execPath, [path.resolve("scripts/check-diagnostics.ts"), "--fixture"], {
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
});
|
|
const { failures } = JSON.parse(
|
|
await readFile(path.join(root, "artifacts/quality/diagnostics-fixture.json"), "utf8"),
|
|
) as { failures: string[] };
|
|
return { status: result.status, stderr: result.stderr, failures };
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
};
|
|
|
|
it("rejects every forbidden fixture by its own rule", async () => {
|
|
const { status, stderr, failures } = await runFixtureMode();
|
|
expect(status, stderr).toBe(1);
|
|
expect(stderr).toContain("Diagnostics contract failed:");
|
|
expect([...failures].sort()).toEqual([
|
|
`direct console diagnostics bypass in ${fixtures}/direct-console.ts`,
|
|
`sensitive diagnostic or telemetry context in ${fixtures}/raw-context.ts`,
|
|
]);
|
|
});
|
|
|
|
it("exits 2 when a fixture file is not rejected", async () => {
|
|
const { status, stderr } = await runFixtureMode({
|
|
file: "probe.ts",
|
|
source: "export function probe(): number {\n return 1;\n}\n",
|
|
});
|
|
expect(status, stderr).toBe(2);
|
|
expect(stderr).toBe(`Diagnostics fixture was not rejected:\n${fixtures}/probe.ts\n`);
|
|
});
|
|
});
|
|
});
|