Files
clean-architecture-frontend…/tests/unit/feature-residue.test.ts
T
DongHyeonka af3344b310 fix(removal): 본문에만 기능 ID를 적은 Playwright spec을 잔여로 센다
문제: 1105/16-04 수정 뒤 제품 기능 제거 드릴의 tests 잔여는 파일
이름에 기능 ID가 있거나 기능 폴더에서 import하는 파일뿐이다. 주석과 매뉴얼
01 11단계는 빠진 경우(본문에만 ID가 있는 테스트)를 test:all이 잡는다고
적었다. 그런데 test:all은 vitest 묶음이고 vitest는 tests의 *.test.ts(x)만
돈다. tests/e2e·visual 등의 *.spec.ts는 test:all도 드릴의 다른 단계도
돌리지 않는다. 그래서 `test.describe("invoice-feature", …)`처럼 본문에만
ID를 담은 spec은 드릴을 통과하고, 다음 CI의 브라우저 게이트에서 지운
라우트를 열다가 실패한다.

고른 방법: 리뷰의 (b). tests 중 vitest가 돌지 않는 Playwright spec
(`*.spec.[cm]?[jt]sx?`)은 본문도 찾는다. 다만 1105/16-04가 없앤 부분
문자열 검색으로 돌아가지 않고, 기능 ID·폴더 이름을 앞뒤가 영문·숫자·`-`가
아닌 한 이름으로만 찾는다. `"invoice-feature"`, `'invoices'`,
`/features/invoices/`는 잔여이고, product-feature를 지울 때
`generate-product-feature-index.ts`·`data-product-feature`·
`product-features`는 잔여가 아니다. vitest 테스트 본문은 그대로 찾지 않는다
(템플릿 테스트가 예시 ID를 데이터로 쓴다). 템플릿 자신의 spec에는
invoice-feature·product-feature·scaffold-feature가 한 이름으로 나오지 않는다
(git grep 0건). 그래서 16-R2(invoice-feature 제거)와 FE-GATE-020
(scaffold-feature)은 그대로 통과해야 한다. 주석, 매뉴얼 01 11단계, errors.md의
판정 문장을 고쳤다.
버린 대안: (a) 문서만 고친다. 빈틈이 남는다. spec 본문을 부분 문자열로
찾는다: 짧은 ID와 템플릿 이름(`generate-product-feature-index`)이 거짓
양성을 다시 낸다. tests의 모든 비-vitest 파일(helpers, mocks, fixtures)을
찾는다: tests/helpers/runtime-capabilities-stub.ts가 주석에
"product-feature"를 한 이름으로 적어 거짓 양성이 된다. spec이 import하는
helper는 spec이 지워지면 아무 데서도 돌지 않아 해가 없다.

위험·한계: route ID나 URL만 적은 spec은 여전히 못 잡는다(03 손 목록).
다운스트림 spec이 무관한 이유로 기능 ID를 한 이름으로 적으면 거짓 양성이
난다. 1105/16-04의 남은 부분(src 경로·본문과 tests 파일 이름의 부분 문자열
검색, dist 빌드 잔여 검사)은 이 변경이 덮지 않아 그대로 두었다. 같은 이름
단위 검색으로 바꾸면 product-feature의 거짓 양성(16-R3, 20파일)은 풀리지만,
폴더 이름에 붙은 식별자(`invoices` → `InvoicesPage`)와
`<id>-helpers.test.ts` 같은 파일 이름을 놓쳐 검사가 좁아진다. 따로 정한다.

검증: desktop batch에서 확인.
node scripts/run-vitest.ts run tests/unit/feature-residue.test.ts
corepack pnpm create:feature invoice-feature에 본문에만 ID를 적은
tests/e2e/checkout.spec.ts를 더한 뒤 corepack pnpm test:sample-removal --
--feature=invoice-feature가 fixture-id-residue로 실패, spec 없이는 통과

Refs: 1106/16-01
2026-11-06 05:32:31 +09:00

115 lines
4.4 KiB
TypeScript

import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterAll, describe, expect, it } from "vitest";
import { productFeatureResidue } from "../../scripts/lib/feature-residue.ts";
/**
* 1105/16-04. The manual's example ID is `invoice-feature` (01 1단계), and
* its step 11 removes that feature with
* `test:sample-removal -- --feature=invoice-feature`. The drill searched every
* file under `src` and `tests` for the ID as a substring, so the template's
* own tests/unit/create-feature.test.ts, which writes that example ID 51
* times as data, failed the removal (`fixture-id-residue`), and the advice
* was to edit that template file.
*/
const ID = "invoice-feature";
const roots: string[] = [];
afterAll(async () => {
await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true })));
});
async function fixture(files: Readonly<Record<string, string>>): Promise<string> {
const root = await mkdtemp(path.join(tmpdir(), "feature-residue-"));
roots.push(root);
for (const [file, content] of Object.entries(files)) {
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
await writeFile(path.join(root, file), content);
}
return root;
}
// Built at run time so this file does not itself read as an import of the
// feature when the repository is searched below.
const importOf = (target: string) => ["import { x } from", JSON.stringify(target)].join(" ");
describe("product feature residue (1105/16-04)", () => {
it("does not count the template's own tests that name the manual's example ID", async () => {
expect(await productFeatureResidue(process.cwd(), ID, ID)).toEqual([]);
});
it("counts what still points at the removed feature", async () => {
const root = await fixture({
"src/contracts/leftover.ts": `export const OWNER = "${ID}";\n`,
"src/platform/clean.ts": "export const NOTHING = 1;\n",
[`tests/e2e/${ID}.spec.ts`]: "test('opens', () => {});\n",
"tests/unit/imports-feature.test.ts": `${importOf(`../../src/features/${ID}/feature-module.ts`)};\n`,
"tests/unit/imports-feature-tests.test.ts": `${importOf(`../features/${ID}/helpers.ts`)};\n`,
"tests/unit/example-data.test.ts": `const request = { id: "${ID}" };\nconst path = "src/features/${ID}/feature-module.ts";\n`,
});
expect(await productFeatureResidue(root, ID, ID)).toEqual([
"src/contracts/leftover.ts",
`tests/e2e/${ID}.spec.ts`,
"tests/unit/imports-feature-tests.test.ts",
"tests/unit/imports-feature.test.ts",
]);
});
// 1106/16-01. test:all is vitest only and the drill runs no Playwright
// spec, so a spec that names the removed feature in its text and nowhere
// else was caught by no step.
it("counts a Playwright spec that names the feature only in its text", async () => {
const spec = [
`test.describe("${ID}", () => {`,
' test("opens", async ({ page }) => {',
' await page.goto("/invoice");',
" });",
"});",
"",
].join("\n");
const root = await fixture({
"tests/e2e/checkout.spec.ts": spec,
"tests/visual/billing.visual.spec.ts": `const FEATURE = '${ID}';\n`,
// The same text in a vitest test is data (1105/16-04).
"tests/unit/checkout.test.ts": spec,
"tests/e2e/route-only.spec.ts": 'test("opens", ({ page }) => page.goto("/invoice"));\n',
});
expect(await productFeatureResidue(root, ID, ID)).toEqual([
"tests/e2e/checkout.spec.ts",
"tests/visual/billing.visual.spec.ts",
]);
});
it("does not count a spec whose longer names only contain the ID", async () => {
const root = await fixture({
"tests/e2e/builds.spec.ts": [
'run("scripts/generate-product-feature-index.ts");',
'const attribute = "data-product-feature";',
'const registry = "product-features";',
"",
].join("\n"),
});
expect(
await productFeatureResidue(root, "product-feature", "product-feature"),
).toEqual([]);
});
it("matches the folder name as well as the ID", async () => {
const root = await fixture({
"src/contracts/leftover.ts": 'export const DIRECTORY = "invoices";\n',
"tests/unit/x.test.ts": `${importOf("../../src/features/invoices/index.ts")};\n`,
});
expect(await productFeatureResidue(root, ID, "invoices")).toEqual([
"src/contracts/leftover.ts",
"tests/unit/x.test.ts",
]);
});
});