Files
clean-architecture-frontend…/scripts/lib/feature-residue.ts
T
DongHyeonka e3c8db48ae chore(features): 참조 기능과 예제 화면을 지우고 레지스트리를 다시 승인한다
소유자 결정(2026-11-07, design-docs repo-structure/README.md 3.4절)으로
템플릿 샘플을 지운다. 샘플이 맡던 시험 대상은 앞 커밋들이 옮겼다.

참조 기능과 예제 화면, 두 context, 그 시험, e2e 3개, 수동 접근성 기록
7개, 런타임 프로필 키, test:reference-feature(명령, 산출물, 게이트
참조), 커버리지 정책 행을 지웠다. removable-template-features 목록은
비우고 장치는 남겼다: test:sample-removal은 인자가 없으면 목록을
하나씩 지우고, 비면 SKIP을 출력하고 보고서에 건너뛴 사례를 남긴다.
기능 스위치 시험과 홈 시작 링크 스위치 시험은 시험 전용 fixture 기능으로
옮겼다. browser soak은 생성 기능을 넣은 빌드에서 돈다. 문서의 샘플
경로를 고쳤다. 날짜가 붙은 설계·리뷰 기록의 본문은 그대로 두었다.
레지스트리 기준선(update:registry-baseline, OWNER DongHyeonka), CI 계약
기준선과 workflow, 초기 JS 기록(194,354B, 17파일, 첫 기능 6,327B, 기능
539B, context 4B)을 다시 받았다.

위험: 레지스트리 행 삭제는 breaking이다. 샘플을 고쳐 쓰는 다운스트림은
수정/삭제 충돌을 만난다. 성능 lab의 기능 라우트 측정은 템플릿에
공개 기능 라우트가 없어 measured:false다. TEMPLATE_FIXTURE 출처는
플랫폼 코드에 남았다.

검증(desktop): check:types, lint, check:architecture, check:registries,
check:ci, verify:documentation, test:unit, test:component,
test:contract, test:integration, test:recipes, test:coverage(Risk
coverage PASS 378/378, 문턱 68개), test:e2e 183, test:a11y, test:visual,
test:storybook, test:browser-capabilities, test:feature-scaffold PASS(76
checks), test:sample-removal SKIP, build, check:bundle.
2026-11-08 14:07:58 +09:00

93 lines
4.0 KiB
TypeScript

import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
/**
* 1105/16-04. What a product feature leaves behind after
* `test:sample-removal -- --feature=<id>` deleted its folders, in the copy the
* drill made.
*
* - `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
* feature's `src/features/<dir>/` or `tests/features/<dir>/`. 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
* `invoice-feature`, the manual's example, 51 times), and the drill flagged
* them as residue of a product feature that took that name. A vitest test
* that still depends on the removed feature fails `test:all`, which the
* drill runs.
* - 1106/16-01. `test:all` runs vitest only (the `*.test.ts(x)` files under
* `tests/`, vitest.config.ts), and no step of the drill runs a Playwright
* spec. So a spec (`*.spec.ts`) that names the feature only in its text,
* such as `test.describe("invoice-feature", ...)`, is residue: its text is
* 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.
* 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.
*
* The drill applies the same rule to a sample a project lists in
* scripts/lib/removable-template-features.ts.
*/
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
}
async function filesUnder(directory: string): Promise<string[]> {
const entries = await readdir(directory, { withFileTypes: true }).catch(() => []);
const nested = await Promise.all(
entries.map((entry) => {
const target = path.join(directory, entry.name);
return entry.isDirectory() ? filesUnder(target) : Promise.resolve([target]);
}),
);
return nested.flat();
}
export async function productFeatureResidue(
root: string,
featureId: string,
directory: string,
): Promise<string[]> {
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
const named = new RegExp(names, "iu");
const imported = new RegExp(
String.raw`(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bmock\s*\(\s*)["'][^"'\n]*/features/(?:${names})/`,
"u",
);
const specNames = [...new Set([featureId, directory])]
.filter((name) => name.includes("-"))
.map(escapeRegExp);
const wholeName =
specNames.length === 0
? null
: new RegExp(`(?<![A-Za-z0-9_-])(?:${specNames.join("|")})(?![A-Za-z0-9_-])`, "u");
const playwrightSpec = /\.spec\.[cm]?[jt]sx?$/u;
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 (named.test(`${name}\n${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) ||
imported.test(text) ||
(wholeName !== null && playwrightSpec.test(name) && wholeName.test(text))
) {
residue.push(name);
}
}
return residue.sort();
}