merge: PR #38을 합친 검사 브랜치에 넣는다
frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s

This commit is contained in:
DongHyeonka
2026-11-13 07:16:02 +09:00
3 changed files with 304 additions and 20 deletions
+129 -12
View File
@@ -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/<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
@@ -25,14 +33,24 @@ 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. `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.
@@ -41,6 +59,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(
@@ -52,13 +82,73 @@ async function filesUnder(directory: string): Promise<string[]> {
return nested.flat();
}
/**
* 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("*") || 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<string[]> {
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,
routes: FeatureRoutes = {},
): Promise<string[]> {
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 = 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(`(?<![A-Za-z0-9_-])(?:${routeIds.join("|")})(?![A-Za-z0-9_-])`, "u");
const pathNames = (relativePath: string) =>
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",
@@ -70,20 +160,47 @@ export async function productFeatureResidue(
specNames.length === 0
? null
: new RegExp(`(?<![A-Za-z0-9_-])(?:${specNames.join("|")})(?![A-Za-z0-9_-])`, "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 (named.test(`${name}\n${await readFile(file, "utf8")}`)) residue.push(name);
if (name.startsWith("src/.generated/")) continue;
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);
const text = await readFile(file, "utf8");
if (
named.test(name) ||
pathNames(name) ||
imported.test(text) ||
(wholeName !== null && playwrightSpec.test(name) && wholeName.test(text))
(playwrightSpec.test(name) && wholeName !== null && wholeName.test(text)) ||
(browserFile(name) && opensRemovedRoute(text))
) {
residue.push(name);
}
+29 -6
View File
@@ -10,10 +10,11 @@ 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";
import { featureNamePattern, type FeatureRoutes, productFeatureResidue } from "./lib/feature-residue.ts";
import { isProductionModulePath } from "./lib/risk-coverage.ts";
import {
createRemovalFixtureRoot,
@@ -164,6 +165,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 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<string>(
Object.values(PLATFORM_ROUTE_REGISTRY).map((route) => route.path),
);
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");
@@ -455,11 +472,17 @@ 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);
const builtResiduePattern = new RegExp(
`${escapeRegExp(featureId)}|${escapeRegExp(located.directory)}`,
"i",
// 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,
featureRoutes,
);
// 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) {