Files
clean-architecture-frontend…/tests/unit/a11y-report.test.ts
T
DongHyeonka 757d1c736b fix(a11y)!: 실패 화면으로만 검사한 라우트를 a11y.json에서 통과로 세지 않는다
문제
접근성 e2e는 보호 라우트의 목록 조회에 빈 목록을 답한다. 자원 하나를
읽는 상세 라우트(참조 기능의 상세, 생성기 --with-create의 상세)는
일반 답이 없어 실패 화면에서 axe를 돌린다. 그런데
scripts/write-a11y-report.ts는 설치된 라우트 전체를 scope에 넣고
automatedStatus "passed"를 쓴다. 화면 내용은 한 번도 검사하지 않은
라우트가 통과로 보고된다. annotation은 test 결과에만 남는다.

고른 방법과 버린 대안
- scripts/lib/a11y-data-state.ts(새 파일): 라우트 test가 끝날 때
  자기 상태를 artifacts/tests/a11y-data-state/<ROUTE_ID>.json에 남긴다.
  실패 화면으로만 봤으면 이유를 쓰고, 아니면 지운다. 그래서 라우트마다
  마지막 실행이 정한다. 세 엔진이 같은 파일을 쓰므로 임시 파일에 쓰고
  rename한다.
- tests/e2e/accessibility.spec.ts: 위 기록을 남긴다(공개 라우트와
  데이터 상태로 본 라우트는 지운다).
- a11y.json schemaVersion 2: scope에는 자기 상태로 검사한 라우트만,
  notChecked에는 실패 화면으로만 본 라우트와 이유를 넣는다. 둘을
  합치면 설치된 라우트 레지스트리와 같아야 한다(schema가 본다).
- 상세 라우트를 실제 데이터 상태로 검사하는 안은 버렸다. 출력
  validator에서 유효한 값을 일반적으로 만들 수 없고, 기능마다 견본
  응답을 받는 자리를 새로 열어야 한다.
- annotation을 Playwright JSON reporter로 읽는 안은 버렸다. test:a11y
  스크립트의 reporter와 산출물 경로를 바꿔야 하고, 경로는 다른 작업
  (12-04)이 바꾸는 중이다.
- 매뉴얼(docs/manual/reference/create-feature.md)에 상세 라우트가
  notChecked로 적히고 수동 검토가 맡는다고 적는다.

위험·한계
- a11y.json 모양이 바뀐다(schemaVersion 1 → 2, scope 의미, 새 필드).
  템플릿 안의 소비자는 ci-artifact-validator 하나이고 같이 바꿨다.
- 템플릿 상태에서도 참조 기능의 상세 라우트가 notChecked로 나온다.
  지금까지 실제로 검사하지 않던 것이 드러나는 것이다.
- 기록 디렉터리는 artifacts/tests 아래 고정 경로다. 12-04가 산출물
  경로를 실행마다 나누면 이 경로도 따라가야 한다.
- 라우트 test가 돌지 않은 실행에서는 그 라우트의 지난 기록이 남는다.
  지난 기록이 "검사 안 함"이면 덜 주장하는 쪽이라 위험하지 않다.

검증
- desktop batch에서 확인:
  node scripts/run-vitest.ts run tests/unit/a11y-report.test.ts
  corepack pnpm test:a11y (세 엔진) 뒤 artifacts/tests/a11y.json의
  notChecked에 REFERENCE_RESOURCE_DETAIL이 있고 scope에 없어야 한다.
- RED: 부모 커밋에는 scripts/lib/a11y-data-state.ts가 없어 새 unit
  test 파일 전체가 실패한다.

Refs: 1103/11-01
BREAKING CHANGE: artifacts/tests/a11y.json이 schemaVersion 2가 된다. scope는 실패 화면으로만 본 라우트를 빼고, 그 라우트는 새 notChecked 배열에 { routeId, reason }으로 들어간다. scope를 설치된 라우트 전체로 읽던 도구는 scope와 notChecked를 합쳐 읽는다.
2026-11-06 01:05:22 +09:00

102 lines
3.4 KiB
TypeScript

import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { automatedA11yArtifactSchema } from "../../scripts/contracts/release-artifacts.ts";
import {
automatedA11yReport,
readA11yNotCheckedRoutes,
recordA11yDataState,
} from "../../scripts/lib/a11y-data-state.ts";
import { MANUAL_A11Y_ROUTE_IDS } from "../../scripts/lib/manual-a11y-evidence.ts";
/**
* 1103/11-01. The accessibility spec scans a detail page on its failure state
* (no generic answer exists for a read of one resource). `a11y.json` must not
* count that route as passed: it goes to `notChecked` with its reason.
*/
const ROUTES: readonly string[] = MANUAL_A11Y_ROUTE_IDS;
const [CHECKED_ROUTE = "", FAILURE_STATE_ROUTE = ""] = ROUTES;
const REASON = "scanned on its failure state only: TEST_GET_ENTITY reads one resource";
const GENERATED_AT = "2026-11-05T00:00:00.000Z";
const directories: string[] = [];
async function recordDirectory(): Promise<string> {
const directory = await mkdtemp(path.join(tmpdir(), "a11y-data-state-"));
directories.push(directory);
return directory;
}
afterEach(async () => {
await Promise.all(
directories.splice(0).map((directory) =>
rm(directory, { recursive: true, force: true }),
),
);
});
describe("automated accessibility report", () => {
it("needs two installed routes to tell a checked route from a failure-state one", () => {
expect(ROUTES.length).toBeGreaterThanOrEqual(2);
});
it("reports a route scanned only on its failure state as not checked", async () => {
const directory = await recordDirectory();
await recordA11yDataState(CHECKED_ROUTE, null, directory);
await recordA11yDataState(FAILURE_STATE_ROUTE, REASON, directory);
const report = automatedA11yReport({
routeIds: ROUTES,
notChecked: await readA11yNotCheckedRoutes(ROUTES, directory),
generatedAt: GENERATED_AT,
});
expect(report.scope).toContain(CHECKED_ROUTE);
expect(report.scope).not.toContain(FAILURE_STATE_ROUTE);
expect(report.notChecked).toEqual([
{ routeId: FAILURE_STATE_ROUTE, reason: REASON },
]);
expect(automatedA11yArtifactSchema.safeParse(report).success).toBe(true);
});
it("lets a route's latest run decide", async () => {
const directory = await recordDirectory();
await recordA11yDataState(FAILURE_STATE_ROUTE, REASON, directory);
await recordA11yDataState(FAILURE_STATE_ROUTE, null, directory);
await expect(readA11yNotCheckedRoutes(ROUTES, directory)).resolves.toEqual([]);
});
it("refuses a report that counts a failure-state route as passed", () => {
const report = automatedA11yReport({
routeIds: ROUTES,
notChecked: [{ routeId: FAILURE_STATE_ROUTE, reason: REASON }],
generatedAt: GENERATED_AT,
});
expect(
automatedA11yArtifactSchema.safeParse({ ...report, scope: [...ROUTES] })
.success,
).toBe(false);
});
it("refuses a report that drops an installed route from both lists", () => {
const report = automatedA11yReport({
routeIds: ROUTES,
notChecked: [],
generatedAt: GENERATED_AT,
});
expect(automatedA11yArtifactSchema.safeParse(report).success).toBe(true);
expect(
automatedA11yArtifactSchema.safeParse({
...report,
scope: ROUTES.filter((routeId) => routeId !== FAILURE_STATE_ROUTE),
}).success,
).toBe(false);
});
});