Files
clean-architecture-frontend…/scripts/lib/ungated-scripts.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

77 lines
3.1 KiB
TypeScript

import { z } from "zod";
import { reachablePackageScripts } from "./package-script-graph.ts";
/**
* 12-04. A verification package script protects nothing unless a CI gate runs
* it. `ungated-tests.ts` covers test files; this covers the scripts. A script
* of a verification family is gated when a gate command reaches it through
* the package script graph, or when it only re-runs Vitest paths a gate
* already runs. Anything else needs a reasoned entry in
* config/ci/ungated-scripts.json.
*/
export const UNGATED_SCRIPTS_PATH = "config/ci/ungated-scripts.json";
const VERIFICATION_SCRIPT = /^(?:check|verify|test|drill|review|scan):/u;
const ungatedScriptsSchema = z
.object({
schemaVersion: z.literal(1),
entries: z.array(
z
.object({
script: z.string().regex(VERIFICATION_SCRIPT),
reason: z.string().trim().min(1, "exclusion reason is required"),
})
.strict(),
),
})
.strict();
export type UngatedScriptExclusion = Readonly<{ script: string; reason: string }>;
export function parseUngatedScriptExclusions(value: unknown): readonly UngatedScriptExclusion[] {
return ungatedScriptsSchema.parse(value).entries;
}
/** Every segment is a Vitest run whose paths all lie inside gated paths. */
function rerunsGatedTests(command: string, gatedTestPaths: readonly string[]): boolean {
const gated = (target: string) =>
gatedTestPaths.some((gatedPath) => target === gatedPath || target.startsWith(`${gatedPath}/`));
return command.split("&&").every((segment) => {
const tokens = segment.trim().split(/\s+/u);
const run = tokens.findIndex(
(token, index) => token === "run" && /(?:run-vitest\.ts|vitest)$/u.test(tokens[index - 1] ?? ""),
);
if (run < 0) return false;
const paths = tokens.slice(run + 1).filter((token) => !token.startsWith("-"));
return paths.length > 0 && paths.every((target) => gated(target.replace(/\/$/u, "")));
});
}
export function ungatedScriptFailures(input: Readonly<{
scripts: Readonly<Record<string, string>>;
entryScripts: readonly string[];
gatedTestPaths: readonly string[];
exclusions: readonly UngatedScriptExclusion[];
}>): string[] {
const reached = new Set(reachablePackageScripts(input.scripts, input.entryScripts));
const gated = (script: string) =>
reached.has(script) || rerunsGatedTests(input.scripts[script] ?? "", input.gatedTestPaths);
const excluded = new Set(input.exclusions.map(({ script }) => script));
const failures = Object.keys(input.scripts)
.filter((script) => VERIFICATION_SCRIPT.test(script) && !gated(script) && !excluded.has(script))
.sort()
.map((script) =>
`verification script is not reached by any CI gate command and is not in ${UNGATED_SCRIPTS_PATH}: ${script}`
);
// An entry for a script a removal deleted is harmless; one for a script a
// gate now reaches would hide the next regression, so it has to go.
for (const { script } of input.exclusions) {
if (input.scripts[script] !== undefined && gated(script)) {
failures.push(`ungated script exclusion is stale; a CI gate reaches it: ${script}`);
}
}
return failures;
}