fix(scripts): 기능 제거 드릴의 src 잔여물 검사가 이름 단위로 찾는다
문제: 제거 드릴(`test:sample-removal -- --feature=<id>`)의 잔여물 검사는 `src`의 경로와 본문을 대소문자 무시 부분 문자열로 찾는다. 그래서 합법 ID `product-feature`를 지우면 템플릿 파일 열 개(`product-features.ts`, `product-features-port.ts`와 그것을 가져오는 파일들)와 템플릿 시험 이름 여섯(`product-feature-switch.test.tsx` 등)이 잔여물로 잡혀 드릴이 실패한다. 매뉴얼 예시 ID `invoice-feature`는 걸리지 않아 남아 있었다. 고른 방법: spec 본문에 이미 쓰는 규칙에 맞춘다. 본문은 이름 단위 (대소문자 구분, 앞뒤에 `[A-Za-z0-9_-]` 없음), 경로는 세그먼트가 이름과 같거나 그 첫 `.` 앞부분이 같을 때만 센다. `src/.generated/`는 기능 목록에서 다시 만드는 파생물이라 뺀다. - 버린 대안: 「파일 이름이 ID로 시작」. 템플릿의 `product-feature-*` 시험 이름이 그대로 걸린다. 위험·한계: 한 단어 ID(`search` 등)는 템플릿 본문에 보통 낱말로 있어 여전히 잡힐 수 있다. 본문 규칙으로는 자료와 참조를 가릴 수 없다(spec은 한 단어 이름을 아예 보지 않는다). 검증(desktop): 구현을 main으로 되돌린 상태에서 새 시험 2개 실패(RED), 고친 뒤 feature-residue·feature-removal-argument 11개 통과, eslint· check:types rc=0. 로그 /tmp/claude-gates/w2fe2-res1/. Refs: 1105/16-04
This commit is contained in:
@@ -9,8 +9,16 @@ import path from "node:path";
|
||||
* - `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
|
||||
* runtime override, a link). The name counts as a whole name only: in the
|
||||
* text, case-sensitive with no identifier character (`[A-Za-z0-9_-]`) on
|
||||
* either side; in the path, a segment equal to it or whose part before the
|
||||
* first `.` is. A substring search counted ten template files for
|
||||
* `product-feature` (`product-features.ts`, `product-features-port.ts` and
|
||||
* their importers). `src/.generated/` is derived from the feature list and
|
||||
* left out. A one-word ID that is an ordinary word in the template
|
||||
* (`search`) can still be found in its text.
|
||||
* - `tests/`: a file named after the feature (the same path rule; the
|
||||
* template's `product-feature-switch.test.tsx` is not), 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
|
||||
@@ -57,8 +65,13 @@ export async function productFeatureResidue(
|
||||
featureId: string,
|
||||
directory: string,
|
||||
): Promise<string[]> {
|
||||
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
|
||||
const named = new RegExp(names, "iu");
|
||||
const nameSet = new Set([featureId, directory]);
|
||||
const names = [...nameSet].map(escapeRegExp).join("|");
|
||||
const wholeAnyName = new RegExp(`(?<![A-Za-z0-9_-])(?:${names})(?![A-Za-z0-9_-])`, "u");
|
||||
const pathNames = (relativePath: string) =>
|
||||
relativePath
|
||||
.split("/")
|
||||
.some((segment) => nameSet.has(segment) || nameSet.has(segment.split(".")[0] ?? ""));
|
||||
const imported = new RegExp(
|
||||
String.raw`(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bmock\s*\(\s*)["'][^"'\n]*/features/(?:${names})/`,
|
||||
"u",
|
||||
@@ -75,13 +88,14 @@ export async function productFeatureResidue(
|
||||
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);
|
||||
if (name.startsWith("src/.generated/")) continue;
|
||||
if (pathNames(name) || wholeAnyName.test(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) ||
|
||||
pathNames(name) ||
|
||||
imported.test(text) ||
|
||||
(wholeName !== null && playwrightSpec.test(name) && wholeName.test(text))
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user