Files
clean-architecture-frontend…/tests/unit/feature-scaffold-drill.test.ts
T
DongHyeonka b4210753f0 perf(scripts): FE-GATE-020 드릴이 같은 시험 파일을 한 복사본에서 두 번 돌지 않는다
문제: FE-GATE-020이 desktop merge 단계 27.4분 중 17.2분이다. 그 안에서
같은 시험 파일이 한 복사본에서 두 번 돈다.
- feature-scaffold 드릴은 merge 단계 명령을 차례로 돌며 test:runtime-schema
  ·test:unit·test:contract·test:component·test:integration을 돌고, 바로
  FE-GATE-005의 test:coverage가 같은 경로를 다시 돈다(약 80초).
- feature-removal 확인은 test:all을 돈 뒤 test:coverage를 돈다. test:all의
  경로는 tests/recipes 말고 모두 coverage 안에 있다(약 110초).

고른 방법:
- scaffold 드릴 제외 목록에 다섯 suite를 넣는다. 그 복사본의 merge 단계에
  test:coverage가 있을 때만 뺀다. 없으면 plain으로 다시 돈다.
- feature-removal은 test:coverage 다음에 coverage 밖에 남는 suite
  (REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE = test:recipes)만 돈다.
- tests/unit/removal-drill-test-paths.test.ts가 경로를 package.json에서
  읽어 「뺀 suite의 경로 ⊆ coverage 경로」, 「test:all 경로 ⊆ coverage +
  남긴 suite」, coverage가 없으면 다시 도는 것을 지킨다.
- 버린 대안: FE-GATE-005 자체의 plain test:unit·test:contract를 빼고
  coverage 실행에서 junit을 나누기. 그 script가 어느 게이트에서도 안 돌게
  되어 ungated 목록을 늘려야 한다(게이트 기준을 낮추는 일).

위험·한계: plain 실행만의 차이(coverage 계측 없음, worker 수 기본값,
tests/platform을 test:platform처럼 파일 차례로 도는 것)는 드릴에서 더
보지 않는다. merge 단계의 FE-GATE-005가 coverage로 같은 파일을 병렬로
돌고 있어 그 모양이 이미 게이트다. 선택 기능 제거 드릴 셋의 test:all은
그대로다(그 드릴은 coverage를 돌지 않는다).

검증(desktop, 38c0dc7d 위): removal-drill-test-paths·feature-scaffold-drill
·example-feature-rules·test-all-paths·fixture-node-modules 20개 통과,
check:types·eslint rc=0. 변이 두 개(남긴 suite 목록 비우기, test:unit에
tests/recipes 더하기)에서 각각 해당 시험이 실패.
2026-11-11 23:46:41 +09:00

100 lines
4.8 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);
}
// test:unit, test:contract and the other plain suites run inside
// test:coverage (tests/unit/removal-drill-test-paths.test.ts).
expect(commands.map(({ script }) => script)).toEqual(expect.arrayContaining([
"check:types", "lint", "test:coverage", "build", "check:bundle",
"test:recipes", "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)");
});
});