문제: 제품 기능 제거 드릴(`test:sample-removal -- --feature=<id>`)은
Playwright spec을 돌리지 않는다. 잔여 검사는 spec 본문에서 하이픈 든
기능 이름만 찾아서, 기능을 URL로만 여는 spec(`page.goto("/invoices")`)은
드릴을 통과하고 그 제품의 FE-GATE-008에서야 깨졌다.
고친 것: 드릴이 지우기 전에 그 기능의 route 경로를 받아 둔다(기능이
넘겨받은 플랫폼 경로는 뺀다). `productFeatureResidue`가 그 경로를 받아,
첫 매개변수 앞까지의 경로로 시작하고 문자열 끝이나 `/`·`?`·`#`가
이어지는 문자열이 있는 spec을 잔여물로 센다. `/`뿐인 경로는 찾지 않는다.
버린 대안: 드릴 안에서 FE-GATE-008을 돌리기. 사본 빌드와 세 엔진 실행이
드릴 시간을 몇 분 늘리고, 지운 기능을 가리키는 spec은 이름·경로로 먼저
찾을 수 있다.
위험·한계: 한 단어 ID만 쓰는 spec, URL을 조각으로 만드는 spec은 여전히
못 찾는다(머리 주석에 적음). vitest 시험 본문은 찾지 않는다(test:all이
돈다). 템플릿 자기 spec은 생성 기능 경로 `/product`로 찾아도 0건이다.
검증(desktop): 새 시험 셋 중 경로 시험이 고치기 전 lib에서 실패(RED 1),
고친 뒤 12개 통과. check:types·eslint rc=0. 로그
/tmp/claude-gates/w2fe2-res907/.
Refs: 0925 FOLLOW-UP 09-07
132 lines
6.2 KiB
TypeScript
132 lines
6.2 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). 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
|
|
* `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 written, case-sensitive, with no
|
|
* identifier character (`[A-Za-z0-9_-]`) on either side. A longer name
|
|
* that contains it (`generate-product-feature-index.ts` for
|
|
* `product-feature`, `KO_MESSAGES` for `messages`) does not count.
|
|
* Diff review DR-02: only a name with a hyphen is searched. A one-word ID
|
|
* or folder (`status`, `reports`, `messages`) is an ordinary word in the
|
|
* template's own specs (`status: 200`, `getByRole("status")`, "reports" in
|
|
* a test title), and no text rule tells that from a reference.
|
|
* - 0925 FOLLOW-UP 09-07. A spec that opens the feature by its URL alone
|
|
* (`page.goto("/invoices")`) failed only in FE-GATE-008, after the drill
|
|
* passed. `routePaths` are the removed feature's route paths: a spec with a
|
|
* string that starts with one, up to its first parameter (`/invoices` of
|
|
* `/invoices/:id`) and followed by the string's end or `/`, `?`, `#`, is
|
|
* residue. A path that is `/` up to its first parameter is not searched.
|
|
* What is still not found: a spec that names only a one-word ID, or builds
|
|
* the URL from parts. 03's hand list removes the feature's specs.
|
|
*
|
|
* The drill applies the same rule to a sample a project lists in
|
|
* scripts/lib/removable-template-features.ts.
|
|
*/
|
|
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();
|
|
}
|
|
|
|
/** The part of a route path before its first parameter or wildcard, or null for `/`. */
|
|
function staticRoutePrefix(routePath: string): string | null {
|
|
const segments: string[] = [];
|
|
for (const segment of routePath.split("/").filter(Boolean)) {
|
|
if (segment.startsWith(":") || segment.includes("*")) break;
|
|
segments.push(segment);
|
|
}
|
|
return segments.length === 0 ? null : `/${segments.join("/")}`;
|
|
}
|
|
|
|
export async function productFeatureResidue(
|
|
root: string,
|
|
featureId: string,
|
|
directory: string,
|
|
routePaths: readonly string[] = [],
|
|
): Promise<string[]> {
|
|
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",
|
|
);
|
|
const specNames = [...new Set([featureId, directory])]
|
|
.filter((name) => name.includes("-"))
|
|
.map(escapeRegExp);
|
|
const wholeName =
|
|
specNames.length === 0
|
|
? null
|
|
: new RegExp(`(?<![A-Za-z0-9_-])(?:${specNames.join("|")})(?![A-Za-z0-9_-])`, "u");
|
|
const prefixes = [
|
|
...new Set(routePaths.map(staticRoutePrefix).filter((prefix): prefix is string => prefix !== null)),
|
|
].map(escapeRegExp);
|
|
const routeString =
|
|
prefixes.length === 0
|
|
? null
|
|
: new RegExp(`["'\`](?:${prefixes.join("|")})(?=["'\`/?#])`, "u");
|
|
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 (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 (
|
|
pathNames(name) ||
|
|
imported.test(text) ||
|
|
(playwrightSpec.test(name) &&
|
|
((wholeName !== null && wholeName.test(text)) ||
|
|
(routeString !== null && routeString.test(text))))
|
|
) {
|
|
residue.push(name);
|
|
}
|
|
}
|
|
return residue.sort();
|
|
}
|