Files
clean-architecture-frontend…/scripts/check-ci-gating.ts
DongHyeonka 32982e5547 ci(gates): FE-GATE-029가 --grep-invert 실행마다 같은 testDir의 --grep 짝을 요구한다
문제: FE-GATE-029(check:ci:gating)는 게이트가 닿는 `playwright test` 실행마다
설정의 testDir을 gated로 셌고, `--grep`·`--grep-invert`·파일 필터를 읽지
않았다. FE-GATE-009의 test:a11y에서 Playwright 실행을 빼도 029는 통과했다.
test:e2e(FE-GATE-008)가 tests/e2e를 `--grep-invert @a11y`로 돌기 때문에, 시험이
모두 @a11y인 tests/e2e/accessibility.spec.ts는 어느 게이트에서도 돌지 않는다.
설정도 `--config X`만 읽어서 `-c X`·`--config=X` 실행은 e2e 설정의 testDir로
셌다. result-paths 시험은 세 꼴을 따로 읽고 있었다.

고른 방법: 시험 본문이 아니라 게이트가 도는 인자만 본다. testDir 하나는
필터 없는 gated 실행이 있거나, `--grep-invert P` 실행마다 같은 testDir을
`--grep P`(같은 글자)로 도는 gated 실행이 있을 때만 gated다. 파일 필터가 있는
실행, `--grep`·`--grep-invert`를 합쳐 둘 이상 쓴 실행, 설정(또는 그 설정이 상대
경로로 import한 설정)의 글자에 `grep`·`grepInvert` 속성이 있는 실행은 나누지
않는 부분 실행으로 센다. 그런 testDir 아래 게이트 밖 파일은 testDir 한 줄로
알린다: testDir, 실행과 그 script, 빠진 짝. 인자 parser는
`scripts/lib/playwright-test-args.ts` 하나로 두고 029와 result-paths 시험이
같이 쓴다. `docs/operations/ci-quality-gates.md`의 029 설명에
이 규칙을 적는다.

버린 안:
- `playwright test --list --reporter=json`으로 Playwright에 묻기: 시험 파일을
  in-process로 불러 생성물(`src/features/*` 색인)에 기대고, 실행마다 수 초가 든다.
- Babel로 시험 파일을 읽어 Playwright grep 판정을 흉내 내기: 제목 경로, 태그,
  forceRegExp 같은 Playwright 1.62 내부 규칙을 템플릿 안에 다시 만든다. 버전에
  묶이고, 템플릿 리터럴 제목 때문에 파생 서비스에서 거짓 실패가 난다.

위험·한계: 짝은 글자로만 맞춘다. 정규식으로 같은 뜻이라도 글자가 다르면
실패한다(실패 쪽). 모르는 옵션 뒤 맨 토큰은 파일 필터로 센다(실패 쪽).
`--project=X`·`--shard=X`처럼 `=`로 붙인 다른 옵션과 설정의 testMatch·
testIgnore는 읽지 않는다. 필터는 package script 글자에서만 읽어, 게이트
계약의 `args`로 붙는 인자는 보지 않는다(전에도 읽지 않았다). Playwright 설정
파일의 주석에 `grep:` 꼴을 쓰면 부분 실행으로 센다.

검증: 고치기 전 desktop에서 009의 실행을 뺀 변이로 FE-GATE-029 rc=0, 새 단위
시험 17개 실패(변이 저장소에서 tests/e2e를 셈, -c·--config= 못 읽음, 짝 없는
실행을 셈). 고친 뒤 단위 시험 3파일 61개 통과, 같은 변이에서 FE-GATE-029 rc=1
(「Playwright testDir tests/e2e is only partly run … has no gated
`--grep @a11y` run to pair with」). 리뷰에서 나온 `-cX`·`-gP`·`-GP` 꼴: parser만
고치기 전으로 되돌린 변이에서 새 시험 4개 실패, 되돌리면 61개 통과. 확인
리뷰에서 나온 `-xGP` 꼴(값 없는 `-x` 뒤에 붙인 옵션)과 `--grep-invert`를 두 번
쓴 실행: 두 고침을 되돌린 변이에서 새 시험 6개 실패, 되돌리면 67개 통과.
2026-11-21 00:36:39 +09:00

80 lines
3.2 KiB
TypeScript

import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { loadCiGateContract } from "./contracts/ci-gates.ts";
import { loadProductCiOverlay } from "./contracts/product-ci-overlay.ts";
import {
gatedTestPaths,
gatedTestTargets,
listTestFiles,
parseUngatedTestExclusions,
playwrightTestDirGaps,
ungatedTestFailures,
UNGATED_TESTS_PATH,
} from "./lib/ungated-tests.ts";
import {
parseUngatedScriptExclusions,
ungatedScriptFailures,
UNGATED_SCRIPTS_PATH,
} from "./lib/ungated-scripts.ts";
/**
* 12-04. Every test file and every verification package script is reached by
* a gate command of any stage, or config/ci/ungated-tests.json and
* config/ci/ungated-scripts.json say why not. It checks how the gates are
* wired, not the change, so it runs in the main stage (FE-GATE-029) after a
* merge (design-docs repo-structure/03-ci.md F2); check:ci keeps the contract
* and workflow checks on every pull request.
*/
const contract = await loadCiGateContract(process.cwd());
// 1103/12-07. The product's merge gates are entry scripts of CI as well.
const { mergeGates: productGates } = await loadProductCiOverlay(process.cwd());
const productGateScripts = productGates.map(({ script }) => script);
const packageScripts =
(JSON.parse(await readFile("package.json", "utf8")) as { scripts?: Record<string, string> }).scripts ?? {};
const failures: string[] = [];
// 12-04: every test file runs in a gate, or config/ci/ungated-tests.json says why not.
try {
const entryScripts = [...contract.commands.map(({ script }) => script), ...productGateScripts];
const readConfig = (file: string) => readFileSync(file, "utf8");
failures.push(
...ungatedTestFailures({
testFiles: await listTestFiles(process.cwd()),
gatedPaths: gatedTestTargets(packageScripts, entryScripts, readConfig),
exclusions: parseUngatedTestExclusions(
JSON.parse(await readFile(UNGATED_TESTS_PATH, "utf8")),
),
// fe-ci-next-12: a testDir the gates run only part of, with the runs that leave the rest out.
playwrightGaps: playwrightTestDirGaps(packageScripts, entryScripts, readConfig),
}),
);
} catch (error) {
failures.push(`ungated test check could not run: ${error instanceof Error ? error.message : String(error)}`);
}
// 12-04: every verification package script is reached by a gate, or
// config/ci/ungated-scripts.json says why not.
try {
const entryScripts = [...contract.commands.map(({ script }) => script), ...productGateScripts];
failures.push(
...ungatedScriptFailures({
scripts: packageScripts,
entryScripts,
gatedTestPaths: gatedTestPaths(packageScripts, entryScripts, (file) => readFileSync(file, "utf8")),
exclusions: parseUngatedScriptExclusions(
JSON.parse(await readFile(UNGATED_SCRIPTS_PATH, "utf8")),
),
}),
);
} catch (error) {
failures.push(`ungated script check could not run: ${error instanceof Error ? error.message : String(error)}`);
}
if (failures.length > 0) {
process.stderr.write(`CI gating failed:\n${failures.join("\n")}\n`);
process.exit(1);
}
process.stdout.write("CI gating: every test file and verification script is gated or excluded with a reason PASS\n");