Scripts/audit-a11y.sh

125 lines · 4359 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# shellcheck source=lib/audit-pass.sh
 37source "$(dirname "$0")/lib/audit-pass.sh"
 38
 39case "$TIER" in
 40  floor | current | both) ;;
 41  *)
 42    echo "usage: $0 [floor|current|both]" >&2
 43    exit 2
 44    ;;
 45esac
 46
 47echo "==> Reading deployment target from $PROJECT"
 48read_deployment_target
 49echo "    deployment target: $DEPLOYMENT_TARGET (rank $FLOOR_RANK)"
 50
 51run_tier() {
 52  local which="$1"
 53  local sim udid label
 54
 55  sim=$(select_sim "$which")
 56  if [[ -z "$sim" ]]; then
 57    echo "error: no iPhone simulator at or above iOS $DEPLOYMENT_TARGET installed" >&2
 58    echo "hint: install one with 'xcodebuild -downloadPlatform iOS'" >&2
 59    return 1
 60  fi
 61
 62  udid=$(echo "$sim" | jq -r .udid)
 63  label=$(echo "$sim" | jq -r '"\(.name) (iOS \(.os))"')
 64
 65  echo
 66  echo "==> $which: $label"
 67
 68  if [[ "$which" = "floor" ]] && floor_is_approximate "$sim"; then
 69    echo "    NOTE: nearest installed runtime is a major version above the $DEPLOYMENT_TARGET"
 70    echo "          deployment target, so this is not true floor coverage."
 71  fi
 72
 73  # Findings are printed by the suite itself; surface them plus the verdict.
 74  #
 75  # The grep is wrapped in a brace group so that matching nothing does not read
 76  # as a failure. With pipefail the pipeline then carries xcodebuild's own
 77  # status, so an enforced audit failure reaches the caller — and is never
 78  # recorded as a pass — rather than being reported and exited 0.
 79  local code=0
 80  set -o pipefail
 81  xcodebuild test \
 82    -project "$PROJECT" \
 83    -scheme "$SCHEME" \
 84    -destination "id=$udid" \
 85    CODE_SIGNING_ALLOWED=NO 2>&1 \
 86    | { grep -E 'finding\(s\)|no accessibility findings|^  • |did not complete in time|Executed [0-9]+ test|\*\* TEST (SUCCEEDED|FAILED)' || true; } \
 87    || code=$?
 88
 89  return "$code"
 90}
 91
 92status=0
 93if [[ "$TIER" = "both" ]]; then
 94  run_tier floor || status=1
 95  run_tier current || status=1
 96else
 97  run_tier "$TIER" || status=1
 98fi
 99
100# A pass on both tiers is recorded against the tree it ran on, for the pre-push
101# hook to check. Only a tree the build saw exactly counts: no tracked changes,
102# and no untracked file the build would pick up.
103record_pass() {
104  if [[ -n "$(git status --porcelain --untracked-files=no)" ]] \
105    || git status --porcelain --untracked-files=all | grep -qE "$AUDIT_INPUTS"; then
106    echo "    Not recorded for the pre-push hook: the working tree differs from HEAD."
107    return
108  fi
109  git rev-parse 'HEAD^{tree}' >> "$(audit_pass_file)"
110  echo "    Recorded for the pre-push hook: $(git log -1 --format='%h %s')"
111}
112
113echo
114if [[ "$status" -eq 0 ]]; then
115  echo "==> Done. Findings above are the burndown list for issue #21."
116  echo "    They are reported, not enforced — widen"
117  echo "    AccessibilityAuditHarness.enforcedAuditTypes as each phase lands."
118  if [[ "$TIER" = "both" ]]; then
119    record_pass
120  fi
121else
122  echo "==> A tier failed. An enforced category reported a named finding, or the" >&2
123  echo "    suite could not run. Read the verdict line for each tier above." >&2
124fi
125exit "$status"