omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / orig4 / run.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # tests/orig4/run.sh: omega-mv#731 ORIG-4 host glue (POSIX sh, disclosed). It only sequences: |
| 18 | # verify the seeded compiler and every pinned source against native/orig4/orig4.pin, |
| 19 | # concatenate, compile, generate the SYNTHETIC fixture, run the in-process tests, run the |
| 20 | # shadow advisor over the fixture with both candidate images, the kill switch, the |
| 21 | # process-path refusals and the budget, the static default-off proof, and record every |
| 22 | # status under OUT. Every judgment about records, images and scores is made by the .om |
| 23 | # units; this file compares exit codes, line shapes and counts. |
| 24 | # Host CPU only. No GPU, network, service or model process is touched. |
| 25 | # ORIG4_RECORDS=<omexp-v1 file> ORIG4_ALLOW=<allow-list file>: real-record mode, the advisor |
| 26 | # runs over that file (owner records stay local; point OUT outside the tree). |
| 27 | # ORIG4_OVERHEAD=1 with ORIG4_RECORDS, ORIG4_ALLOW and ORIG4_IMAGE (a v2 MLP image): the |
| 28 | # per-decision overhead runs of benchmarks-mv docs/orig3/PROTOCOL-v2.md, v2 admission, |
| 29 | # interleaved ORIG4_REPS (default 5) times: disabled, image scorer, retrieval. Wall times in |
| 30 | # microseconds land in OUT/<run>.wall_us; the judge computes the overhead from them. |
| 31 | set -u |
| 32 | ROOT=$(cd "$(dirname "$0")/../.." && pwd) |
| 33 | OUT=${OUT:-$ROOT/build/orig4} |
| 34 | if [ -n "${BUILD:-}" ]; then |
| 35 | mkdir -p "$BUILD" |
| 36 | else |
| 37 | BUILD=$(mktemp -d "${TMPDIR:-/tmp}/orig4.XXXXXX") |
| 38 | trap 'rm -rf "$BUILD"' EXIT |
| 39 | fi |
| 40 | OMC=$ROOT/seed/out/omc |
| 41 | TRAIN=${ORIG4_TRAIN_GIT:-$ROOT/../aien-train} |
| 42 | EXPECT=$ROOT/tests/orig4/expected |
| 43 | PIN=$ROOT/native/orig4/orig4.pin |
| 44 | CAND=$ROOT/native/orig4/candidates |
| 45 | N=$ROOT/native/orig4 |
| 46 | FIXSEED=7 |
| 47 | FIXCOUNT=780 |
| 48 | FIXFNV=626048380840256264 |
| 49 | FIX100FNV=3415637669635212362 |
| 50 | MLP=$CAND/mlp-scratch-seed19024.img |
| 51 | AFF=$CAND/affine-seed19024.img |
| 52 | mkdir -p "$OUT" "$BUILD/units" |
| 53 | SUM="$OUT/summary.txt" |
| 54 | : > "$SUM" |
| 55 | note() { echo "$*" | tee -a "$SUM"; } |
| 56 | fail() { note "ORIG4_SHADOW_RUN_FAIL $*"; exit 1; } |
| 57 | ms() { date +%s%N; } |
| 58 | |
| 59 | note "build_dir=$BUILD" |
| 60 | note "source_commit=$(git -C "$ROOT" rev-parse HEAD)" |
| 61 | note "host=$(uname -srm)" |
| 62 | |
| 63 | # 1. The compiler: seed/out/omc must match seed/out/omc.sha256 and the pin. |
| 64 | set -- $(sha256sum "$OMC") |
| 65 | OMC_SHA=$1 |
| 66 | [ "$OMC_SHA" = "$(awk '{print $1}' "$ROOT/seed/out/omc.sha256")" ] || fail "compiler hash $OMC_SHA differs from seed/out/omc.sha256" |
| 67 | [ "$OMC_SHA" = "$(awk '$1 == "omc" {print $2}' "$PIN")" ] || fail "compiler hash $OMC_SHA differs from orig4.pin" |
| 68 | note "compiler_sha256=$OMC_SHA" |
| 69 | |
| 70 | # 2. The pinned units: git show from the pinned object stores, hash against the pin. Every |
| 71 | # aien-train unit names one commit (the gate step checks out exactly that one), and every |
| 72 | # omega unit names an ancestor of this checkout. |
| 73 | LIB="" |
| 74 | TRAIN_SHA="" |
| 75 | while read -r kind order repo commit path sha; do |
| 76 | [ "$kind" = "unit" ] || continue |
| 77 | case "$repo" in |
| 78 | omega) |
| 79 | dir=$ROOT |
| 80 | git -C "$ROOT" merge-base --is-ancestor "$commit" HEAD 2> /dev/null || fail "omega pin $commit is not an ancestor of HEAD" ;; |
| 81 | aien-train) |
| 82 | dir=$TRAIN |
| 83 | [ -z "$TRAIN_SHA" ] || [ "$TRAIN_SHA" = "$commit" ] || fail "aien-train units pin two commits: $TRAIN_SHA $commit" |
| 84 | TRAIN_SHA=$commit ;; |
| 85 | *) fail "unknown pin repo $repo" ;; |
| 86 | esac |
| 87 | f="$BUILD/units/$order-$(basename "$path")" |
| 88 | git -C "$dir" show "$commit:$path" > "$f" 2>> "$OUT/materialize.stderr" || fail "materialize $repo $commit:$path" |
| 89 | set -- $(sha256sum "$f") |
| 90 | [ "$1" = "$sha" ] || fail "unit $path hash $1 differs from the pin $sha" |
| 91 | LIB="$LIB $f" |
| 92 | done < "$PIN" |
| 93 | [ -n "$LIB" ] || fail "no units in the pin" |
| 94 | note "units_pinned=$(echo $LIB | wc -w)" |
| 95 | (cd "$CAND" && sha256sum -c SHA256SUMS) > "$OUT/candidates-check.txt" 2>&1 || fail candidate hashes |
| 96 | awk '$1 == "image" {print $2 " " $3}' "$PIN" | while read -r img sha; do |
| 97 | set -- $(sha256sum "$CAND/$img") |
| 98 | [ "$1" = "$sha" ] || exit 1 |
| 99 | done || fail "candidate image differs from the pin" |
| 100 | |
| 101 | # build NAME CALLER...: one concatenated unit compiled by the seeded compiler. |
| 102 | build() { |
| 103 | name=$1; shift |
| 104 | cat $LIB "$@" > "$BUILD/$name.om" |
| 105 | "$OMC" < "$BUILD/$name.om" > "$BUILD/$name.elf" 2> "$OUT/$name.compile.stderr" |
| 106 | rc=$? |
| 107 | echo "$rc" > "$OUT/$name.compile.rc" |
| 108 | [ "$rc" -eq 0 ] || return "$rc" |
| 109 | head -c 4 "$BUILD/$name.elf" | od -An -c | grep -q 'E L F' || return 70 |
| 110 | chmod 700 "$BUILD/$name.elf" |
| 111 | } |
| 112 | build shadow "$N/shadow.om" "$N/shadowmain.om" || fail compile shadow |
| 113 | build shadow-test "$N/shadow.om" "$ROOT/tests/orig4/shadow-test.om" || fail compile shadow-test |
| 114 | SH="$BUILD/shadow.elf" |
| 115 | note "binaries_sha256 shadow=$(sha256sum "$SH" | cut -c1-16) shadow-test=$(sha256sum "$BUILD/shadow-test.elf" | cut -c1-16)" |
| 116 | |
| 117 | # le64 N: 8 little-endian bytes. cfg W...: config words. allowblock FILE: the 4096-byte block. |
| 118 | le64() { n=$1; i=0; while [ "$i" -lt 8 ]; do b=$((n % 256)); n=$((n / 256)); printf "\\$(printf '%03o' "$b")"; i=$((i + 1)); done; } |
| 119 | cfg() { for v in "$@"; do le64 "$v"; done; } |
| 120 | allowblock() { { cat "$1"; head -c 4096 /dev/zero; } | head -c 4096; } |
| 121 | count() { grep -c -E "$1" "$OUT/$2.stdout"; } |
| 122 | |
| 123 | # run NAME ENABLE BUDGET IMGLEN IMAGE RECORDS ALLOWFILE [ADMISSION KIND]: one advisor run |
| 124 | # (mode S); the exit code is returned, stdout/stderr/rc and the wall time land in OUT. |
| 125 | run() { |
| 126 | name=$1 |
| 127 | t0=$(ms) |
| 128 | { printf 'S'; cfg "$2" "$3" "$4" "${8:-0}" "${9:-0}" 0 0 0; allowblock "$7"; cat "$5"; cat "$6"; } \ |
| 129 | | "$SH" > "$OUT/$name.stdout" 2> "$OUT/$name.stderr" |
| 130 | rc=$?; t1=$(ms) |
| 131 | echo "$rc" > "$OUT/$name.rc" |
| 132 | echo "$(( (t1 - t0) / 1000000 ))" > "$OUT/$name.wall_ms" |
| 133 | echo "$(( (t1 - t0) / 1000 ))" > "$OUT/$name.wall_us" |
| 134 | note "$name rc=$rc wall_ms=$(cat "$OUT/$name.wall_ms") lines=$(wc -l < "$OUT/$name.stdout") $(grep -E '^(COST|FALLBACK all|SHADOW disabled)' "$OUT/$name.stdout" | tail -n 1)" |
| 135 | return "$rc" |
| 136 | } |
| 137 | # shape NAME: every stdout line of a run is SHADOW, ADVICE, FALLBACK or COST. |
| 138 | shape() { |
| 139 | if grep -v -E '^(SHADOW|ADVICE|FALLBACK|COST) ' "$OUT/$1.stdout" | grep -q .; then |
| 140 | note "$1: unexpected output line: $(grep -v -E '^(SHADOW|ADVICE|FALLBACK|COST) ' "$OUT/$1.stdout" | head -n 1)" |
| 141 | return 1 |
| 142 | fi |
| 143 | } |
| 144 | # expect NAME RC: the run's exit code. |
| 145 | expect() { [ "$(cat "$OUT/$1.rc")" -eq "$2" ] || fail "$1 exit $(cat "$OUT/$1.rc"), expected $2"; } |
| 146 | # armcost NAME: every advised arm is one of the fixture's measured arms 0..4, and the COST |
| 147 | # line has adv_cost >= oracle_cost and incumbent_cost >= oracle_cost (the oracle is the |
| 148 | # per-record minimum over admissible arms, so nothing admissible beats it). |
| 149 | armcost() { |
| 150 | [ "$(count '^ADVICE seq=[0-9]+ arm=[5-7] ' "$1")" -eq 0 ] || fail "$1 advised an arm above 4" |
| 151 | awk '/^COST / { for (i = 2; i <= NF; i++) { split($i, kv, "="); v[kv[1]] = kv[2] }; n++ |
| 152 | if (v["adv_cost"] + 0 < v["oracle_cost"] + 0 || v["incumbent_cost"] + 0 < v["oracle_cost"] + 0) bad = 1 } |
| 153 | END { exit (n == 1 && !bad) ? 0 : 1 }' "$OUT/$1.stdout" || fail "$1 cost below the oracle" |
| 154 | } |
| 155 | # hash FILE: the records' FNV-1a 64 through the advisor's H mode. |
| 156 | hash() { { printf 'H'; cat "$1"; } | "$SH"; } |
| 157 | |
| 158 | if [ "${ORIG4_OVERHEAD:-0}" = 1 ]; then |
| 159 | [ -f "${ORIG4_RECORDS:-}" ] || fail "ORIG4_RECORDS ${ORIG4_RECORDS:-unset}" |
| 160 | [ -f "${ORIG4_ALLOW:-}" ] || fail "ORIG4_ALLOW ${ORIG4_ALLOW:-unset}" |
| 161 | [ -f "${ORIG4_IMAGE:-}" ] || fail "ORIG4_IMAGE ${ORIG4_IMAGE:-unset}" |
| 162 | note "overhead records fnv=$(hash "$ORIG4_RECORDS") bytes=$(wc -c < "$ORIG4_RECORDS") image_sha256=$(sha256sum "$ORIG4_IMAGE" | cut -c1-64)" |
| 163 | i=1 |
| 164 | while [ "$i" -le "${ORIG4_REPS:-5}" ]; do |
| 165 | run "ovh_disabled_$i" 0 2048 11560 "$ORIG4_IMAGE" "$ORIG4_RECORDS" "$ORIG4_ALLOW" 1 0; expect "ovh_disabled_$i" 0 |
| 166 | run "ovh_mlp_$i" 1 2048 11560 "$ORIG4_IMAGE" "$ORIG4_RECORDS" "$ORIG4_ALLOW" 1 0; expect "ovh_mlp_$i" 0 |
| 167 | shape "ovh_mlp_$i" || fail "ovh_mlp_$i shape" |
| 168 | grep -q '^SHADOW admission=v2 admitted=[0-9]* advisor=0$' "$OUT/ovh_mlp_$i.stdout" || fail "ovh_mlp_$i admission line" |
| 169 | run "ovh_near_$i" 1 2048 11560 "$ORIG4_IMAGE" "$ORIG4_RECORDS" "$ORIG4_ALLOW" 1 1; expect "ovh_near_$i" 0 |
| 170 | shape "ovh_near_$i" || fail "ovh_near_$i shape" |
| 171 | grep -q '^SHADOW admission=v2 admitted=[0-9]* advisor=1$' "$OUT/ovh_near_$i.stdout" || fail "ovh_near_$i admission line" |
| 172 | for k in disabled mlp near; do note "OVERHEAD run=$k rep=$i wall_us=$(cat "$OUT/ovh_${k}_$i.wall_us")"; done |
| 173 | i=$((i + 1)) |
| 174 | done |
| 175 | (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr *.wall_us) > "$OUT/raw.sha256" |
| 176 | note "ORIG4_SHADOW_OVERHEAD_PASS" |
| 177 | exit 0 |
| 178 | fi |
| 179 | |
| 180 | if [ -n "${ORIG4_RECORDS:-}" ]; then |
| 181 | # Real-record mode: the given records, the given allow-list, both candidates; nothing else. |
| 182 | [ -f "$ORIG4_RECORDS" ] || fail "ORIG4_RECORDS $ORIG4_RECORDS" |
| 183 | [ -f "${ORIG4_ALLOW:-}" ] || fail "ORIG4_ALLOW ${ORIG4_ALLOW:-unset}" |
| 184 | note "records_source=owner-records fnv=$(hash "$ORIG4_RECORDS") bytes=$(wc -c < "$ORIG4_RECORDS") (real-record run; development-only; bytes stay local)" |
| 185 | run owner_mlp 1 2048 11560 "$MLP" "$ORIG4_RECORDS" "$ORIG4_ALLOW"; expect owner_mlp 0; shape owner_mlp || fail owner_mlp shape |
| 186 | run owner_affine 1 2048 1816 "$AFF" "$ORIG4_RECORDS" "$ORIG4_ALLOW"; expect owner_affine 0; shape owner_affine || fail owner_affine shape |
| 187 | note "COST_WALL records=$(sed -n 's/^SHADOW records=\([0-9]*\) .*/\1/p' "$OUT/owner_mlp.stdout") ms=$(cat "$OUT/owner_mlp.wall_ms") image=mlp owner-records" |
| 188 | note "COST_WALL records=$(sed -n 's/^SHADOW records=\([0-9]*\) .*/\1/p' "$OUT/owner_affine.stdout") ms=$(cat "$OUT/owner_affine.wall_ms") image=affine owner-records" |
| 189 | (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr) > "$OUT/raw.sha256" |
| 190 | note "ORIG4_SHADOW_RUN_PASS (owner-records)" |
| 191 | exit 0 |
| 192 | fi |
| 193 | |
| 194 | # 3. The SYNTHETIC fixture (sxgen seed 7, 780 records) through the advisor's G mode, and the |
| 195 | # allow-list of docs/si19/orig1-datasets.txt entries for it (aien-train, hashes only). |
| 196 | { printf 'G'; cfg "$FIXSEED" "$FIXCOUNT"; } | "$SH" > "$BUILD/fixture.rb" 2> "$OUT/fixture.stderr" |
| 197 | rc=$?; echo "$rc" > "$OUT/fixture.rc" |
| 198 | [ "$rc" -eq 0 ] || fail fixture generation |
| 199 | [ "$(wc -c < "$BUILD/fixture.rb")" -eq $((FIXCOUNT * 256)) ] || fail fixture size |
| 200 | FNV=$(hash "$BUILD/fixture.rb") |
| 201 | [ "$FNV" = "$FIXFNV" ] || fail "fixture fnv $FNV, expected $FIXFNV" |
| 202 | printf '%s SYNTHETIC fixture-seed7-780-records\n%s SYNTHETIC fixture-seed7-100-records\n' "$FIXFNV" "$FIX100FNV" > "$BUILD/allow.txt" |
| 203 | note "records_source=SYNTHETIC fixture seed=$FIXSEED count=$FIXCOUNT fnv=$FNV sha256=$(sha256sum "$BUILD/fixture.rb" | cut -d' ' -f1)" |
| 204 | |
| 205 | # 4. In-process tests (the candidate MLP image, then the affine image, on stdin). |
| 206 | t0=$(ms) |
| 207 | cat "$MLP" "$AFF" | "$BUILD/shadow-test.elf" > "$OUT/shadow-test.stdout" 2> "$OUT/shadow-test.stderr" |
| 208 | rc=$?; t1=$(ms) |
| 209 | echo "$rc" > "$OUT/shadow-test.rc" |
| 210 | note "shadow-test rc=$rc wall_ms=$(( (t1 - t0) / 1000000 )) $(cat "$OUT/shadow-test.stdout")" |
| 211 | [ "$rc" -eq 0 ] || fail shadow-test |
| 212 | grep -q '^ORIG4_SHADOW_TEST_PASS checks=[1-9]' "$OUT/shadow-test.stdout" || fail shadow-test verdict line |
| 213 | |
| 214 | # 5. The advisor over the fixture with both candidates (config: enable 1, budget 2048). |
| 215 | run fixture_mlp 1 2048 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect fixture_mlp 0 |
| 216 | shape fixture_mlp || fail fixture_mlp shape |
| 217 | grep -q "^SHADOW records=$FIXCOUNT data_fnv=$FIXFNV allow=2\$" "$OUT/fixture_mlp.stdout" || fail fixture_mlp records line |
| 218 | grep -q '^SHADOW image_fnv=9232652764948363499 kind=2 nparams=705 data_bound=16622604375676129865 bound_matches=no$' "$OUT/fixture_mlp.stdout" || fail fixture_mlp image line |
| 219 | [ "$(count '^ADVICE seq=[0-9]+ arm=[0-7] incumbent=[0-7] oracle=[0-7] score=[0-9]+$' fixture_mlp)" -eq "$FIXCOUNT" ] || fail fixture_mlp advice count |
| 220 | [ "$(count '^COST records=780 scored=780 fallback=0 adv_cost=[0-9]+ oracle_cost=[0-9]+ incumbent_cost=[0-9]+$' fixture_mlp)" -eq 1 ] || fail fixture_mlp cost line |
| 221 | note "COST_WALL records=$FIXCOUNT ms=$(cat "$OUT/fixture_mlp.wall_ms") image=mlp fixture" |
| 222 | run fixture_affine 1 2048 1816 "$AFF" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect fixture_affine 0 |
| 223 | shape fixture_affine || fail fixture_affine shape |
| 224 | grep -q '^SHADOW image_fnv=3416091170583141300 kind=1 nparams=96 data_bound=16622604375676129865 bound_matches=no$' "$OUT/fixture_affine.stdout" || fail fixture_affine image line |
| 225 | [ "$(count '^ADVICE ' fixture_affine)" -eq "$FIXCOUNT" ] || fail fixture_affine advice count |
| 226 | [ "$(count '^COST records=780 scored=780 fallback=0 ' fixture_affine)" -eq 1 ] || fail fixture_affine cost line |
| 227 | note "COST_WALL records=$FIXCOUNT ms=$(cat "$OUT/fixture_affine.wall_ms") image=affine fixture" |
| 228 | |
| 229 | # 6. Kill switch: enable 0 prints only SHADOW disabled and exits 0 (the stream after the |
| 230 | # config is never read). |
| 231 | run disabled 0 2048 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect disabled 0 |
| 232 | [ "$(cat "$OUT/disabled.stdout")" = "SHADOW disabled" ] || fail kill switch output |
| 233 | |
| 234 | # 7. Process-path refusals. Every mutated record file is authorized through its own hash so |
| 235 | # the refusal under test is the record admission, not the allow-list. |
| 236 | cp "$MLP" "$BUILD/damaged.img"; printf '\001' | dd of="$BUILD/damaged.img" bs=1 seek=5000 conv=notrunc 2> /dev/null |
| 237 | run damaged_image 1 2048 11560 "$BUILD/damaged.img" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect damaged_image 0 |
| 238 | shape damaged_image || fail damaged_image shape |
| 239 | grep -q '^FALLBACK all reason=image-5$' "$OUT/damaged_image.stdout" || fail damaged image not refused |
| 240 | [ "$(count '^ADVICE ' damaged_image)" -eq 0 ] || fail damaged image advised |
| 241 | head -c 11000 "$MLP" > "$BUILD/short.img" |
| 242 | run short_image 1 2048 11000 "$BUILD/short.img" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect short_image 0 |
| 243 | grep -q '^FALLBACK all reason=image-1$' "$OUT/short_image.stdout" || fail truncated image not refused |
| 244 | cp "$BUILD/fixture.rb" "$BUILD/forged.rb"; printf '\001' | dd of="$BUILD/forged.rb" bs=1 seek=$((3 * 256 + 31 * 8)) conv=notrunc 2> /dev/null |
| 245 | printf '%s SYNTHETIC forged-fixture-test-only\n' "$(hash "$BUILD/forged.rb")" > "$BUILD/allow-forged.txt" |
| 246 | run forged_record 1 2048 11560 "$MLP" "$BUILD/forged.rb" "$BUILD/allow-forged.txt"; expect forged_record 66 |
| 247 | grep -q '^FALLBACK all reason=records-7$' "$OUT/forged_record.stdout" || fail forged record not refused |
| 248 | cp "$BUILD/fixture.rb" "$BUILD/profile.rb"; { le64 1048576; } | dd of="$BUILD/profile.rb" bs=1 seek=$((0 * 256 + 10 * 8)) conv=notrunc 2> /dev/null |
| 249 | printf '%s SYNTHETIC profile-fixture-test-only\n' "$(hash "$BUILD/profile.rb")" > "$BUILD/allow-profile.txt" |
| 250 | run wrong_profile 1 2048 11560 "$MLP" "$BUILD/profile.rb" "$BUILD/allow-profile.txt"; expect wrong_profile 66 |
| 251 | grep -q '^FALLBACK all reason=records-9$' "$OUT/wrong_profile.stdout" || fail wrong-profile record not refused |
| 252 | sed 's/^\(626048380840256264\) SYNTHETIC/\1 REVOKED/' "$BUILD/allow.txt" > "$BUILD/allow-revoked.txt" |
| 253 | grep -q "^$FIXFNV REVOKED" "$BUILD/allow-revoked.txt" || fail revoked allow-list edit |
| 254 | run revoked 1 2048 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow-revoked.txt"; expect revoked 67 |
| 255 | grep -q '^FALLBACK all reason=allow-12$' "$OUT/revoked.stdout" || fail revoked dataset admitted |
| 256 | grep -v "^$FIXFNV " "$BUILD/allow.txt" > "$BUILD/allow-absent.txt" |
| 257 | run absent 1 2048 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow-absent.txt"; expect absent 67 |
| 258 | grep -q '^FALLBACK all reason=allow-13$' "$OUT/absent.stdout" || fail unlisted dataset admitted |
| 259 | for f in damaged_image short_image forged_record wrong_profile revoked absent; do shape "$f" || fail "$f shape"; done |
| 260 | run budget10 1 10 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect budget10 0 |
| 261 | shape budget10 || fail budget10 shape |
| 262 | [ "$(count '^FALLBACK seq=[0-9]+ reason=budget$' budget10)" -eq $((FIXCOUNT - 10)) ] || fail budget fallback count |
| 263 | [ "$(count '^ADVICE ' budget10)" -eq 10 ] || fail budget advice count |
| 264 | grep -q '^COST records=780 scored=10 fallback=770 ' "$OUT/budget10.stdout" || fail budget cost line |
| 265 | # v2 admission (ORIG1-CONTRACT-v2.md): the retrieval advisor over the fixture scores the 468 |
| 266 | # admitted records and falls back on the 312 refused ones; the v1 image under the v2 scorer |
| 267 | # is refused (image-9: its SS[20] is 0). |
| 268 | run fixture_v2_near 1 2048 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow.txt" 1 1; expect fixture_v2_near 0 |
| 269 | shape fixture_v2_near || fail fixture_v2_near shape |
| 270 | grep -q '^SHADOW admission=v2 admitted=468 advisor=1$' "$OUT/fixture_v2_near.stdout" || fail fixture_v2_near admission line |
| 271 | [ "$(count '^FALLBACK seq=[0-9]+ reason=refused$' fixture_v2_near)" -eq 312 ] || fail fixture_v2_near refused count |
| 272 | grep -q '^COST records=780 scored=468 fallback=312 ' "$OUT/fixture_v2_near.stdout" || fail fixture_v2_near cost line |
| 273 | run fixture_v2_v1image 1 2048 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow.txt" 1 0; expect fixture_v2_v1image 0 |
| 274 | grep -q '^FALLBACK all reason=image-9$' "$OUT/fixture_v2_v1image.stdout" || fail v1 image accepted under v2 |
| 275 | [ "$(count '^ADVICE ' fixture_v2_v1image)" -eq 0 ] || fail v1 image advised under v2 |
| 276 | run bad_config 1 4096 11560 "$MLP" "$BUILD/fixture.rb" "$BUILD/allow.txt"; expect bad_config 68 |
| 277 | [ ! -s "$OUT/bad_config.stdout" ] || fail bad config printed |
| 278 | printf 'X' | "$SH" > "$OUT/bad_mode.stdout" 2> "$OUT/bad_mode.stderr"; echo $? > "$OUT/bad_mode.rc"; expect bad_mode 64 |
| 279 | for f in fixture_mlp fixture_affine budget10 fixture_v2_near; do armcost "$f"; done |
| 280 | for f in fixture_mlp fixture_affine disabled damaged_image short_image forged_record wrong_profile revoked absent budget10 fixture_v2_near fixture_v2_v1image bad_config bad_mode shadow-test; do |
| 281 | [ -s "$OUT/$f.stderr" ] && fail "$f wrote to stderr" |
| 282 | done |
| 283 | # Golden output: every run's stdout byte for byte against tests/orig4/expected (the ADVICE |
| 284 | # incumbent/oracle fields and the COST sums are judged here, not only their shape). |
| 285 | for f in shadow-test fixture_mlp fixture_affine disabled damaged_image short_image forged_record wrong_profile revoked absent budget10 fixture_v2_near fixture_v2_v1image bad_config bad_mode; do |
| 286 | cmp -s "$EXPECT/$f.stdout" "$OUT/$f.stdout" || fail "$f stdout differs from tests/orig4/expected/$f.stdout" |
| 287 | done |
| 288 | note "golden: 15 stdout files byte-identical to tests/orig4/expected" |
| 289 | note "refusals: damaged image-5, truncated image-1, forged records-7, wrong-profile records-9, revoked allow-12, absent allow-13, budget 10/770, config 68, mode 64" |
| 290 | |
| 291 | # 8. Default-off proof, static: the tap's environment variable has exactly one reader in the |
| 292 | # code (the test harness), and the serving/runtime sources never reference the advisor. |
| 293 | readers=$(cd "$ROOT" && grep -rl 'OMEGA_EMPIRICAL_RECORDS' src tests/runtime tests/gates mk tools Makefile 2> /dev/null | sort) |
| 294 | echo "$readers" > "$OUT/tap-readers.txt" |
| 295 | [ "$readers" = "tests/runtime/rx_empirical_optimizer.c" ] || fail "OMEGA_EMPIRICAL_RECORDS readers: $readers" |
| 296 | srcrefs=$(cd "$ROOT" && grep -rlE 'omexp|orig4|shadow\.om|hvscore|shadow-advice' src | sort) |
| 297 | echo "$srcrefs" > "$OUT/src-advisor-refs.txt" |
| 298 | [ -z "$srcrefs" ] || fail "src/ references the advisor: $srcrefs" |
| 299 | note "default_off: tap readers = tests/runtime/rx_empirical_optimizer.c only; src/ references to omexp|orig4|shadow.om|hvscore|shadow-advice = none" |
| 300 | |
| 301 | (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr *.wall_ms candidates-check.txt tap-readers.txt src-advisor-refs.txt) > "$OUT/raw.sha256" |
| 302 | (cd "$BUILD" && sha256sum -- *.elf *.om *.rb *.img *.txt) > "$OUT/build.sha256" |
| 303 | note "ORIG4_SHADOW_RUN_PASS" |