문제: 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
80 lines
3.4 KiB
TypeScript
80 lines
3.4 KiB
TypeScript
import { readdir, readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
/**
|
|
* 1105/16-04. What a product feature leaves behind after
|
|
* `test:sample-removal -- --feature=<id>` deleted its folders, in the copy the
|
|
* drill made.
|
|
*
|
|
* - `src/`: any file whose path or text still names the feature ID or its
|
|
* folder. Platform source never names a product feature, so a name left
|
|
* there is a reference the type checker cannot see (a catalog key, a
|
|
* runtime override, a link).
|
|
* - `tests/`: a file named after the feature, or one that imports from the
|
|
* feature's `src/features/<dir>/` or `tests/features/<dir>/`. A vitest
|
|
* test's text is not searched for the bare name: the template's own tests
|
|
* use example IDs as data (`tests/unit/create-feature.test.ts` writes
|
|
* `invoice-feature`, the manual's example, 51 times), and the drill flagged
|
|
* them as residue of a product feature that took that name. A vitest test
|
|
* that still depends on the removed feature fails `test:all`, which the
|
|
* drill runs.
|
|
* - 1106/16-01. `test:all` runs vitest only (the `*.test.ts(x)` files under
|
|
* `tests/`, vitest.config.ts), and no step of the drill runs a Playwright
|
|
* spec. So a spec (`*.spec.ts`) that names the feature only in its text,
|
|
* such as `test.describe("invoice-feature", ...)`, is residue: its text is
|
|
* searched for the ID or folder name as a whole kebab-case name. A longer
|
|
* name that contains it (`generate-product-feature-index.ts` for
|
|
* `product-feature`) does not count. A spec that names only the feature's
|
|
* routes or URLs is not found; 03's hand list removes the feature's specs.
|
|
*
|
|
* The reference sample keeps its own, wider pattern in
|
|
* scripts/test-sample-removal.ts: the template owns all of its files.
|
|
*/
|
|
function escapeRegExp(value: string): string {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
}
|
|
|
|
async function filesUnder(directory: string): Promise<string[]> {
|
|
const entries = await readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
const nested = await Promise.all(
|
|
entries.map((entry) => {
|
|
const target = path.join(directory, entry.name);
|
|
return entry.isDirectory() ? filesUnder(target) : Promise.resolve([target]);
|
|
}),
|
|
);
|
|
return nested.flat();
|
|
}
|
|
|
|
export async function productFeatureResidue(
|
|
root: string,
|
|
featureId: string,
|
|
directory: string,
|
|
): Promise<string[]> {
|
|
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
|
|
const named = new RegExp(names, "iu");
|
|
const imported = new RegExp(
|
|
String.raw`(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bmock\s*\(\s*)["'][^"'\n]*/features/(?:${names})/`,
|
|
"u",
|
|
);
|
|
const wholeName = new RegExp(`(?<![A-Za-z0-9-])(?:${names})(?![A-Za-z0-9-])`, "iu");
|
|
const playwrightSpec = /\.spec\.[cm]?[jt]sx?$/u;
|
|
const residue: string[] = [];
|
|
const relative = (file: string) => path.relative(root, file).split(path.sep).join("/");
|
|
for (const file of await filesUnder(path.join(root, "src"))) {
|
|
const name = relative(file);
|
|
if (named.test(`${name}\n${await readFile(file, "utf8")}`)) residue.push(name);
|
|
}
|
|
for (const file of await filesUnder(path.join(root, "tests"))) {
|
|
const name = relative(file);
|
|
const text = await readFile(file, "utf8");
|
|
if (
|
|
named.test(name) ||
|
|
imported.test(text) ||
|
|
(playwrightSpec.test(name) && wholeName.test(text))
|
|
) {
|
|
residue.push(name);
|
|
}
|
|
}
|
|
return residue.sort();
|
|
}
|