Files
clean-architecture-frontend…/tests/unit/ungated-scripts.test.ts
T
DongHyeonka 98b9682241 chore(scripts): 쓰지 않는 npm script 4개를 지우고 scan:도 게이트 검사한다 (12-05)
문제
package.json에 어디서도 부르지 않는 script 4개가 있다.
- scan:security:fixture: FE-GATE-013은 이것 대신 check:security:fixtures를
  돈다. supply-chain.test.ts는 "게이트에 없어야 한다"고 단언하는데 script는
  남아 있다. 게이트 밖 script 검사는 check|verify|test|drill|review만 봐서
  scan:을 놓쳤다.
- build:profile: 이름과 달리 generate-runtime-config.ts만 돈다.
- generate:contract-set: 참조 0건.
- build:app-only: vite build와 매니페스트만 만든다. build-frontend.ts의
  계약 세트·런타임 설정·Service Worker 단계가 빠진 dist가 나온다. 참조는
  product-index-entrypoints 테스트의 진입점 목록 하나다.
참조 확인(새 기준 298201f, docs/reviews 제외): package.json 정의와 위 두
테스트 말고는 config/ci/gates.json, 생성 workflow, scripts, docs 어디에도
없다. 아래 세 script가 부르던 파일(generate-runtime-config.ts,
generate-contract-set.ts, generate-build-manifest.ts)은 build-frontend.ts가
그대로 부른다.

고른 방법
- 네 script를 지우고 진입점 목록에서 build:app-only를 뺀다.
- VERIFICATION_SCRIPT에 scan을 더한다. 게이트가 닿지 않는 scan:* script는
  ungated-scripts.json 항목 없이는 check:ci에서 실패한다. 지금 남은
  scan:security는 build:release-candidate를 거쳐 게이트가 닿는다.
- docs/operations/ci-quality-gates.md의 접두어 목록에 scan:*을 더한다.
버린 대안
- build:app-only를 build:vite-only로 이름만 바꾸기: 남길 사용처를 찾지
  못했다.
- 접두어 대신 "게이트 밖 모든 script는 예외 목록에": dev·storybook·
  update:*까지 목록에 올라가 목록이 커진다(리뷰 대안 비교와 같다).
- check:feature-index 정리(리뷰 개선 (4)): 지우기와 이유 문구 고치기 중
  하나를 고르는 일이라 이번에 하지 않았다.

위험·한계
- 개인 습관으로 이 script를 쓰던 사람은 build-frontend.ts나 node
  scripts/...를 직접 불러야 한다.
- 게이트 명령은 바뀌지 않아 CI 계약 기준선은 그대로다.

검증
- RED: 새 테스트 "rejects a scan script that no gate reaches"가 실패
  (expected [ …(2) ] to deep equally contain '…: scan:orphan'). 정규식만
  넓히면 저장소 검사 "reaches every verification script …"가
  scan:security:fixture 한 건으로 실패.
- GREEN: ungated-scripts·product-index-entrypoints·supply-chain·
  ci-workflow-generation 4파일 457/457 통과. check:ci의 세 단계를 pnpm
  없이 직접 실행: generate-artifact-schemas --check PASS,
  check-ci-contract.ts PASS(27 gates), generate-ci-workflow --check PASS.
  tsc(tsconfig.node, tsconfig.test), 바꾼 파일 eslint 통과.

Refs: docs/reviews/2026-11-01-maturity-review/12-guardrails-ci.md 12-05
2026-11-01 22:16:26 +09:00

118 lines
4.3 KiB
TypeScript

import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import {
parseUngatedScriptExclusions,
ungatedScriptFailures,
UNGATED_SCRIPTS_PATH,
} from "../../scripts/lib/ungated-scripts.ts";
import { gatedTestPaths } from "../../scripts/lib/ungated-tests.ts";
/**
* 12-04. Test files had an orphan check; package scripts did not. A `check:*`
* script that no gate reaches (check:remediation-ledger, and the checks only
* verify:extreme-scale ran) could break without anyone noticing.
*/
async function repositoryInputs() {
const contract = await loadCiGateContract(process.cwd());
const packageDocument = JSON.parse(await readFile("package.json", "utf8")) as {
scripts: Record<string, string>;
};
const entryScripts = contract.commands.map(({ script }) => script);
return {
scripts: packageDocument.scripts,
entryScripts,
gatedTestPaths: gatedTestPaths(packageDocument.scripts, entryScripts, (file) =>
readFileSync(file, "utf8"),
),
exclusions: parseUngatedScriptExclusions(
JSON.parse(await readFile(UNGATED_SCRIPTS_PATH, "utf8")),
),
};
}
const fixture = {
scripts: {
gate: "corepack pnpm check:wired && node scripts/run-vitest.ts run tests/unit",
"check:wired": "node scripts/wired.ts",
"check:orphan": "node scripts/orphan.ts",
"check:subset": "node scripts/run-vitest.ts run tests/unit/one.test.ts --reporter=default",
"check:outside": "node scripts/run-vitest.ts run tests/scale/heavy.test.ts",
"lint:fix": "eslint . --fix",
},
entryScripts: ["gate"],
gatedTestPaths: ["tests/unit"],
exclusions: [],
};
describe("ungated verification scripts", () => {
it("reaches every verification script from a CI gate or names why not", async () => {
expect(ungatedScriptFailures(await repositoryInputs())).toEqual([]);
});
it.each(["check:request-fanout", "check:app-build-input", "check:app-build-input:bundle"])(
"gates %s",
async (script) => {
const inputs = await repositoryInputs();
expect(inputs.exclusions.some((entry) => entry.script === script)).toBe(false);
expect(
ungatedScriptFailures({ ...inputs, scripts: { ...inputs.scripts }, exclusions: [] }),
).not.toContainEqual(expect.stringContaining(`: ${script}`));
},
);
it("rejects a check script that no gate reaches", () => {
expect(ungatedScriptFailures(fixture)).toEqual([
`verification script is not reached by any CI gate command and is not in ${UNGATED_SCRIPTS_PATH}: check:orphan`,
`verification script is not reached by any CI gate command and is not in ${UNGATED_SCRIPTS_PATH}: check:outside`,
]);
});
// 12-05: scan:security:fixture stayed in package.json after FE-GATE-013
// replaced it with check:security:fixtures, because scan: was not a
// verification family.
it("rejects a scan script that no gate reaches", () => {
expect(
ungatedScriptFailures({
...fixture,
scripts: { ...fixture.scripts, "scan:orphan": "node scripts/scan.ts" },
}),
).toContainEqual(
`verification script is not reached by any CI gate command and is not in ${UNGATED_SCRIPTS_PATH}: scan:orphan`,
);
});
it("counts a Vitest subset as gated only when a gate runs every path", () => {
const failures = ungatedScriptFailures(fixture);
expect(failures.join("\n")).not.toContain("check:subset");
expect(failures.join("\n")).toContain("check:outside");
});
it("accepts a reasoned exclusion and rejects a stale one", () => {
expect(
ungatedScriptFailures({
...fixture,
exclusions: [
{ script: "check:orphan", reason: "local only" },
{ script: "check:outside", reason: "heavy" },
{ script: "check:wired", reason: "stale" },
// A removal may delete the script; its entry is harmless.
{ script: "check:removed", reason: "gone" },
],
}),
).toEqual([`ungated script exclusion is stale; a CI gate reaches it: check:wired`]);
});
it("requires a reason for every exclusion", () => {
expect(() =>
parseUngatedScriptExclusions({
schemaVersion: 1,
entries: [{ script: "check:orphan", reason: " " }],
}),
).toThrow(/reason/u);
});
});