From a28b8a41728b2cea40960424876b328f017d96a1 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 21:31:16 +0900 Subject: [PATCH] =?UTF-8?q?fix(removal):=20=EC=83=88=20=EB=93=9C=EB=A6=B4?= =?UTF-8?q?=20=EA=B0=80=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20fixture=20=EC=95=88=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8F=84=20=EC=84=B1=EB=A6=BD=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 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 --- scripts/lib/feature-scaffold-drill.ts | 12 ++++++--- tests/unit/feature-scaffold-drill.test.ts | 28 +++++++++++++++++--- tests/unit/removal-fixture.test.ts | 32 ++++++++++++++--------- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/scripts/lib/feature-scaffold-drill.ts b/scripts/lib/feature-scaffold-drill.ts index f125bdbf..bbbd06f7 100644 --- a/scripts/lib/feature-scaffold-drill.ts +++ b/scripts/lib/feature-scaffold-drill.ts @@ -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); diff --git a/tests/unit/feature-scaffold-drill.test.ts b/tests/unit/feature-scaffold-drill.test.ts index 414ae81a..603118db 100644 --- a/tests/unit/feature-scaffold-drill.test.ts +++ b/tests/unit/feature-scaffold-drill.test.ts @@ -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 () => { diff --git a/tests/unit/removal-fixture.test.ts b/tests/unit/removal-fixture.test.ts index b34457c0..e48b8283 100644 --- a/tests/unit/removal-fixture.test.ts +++ b/tests/unit/removal-fixture.test.ts @@ -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"])); }); });