Files
clean-architecture-frontend…/tests/unit/manual-a11y-evidence.test.ts
DongHyeonka aa4bddac36 fix(a11y): 수동 접근성 기록이 릴리스 태그로 서명되고 WCAG 2.2 칸을 갖는다
수동 접근성 기록 검사에 구멍이 둘 있다.
- FE-GATE-028(`review:a11y-manual`)은 기록끼리 Release ID가 같은지만 본다
  (05-01). 후보를 받는 입력이 없어, 첫 release에 세 기록을 서명한 뒤 화면을
  바꾸고 기록을 그대로 둔 채 다음 release를 돌아도 통과한다. checklist의
  "release 후보마다 한 번"이 지켜지지 않는다(결함 패턴 G7).
- 제품은 WCAG 2.2 AA를 약속하는데 기록 양식은 M1~M7과 스크린 리더뿐이다
  (05-05의 남은 것). axe에 규칙이 없는 2.4.11 포커스 가림과 일부만 보는 2.5.8
  목표 크기를 볼 칸이 없다.

고른 방법:
- 결정(2026-11-13, r9-fe·w2-fe-2: 후보 ID는 릴리스 태그)대로
  `scripts/verify-a11y-manual.ts`가 env `RELEASE_TAG`를 읽고, 각 기록의
  `Release ID`가 그 태그와 같지 않으면 실패한다. 태그가 비면 비교할 것이 없으니
  모두 실패한다(fail-closed). release job은 이미 `RELEASE_TAG`를 넘기고
  FE-GATE-028이 그것을 요구한다(main `000b5a35`). 규칙은
  `releaseTagFailures`(`scripts/lib/manual-a11y-evidence.ts`)에 둔다.
- 결정 R9-D9(2026-11-12, 총괄)대로 기록 양식에 `M8 Focus not obscured`
  (2.4.11)와 `M9 Target size`(2.5.8)를 더한다: 검사기의 필드 목록, checklist,
  템플릿 기록 셋, `create:feature`가 만드는 기록. checklist의 `Release ID` 예는
  "release tag"로 바꿨다.
- 버린 대안: workflow의 `RELEASE_ID`와 대조(run마다 달라 사람이 미리 적을 수
  없다), 칸 없이 태그만 더하기(2.2 AA 일부를 아무도 보지 않는다).

위험·한계: 다운스트림의 기존 route 기록에는 M8·M9가 없어 다음 동기화 뒤
FE-GATE-009 형식 검사가 그 필드 이름을 대며 실패한다. 기록마다
`M8 Focus not obscured: pending`, `M9 Target size: pending` 두 줄을 더하면 된다.
서명한 기록의 `Release ID`는 다음 release부터 태그(예 `v1.4.0`)로 적는다.

검증: `tests/unit/manual-a11y-evidence.test.ts`(M8·M9가 빠진 기록 거절, 태그
같음·다름·빔, `review:a11y-manual`을 실제로 띄워 태그로 통과·다음 태그와 빈
태그로 실패)가 고치기 전 코드에서 실패하고 고친 뒤 통과한다(desktop, PR 본문).

Refs: 1112/05-01, 1112/05-05
2026-11-13 18:45:16 +09:00

182 lines
6.9 KiB
TypeScript

import { afterAll, describe, expect, it } from "vitest";
import { spawnSync } from "node:child_process";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import {
MANUAL_A11Y_ROUTE_IDS,
releaseTagFailures,
validateManualA11yEvidence,
validateManualA11yRecordFormat,
} from "../../scripts/lib/manual-a11y-evidence.ts";
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
const reviewed = `Status: reviewed
Route ID: APP_HOME
Release ID: v1.4.0
Reviewer: reviewer@example.test
Reviewed at: 2026-07-25T12:00:00Z
Signature: review-record-1
Attestation: accepted
M1 Keyboard: pass
M2 Visible focus: pass
M3 Route focus: pass
M4 Modal focus: not-applicable (no modal)
M5 Error association: not-applicable (no form error)
M6 Color signal: pass
M7 Reduced motion: pass
M8 Focus not obscured: pass
M9 Target size: pass
Screen reader: pass
Notes: no defects`;
describe("manual accessibility evidence", () => {
it("requires evidence for every registered user-visible route", () => {
expect([...MANUAL_A11Y_ROUTE_IDS].sort()).toEqual(
Object.keys(ROUTE_REGISTRY).sort(),
);
});
it("accepts a complete signed human review record", () => {
expect(validateManualA11yEvidence(reviewed)).toMatchObject({
failures: [],
passed: true,
});
});
it("rejects pending, unsigned, or incomplete evidence", () => {
expect(
validateManualA11yEvidence(
reviewed
.replace("Status: reviewed", "Status: pending-manual-review")
.replace("Signature: review-record-1", "Signature:")
.replace("Screen reader: pass", "Screen reader: pending"),
),
).toMatchObject({
failures: ["Status", "Signature", "Screen reader"],
passed: false,
});
});
it("does not treat an unexplained not-applicable verdict as evidence", () => {
expect(
validateManualA11yEvidence(
reviewed.replace(
"M4 Modal focus: not-applicable (no modal)",
"M4 Modal focus: not-applicable",
),
),
).toMatchObject({
failures: ["M4 Modal focus"],
passed: false,
});
});
// 08-06: the merge stage checks only that each record keeps the template's
// shape; the signed review itself is a release-stage gate (FE-GATE-028).
describe("record format", () => {
const pending = reviewed
.replace("Status: reviewed", "Status: pending-manual-review")
.replace("Release ID: v1.4.0", "Release ID:")
.replace("Reviewer: reviewer@example.test", "Reviewer:")
.replace("Reviewed at: 2026-07-25T12:00:00Z", "Reviewed at:")
.replace("Signature: review-record-1", "Signature:")
.replace("Attestation: accepted", "Attestation: pending")
.replace("M1 Keyboard: pass", "M1 Keyboard: pending");
it("accepts a pending template and a signed record", () => {
expect(validateManualA11yRecordFormat(pending, "APP_HOME")).toEqual([]);
expect(validateManualA11yRecordFormat(reviewed, "APP_HOME")).toEqual([]);
});
it("accepts every checked-in route record", () => {
for (const routeId of MANUAL_A11Y_ROUTE_IDS) {
const record = readFileSync(`docs/accessibility/route-reviews/${routeId}.md`, "utf8");
expect(validateManualA11yRecordFormat(record, routeId), routeId).toEqual([]);
}
});
it.each([
["a missing field", pending.replace("Signature:\n", ""), "APP_HOME", "Signature"],
["an unknown status", pending.replace("Status: pending-manual-review", "Status: done"), "APP_HOME", "Status"],
["an unknown verdict", pending.replace("M1 Keyboard: pending", "M1 Keyboard: ok"), "APP_HOME", "M1 Keyboard"],
["another route's record", pending, "NOT_FOUND", "Route ID"],
["a reviewed record that is not complete", reviewed.replace("Signature: review-record-1", "Signature:"), "APP_HOME", "Signature"],
// 1112/05-05. The WCAG 2.2 AA criteria axe does not cover.
["a record without the focus-not-obscured review", pending.replace("M8 Focus not obscured: pass\n", ""), "APP_HOME", "M8 Focus not obscured"],
["a record without the target-size review", pending.replace("M9 Target size: pass\n", ""), "APP_HOME", "M9 Target size"],
])("rejects %s", (_name, record, routeId, field) => {
expect(validateManualA11yRecordFormat(record, routeId)).toContain(field);
});
});
// 1112/05-01. A record signed for one release tag is not evidence for the
// next one, and with no tag there is nothing to sign against.
describe("release tag", () => {
it("accepts the Release ID that is the release tag", () => {
expect(releaseTagFailures("v1.4.0", "v1.4.0")).toEqual([]);
});
it("rejects a record signed for an earlier release", () => {
expect(releaseTagFailures("v1.5.0", "v1.4.0")).toEqual([
'Release ID "v1.4.0" is not the release tag "v1.5.0"',
]);
});
it.each([undefined, "", " "])("fails closed when the tag is %j", (tag) => {
expect(releaseTagFailures(tag, "v1.4.0")).toEqual([
"no release tag to compare the Release ID with (RELEASE_TAG is empty)",
]);
});
});
});
// 1112/05-01. FE-GATE-028 runs `review:a11y-manual`; it reads RELEASE_TAG.
describe("review:a11y-manual against the release tag", () => {
const roots: string[] = [];
afterAll(() => {
for (const root of roots) rmSync(root, { recursive: true, force: true });
});
function signedRecords(releaseId: string): string {
const root = mkdtempSync(path.join(tmpdir(), "a11y-manual-"));
roots.push(root);
mkdirSync(path.join(root, "docs/accessibility/route-reviews"), { recursive: true });
for (const routeId of MANUAL_A11Y_ROUTE_IDS) {
writeFileSync(
path.join(root, `docs/accessibility/route-reviews/${routeId}.md`),
reviewed
.replace("Route ID: APP_HOME", `Route ID: ${routeId}`)
.replace("Release ID: v1.4.0", `Release ID: ${releaseId}`),
);
}
return root;
}
function review(root: string, releaseTag: string | undefined) {
const environment = { ...process.env };
delete environment["RELEASE_TAG"];
if (releaseTag !== undefined) environment["RELEASE_TAG"] = releaseTag;
return spawnSync(process.execPath, [path.resolve("scripts/verify-a11y-manual.ts")], {
cwd: root,
encoding: "utf8",
env: environment,
});
}
it("passes records signed for the tag and refuses them for the next tag or no tag", () => {
const root = signedRecords("v1.4.0");
expect(review(root, "v1.4.0")).toMatchObject({ status: 0 });
const next = review(root, "v1.5.0");
expect(next.status).toBe(1);
expect(next.stderr).toContain('is not the release tag "v1.5.0"');
const untagged = review(root, undefined);
expect(untagged.status).toBe(1);
expect(untagged.stderr).toContain("RELEASE_TAG is empty");
}, childProcessTimeout(771));
});