The signed review is per release candidate, so the merge gate could never pass. FE-GATE-009 now checks only the record format; the checked-in records are source-controlled evidence, not command output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
3.1 KiB
TypeScript
101 lines
3.1 KiB
TypeScript
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
|
|
|
|
export const MANUAL_A11Y_ROUTE_IDS = Object.freeze(
|
|
Object.values(ROUTE_REGISTRY).map((route) => route.routeId),
|
|
);
|
|
|
|
const REVIEW_FIELDS = Object.freeze([
|
|
"M1 Keyboard",
|
|
"M2 Visible focus",
|
|
"M3 Route focus",
|
|
"M4 Modal focus",
|
|
"M5 Error association",
|
|
"M6 Color signal",
|
|
"M7 Reduced motion",
|
|
"Screen reader",
|
|
]);
|
|
|
|
const IDENTITY_FIELDS = Object.freeze([
|
|
"Status",
|
|
"Route ID",
|
|
"Release ID",
|
|
"Reviewer",
|
|
"Reviewed at",
|
|
"Signature",
|
|
"Attestation",
|
|
]);
|
|
|
|
const NOT_APPLICABLE = /^not-applicable \(.+\)$/;
|
|
|
|
function parseRecordFields(content: string): Record<string, string> {
|
|
return Object.fromEntries(
|
|
content
|
|
.split(/\r?\n/)
|
|
.map((line) => /^([^:]+):\s*(.*)$/.exec(line))
|
|
.filter((match): match is RegExpExecArray => match !== null)
|
|
.map((match) => [
|
|
match[1].trim(),
|
|
match[2].trim(),
|
|
]),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 08-06. The merge-stage check: the record for `routeId` keeps the template's
|
|
* fields and vocabulary, whether or not a human has reviewed it yet. A record
|
|
* that claims `reviewed` must also be complete. Returns the offending fields.
|
|
*/
|
|
export function validateManualA11yRecordFormat(content: string, routeId: string): string[] {
|
|
const fields = parseRecordFields(content);
|
|
const failures = [...IDENTITY_FIELDS, ...REVIEW_FIELDS].filter(
|
|
(field) => !(field in fields),
|
|
);
|
|
if (fields.Status !== undefined && !["pending-manual-review", "reviewed"].includes(fields.Status)) {
|
|
failures.push("Status");
|
|
}
|
|
if (fields["Route ID"] !== undefined && fields["Route ID"] !== routeId) failures.push("Route ID");
|
|
if (fields.Attestation !== undefined && !["pending", "accepted"].includes(fields.Attestation)) {
|
|
failures.push("Attestation");
|
|
}
|
|
for (const field of REVIEW_FIELDS) {
|
|
const verdict = fields[field];
|
|
if (verdict !== undefined && verdict !== "pass" && verdict !== "pending" && !NOT_APPLICABLE.test(verdict)) {
|
|
failures.push(field);
|
|
}
|
|
}
|
|
if (fields.Status === "reviewed") failures.push(...validateManualA11yEvidence(content).failures);
|
|
return [...new Set(failures)];
|
|
}
|
|
|
|
export function validateManualA11yEvidence(content: string) {
|
|
const fields = parseRecordFields(content);
|
|
const failures: string[] = [];
|
|
if (fields.Status !== "reviewed") failures.push("Status");
|
|
if (!fields["Route ID"]) failures.push("Route ID");
|
|
if (!fields["Release ID"]) failures.push("Release ID");
|
|
if (!fields.Reviewer) failures.push("Reviewer");
|
|
if (!fields.Signature) failures.push("Signature");
|
|
if (fields.Attestation !== "accepted") failures.push("Attestation");
|
|
if (
|
|
!fields["Reviewed at"] ||
|
|
!Number.isFinite(Date.parse(fields["Reviewed at"]))
|
|
) {
|
|
failures.push("Reviewed at");
|
|
}
|
|
|
|
for (const field of REVIEW_FIELDS) {
|
|
const result = fields[field];
|
|
if (
|
|
result !== "pass" &&
|
|
!NOT_APPLICABLE.test(result ?? "")
|
|
) {
|
|
failures.push(field);
|
|
}
|
|
}
|
|
return Object.freeze({
|
|
fields: Object.freeze(fields),
|
|
failures: Object.freeze(failures),
|
|
passed: failures.length === 0,
|
|
});
|
|
}
|