fix(scripts): 제거 드릴이 지운 기능의 URL을 여는 Playwright spec을 잔여물로 센다

문제: 제품 기능 제거 드릴(`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
This commit is contained in:
DongHyeonka
2026-11-13 05:14:20 +09:00
parent aff267db76
commit 57cc579a15
3 changed files with 91 additions and 8 deletions
+31 -6
View File
@@ -33,14 +33,19 @@ import path from "node:path";
* 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. A spec
* that names only the feature's routes or URLs is not found; 03's hand list
* removes the feature's specs.
* `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, so a spec
* that names only a one-word ID is not found either.
* 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.
@@ -60,10 +65,21 @@ async function filesUnder(directory: string): Promise<string[]> {
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("|");
@@ -83,6 +99,13 @@ export async function productFeatureResidue(
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("/");
@@ -97,7 +120,9 @@ export async function productFeatureResidue(
if (
pathNames(name) ||
imported.test(text) ||
(wholeName !== null && playwrightSpec.test(name) && wholeName.test(text))
(playwrightSpec.test(name) &&
((wholeName !== null && wholeName.test(text)) ||
(routeString !== null && routeString.test(text))))
) {
residue.push(name);
}
+19 -2
View File
@@ -10,7 +10,8 @@ import { spawnSync } from "node:child_process";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { ROUTE_FEATURE_OWNER } from "../src/features/installed-feature-contracts.ts";
import { PLATFORM_ROUTE_REGISTRY } from "../src/contracts/routes.ts";
import { ROUTE_FEATURE_OWNER, routePath } from "../src/features/installed-feature-contracts.ts";
import { loadCiGateContract } from "./contracts/ci-gates.ts";
import { createFileSystemDeclarationSource } from "./generate-product-feature-index.ts";
import { productFeatureResidue } from "./lib/feature-residue.ts";
@@ -163,6 +164,15 @@ const located = await locateFeature(featureId);
const featureRouteIds = Object.entries(ROUTE_FEATURE_OWNER)
.filter(([, owner]) => owner === featureId)
.map(([routeId]) => routeId);
// 0925 FOLLOW-UP 09-07. A spec that opens the feature by one of these paths is
// residue (scripts/lib/feature-residue.ts). A platform path the feature took
// over (its home) goes back to the platform with the removal.
const platformRoutePaths = new Set<string>(
Object.values(PLATFORM_ROUTE_REGISTRY).map((route) => route.path),
);
const featureRoutePaths = featureRouteIds
.map(routePath)
.filter((candidate) => !platformRoutePaths.has(candidate));
const fixtureRoot = await createRemovalFixtureRoot(`${featureId}-removal`);
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
@@ -454,7 +464,14 @@ try {
// 1105/16-04. Template tests use example feature IDs as data; only what
// still points at the removed feature counts (scripts/lib/feature-residue.ts).
const residue = await productFeatureResidue(fixtureRoot, featureId, located.directory);
// 0925 FOLLOW-UP 09-07. The drill runs no Playwright spec; one that still
// opens the feature's URL is found here instead of in FE-GATE-008.
const residue = await productFeatureResidue(
fixtureRoot,
featureId,
located.directory,
featureRoutePaths,
);
const builtResiduePattern = new RegExp(
`${escapeRegExp(featureId)}|${escapeRegExp(located.directory)}`,
"i",
+41
View File
@@ -85,6 +85,47 @@ describe("product feature residue (1105/16-04)", () => {
]);
});
// 0925 FOLLOW-UP 09-07. No step of the drill runs a Playwright spec, so a
// spec that opens the removed feature by its URL alone passed the drill and
// failed FE-GATE-008 afterwards.
it("counts a Playwright spec that opens one of the feature's route paths", async () => {
const root = await fixture({
"tests/e2e/route-only.spec.ts": 'test("opens", ({ page }) => page.goto("/invoice"));\n',
"tests/e2e/detail.spec.ts": "await page.goto(`/invoice/${id}?tab=lines`);\n",
"tests/visual/hash.visual.spec.ts": "await page.goto('/invoice#total');\n",
"tests/e2e/longer-path.spec.ts": 'await page.goto("/invoices-archive");\n',
"tests/e2e/other-base.spec.ts": 'await page.goto("/admin/invoice");\n',
// The same text in a vitest test is data (1105/16-04).
"tests/unit/route.test.ts": 'const target = "/invoice";\n',
});
expect(await productFeatureResidue(root, ID, ID, ["/invoice", "/invoice/:invoiceId"])).toEqual([
"tests/e2e/detail.spec.ts",
"tests/e2e/route-only.spec.ts",
"tests/visual/hash.visual.spec.ts",
]);
});
it("does not search a route path that is the root before its first parameter", async () => {
const root = await fixture({
"tests/e2e/home.spec.ts": 'await page.goto("/");\nawait page.goto("/?lang=ko");\n',
});
expect(await productFeatureResidue(root, ID, ID, ["/", "/:invoiceId", "*"])).toEqual([]);
});
it("does not count the template's own specs for the route paths of a generated feature", async () => {
const specs: Record<string, string> = {};
for (const entry of await readdir("tests", { recursive: true })) {
const file = path.join("tests", entry).split(path.sep).join("/");
if (/\.spec\.[cm]?[jt]sx?$/u.test(file)) specs[file] = await readFile(file, "utf8");
}
const root = await fixture(specs);
// create:feature product-feature declares PRODUCT_LIST at /product.
expect(await productFeatureResidue(root, "product-feature", "product-feature", ["/product"])).toEqual([]);
});
it("does not count a spec whose longer names only contain the ID", async () => {
const root = await fixture({
"tests/e2e/builds.spec.ts": [