75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { mkdir, readFile } from "node:fs/promises";
|
|
|
|
import { manualA11yReportArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
import {
|
|
MANUAL_A11Y_ROUTE_IDS,
|
|
validateManualA11yEvidence,
|
|
} from "./lib/manual-a11y-evidence.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
|
|
type ManualA11yResult = Readonly<{
|
|
routeId: string;
|
|
path: string;
|
|
reviewer: string | null;
|
|
reviewedAt: string | null;
|
|
releaseId: string | null;
|
|
failures: readonly string[];
|
|
passed: boolean;
|
|
}>;
|
|
|
|
const results: ManualA11yResult[] = [];
|
|
for (const routeId of MANUAL_A11Y_ROUTE_IDS) {
|
|
const path = `artifacts/tests/a11y-manual/${routeId}.md`;
|
|
const evidence = await readFile(path, "utf8");
|
|
const validation = validateManualA11yEvidence(evidence);
|
|
const failures =
|
|
validation.fields["Route ID"] === routeId
|
|
? validation.failures
|
|
: Object.freeze([...validation.failures, "Route ID mismatch"]);
|
|
results.push({
|
|
routeId,
|
|
path,
|
|
reviewer: validation.fields.Reviewer ?? null,
|
|
reviewedAt: validation.fields["Reviewed at"] ?? null,
|
|
releaseId: validation.fields["Release ID"] ?? null,
|
|
failures,
|
|
passed: validation.passed && failures.length === 0,
|
|
});
|
|
}
|
|
const releaseIds = new Set(
|
|
results.map((result) => result.releaseId).filter((releaseId): releaseId is string => Boolean(releaseId)),
|
|
);
|
|
const coherentRelease =
|
|
releaseIds.size === 1 && results.every((result) => Boolean(result.releaseId));
|
|
const passed =
|
|
results.every((result) => result.passed) &&
|
|
coherentRelease;
|
|
|
|
await mkdir("artifacts/tests/a11y-manual", { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: "artifacts/tests/a11y-manual/report.json",
|
|
schema: manualA11yReportArtifactSchema,
|
|
value: {
|
|
schemaVersion: 1,
|
|
generatedAt: new Date().toISOString(),
|
|
scope: MANUAL_A11Y_ROUTE_IDS,
|
|
results,
|
|
coherentRelease,
|
|
passed,
|
|
},
|
|
});
|
|
|
|
if (!passed) {
|
|
const failures = results
|
|
.filter((result) => !result.passed)
|
|
.map((result) => `${result.routeId}: ${result.failures.join(", ")}`);
|
|
if (!coherentRelease) failures.push("release IDs do not match");
|
|
process.stderr.write(
|
|
`Manual accessibility evidence is incomplete:\n${failures.join("\n")}\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Manual accessibility evidence: PASS (${results.length} routes)\n`,
|
|
);
|