From aff267db766ea849d6033016b372add8cdafbb9a Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 04:57:04 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix(scripts):=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EB=93=9C=EB=A6=B4=EC=9D=98=20src=20?= =?UTF-8?q?=EC=9E=94=EC=97=AC=EB=AC=BC=20=EA=B2=80=EC=82=AC=EA=B0=80=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=8B=A8=EC=9C=84=EB=A1=9C=20=EC=B0=BE?= =?UTF-8?q?=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 제거 드릴(`test:sample-removal -- --feature=`)의 잔여물 검사는 `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 --- scripts/lib/feature-residue.ts | 26 ++++++++++++++++++++------ tests/unit/feature-residue.test.ts | 29 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/scripts/lib/feature-residue.ts b/scripts/lib/feature-residue.ts index 95202ea2..615dc42b 100644 --- a/scripts/lib/feature-residue.ts +++ b/scripts/lib/feature-residue.ts @@ -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//` or `tests/features//`. 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 { - 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(`(? + 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)) ) { diff --git a/tests/unit/feature-residue.test.ts b/tests/unit/feature-residue.test.ts index 7b3f374c..ec2c2511 100644 --- a/tests/unit/feature-residue.test.ts +++ b/tests/unit/feature-residue.test.ts @@ -111,7 +111,8 @@ describe("product feature residue (1105/16-04)", () => { if (/\.spec\.[cm]?[jt]sx?$/u.test(file)) specs[file] = await readFile(file, "utf8"); } expect(Object.keys(specs)).toContain("tests/e2e/accessibility.spec.ts"); - // A copy of the specs alone: `src` is searched by substring (1105/16-04). + // A copy of the specs alone: a one-word ID that the template's source uses + // as a word (`status`) is still found in `src` text (feature-residue.ts). const root = await fixture(specs); for (const id of ["product-feature", "messages", "status", "reports"]) { @@ -144,4 +145,30 @@ describe("product feature residue (1105/16-04)", () => { "tests/unit/x.test.ts", ]); }); + + // 1112 round9 (1105/16-04 remainder). `src` was searched by case-insensitive + // substring over path and text, so a legitimate ID such as + // `product-feature` counted ten template files (`product-features.ts`, + // `product-features-port.ts` and their importers) as residue. + it("does not count the template's own source and tests for an ID that longer names contain", async () => { + expect(await productFeatureResidue(process.cwd(), "product-feature", "product-feature")).toEqual([]); + }); + + it("counts a source path or text that names the ID as a whole name, and ignores the generated index", async () => { + const root = await fixture({ + "src/contracts/leftover.ts": 'export const OWNER = "product-feature";\n', + "src/features/product-feature/stale.ts": "export const STALE = 1;\n", + "src/contracts/product-feature-port.ts": "export const PORT = 1;\n", + "src/contracts/product-features.ts": 'export const KEY = "data-product-feature";\n', + "src/contracts/title-case.ts": 'export const TITLE = "Product-Feature";\n', + "src/.generated/product-feature-index.ts": 'export const IDS = ["product-feature"];\n', + }); + + // A longer file name that starts with the ID is not the feature's file; + // the template's own tests/component/product-feature-switch.test.tsx is one. + expect(await productFeatureResidue(root, "product-feature", "product-feature")).toEqual([ + "src/contracts/leftover.ts", + "src/features/product-feature/stale.ts", + ]); + }); }); From 57cc579a159e7476b78c7bc505bb0cc0d0131825 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 05:14:20 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix(scripts):=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=93=9C=EB=A6=B4=EC=9D=B4=20=EC=A7=80=EC=9A=B4=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=EC=9D=98=20URL=EC=9D=84=20=EC=97=AC=EB=8A=94=20Playwr?= =?UTF-8?q?ight=20spec=EC=9D=84=20=EC=9E=94=EC=97=AC=EB=AC=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=84=BC=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": [ From b05bf19c0596512d0e15e05a4b042dda1e4281b0 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 05:25:04 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix(scripts):=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=93=9C=EB=A6=B4=EC=9D=98=20=EB=B9=8C=EB=93=9C=20=EC=9E=94?= =?UTF-8?q?=EC=97=AC=EB=AC=BC=20=EA=B2=80=EC=82=AC=EB=8F=84=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=8B=A8=EC=9C=84=EB=A1=9C=20=EC=B0=BE=EB=8A=94?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 앞 커밋으로 `src` 검사는 이름 단위가 됐지만, 빌드한 `dist`는 여전히 기능 ID를 대소문자 무시 부분 문자열로 찾았다. desktop에서 `create:feature product-feature` 뒤 그 기능을 지우는 드릴을 돌리면 `src` 검사는 통과하고 `built-fixture-id-residue`가 템플릿 자기 청크 `platform-overview-page-*.js`(`data-product-feature` 속성)로 실패했다. 고친 것: 이름 단위 규칙을 `featureNamePattern`으로 꺼내 `src` 본문과 빌드 결과에 같이 쓴다. 위험·한계: 빌드 결과에서도 대소문자를 가린다. 기능 ID와 폴더는 소문자 kebab이라 놓치는 경우는 없다고 본다. 검증(desktop): feature-residue·feature-removal-argument 15개 통과, check:types·eslint rc=0(로그 /tmp/claude-gates/w2fe2-res3/). 고치기 전 드릴 실패는 /tmp/claude-gates/w2fe2-resx3/. Refs: 1105/16-04 --- scripts/lib/feature-residue.ts | 14 +++++++++++++- scripts/test-sample-removal.ts | 9 ++++----- tests/unit/feature-residue.test.ts | 14 +++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/scripts/lib/feature-residue.ts b/scripts/lib/feature-residue.ts index 79f595de..2d533f0a 100644 --- a/scripts/lib/feature-residue.ts +++ b/scripts/lib/feature-residue.ts @@ -54,6 +54,18 @@ function escapeRegExp(value: string): string { return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); } +/** + * The feature ID or folder as a whole name: case-sensitive, with no + * identifier character (`[A-Za-z0-9_-]`) on either side. The drill searches + * `src` text and the built `dist` with it; the template's own bundle holds + * `data-product-feature` and `product-features`, which a substring search + * counted for a feature named `product-feature`. + */ +export function featureNamePattern(featureId: string, directory: string): RegExp { + const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|"); + return new RegExp(`(? { const entries = await readdir(directory, { withFileTypes: true }).catch(() => []); const nested = await Promise.all( @@ -83,7 +95,7 @@ export async function productFeatureResidue( ): Promise { const nameSet = new Set([featureId, directory]); const names = [...nameSet].map(escapeRegExp).join("|"); - const wholeAnyName = new RegExp(`(? relativePath .split("/") diff --git a/scripts/test-sample-removal.ts b/scripts/test-sample-removal.ts index 389aefad..db54a02a 100644 --- a/scripts/test-sample-removal.ts +++ b/scripts/test-sample-removal.ts @@ -14,7 +14,7 @@ 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"; +import { featureNamePattern, productFeatureResidue } from "./lib/feature-residue.ts"; import { isProductionModulePath } from "./lib/risk-coverage.ts"; import { createRemovalFixtureRoot, @@ -472,10 +472,9 @@ try { located.directory, featureRoutePaths, ); - const builtResiduePattern = new RegExp( - `${escapeRegExp(featureId)}|${escapeRegExp(located.directory)}`, - "i", - ); + // 1105/16-04. The same whole-name rule as `src`: the template's bundle + // holds `data-product-feature`, which a substring search counted. + const builtResiduePattern = featureNamePattern(featureId, located.directory); const missingCommonTests: string[] = []; for (const testPath of commonTestPaths) { diff --git a/tests/unit/feature-residue.test.ts b/tests/unit/feature-residue.test.ts index 9adfd627..53a1cbd8 100644 --- a/tests/unit/feature-residue.test.ts +++ b/tests/unit/feature-residue.test.ts @@ -4,7 +4,7 @@ import path from "node:path"; import { afterAll, describe, expect, it } from "vitest"; -import { productFeatureResidue } from "../../scripts/lib/feature-residue.ts"; +import { featureNamePattern, productFeatureResidue } from "../../scripts/lib/feature-residue.ts"; /** * 1105/16-04. The manual's example ID is `invoice-feature` (01 1단계), and @@ -195,6 +195,18 @@ describe("product feature residue (1105/16-04)", () => { expect(await productFeatureResidue(process.cwd(), "product-feature", "product-feature")).toEqual([]); }); + // 1112 round9 (1105/16-04 remainder). The drill searched the built `dist` + // by case-insensitive substring too, so removing `product-feature` failed + // on the template's own platform-overview chunk (`data-product-feature`). + it("finds the feature in a built chunk by its whole name only", () => { + const pattern = featureNamePattern("product-feature", "product-feature"); + expect(pattern.test('createElement("p",{"data-product-feature":e.featureId})')).toBe(false); + expect(pattern.test('const r="product-features";')).toBe(false); + expect(pattern.test('const t="Product-Feature";')).toBe(false); + expect(pattern.test('chunkId:"route-product",owner:"product-feature"')).toBe(true); + expect(featureNamePattern(ID, "invoices").test('import("./invoices/page.js")')).toBe(true); + }); + it("counts a source path or text that names the ID as a whole name, and ignores the generated index", async () => { const root = await fixture({ "src/contracts/leftover.ts": 'export const OWNER = "product-feature";\n', From 03744e19cffcff314a5fcfc73831d887ab538823 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 05:40:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix(scripts):=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=93=9C=EB=A6=B4=EC=9D=98=20URL=20=EC=9E=94=EC=97=AC=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=EA=B0=80=20=EB=82=A8=EB=8A=94=20route?= =?UTF-8?q?=EC=99=80=20page=20object=EB=A5=BC=20=EA=B0=80=EB=A6=B0?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 새 눈 리뷰(정적 읽기)가 앞 두 커밋에서 넷을 찾았다. - 같은 context의 첫 기능은 context 경로(`/invoice`)를, 뒤 기능은 그 아래 경로(`/invoice/line`)를 받는다. 첫 기능을 지우면 context가 남는데도 형제 기능 spec의 `"/invoice/line"`이 잔여물로 잡혔다. - 선택 정적 세그먼트(`/invoice/edit?`)는 접두어가 `/invoice/edit?`가 되어 아무 URL도 맞지 않았다. - `` `/invoice${query}` ``와 Playwright `testDir` 안의 page object (`tests/e2e/support/*.ts`)는 찾지 않았다. - `src` 검색이 대소문자를 가리게 되면서, 한 단어 ID(`invoices`)의 옛 부분 문자열 검색이 잡던 route ID 잔여(`route.INVOICES_LIST.title`)를 놓쳤다. 고친 것: 드릴이 지우기 전에 지울 route 경로, 남는 route 경로(플랫폼 포함), 지울 route ID(넘겨받은 플랫폼 ID 제외)를 함께 넘긴다. URL 문자열은 맞는 접두어 중 가장 긴 것이 지운 route일 때만 센다(남는 route와 접두어가 같으면 세지 않는다). 접두어는 선택 세그먼트 앞에서 끊고, `${`도 이어짐으로 본다. `playwright*.config.ts`의 `testDir` 안 파일 중 vitest 시험이 아닌 것도 본다. route ID는 `src` 본문에서 이름 단위로 찾는다. 버린 대안: react-router `matchRoutes`로 모든 문자열을 route 표에 맞추기. 드릴 lib가 앱 라우터에 묶이고, 고정 접두어 비교로 같은 판정을 낸다. 위험·한계: 지운 route와 남는 route의 고정 접두어가 같으면(`/invoice/:id`를 지우고 `/invoice`가 남음) `/invoice/7`을 세지 않는다. 조각으로 만든 URL은 여전히 못 찾는다. 검증(desktop): feature-residue·feature-removal-argument 19개 통과, check:types·eslint rc=0(로그 /tmp/claude-gates/w2fe2-res4/). 변이 다섯 (남는 route 비교, 선택 세그먼트, `${`, testDir 파일, route ID 검색을 하나씩 끔)마다 해당 시험 하나가 실패했다(로그 /tmp/claude-gates/w2fe2-resmut/). Refs: 0925 FOLLOW-UP 09-07, 1105/16-04 --- scripts/lib/feature-residue.ts | 106 +++++++++++++++++++++++------ scripts/test-sample-removal.ts | 23 ++++--- tests/unit/feature-residue.test.ts | 82 +++++++++++++++++++--- 3 files changed, 174 insertions(+), 37 deletions(-) diff --git a/scripts/lib/feature-residue.ts b/scripts/lib/feature-residue.ts index 2d533f0a..0dbae38c 100644 --- a/scripts/lib/feature-residue.ts +++ b/scripts/lib/feature-residue.ts @@ -40,12 +40,17 @@ import path from "node:path"; * 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. + * passed. `routes.paths` are the removed feature's route paths: a spec, or + * another file in a Playwright `testDir` that is not a vitest test (a page + * object), with a string that opens one is residue. A string opens a route + * when it starts with the route's fixed prefix (`/invoices` of + * `/invoices/:id` or `/invoices/edit?`) followed by the string's end, `/`, + * `?`, `#` or `${`, and no route left behind (`routes.remainingPaths`) has + * a longer prefix that fits it. A prefix that is `/` is not searched. + * `routes.ids`, the feature's route IDs, are searched in `src` text by the + * whole-name rule. 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. @@ -77,25 +82,69 @@ async function filesUnder(directory: string): Promise { return nested.flat(); } -/** The part of a route path before its first parameter or wildcard, or null for `/`. */ +/** + * The part of a route path before its first parameter, wildcard or optional + * segment (`/invoices` of `/invoices/:id` or `/invoices/edit?`), or null when + * that is `/`. + */ function staticRoutePrefix(routePath: string): string | null { const segments: string[] = []; for (const segment of routePath.split("/").filter(Boolean)) { - if (segment.startsWith(":") || segment.includes("*")) break; + if (segment.startsWith(":") || segment.includes("*") || segment.endsWith("?")) break; segments.push(segment); } return segments.length === 0 ? null : `/${segments.join("/")}`; } +const prefixesOf = (routePaths: readonly string[]) => + new Set(routePaths.map(staticRoutePrefix).filter((prefix): prefix is string => prefix !== null)); + +/** `/invoices`, `/invoices/7`, `/invoices?tab=1`, `/invoices#x`, `/invoices${query}` open `/invoices`. */ +function opens(value: string, prefix: string): boolean { + if (!value.startsWith(prefix)) return false; + const rest = value.slice(prefix.length); + return rest === "" || /^[/?#]/u.test(rest) || rest.startsWith("${"); +} + +/** The Playwright `testDir`s the repository's `playwright*.config.ts` files name. */ +async function browserTestDirectories(root: string): Promise { + const configs = (await readdir(root).catch(() => [])).filter((name) => + /^playwright(?:\.[\w-]+)?\.config\.[cm]?[jt]s$/u.test(name), + ); + const directories = await Promise.all( + configs.map(async (config) => + /testDir:\s*["']\.?\/?([^"']+)["']/u.exec(await readFile(path.join(root, config), "utf8"))?.[1] + ?.replace(/\/$/u, ""), + ), + ); + return directories.filter((directory): directory is string => directory !== undefined); +} + +export type FeatureRoutes = Readonly<{ + /** The removed feature's route paths. */ + paths?: readonly string[]; + /** Every route path left after the removal, platform routes included. */ + remainingPaths?: readonly string[]; + /** The removed feature's route IDs, platform IDs it took over left out. */ + ids?: readonly string[]; +}>; + export async function productFeatureResidue( root: string, featureId: string, directory: string, - routePaths: readonly string[] = [], + routes: FeatureRoutes = {}, ): Promise { const nameSet = new Set([featureId, directory]); const names = [...nameSet].map(escapeRegExp).join("|"); const wholeAnyName = featureNamePattern(featureId, directory); + // A route ID left in platform source (a catalog key, `route.INVOICES_LIST`) + // is found by its whole name too. + const routeIds = [...new Set(routes.ids ?? [])].map(escapeRegExp); + const wholeRouteId = + routeIds.length === 0 + ? null + : new RegExp(`(? relativePath .split("/") @@ -111,20 +160,38 @@ 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"); + // A URL opens the route whose fixed prefix is the longest that fits it, so + // a sibling feature's `/invoices/lines` in the same context is not the + // removed `/invoices`. When a route left behind has the same prefix + // (`/invoices` beside a removed `/invoices/:id`), the URL is not counted. + const removed = prefixesOf(routes.paths ?? []); + const remaining = prefixesOf(routes.remainingPaths ?? []); + const candidates = [...new Set([...removed, ...remaining])].sort((a, b) => b.length - a.length); + const opensRemovedRoute = (text: string) => { + if (removed.size === 0) return false; + for (const match of text.matchAll(/["'`](\/[^"'`\s]*)/gu)) { + const best = candidates.find((prefix) => opens(match[1]!, prefix)); + if (best !== undefined && removed.has(best) && !remaining.has(best)) return true; + } + return false; + }; + const browserDirectories = await browserTestDirectories(root); const playwrightSpec = /\.spec\.[cm]?[jt]sx?$/u; + // A page object or helper beside the specs (`tests/e2e/support/*.ts`) runs + // only in a browser too; a vitest test (`*.test.*`) does not. + const browserFile = (name: string) => + playwrightSpec.test(name) || + (!/\.test\.[cm]?[jt]sx?$/u.test(name) && + browserDirectories.some((directory) => name.startsWith(`${directory}/`))); 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); + const text = await readFile(file, "utf8"); + if (pathNames(name) || wholeAnyName.test(text) || (wholeRouteId !== null && wholeRouteId.test(text))) { + residue.push(name); + } } for (const file of await filesUnder(path.join(root, "tests"))) { const name = relative(file); @@ -132,9 +199,8 @@ export async function productFeatureResidue( if ( pathNames(name) || imported.test(text) || - (playwrightSpec.test(name) && - ((wholeName !== null && wholeName.test(text)) || - (routeString !== null && routeString.test(text)))) + (playwrightSpec.test(name) && wholeName !== null && wholeName.test(text)) || + (browserFile(name) && opensRemovedRoute(text)) ) { residue.push(name); } diff --git a/scripts/test-sample-removal.ts b/scripts/test-sample-removal.ts index db54a02a..b84178be 100644 --- a/scripts/test-sample-removal.ts +++ b/scripts/test-sample-removal.ts @@ -14,7 +14,7 @@ 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 { featureNamePattern, productFeatureResidue } from "./lib/feature-residue.ts"; +import { featureNamePattern, type FeatureRoutes, productFeatureResidue } from "./lib/feature-residue.ts"; import { isProductionModulePath } from "./lib/risk-coverage.ts"; import { createRemovalFixtureRoot, @@ -164,15 +164,22 @@ 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. +// 0925 FOLLOW-UP 09-07. A browser test that opens the feature by one of these +// paths is residue (scripts/lib/feature-residue.ts). A platform route 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 featureRoutes: FeatureRoutes = Object.freeze({ + paths: featureRouteIds.map(routePath).filter((candidate) => !platformRoutePaths.has(candidate)), + remainingPaths: [ + ...platformRoutePaths, + ...Object.keys(ROUTE_FEATURE_OWNER) + .filter((routeId) => !featureRouteIds.includes(routeId)) + .map(routePath), + ], + ids: featureRouteIds.filter((routeId) => !Object.hasOwn(PLATFORM_ROUTE_REGISTRY, routeId)), +}); const fixtureRoot = await createRemovalFixtureRoot(`${featureId}-removal`); const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath"); @@ -470,7 +477,7 @@ try { fixtureRoot, featureId, located.directory, - featureRoutePaths, + featureRoutes, ); // 1105/16-04. The same whole-name rule as `src`: the template's bundle // holds `data-product-feature`, which a substring search counted. diff --git a/tests/unit/feature-residue.test.ts b/tests/unit/feature-residue.test.ts index 53a1cbd8..01352019 100644 --- a/tests/unit/feature-residue.test.ts +++ b/tests/unit/feature-residue.test.ts @@ -99,31 +99,95 @@ describe("product feature residue (1105/16-04)", () => { "tests/unit/route.test.ts": 'const target = "/invoice";\n', }); - expect(await productFeatureResidue(root, ID, ID, ["/invoice", "/invoice/:invoiceId"])).toEqual([ + expect(await productFeatureResidue(root, ID, ID, { paths: ["/invoice", "/invoice/:invoiceId"] })).toEqual([ "tests/e2e/detail.spec.ts", "tests/e2e/route-only.spec.ts", "tests/visual/hash.visual.spec.ts", ]); }); + // Diff review of 09-07. The first feature of a context takes the context's + // path (`/invoice`) and a later one a path under it (`/invoice/line`), and + // the context stays while another feature is in it. + it("leaves a URL to a route still there with a longer prefix, such as a sibling feature's", async () => { + const root = await fixture({ + "tests/e2e/lines.spec.ts": 'await page.goto("/invoice/line");\nawait page.goto("/invoice/line/7");\n', + "tests/e2e/detail.spec.ts": 'await page.goto("/invoice/7");\n', + "tests/e2e/shared-prefix.spec.ts": 'await page.goto("/report/2026");\n', + }); + + expect( + await productFeatureResidue(root, ID, ID, { + paths: ["/invoice", "/report/:year"], + remainingPaths: ["/", "/invoice/line", "/report"], + }), + ).toEqual(["tests/e2e/detail.spec.ts"]); + }); + + it("stops a route prefix at an optional segment and finds a URL built with a template", async () => { + const root = await fixture({ + "tests/e2e/edit.spec.ts": 'await page.goto("/invoice/edit");\n', + "tests/e2e/query.spec.ts": "await page.goto(`/invoice${query}`);\n", + }); + + expect(await productFeatureResidue(root, ID, ID, { paths: ["/invoice/edit?"] })).toEqual([ + "tests/e2e/edit.spec.ts", + "tests/e2e/query.spec.ts", + ]); + }); + + it("searches a page object in a Playwright testDir, not a mock or a vitest test", async () => { + const root = await fixture({ + "playwright.config.ts": 'export default defineConfig({ testDir: "./tests/e2e" });\n', + "tests/e2e/support/invoice-page.ts": 'export const open = (page) => page.goto("/invoice");\n', + "tests/e2e/support/route.test.ts": 'const target = "/invoice";\n', + "tests/mocks/handlers/routes.ts": 'export const PAGE = "/invoice";\n', + }); + + expect(await productFeatureResidue(root, ID, ID, { paths: ["/invoice"] })).toEqual([ + "tests/e2e/support/invoice-page.ts", + ]); + }); + + it("finds the feature's route IDs in source by their whole name", async () => { + const root = await fixture({ + "src/contracts/titles.ts": "export const TITLE = messages.route.INVOICE_LIST.title;\n", + "src/contracts/longer.ts": 'export const KEY = "INVOICE_LIST_V2";\n', + }); + + expect(await productFeatureResidue(root, ID, ID, { ids: ["INVOICE_LIST"] })).toEqual([ + "src/contracts/titles.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([]); + expect(await productFeatureResidue(root, ID, ID, { paths: ["/", "/: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"); + it("does not count the template's own browser tests for the route paths of a generated feature", async () => { + const files: Record = {}; + for (const entry of await readdir(".")) { + if (/^playwright.*\.config\.ts$/u.test(entry)) files[entry] = await readFile(entry, "utf8"); } - const root = await fixture(specs); + expect(Object.keys(files)).toContain("playwright.config.ts"); + for (const entry of await readdir("tests", { recursive: true, withFileTypes: true })) { + if (!entry.isFile()) continue; + const file = path.join(entry.parentPath, entry.name).split(path.sep).join("/"); + if (!/\.[cm]?[jt]sx?$/u.test(file)) continue; + if (/^tests\/(?:e2e|visual|storybook|browser-capabilities)\//u.test(file) || /\.spec\./u.test(file)) { + files[file] = await readFile(file, "utf8"); + } + } + const root = await fixture(files); // create:feature product-feature declares PRODUCT_LIST at /product. - expect(await productFeatureResidue(root, "product-feature", "product-feature", ["/product"])).toEqual([]); + expect( + await productFeatureResidue(root, "product-feature", "product-feature", { paths: ["/product"] }), + ).toEqual([]); }); it("does not count a spec whose longer names only contain the ID", async () => {