fix(removal): 새 드릴 가드 테스트가 제거 fixture 안에서도 성립한다

문제
capability 제거 드릴의 fixture도 test:unit을 돈다. 앞 커밋들이 더한 가드
테스트 두 개가 그 안에서 실패했다.
- removal-fixture.test.ts: 문서 테스트 파일과 드릴 스크립트를 이름으로 읽는데,
  fixture는 문서 테스트를 지우고(02-06) 드릴은 자기 스크립트를 지운다.
  browser-file-storage·realtime 드릴이 이 두 건으로 `test` 검사에서 실패했다.
- feature-scaffold-drill: 제거 드릴이 자기 capability 명령을 계약에서 빼면,
  scaffold 드릴 제외 목록의 그 스크립트가 "merge 단계에 없음"으로 실패한다.

고른 방법
- 문서 테스트는 "문서가 있는 곳에만 있다"를 단언한다(저장소: 둘 다 있음,
  capability fixture: 둘 다 없음).
- 드릴 목록은 scripts/test-*.ts 중 removal-fixture.ts를 import하는 파일로 찾고,
  sample·scaffold 드릴이 그 안에 있는지 확인한다.
- 제외 목록이 낡았다는 판정은 계약에 있으나 merge 단계 밖인 명령에만 한다.
  계약에서 아예 빠진 명령(제거 드릴이 정리한 capability)은 낡은 것이 아니다.

위험·한계
- 계약에서 지운 스크립트의 제외 항목이 저장소에 남아도 이 검사는 알리지
  않는다. 남아도 아무 명령을 숨기지 않는다.

검증
- 수정 전 snapshot(0edc3fc)에서 test:browser-file-storage-removal,
  test:realtime-removal 모두 이 두 테스트로 exit 1(ENOENT).
- 수정 뒤 removal-fixture·feature-scaffold-drill 18건 통과, eslint·tsc 통과.

Refs: docs/reviews/2026-11-03-maturity-review/02-adapters-browser-files-cache.md 02-06
Refs: docs/reviews/2026-11-03-maturity-review/12-guardrails-ci.md 12-02
This commit is contained in:
DongHyeonka
2026-11-04 21:31:16 +09:00
parent ed49973652
commit a28b8a4172
3 changed files with 52 additions and 20 deletions
+8 -4
View File
@@ -88,12 +88,16 @@ export function scaffoldDrillCommands(
}));
}
}
// An exclusion the merge stage no longer runs would hide nothing today and
// silently drop the command if it came back under the same name.
const stale = Object.keys(excluded).filter((script) => !mergeScripts.has(script));
// An exclusion for a command that moved out of the merge stage would hide
// nothing today and silently drop it if it came back. A command the contract
// no longer has at all (a removal drill pruned its capability) is not stale.
const contractScripts = new Set(contract.commands.map(({ script }) => script));
const stale = Object.keys(excluded).filter(
(script) => contractScripts.has(script) && !mergeScripts.has(script),
);
if (stale.length > 0) {
throw new TypeError(
`the scaffold drill excludes scripts the merge stage does not run: ${stale.join(", ")}`,
`the scaffold drill excludes scripts the contract runs outside the merge stage: ${stale.join(", ")}`,
);
}
return Object.freeze(selected);
+25 -3
View File
@@ -49,12 +49,34 @@ describe("feature scaffold drill commands", () => {
expect(scaffoldDrillCommands(contract).map(({ name }) => name)).toContain("FE-GATE-010:check-probe");
});
it("refuses an exclusion for a script the merge stage does not run", async () => {
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,
"check:gone": "no longer in the merge stage",
})).toThrow(/does not run: check:gone/u);
[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 () => {
+19 -13
View File
@@ -1,4 +1,5 @@
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { existsSync } from "node:fs";
import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -149,26 +150,31 @@ describe("document tests in a removal fixture", () => {
])).toEqual([]);
});
it("names tests that exist and read the documents", async () => {
// This file also runs inside the capability fixtures, which hold neither
// the documents nor these tests; the two go together.
it("names tests that read the documents, present exactly where the documents are", async () => {
const documentsPresent = REMOVAL_FIXTURE_DOCUMENT_TARGETS.every((target) => existsSync(target));
for (const test of REMOVAL_FIXTURE_DOCUMENT_TESTS) {
await expect(readFile(test, "utf8")).resolves.toMatch(/README\.md|CHANGELOG\.md/u);
expect(existsSync(test), test).toBe(documentsPresent);
if (documentsPresent) {
await expect(readFile(test, "utf8")).resolves.toMatch(/README\.md|CHANGELOG\.md/u);
}
}
});
it("is the only exclusion list: every drill prepares its fixture through it", async () => {
for (const drill of [
"scripts/test-sample-removal.ts",
"scripts/test-feature-scaffold.ts",
"scripts/test-browser-file-storage-runtime-removal.ts",
"scripts/test-realtime-runtime-removal.ts",
"scripts/test-optional-recipe-removal.ts",
]) {
const source = await readFile(drill, "utf8");
expect(source, drill).toContain("prepareRemovalFixture(");
const drills: string[] = [];
for (const name of await readdir("scripts")) {
if (!/^test-.*\.ts$/u.test(name)) continue;
const source = await readFile(path.join("scripts", name), "utf8");
if (!source.includes("./lib/removal-fixture.ts")) continue;
drills.push(name);
expect(source, name).toContain("prepareRemovalFixture(");
for (const test of REMOVAL_FIXTURE_DOCUMENT_TESTS) {
expect(source, drill).not.toContain(test);
expect(source, name).not.toContain(test);
}
}
expect(drills).toEqual(expect.arrayContaining(["test-sample-removal.ts", "test-feature-scaffold.ts"]));
});
});