From 57cc579a159e7476b78c7bc505bb0cc0d0131825 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 05:14:20 +0900 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20=EC=A0=9C=EA=B1=B0=20=EB=93=9C?= =?UTF-8?q?=EB=A6=B4=EC=9D=B4=20=EC=A7=80=EC=9A=B4=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=9D=98=20URL=EC=9D=84=20=EC=97=AC=EB=8A=94=20Playwright=20sp?= =?UTF-8?q?ec=EC=9D=84=20=EC=9E=94=EC=97=AC=EB=AC=BC=EB=A1=9C=20=EC=84=BC?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 제품 기능 제거 드릴(`test:sample-removal -- --feature=`)은 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 --- scripts/lib/feature-residue.ts | 37 ++++++++++++++++++++++----- scripts/test-sample-removal.ts | 21 +++++++++++++-- tests/unit/feature-residue.test.ts | 41 ++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/scripts/lib/feature-residue.ts b/scripts/lib/feature-residue.ts index 615dc42b..79f595de 100644 --- a/scripts/lib/feature-residue.ts +++ b/scripts/lib/feature-residue.ts @@ -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 { 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 { 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(`(? 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); } diff --git a/scripts/test-sample-removal.ts b/scripts/test-sample-removal.ts index 7437e854..389aefad 100644 --- a/scripts/test-sample-removal.ts +++ b/scripts/test-sample-removal.ts @@ -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( + 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", diff --git a/tests/unit/feature-residue.test.ts b/tests/unit/feature-residue.test.ts index ec2c2511..9adfd627 100644 --- a/tests/unit/feature-residue.test.ts +++ b/tests/unit/feature-residue.test.ts @@ -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 = {}; + 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": [