Files
clean-architecture-frontend…/tests/unit/feature-scaffold-drill.test.ts
T
donghyeon.kang f6b2b96c53 ci(gates): 검사기 자기 시험과 gating 검사를 main 단계로 내리고 계약 기준선을 지운다
merge 단계(=PR)가 변경이 아니라 검사기 자신을 시험하는 명령까지 돈다.
검사기가 나쁜 입력을 거부하는지 보는 `*:fixture` 명령 15개, 모든 시험
파일과 검증 script가 게이트에 걸렸는지 보는 ungated 검사, CI 계약의
개수·해시 기준선(`config/ci/contract-baseline.json`)이다. 기준선은 게이트
명령 하나를 더하거나 빼도 OWNER·REASON을 붙여 다시 받아야 했다.
소유자 결정(2026-09-16)은 개수·배선 검사를 main 단계에 두는 것이다.

고른 방법(design-docs repo-structure/03-ci.md 7.3절 F2, README.md 3.3절,
소유자 승인 2026-11-07):
- 새 게이트 FE-GATE-029 `checker-self-tests`, 새 단계 `main`
  (`MAIN_READY`, 승격을 막지 않는다), 새 job `main_gate`. 브랜치 push와
  `workflow_dispatch`(stage=main)에서만 돈다. PR과 태그에서는 돌지 않는다.
- FE-GATE-001·005·008·010·013의 `*:fixture` 명령 15개와 그 증거
  산출물 10개를 FE-GATE-029로 옮긴다.
- `check:ci`의 ungated 검사를 `scripts/check-ci-gating.ts`
  (`check:ci:gating`)로 떼어 FE-GATE-029에 둔다. `check:ci`는 계약·
  workflow 검사만 PR에서 돈다.
- 기준선 파일, `update:ci-contract-baseline`, 그 검사를 지운다(소유자
  결정). 계약 모양은 ci-gates.ts의 의미 검사가 지킨다. 개수를 고정하던
  단위 시험의 개수 단언도 뺐다.

남긴 것: 음성 타입 fixture(`check:types:fixtures`, FE-GATE-003)는
이름이 `*:fixture`여도 merge에 둔다. 검사기가 아니라 src의 포트·계약
타입을 시험한다. `TelemetryPort.emit`을 넓히는 변경을 PR에서 막는다(정리
3단계 9.3절 변이로 확인). merge 단계 명령 참조 64 → 49.

위험: 검사기를 망가뜨린 PR은 merge를 통과하고 main에서 빨개진다. 그
대가로 PR이 검사기 자기 시험을 기다리지 않는다(설계 7.5절의 같은 교환).
FE-GATE-029의 명령이 앞 게이트 산출물 없이 새 checkout에서 도는지는
desktop에서 따로 확인했다(PR 본문).

검증(desktop): check:ci, check:ci:gating, check:types, CI 시험 통과.
merge 단계·FE-GATE-029 실행 결과는 PR 본문에 적는다.

Refs: design-docs repo-structure/03-ci.md 7.3·7.4절, README.md 3.3절
2026-11-08 21:56:37 +09:00

98 lines
4.7 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import {
SCAFFOLD_DRILL_EXCLUDED_SCRIPTS,
scaffoldDrillCommands,
} from "../../scripts/lib/feature-scaffold-drill.ts";
// 1103/12-02. The scaffold drill claimed "every merge gate" and ran 15
// hand-picked commands of the 88 in the merge stage.
describe("feature scaffold drill commands", () => {
it("are the merge stage minus the named exclusions, each command once", async () => {
const contract = await loadCiGateContract(process.cwd());
const merge = contract.stages.find(({ id }) => id === "merge")!;
const mergeCommandIds = new Set(
merge.gateIds.flatMap((gateId) => contract.gates.find(({ id }) => id === gateId)!.commandIds),
);
const commands = scaffoldDrillCommands(contract);
const runCommandIds = commands.map(({ name }) => name.split(":").slice(1).join(":"));
expect(new Set(runCommandIds).size).toBe(runCommandIds.length);
for (const commandId of mergeCommandIds) {
const command = contract.commands.find(({ id }) => id === commandId)!;
expect(
runCommandIds.includes(commandId) || Object.hasOwn(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, command.script),
commandId,
).toBe(true);
}
expect(commands.map(({ script }) => script)).toEqual(expect.arrayContaining([
"check:types", "lint", "test:unit", "test:coverage", "build", "check:bundle",
"test:contract", "test:runtime-schema", "check:request-fanout", "build:release-candidate",
]));
for (const reason of Object.values(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS)) {
expect(reason.length).toBeGreaterThan(10);
}
});
// The checkers' negative fixtures moved to the main stage (FE-GATE-029) on
// 2026-11-08, so the merge stage has none; a probe stands in for one.
it("keeps a negative fixture's registered exit and diagnostic", async () => {
const contract = structuredClone(await loadCiGateContract(process.cwd()));
contract.commands.push({
id: "check-probe-fixture",
script: "check:probe:fixture",
expect: "fail",
expectedExitCode: 1,
expectedDiagnosticId: "probe failed:",
} as never);
contract.gates.find(({ id }) => id === "FE-GATE-010")!.commandIds.push("check-probe-fixture");
expect(scaffoldDrillCommands(contract).find(({ script }) => script === "check:probe:fixture"))
.toMatchObject({ expectation: { kind: "fail", expectedExitCode: 1, expectedDiagnosticId: "probe failed:" } });
});
it("runs a command added to the merge stage without an edit to the drill", async () => {
const contract = structuredClone(await loadCiGateContract(process.cwd()));
contract.commands.push({ id: "check-probe", script: "check:probe", expect: "pass" } as never);
contract.gates.find(({ id }) => id === "FE-GATE-010")!.commandIds.push("check-probe");
expect(scaffoldDrillCommands(contract).map(({ name }) => name)).toContain("FE-GATE-010:check-probe");
});
it("refuses an exclusion for a command the contract runs outside the merge stage", async () => {
const contract = await loadCiGateContract(process.cwd());
const merge = new Set(contract.stages.find(({ id }) => id === "merge")!.gateIds);
const mergeCommandIds = new Set(
contract.gates.filter(({ id }) => merge.has(id)).flatMap(({ commandIds }) => commandIds),
);
const mergeScripts = new Set(
contract.commands.filter(({ id }) => mergeCommandIds.has(id)).map(({ script }) => script),
);
const outside = contract.commands.find(({ script }) => !mergeScripts.has(script))!;
expect(() => scaffoldDrillCommands(contract, {
...SCAFFOLD_DRILL_EXCLUDED_SCRIPTS,
[outside.script]: "not in the merge stage",
})).toThrow(`outside the merge stage: ${outside.script}`);
});
// A removal drill prunes its capability's commands from the contract, and
// this file runs inside that fixture too.
it("accepts an exclusion whose command the contract no longer has", async () => {
const contract = structuredClone(await loadCiGateContract(process.cwd()));
const removed = contract.commands.find(({ script }) =>
Object.hasOwn(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, script)
)!;
contract.commands = contract.commands.filter(({ id }) => id !== removed.id);
for (const gate of contract.gates) {
gate.commandIds = gate.commandIds.filter((id) => id !== removed.id);
}
expect(() => scaffoldDrillCommands(contract)).not.toThrow();
});
it("is what test:feature-scaffold runs", async () => {
const drill = await readFile("scripts/test-feature-scaffold.ts", "utf8");
expect(drill).toContain("scaffoldDrillCommands(");
expect(drill).toContain("loadCiGateContract(fixtureRoot)");
});
});