Scripts/audit-a11y.sh
107 lines · 3617 bytes · executable
1#!/usr/bin/env bash
2#
3# Run the accessibility audit suite against real simulator runtimes.
4#
5# ./Scripts/audit-a11y.sh # floor + current
6# ./Scripts/audit-a11y.sh floor # oldest supported runtime only
7# ./Scripts/audit-a11y.sh current # newest installed runtime only
8#
9# Why this exists rather than living entirely in CI: audit coverage is NOT
10# nested across OS versions — each runtime reports findings the others miss, in
11# both directions. Measured on Tracked Domains, iOS 18.6 reported 2 findings and
12# iOS 27.0 reported 6; at accessibility text sizes the Dashboard produced a
13# hit-region finding on 18.6 that 27.0 did not. The GitHub macos-26 image ships
14# only iOS 26.x runtimes, so it structurally cannot cover the floor. This machine
15# can.
16#
17# Scripts/test.sh does the same for the unit suite, for its own reasons.
18#
19# CI covers "current" on a clean checkout (which a local run cannot, since it
20# would miss an uncommitted file). This script covers "floor" (which CI cannot).
21# Together they cover both; neither duplicates the other.
22#
23# The deployment target is read from the project rather than hard-coded, so it
24# cannot drift out of sync.
25
26set -euo pipefail
27
28cd "$(dirname "$0")/.."
29
30PROJECT="DomainDig.xcodeproj"
31SCHEME="DomainDig"
32TIER="${1:-both}"
33
34# shellcheck source=lib/simulators.sh
35source "$(dirname "$0")/lib/simulators.sh"
36
37case "$TIER" in
38 floor | current | both) ;;
39 *)
40 echo "usage: $0 [floor|current|both]" >&2
41 exit 2
42 ;;
43esac
44
45echo "==> Reading deployment target from $PROJECT"
46read_deployment_target
47echo " deployment target: $DEPLOYMENT_TARGET (rank $FLOOR_RANK)"
48
49run_tier() {
50 local which="$1"
51 local sim udid label
52
53 sim=$(select_sim "$which")
54 if [[ -z "$sim" ]]; then
55 echo "error: no iPhone simulator at or above iOS $DEPLOYMENT_TARGET installed" >&2
56 echo "hint: install one with 'xcodebuild -downloadPlatform iOS'" >&2
57 return 1
58 fi
59
60 udid=$(echo "$sim" | jq -r .udid)
61 label=$(echo "$sim" | jq -r '"\(.name) (iOS \(.os))"')
62
63 echo
64 echo "==> $which: $label"
65
66 if [[ "$which" = "floor" ]] && floor_is_approximate "$sim"; then
67 echo " NOTE: nearest installed runtime is a major version above the $DEPLOYMENT_TARGET"
68 echo " deployment target, so this is not true floor coverage."
69 fi
70
71 # Findings are printed by the suite itself; surface them plus the verdict.
72 #
73 # The grep is wrapped in a brace group so that matching nothing does not read
74 # as a failure. With pipefail the pipeline then carries xcodebuild's own
75 # status, so an enforced audit failure reaches the caller — and the pre-push
76 # gate can act on it — rather than being reported and exited 0.
77 local code=0
78 set -o pipefail
79 xcodebuild test \
80 -project "$PROJECT" \
81 -scheme "$SCHEME" \
82 -destination "id=$udid" \
83 CODE_SIGNING_ALLOWED=NO 2>&1 \
84 | { grep -E 'finding\(s\)|no accessibility findings|^ • |did not complete in time|Executed [0-9]+ test|\*\* TEST (SUCCEEDED|FAILED)' || true; } \
85 || code=$?
86
87 return "$code"
88}
89
90status=0
91if [[ "$TIER" = "both" ]]; then
92 run_tier floor || status=1
93 run_tier current || status=1
94else
95 run_tier "$TIER" || status=1
96fi
97
98echo
99if [[ "$status" -eq 0 ]]; then
100 echo "==> Done. Findings above are the burndown list for issue #21."
101 echo " They are reported, not enforced — widen"
102 echo " AccessibilityAuditHarness.enforcedAuditTypes as each phase lands."
103else
104 echo "==> A tier failed. An enforced category reported a named finding, or the" >&2
105 echo " suite could not run. Read the verdict line for each tier above." >&2
106fi
107exit "$status"