Files
clean-architecture-frontend…/tests/unit/feature-scaffold-drill.test.ts
DongHyeonka 35b60a049a fix(tests): 드릴 경로 시험이 선택 recipe를 지운 사본에서도 통과한다
문제: b4210753이 더한 removal-drill-test-paths 시험과 고친
feature-scaffold-drill 시험이 test:recipes가 있다고 가정한다. FE-GATE-020의
optional-recipe-removal 드릴은 recipe를 지운 사본에서 test:all을 돌고,
그 사본의 package.json에는 test:recipes가 없어 두 시험이 실패한다
(desktop merge 단계, 2d3e5889).

고른 방법: 드릴 코드(scripts/test-sample-removal.ts)처럼 사본의
package.json에 남은 suite만 「coverage 밖」으로 본다. scaffold 드릴 시험의
기대 목록에서는 test:recipes를 뺀다(그 드릴의 다른 기대처럼 사본에 늘
있는 명령만 둔다).

위험·한계: test:recipes가 없는 사본에서는 「coverage 밖 suite」 시험이
아무것도 보지 않는다. 그 사본은 그 경로 자체가 없다.

검증: desktop 묶음(w2fe-p4)의 test:optional-recipe-removal과 merge 단계.
2026-11-12 19:51:54 +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",
"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)");
});
});