Files
clean-architecture-frontend…/tests/unit/product-index-entrypoints.test.ts
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

74 lines
2.8 KiB
TypeScript

import { existsSync, readFileSync } from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
// src/.generated is gitignored (R-0): every entry point that loads the product
// index must render it first, or a fresh checkout cannot run the gates.
const GENERATE = "node scripts/generate-product-feature-index.ts && ";
// Entry points the import walk below cannot see (tsc, vite, storybook).
const NON_NODE_ENTRY_SCRIPTS = [
"dev",
"storybook",
"build:storybook",
"check:types:app",
"check:types:node",
"check:types:test",
"check:types:fixture:route-runtime",
"check:types:fixture:page-action",
"check:types:fixture:icon-button",
"check:types:fixture:i18n-key",
"check:types:fixture:i18n-params",
] as const;
const ROOT = process.cwd();
const GENERATED_DIR = path.join(ROOT, "src/.generated");
const RELATIVE_IMPORT =
/(?:import|export)\s[^'"]*?from\s+["'](\.{1,2}\/[^"']+)["']|import\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/gu;
function reachesGeneratedIndex(file: string, seen = new Set<string>()): boolean {
if (seen.has(file) || !existsSync(file)) return false;
seen.add(file);
for (const match of readFileSync(file, "utf8").matchAll(RELATIVE_IMPORT)) {
const resolved = path.resolve(path.dirname(file), match[1] ?? match[2] ?? "");
if (resolved.startsWith(GENERATED_DIR)) return true;
if (reachesGeneratedIndex(resolved, seen)) return true;
}
return false;
}
function packageScripts(): Record<string, string> {
return (JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> })
.scripts;
}
describe("product index entry points", () => {
it("renders the generated index before tsc, vite and storybook entry points", () => {
const scripts = packageScripts();
for (const name of NON_NODE_ENTRY_SCRIPTS) {
expect(scripts[name]?.startsWith(GENERATE), name).toBe(true);
}
});
it("renders the generated index before every node script that imports it", () => {
const missing = Object.entries(packageScripts())
.filter(([, command]) => !command.startsWith(GENERATE))
.filter(([, command]) =>
[...command.matchAll(/node\s+(scripts\/[\w./-]+\.ts)/gu)]
.map((match) => match[1] ?? "")
.filter((entry) => entry !== "scripts/run-vitest.ts")
.some((entry) => reachesGeneratedIndex(path.join(ROOT, entry))),
)
.map(([name]) => name);
expect(missing).toEqual([]);
});
it("renders the generated index before every Vitest run", () => {
const runner = readFileSync("scripts/run-vitest.ts", "utf8");
expect(runner.indexOf("generate-product-feature-index.ts")).toBeGreaterThan(-1);
expect(runner.indexOf("generate-product-feature-index.ts")).toBeLessThan(
runner.indexOf("vitestEntry, ...process.argv"),
);
});
});