Files
DongHyeonka 6ceb84740c chore(ci): check:feature-index 예외 이유에 실제 사용처를 적는다 (1101/12-05)
문제
config/ci/ungated-scripts.json의 check:feature-index 이유는 "--check는
로컬 사본이 오래됐다는 것만 알려 줄 수 있다"이다. 쓸모없다는 말로 읽혀
리뷰가 지울 후보로 올렸다. 실제로는 scripts/verify-extreme-scale.ts가
EXTREME_SCALE_GATES 첫 단계로 이 script를 부른다.

고른 방법
- 지우지 않는다. 이유 문구를 "로컬에서 생성 인덱스가 오래됐는지 확인,
  verify:extreme-scale(scripts/verify-extreme-scale.ts)의 첫 단계. 게이트는
  인덱스를 먼저 다시 만들어서 얻는 것이 없다"로 고친다.
- ungated-scripts 테스트가 EXTREME_SCALE_GATES에 이 script가 있고 이유가
  verify:extreme-scale을 적는지 확인한다. verify:extreme-scale이 이
  script를 그만 부르면 실패해서 다시 지울 후보가 된다.
- 12-05의 나머지(script 4개 삭제, scan: 접두어 검사)는 98b9682가 했다.
버린 대안
- check:feature-index 삭제: verify-extreme-scale.ts의 단계 목록과
  tests/scripts/verify-extreme-scale.test.ts를 같이 고쳐야 하고, 로컬에서
  생성 인덱스가 오래됐는지 볼 방법이 없어진다.

위험·한계
- 게이트 명령은 바뀌지 않는다. CI 계약 기준선은 그대로다.

검증
- RED: 새 테스트 "names verify:extreme-scale as the user of
  check:feature-index"가 실패(expected 'The generated indexes
  (src/.generated…' to contain 'verify:extreme-scale').
- GREEN: ungated-scripts·ungated-tests·verify-extreme-scale 31/31 통과.
- check:ci 세 단계를 pnpm 없이 직접 실행: generate-artifact-schemas --check
  PASS, check-ci-contract.ts PASS(27 gates), generate-ci-workflow --check
  PASS. 바꾼 테스트 eslint 통과.

Refs: docs/reviews/2026-11-01-maturity-review/12-guardrails-ci.md 12-05
2026-11-03 01:24:31 +09:00

130 lines
4.9 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";
import { EXTREME_SCALE_GATES } from "../../scripts/verify-extreme-scale.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}`));
},
);
// 1101/12-05: the exclusion said only that the check can tell a developer
// the local copy is stale, which read as a reason to delete it. It stays
// because verify:extreme-scale runs it; if that stops, it can go.
it("names verify:extreme-scale as the user of check:feature-index", async () => {
const { exclusions } = await repositoryInputs();
expect(EXTREME_SCALE_GATES).toContain("check:feature-index");
expect(
exclusions.find(({ script }) => script === "check:feature-index")?.reason,
).toContain("verify:extreme-scale");
});
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);
});
});