Files
clean-architecture-frontend…/tests/unit/feature-scaffold-drill.test.ts
DongHyeonka 31119cb1a8
frontend-quality-gates / merge / static checks (pull_request) Successful in 1m27s
frontend-quality-gates / merge / tests (pull_request) Successful in 4m26s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m8s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
test(ci): 제거 드릴 사본 호환을 위해 scaffold 드릴 명령 길이 고정을 뺀다
문제:
FE-GATE-030의 test:optional-recipe-removal 사본은 선택 recipe 명령 셋을
제거한 계약에서 tests/unit/feature-scaffold-drill.test.ts를 실행하므로
명령 개수 29를 하드코딩한 단언이 26개로 실패한다.

고른 방법과 버린 대안:
- 고정 길이 29 대신 비어 있지 않음과 자기 스크립트 미포함을 단언하고,
  FE-GATE-020을 merge 단계로 되돌렸을 때의 명령 목록과 동등함을 비교한다.

위험·한계:
- 단위 시험만 바꾸며 런타임 동작과 선택 명령 목록은 변하지 않는다.

검증:
- laptop-gate tests/unit/feature-scaffold-drill.test.ts rc=0 (7 passed)

Refs: CI-FE-0005
2026-12-04 08:03:27 +09:00

120 lines
5.9 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,
SCAFFOLD_DRILL_SELF_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);
}
// The plain suites the merge stage still runs (runtime-schema, component,
// integration) 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 selfScripts = new Set<string>(SCAFFOLD_DRILL_SELF_SCRIPTS);
const outside = contract.commands.find(({ script }) => !mergeScripts.has(script) && !selfScripts.has(script))!;
expect(() => scaffoldDrillCommands(contract, {
...SCAFFOLD_DRILL_EXCLUDED_SCRIPTS,
[outside.script]: "not in the merge stage",
})).toThrow(`outside the merge stage: ${outside.script}`);
});
it("keeps FE-GATE-020's own drill scripts excluded even when FE-GATE-020 lives in main or moves back to merge", async () => {
const contract = structuredClone(await loadCiGateContract(process.cwd()));
const commandsInMain = scaffoldDrillCommands(contract);
expect(commandsInMain.length).toBeGreaterThan(0);
for (const script of SCAFFOLD_DRILL_SELF_SCRIPTS) {
expect(Object.hasOwn(SCAFFOLD_DRILL_EXCLUDED_SCRIPTS, script)).toBe(true);
expect(commandsInMain.map(({ script: runScript }) => runScript)).not.toContain(script);
}
const mergeStage = contract.stages.find(({ id }) => id === "merge")!;
const mainStage = contract.stages.find(({ id }) => id === "main")!;
mainStage.gateIds = mainStage.gateIds.filter((id) => id !== "FE-GATE-020");
mergeStage.gateIds.push("FE-GATE-020");
const commandsIfReverted = scaffoldDrillCommands(contract);
expect(commandsIfReverted).toEqual(commandsInMain);
});
// 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)");
});
});