Files
clean-architecture-frontend…/tests/unit/removal-drill-test-paths.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

75 lines
3.2 KiB
TypeScript

import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import {
REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE,
SCAFFOLD_DRILL_COVERED_SUITES,
scaffoldDrillCommands,
} from "../../scripts/lib/feature-scaffold-drill.ts";
import { gatedTestPaths } from "../../scripts/lib/ungated-tests.ts";
/**
* FE-GATE-020's drills ran each test file twice in one copy: the plain suites
* and then test:coverage over the same paths (feature scaffold), test:all and
* then test:coverage (feature removal). Each runs once now. These tests keep
* the claim true: a path added to a plain suite or to test:all that coverage
* does not run fails here instead of silently leaving the drill.
*/
const scripts = (
JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> }
).scripts;
const readConfig = (file: string) => readFileSync(file, "utf8");
const pathsOf = (entries: readonly string[]) => gatedTestPaths(scripts, entries, readConfig);
const within = (target: string, roots: readonly string[]) =>
roots.some((root) => target === root || target.startsWith(`${root}/`));
// A copy that removed the optional recipes has no test:recipes; the drill then
// runs only what the copy's package.json still has (scripts/test-sample-removal.ts).
const outsideCoverage = REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE.filter((script) =>
Object.hasOwn(scripts, script));
describe("removal drill test paths", () => {
const coverage = pathsOf(["test:coverage"]);
it("leave out of the scaffold drill only suites test:coverage runs whole", () => {
expect(coverage.length).toBeGreaterThan(0);
for (const suite of SCAFFOLD_DRILL_COVERED_SUITES) {
const paths = pathsOf([suite]);
expect(paths.length, suite).toBeGreaterThan(0);
expect(paths.filter((target) => !within(target, coverage)), suite).toEqual([]);
}
});
it("run every test:all path in the feature removal: coverage and what it leaves out", () => {
const run = [...coverage, ...pathsOf(outsideCoverage)];
expect(pathsOf(["test:all"]).filter((target) => !within(target, run))).toEqual([]);
});
it("name as outside coverage only suites coverage does not already run", () => {
for (const suite of outsideCoverage) {
expect(pathsOf([suite]).some((target) => !within(target, coverage)), suite).toBe(true);
}
});
it("run the covered suites plain again when the copy's merge stage has no test:coverage", async () => {
const contract = await loadCiGateContract(process.cwd());
const coverageIds = new Set(
contract.commands.filter(({ script }) => script === "test:coverage").map(({ id }) => id),
);
const withoutCoverage = {
...contract,
gates: contract.gates.map((gate) => ({
...gate,
commandIds: gate.commandIds.filter((id) => !coverageIds.has(id)),
})),
};
const withCoverage = scaffoldDrillCommands(contract).map(({ script }) => script);
const without = scaffoldDrillCommands(withoutCoverage).map(({ script }) => script);
for (const suite of SCAFFOLD_DRILL_COVERED_SUITES) {
expect(withCoverage, suite).not.toContain(suite);
expect(without, suite).toContain(suite);
}
});
});