forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBe12d32fTahinli6 days ago3982 commits

av1-suite-preflight.sh248 lines, 9.9 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# av1-suite-preflight.sh — the gate a server staging must pass BEFORE `=== SUITE`.
3#
4# WHY (lane-av1stagegaps, measured 2026-09-30). Three hosts, three different
5# preflight realities, one identical green suite:
6#
7# host C host-d the driver printed
8# === ORACLE RUNG CHECKER
9# rungs_exit=1 ok_count=0
10# === SUITE
11# and the suite ran. The real cause, with stderr
12# visible, was a MISSING PREREQUISITE: the host has
13# `~/.cache/aom-oracle/build` (aomdec/aomenc binaries)
14# and no `src/` tree, so the checker asserted nothing.
15# host A host-a staged with a bare `cargo test -p ec-av1 --lib`. No
16# pin-gate audit, no rung checker, no self-test: not a
17# failure, an ABSENT check.
18# so "green suite" meant checker-passed, checker-failed and no-checker-ran
19# with equal confidence.
20#
21# WHAT THIS DOES. Runs both preflight pieces, prints one machine-readable state
22# per piece, then a single VERDICT. Exit 0 only when every piece is GREEN or an
23# explicitly waived NOT-RUN, so a `set -e` staging driver CANNOT reach
24# `=== SUITE` on a failed or missing check.
25#
26# pin_audit = GREEN | FAIL | ABSENT (verify-fixture-library.sh: shape,
27# resolve, drift, invariants 1-4 +
28# census self-test)
29# rung_check = GREEN | FAIL | NOT-RUN | ABSENT
30# VERDICT = GREEN | WAIVED | BLOCKED
31#
32# NOT-RUN vs ABSENT is the distinction that matters. NOT-RUN means the checker
33# RAN and reported a missing prerequisite (exit 3 from check-aom-oracle-rungs.sh)
34# — a provisioning fact, not a code defect. ABSENT means the checker is not in
35# this tree at all, which is exactly the host-A defect and is never waivable.
36#
37# WAIVER. not-run can be waived, but only with an explicit non-empty reason that
38# is recorded in the verdict line, so a later reader can tell a deliberate
39# waiver from a check that silently vanished:
40# SUITE_RUNG_WAIVER="host host-d carries oracle binaries only; rung
41# coverage verified on the build host, see report"
42# An empty waiver counts as absent, so a unit's Environment= carrying a bare
43# SUITE_RUNG_WAIVER= cannot accidentally authorise a run.
44#
45# Usage:
46# scripts/av1-suite-preflight.sh [--tree DIR] [--self-test]
47#
48# Env:
49# EC_FIXTURES=<dir> fixture root (default <tree>/fixtures)
50# EC_REQUIRE_FIXTURES=1 make an absent/empty fixture path fatal
51# SUITE_RUNG_WAIVER=<reason> waive rung_check=not-run (see above)
52# SUITE_RUNG_CHECKER=<path> override the rung checker (self-test stubs)
53# SUITE_PIN_CHECKER=<path> override the pin preflight (self-test stubs)
54
55set -uo pipefail
56
57ROOT_DEFAULT=$(cd -- "$(dirname -- "$0")/.." && pwd)
58TREE=$ROOT_DEFAULT
59SELF_TEST=0
60while [ $# -gt 0 ]; do
61 case "$1" in
62 --tree) TREE=$2; shift 2 ;;
63 --self-test) SELF_TEST=1; shift ;;
64 -h|--help) sed -n '2,40p' "$0"; exit 0 ;;
65 *) echo "unknown argument: $1" >&2; exit 2 ;;
66 esac
67done
68PIN_CHECKER=${SUITE_PIN_CHECKER:-$TREE/scripts/verify-fixture-library.sh}
69RUNG_CHECKER=${SUITE_RUNG_CHECKER:-$TREE/scripts/check-aom-oracle-rungs.sh}
70
71pin_state=ABSENT
72rung_state=ABSENT
73
74run_pin() { # sets pin_state, prints every detail line
75 pin_state=ABSENT
76 if [ ! -f "$PIN_CHECKER" ]; then
77 echo "pin_audit_state=ABSENT reason=pin preflight not in tree ($PIN_CHECKER)" >&2
78 return
79 fi
80 local out rc
81 out=$("$PIN_CHECKER" 2>&1)
82 rc=$?
83 printf '%s\n' "$out" | sed 's/^/ /'
84 if [ $rc -eq 0 ]; then pin_state=GREEN; else pin_state=FAIL; fi
85 echo "pin_audit_exit=$rc state=$pin_state"
86}
87
88run_rungs() { # sets rung_state, prints every detail line
89 rung_state=ABSENT
90 if [ ! -f "$RUNG_CHECKER" ]; then
91 echo "rung_check_state=ABSENT reason=checker not in tree ($RUNG_CHECKER)" >&2
92 return
93 fi
94 local out rc ok_count
95 out=$("$RUNG_CHECKER" 2>&1)
96 rc=$?
97 ok_count=$(printf '%s\n' "$out" | grep -c '^ok ' || true)
98 # The detail lines are the whole point: the 2026-09-30 driver logged
99 # `rungs_exit=1 ok_count=0` and no reason at all. Every outcome here prints
100 # the checker's own stdout and stderr together, indented.
101 printf '%s\n' "$out" | sed 's/^/ /'
102 case $rc in
103 0) rung_state=GREEN ;;
104 3) rung_state=NOT-RUN ;;
105 *) rung_state=FAIL ;;
106 esac
107 echo "rungs_exit=$rc ok_count=$ok_count state=$rung_state"
108}
109
110verdict() { # echoes VERDICT; returns 0 iff GREEN or WAIVED
111 # A pin audit that did not run or failed, and a rung check that is absent
112 # or failed, are all fatal: no waiver exists for any of them. Only
113 # rung_check=not-run (a missing prerequisite) is waivable, and only with a
114 # non-empty reason.
115 local v=BLOCKED
116 local waived=""
117 if [ "$pin_state" = GREEN ] && [ "$rung_state" = GREEN ]; then
118 v=GREEN
119 elif [ "$pin_state" = GREEN ] && [ "$rung_state" = NOT-RUN ]; then
120 if [ -n "${SUITE_RUNG_WAIVER:-}" ]; then
121 v=WAIVED
122 waived=" (rung_check=not-run waived: ${SUITE_RUNG_WAIVER})"
123 fi
124 fi
125 echo "VERDICT=$v$waived"
126 if [ "$v" = BLOCKED ]; then
127 {
128 echo "PREFLIGHT BLOCKED: pin_audit=$pin_state rung_check=$rung_state."
129 echo " A staging with a failed or missing check must NOT reach === SUITE."
130 echo " rung_check=not-run (missing oracle source) is waivable only via"
131 echo " SUITE_RUNG_WAIVER='<host and reason>'; an absent checker never is."
132 } >&2
133 return 1
134 fi
135 return 0
136}
137
138self_test() {
139 local d rc=0 out
140 d=$(mktemp -d "${TMPDIR:-/tmp}/av1-preflight-selftest.XXXXXX")
141 # shellcheck disable=SC2064
142 trap "rm -rf '$d'" RETURN
143
144 stub() { # name, exit-code, body
145 printf '#!/usr/bin/env bash\n%s\nexit %s\n' "$3" "$2" >"$d/$1"
146 chmod +x "$d/$1"
147 }
148 # `set -o pipefail` is on, so `verdict | grep -q ...` returns verdict's own
149 # non-zero status even when grep matched, and every BLOCKED case would read
150 # as a self-test failure. Capture first, then compare.
151 v_of() { verdict 2>/dev/null; }
152 expect() { # expected-verdict, label
153 out=$("${@:3}" 2>/dev/null || true)
154 :
155 }
156
157 # 1. all green -> GREEN
158 stub pin-ok 0 'echo "verify-fixture-library: GREEN"'
159 stub rungs-ok 0 'echo "ok derives the rungs"'
160 PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1
161 RUNG_CHECKER=$d/rungs-ok run_rungs >/dev/null 2>&1
162 if [ "$(v_of)" = "VERDICT=GREEN" ]; then
163 echo "ok 1 an all-green staging is GREEN"
164 else
165 echo "FAIL 1 an all-green staging is GREEN"; rc=1
166 fi
167
168 # 2. rung checker FAILS (exit 1) -> BLOCKED. The mutation: red the checker
169 # and the gate must stop.
170 stub rungs-bad 1 'echo "FAIL derived file violates the rung contract"'
171 PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1
172 RUNG_CHECKER=$d/rungs-bad run_rungs >/dev/null 2>&1
173 if [ "$(v_of)" = "VERDICT=BLOCKED" ]; then
174 echo "ok 2 a FAILING rung checker blocks the suite"
175 else
176 echo "FAIL 2 a FAILING rung checker blocks the suite"; rc=1
177 fi
178
179 # 3. rung checker NOT-RUN (exit 3), no waiver -> BLOCKED.
180 stub rungs-notrun 3 'echo "PREREQ-ABSENT: no oracle source at ..."'
181 PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1
182 RUNG_CHECKER=$d/rungs-notrun run_rungs >/dev/null 2>&1
183 if [ "$(v_of)" = "VERDICT=BLOCKED" ]; then
184 echo "ok 3 not-run without a waiver blocks the suite"
185 else
186 echo "FAIL 3 not-run without a waiver blocks the suite"; rc=1
187 fi
188
189 # 4. not-run WITH a waiver -> WAIVED, and the reason lands in the verdict.
190 if [ "$(SUITE_RUNG_WAIVER='host C carries oracle binaries only' v_of)" \
191 = "VERDICT=WAIVED (rung_check=not-run waived: host C carries oracle binaries only)" ]
192 then
193 echo "ok 4 not-run with a named waiver is WAIVED, reason recorded"
194 else
195 echo "FAIL 4 not-run with a named waiver is WAIVED, reason recorded"; rc=1
196 fi
197
198 # 5. an EMPTY waiver authorises nothing: a unit Environment= carrying a bare
199 # SUITE_RUNG_WAIVER= is a real staging shape.
200 if [ "$(SUITE_RUNG_WAIVER='' v_of)" = "VERDICT=BLOCKED" ]; then
201 echo "ok 5 an empty waiver does not authorise a run"
202 else
203 echo "FAIL 5 an empty waiver does not authorise a run"; rc=1
204 fi
205
206 # 6. an ABSENT checker is never waivable: the host-A defect.
207 PIN_CHECKER=$d/pin-ok run_pin >/dev/null 2>&1
208 RUNG_CHECKER=$d/does-not-exist run_rungs >/dev/null 2>&1
209 if [ "$(SUITE_RUNG_WAIVER='a waiver' v_of)" = "VERDICT=BLOCKED" ]; then
210 echo "ok 6 a tree with NO rung checker is blocked even with a waiver"
211 else
212 echo "FAIL 6 a tree with NO rung checker is blocked even with a waiver"; rc=1
213 fi
214
215 # 6b. an ABSENT pin audit is fatal too, and not waivable by the same knob.
216 PIN_CHECKER=$d/does-not-exist run_pin >/dev/null 2>&1
217 RUNG_CHECKER=$d/rungs-ok run_rungs >/dev/null 2>&1
218 if [ "$(SUITE_RUNG_WAIVER='a waiver' v_of)" = "VERDICT=BLOCKED" ]; then
219 echo "ok 7 a tree with NO pin audit is blocked even with a waiver"
220 else
221 echo "FAIL 7 a tree with NO pin audit is blocked even with a waiver"; rc=1
222 fi
223
224 # 8. pin audit FAILING -> BLOCKED even when the rungs are green.
225 stub pin-bad 1 'echo "FAIL [invariant 4]: census self-test did not pass"'
226 PIN_CHECKER=$d/pin-bad run_pin >/dev/null 2>&1
227 RUNG_CHECKER=$d/rungs-ok run_rungs >/dev/null 2>&1
228 if [ "$(v_of)" = "VERDICT=BLOCKED" ]; then
229 echo "ok 8 a FAILING pin audit blocks the suite"
230 else
231 echo "FAIL 8 a FAILING pin audit blocks the suite"; rc=1
232 fi
233
234 return $rc
235}
236
237if [ "$SELF_TEST" = 1 ]; then
238 self_test
239 exit $?
240fi
241
242echo "=== PIN-GATE PREFLIGHT (EC_REQUIRE_FIXTURES=${EC_REQUIRE_FIXTURES:-0})"
243run_pin
244echo "=== ORACLE RUNG CHECKER"
245run_rungs
246echo "=== VERDICT"
247verdict
248exit $?