fix(scripts): 제거 드릴의 빌드 잔여물 검사도 이름 단위로 찾는다

문제: 앞 커밋으로 `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
This commit is contained in:
DongHyeonka
2026-11-13 05:25:04 +09:00
parent 57cc579a15
commit b05bf19c05
3 changed files with 30 additions and 7 deletions
+13 -1
View File
@@ -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(`(?<![A-Za-z0-9_-])(?:${names})(?![A-Za-z0-9_-])`, "u");
}
async function filesUnder(directory: string): Promise<string[]> {
const entries = await readdir(directory, { withFileTypes: true }).catch(() => []);
const nested = await Promise.all(
@@ -83,7 +95,7 @@ export async function productFeatureResidue(
): 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 wholeAnyName = featureNamePattern(featureId, directory);
const pathNames = (relativePath: string) =>
relativePath
.split("/")
+4 -5
View File
@@ -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) {
+13 -1
View File
@@ -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',