chore(review): 1106 검사 범위 조치 브랜치를 합친다

This commit is contained in:
DongHyeonka
2026-11-06 07:02:34 +09:00
11 changed files with 317 additions and 15 deletions
+88
View File
@@ -14,6 +14,12 @@ import path from "node:path";
* only the failure state, no record otherwise. A route's latest run therefore
* decides. `scripts/write-a11y-report.ts` reads the records and reports those
* routes under `notChecked` instead of in the passed `scope`.
*
* 1106/11-01. No record used to mean "checked", and nothing but the spec said
* which routes needed one: a record call changed to `null` (review 11-R2) put
* the detail page back in `scope` and every check passed. The report now
* works the same routes out from the installed descriptors
* (`oneResourceReadRoutes`) and fails when one has no record.
*/
export const A11Y_DATA_STATE_DIRECTORY = "artifacts/tests/a11y-data-state";
@@ -74,6 +80,88 @@ export async function readA11yNotCheckedRoutes(
return Object.freeze(notChecked);
}
export type OneResourceRoute = Readonly<{
routeId: string;
operationIds: readonly string[];
}>;
type RouteFacts = Readonly<{
routeId: string;
access: string;
paramsSchema: string | null;
}>;
type ReadFacts = Readonly<{
contract: Readonly<{
operationId: string;
method: string;
pathTemplate: string;
inputValidator: Readonly<{ schemaId: string }>;
outputValidator: Readonly<{
safeParse(value: unknown): Readonly<{ success: boolean }>;
}>;
}>;
}>;
/**
* 1106/11-01. The installed routes the spec can scan only on their failure
* state, from the descriptors alone: a protected route whose `paramsSchema` is
* the input of a GET that reads one resource. A GET reads one resource by the
* rule `tests/e2e/support/installed-api-answers.ts` answers with: it has a
* path parameter and its output rejects an empty list, so no generic body
* answers it. The spec signs in only on protected routes, so a public route is
* not listed.
*
* This finds the detail pages that take their params schema from their read
* (the reference sample and every `create:feature --with-create` slice). A
* detail page whose params schema differs is not found, and its record alone
* decides, as before.
*/
export function oneResourceReadRoutes(
routes: Iterable<RouteFacts>,
operations: Iterable<ReadFacts>,
): readonly OneResourceRoute[] {
const readsByInput = new Map<string, string[]>();
for (const { contract } of operations) {
if (contract.method !== "GET" || !contract.pathTemplate.includes("{")) continue;
if (contract.outputValidator.safeParse([]).success) continue;
const reads = readsByInput.get(contract.inputValidator.schemaId) ?? [];
reads.push(contract.operationId);
readsByInput.set(contract.inputValidator.schemaId, reads);
}
const found: OneResourceRoute[] = [];
for (const route of routes) {
if (route.access !== "session-required" || route.paramsSchema === null) continue;
const reads = readsByInput.get(route.paramsSchema);
if (reads === undefined) continue;
found.push(
Object.freeze({ routeId: route.routeId, operationIds: Object.freeze([...reads]) }),
);
}
return Object.freeze(found);
}
/**
* 1106/11-01. One line for each route in `expected` that `notChecked` leaves
* out, which `a11y.json` would count as passed. Empty when every route that
* reads one resource has its failure-state record. A record for a route not in
* `expected` claims less and is not refused.
*/
export function oneResourceRoutesCountedAsChecked(
expected: readonly OneResourceRoute[],
notChecked: readonly A11yNotCheckedRoute[],
): readonly string[] {
const recorded = new Set(notChecked.map(({ routeId }) => routeId));
return Object.freeze(
expected
.filter(({ routeId }) => !recorded.has(routeId))
.map(
({ routeId, operationIds }) =>
`${routeId} reads one resource (${operationIds.join(", ")}) but has no failure-state record in ${A11Y_DATA_STATE_DIRECTORY}; tests/e2e/accessibility.spec.ts must record why it scanned the route on its failure state only`,
),
);
}
/**
* The `artifacts/tests/a11y.json` value. `automatedStatus: "passed"` speaks
* for `scope` only: the installed routes axe scanned in their own state.
+24 -7
View File
@@ -11,13 +11,21 @@ import path from "node:path";
* 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>/`. The test
* 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
* 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 test that
* still depends on the removed feature fails `test:all`, which the drill
* runs.
* 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 a whole kebab-case name. A longer
* name that contains it (`generate-product-feature-index.ts` for
* `product-feature`) 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.
*
* The reference sample keeps its own, wider pattern in
* scripts/test-sample-removal.ts: the template owns all of its files.
@@ -48,6 +56,8 @@ export async function productFeatureResidue(
String.raw`(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bmock\s*\(\s*)["'][^"'\n]*/features/(?:${names})/`,
"u",
);
const wholeName = new RegExp(`(?<![A-Za-z0-9-])(?:${names})(?![A-Za-z0-9-])`, "iu");
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"))) {
@@ -56,7 +66,14 @@ export async function productFeatureResidue(
}
for (const file of await filesUnder(path.join(root, "tests"))) {
const name = relative(file);
if (named.test(name) || imported.test(await readFile(file, "utf8"))) residue.push(name);
const text = await readFile(file, "utf8");
if (
named.test(name) ||
imported.test(text) ||
(playwrightSpec.test(name) && wholeName.test(text))
) {
residue.push(name);
}
}
return residue.sort();
}
+20
View File
@@ -1,8 +1,12 @@
import { mkdir } from "node:fs/promises";
import { ROUTE_REGISTRY } from "../src/features/installed-feature-contracts.ts";
import { COMPOSED_CONTRACT_CONTRIBUTIONS } from "../src/features/loaded-feature-runtimes.ts";
import { automatedA11yArtifactSchema } from "./contracts/release-artifacts.ts";
import {
automatedA11yReport,
oneResourceReadRoutes,
oneResourceRoutesCountedAsChecked,
readA11yNotCheckedRoutes,
} from "./lib/a11y-data-state.ts";
import { MANUAL_A11Y_ROUTE_IDS } from "./lib/manual-a11y-evidence.ts";
@@ -12,6 +16,22 @@ await mkdir("artifacts/tests", { recursive: true });
// 1103/11-01. Routes the spec scanned only on their failure state are not
// reported as passed.
const notChecked = await readA11yNotCheckedRoutes(MANUAL_A11Y_ROUTE_IDS);
// 1106/11-01. The records come from the spec alone. The descriptors say which
// routes need one, so a record call the spec lost fails here instead of
// counting a detail page as passed.
const countedAsChecked = oneResourceRoutesCountedAsChecked(
oneResourceReadRoutes(
Object.values(ROUTE_REGISTRY),
COMPOSED_CONTRACT_CONTRIBUTIONS.httpByOperationId.values(),
),
notChecked,
);
if (countedAsChecked.length > 0) {
process.stderr.write(
`a11y.json not written:\n${countedAsChecked.map((line) => `a11y: ${line}`).join("\n")}\n`,
);
process.exit(1);
}
await writeValidatedJsonArtifact({
path: "artifacts/tests/a11y.json",
schema: automatedA11yArtifactSchema,