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',