Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien/blob/main/tests/goal_microjobs/aienet-m1/run.sh # aien aien-dev/aien Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien / tests / goal_microjobs / aienet-m1 / run.sh` 563 lines ยท 26341 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: AGPL-3.0-or-later 3 # Host-only acceptance. Shell sequencing is a migration adapter for aien#22. 4 # No GPU, settlement, public listener, remote host or persistent identities. 5 set -euo pipefail 6 repo=$(cd "$(dirname "$0")/../../.." && pwd) 7 here="$repo/tests/goal_microjobs/aienet-m1" 8 : "${OH_TREE:?own Open Humanity seal-document worktree}" 9 : "${PROTOCOLS:?protocols source tree}" 10 : "${OMEGA_WORKTREE:?Allen pinned compiler tree}" 11 : "${RECOMPUTE_OMC:?`e5b32567` omc}" 12 : "${SHA_OMEGA_TREE:?tree containing pinned SHA unit}" 13 : "${CANON:?compiled canon from feat/aienet-m1-canon}" 14 canon_source=`b5057df61bc2175e6e1bf23d1ebce0a2857f8584` 15 canon_binary=`4d7d2a0bda184622980f61570b8ae5294a1989c89af2aa498bdbfa443abf2b1b` 16 # Pin the canon sources by git blob id, not by commit ancestry: a squash merge 17 # of feat/aienet-m1-canon leaves `b5057df` off main while the sources stay equal. 18 test "$(git -C "$repo" rev-parse HEAD:src/goal_microjobs/canon.om)" = `5719dc992cb358d7ea29dbec4ab82e310369de29` 19 test "$(git -C "$repo" rev-parse HEAD:scripts/goal_microjobs/canon-build.sh)" = `226fcae40b2daa9dcc3da785571b1cef70b41c4b` 20 test "$(sha256sum "$CANON" | cut -d' ' -f1)" = "$canon_binary" 21 export CARGO_BUILD_JOBS=4 PYTHONDONTWRITEBYTECODE=1 22 umask 077 23 E=${1:?usage: run.sh FRESH_EVIDENCE_DIRECTORY} 24 test ! -e "$E" 25 mkdir -p "$E" 26 E=$(cd "$E" && pwd) 27 K=$(mktemp -d /dev/shm/aienet-m1-keys.XXXXXX) 28 cleanup() { rm -rf -- "$K"; } 29 trap cleanup EXIT 30 mkdir "$K/requester" "$K/worker" "$K/pins" "$K/wpins" 31 export KEYS="$K/requester" WKEYS="$K/worker" PINS="$K/pins" WPINS="$K/wpins" 32 for file in "$KEYS/transport.seed" "$KEYS/submitter.p256" "$KEYS/verifier.p256" "$WKEYS/transport.seed" "$WKEYS/executor.p256"; do 33 openssl rand -hex -out "$file" 32 34 done 35 (cd "$OH_TREE"; cargo build --locked --release --bin aienet0-run --bin aienet0-serve --message-format=json) > "$E/build.jsonl" 2> "$E/build.log" 36 export RUN SERVE 37 RUN=$(jq -r 'select(.reason == "compiler-artifact" and .target.name == "aienet0-run" and .profile.test == false) | .executable // empty' "$E/build.jsonl") 38 SERVE=$(jq -r 'select(.reason == "compiler-artifact" and .target.name == "aienet0-serve" and .profile.test == false) | .executable // empty' "$E/build.jsonl") 39 test -x "$RUN"; test -x "$SERVE" 40 oh_source=$(git -C "$OH_TREE" rev-parse HEAD) 41 oh_run_sha=$(sha256sum "$RUN" | cut -d' ' -f1) 42 oh_serve_sha=$(sha256sum "$SERVE" | cut -d' ' -f1) 43 # The test executable enables only the worker's pre-existing cfg(test) pauses. 44 (cd "$OH_TREE"; cargo test --locked -p oh-volunteer --bin aienet0-serve --no-run --message-format=json) > "$E/test-build.jsonl" 2> "$E/test-build.log" 45 TEST_WORKER=$(jq -r 'select(.reason == "compiler-artifact" and .profile.test == true) | .executable // empty' "$E/test-build.jsonl") 46 test -x "$TEST_WORKER" 47 "$RUN" keys --keys "$KEYS" > "$E/requester-public" 48 "$SERVE" keys --keys "$WKEYS" > "$E/worker-public" 49 while read -r name key; do printf '%s\n' "$key" > "$WPINS/$name"; done < "$E/requester-public" 50 while read -r name key; do printf '%s\n' "$key" > "$PINS/$name"; done < "$E/worker-public" 51 export GM_KERNEL="$E/kernel" RECOMPUTE="$E/recompute" 52 bash "$repo/scripts/goal_microjobs/build.sh" "$repo/src/goal_microjobs/kernel.om" "$GM_KERNEL" > "$E/kernel-build.log" 2>&1 53 OMEGA_OMC="$RECOMPUTE_OMC" OMEGA_MV="$SHA_OMEGA_TREE" bash "$PROTOCOLS/specs/aienet/jobpath/build.sh" "$RECOMPUTE" > "$E/recompute-build.log" 2>&1 54 export RECOMPUTE_SHA256=`d2cd7382e0dc64e49498ae3b1ceffc73f1ddcbd3ddcf93e6d607498ccd58ea12` 55 test "$(sha256sum "$RECOMPUTE" | cut -d' ' -f1)" = "$RECOMPUTE_SHA256" 56 export RECOVERY="$E/recovery" 57 OMEGA_OMC="$RECOMPUTE_OMC" sh "$repo/scripts/goal_microjobs/recovery-build.sh" "$RECOVERY" > "$E/recovery-build.log" 2>&1 58 words() { local hex=$1; printf '%u %u %u %u\n' "0x${hex:0:16}" "0x${hex:16:16}" "0x${hex:32:16}" "0x${hex:48:16}"; } 59 hash_words() { words "$(sha256sum | cut -d' ' -f1)"; } 60 export EXECUTOR_WORDS VERIFIER_WORDS 61 EXECUTOR_WORDS=$(xxd -r -p "$PINS/executor.p256" | hash_words) 62 VERIFIER_WORDS=$(xxd -r -p "$WPINS/verifier.p256" | hash_words) 63 objective=$(printf aienet-m1-synthetic-objective | hash_words) 64 tenant=$(printf AIENET0-TENANT-TUR-TEST-V1 | hash_words) 65 capability=$(printf AIENET0-CAPABILITY-MATMUL-U32-V1 | hash_words) 66 subject=$(printf aienet-m1-explicit-subject | hash_words) 67 approval=$(printf aienet-m1-explicit-approval | hash_words) 68 expires=$(date -u -d tomorrow +%s) 69 driver="$repo/scripts/goal_microjobs/microjobs.sh" 70 sequence="$here/sequence.sh" 71 export STATE LISTEN 72 new_state() { 73 local state_seed=${2:-7} state_objective=${3:-$objective} 74 STATE="$E/${CASE_PREFIX:-}$1" 75 mkdir -p "$STATE/bindings" 76 printf '`01000200030002`%016x' "$state_seed" | xxd -r -p > "$STATE/payload1" 77 operand=$(hash_words < "$STATE/payload1") 78 { 79 printf '1 1 %s 7 9 1 1 1 4 0 0 0 0 120000\n' "$state_objective" 80 printf '2 1 1 2 0 0 1 0 0 0 0 1 5 1 1 7 120000 1 %s 0\n' "$operand" 81 } > "$STATE/input-plan" 82 printf '4 %s %s %s %s %s %s 2 3 2 %s 1\n' "$state_objective" "$tenant" "$subject" "$approval" "$capability" "$expires" "$state_seed" > "$STATE/bindings/1" 83 bash "$driver" init "$STATE" "$STATE/input-plan" 84 port=$(shuf -i 49152-65535 -n 1) 85 test -z "$(ss -H -ltn "sport = :$port")" 86 LISTEN="127.0.0.1:$port" 87 } 88 assert_done() { 89 local status_file=$1 wanted=$2 tag id st gen rest matches=0 90 while read -r tag id st gen rest; do 91 if test "$tag" = 101 && test "$id" = 1; then 92 matches=$((matches+1)) 93 test "$st" = 4 || return 1 94 test "$gen" = "$wanted" || return 1 95 fi 96 done < "$status_file" 97 test "$matches" = 1 || return 1 98 } 99 done_negative() { 100 printf '%s\n' "$2" > "$E/done-$1.input" 101 local rc=0 102 assert_done "$E/done-$1.input" 1 || rc=$? 103 test "$rc" = 1 104 } 105 exactly_once() { 106 bash "$driver" status "$STATE" > "$STATE/final-status" 107 assert_done "$STATE/final-status" "${1:-1}" || return 1 108 local tag id gen rest 109 local dispatch=0 result=0 verify=0 110 while read -r tag seq type node attempt gen rest; do 111 if test "$node" = 1 && test "$gen" = "${1:-1}"; then 112 case "$type" in 1) dispatch=$((dispatch+1));; 2) result=$((result+1));; 3) verify=$((verify+1));; esac 113 fi 114 done < "$STATE/journal" 115 test "$dispatch/$result/$verify" = 1/1/1 116 } 117 wait_file() { 118 local file=$1 pid=$2 119 for ((i=0;i<600;i++)); do 120 test ! -f "$file" || return 0 121 kill -0 "$pid" || return 1 122 sleep 0.05 123 done 124 echo "boundary not reached: $file" >&2 125 return 1 126 } 127 semantic() { 128 local name=$1; shift 129 if ! "$@"; then echo "M1_SEMANTIC $name" >&2; return 1; fi 130 } 131 cleanup_case() { 132 if test -n "${active_pid:-}"; then 133 kill "$active_pid" 2>/dev/null || true 134 wait "$active_pid" 2>/dev/null || true 135 fi 136 } 137 run_sequence() { bash "$sequence"; } 138 happy() { new_state happy; run_sequence; exactly_once; } 139 crash() { 140 local boundary=$1 141 new_state "crash-$boundary" 142 M1_PAUSE="$boundary" bash "$sequence" > "$STATE/first.log" 2>&1 & 143 local pid=$!; active_pid=$pid 144 wait_file "$STATE/paused" "$pid" 145 # Persisted artifact must already exist at every post-dispatch boundary. 146 if test "$boundary" != persisted; then semantic persist-before-dispatch test -s "$STATE/g1/job.an0b"; fi 147 sha256sum "$STATE/g1/job.an0b" > "$STATE/bundle.before" 148 kill -KILL "$pid" 149 wait "$pid" || true 150 rm -f "$STATE/paused" 151 run_sequence 152 sha256sum -c "$STATE/bundle.before" 153 exactly_once 154 } 155 worker_crash() { 156 local phase=${1:-admitted} 157 new_state "crash-worker-$phase" 158 M1_TEST_WORKER="$TEST_WORKER" M1_WORKER_PAUSE="$phase" bash "$sequence" > "$STATE/first.log" 2>&1 & 159 local pid=$!; active_pid=$pid 160 wait_file "$STATE/g1/worker.ready" "$pid" 161 read -r worker < "$STATE/g1/worker.pid" 162 sha256sum "$STATE/g1/job.an0b" > "$STATE/bundle.before" 163 kill -KILL "$worker" 164 wait "$pid" || true 165 run_sequence 166 sha256sum -c "$STATE/bundle.before" 167 exactly_once 168 } 169 correct() { 170 printf '`010002000300020000000000000008`' | xxd -r -p > "$STATE/payload2" 171 local changed; changed=$(hash_words < "$STATE/payload2") 172 bash "$driver" propose "$STATE" 6 1 0 1 7 0 $changed 0 0 173 printf '4 %s %s %s %s %s %s 2 3 2 8 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/2" 174 } 175 stale() { 176 local mode=${1:-single} expected=24 target=2 guard=operand-pin 177 new_state "stale-$mode" 178 M1_PAUSE=published bash "$sequence" > "$STATE/first.log" 2>&1 & 179 local pid=$!; active_pid=$pid 180 wait_file "$STATE/paused" "$pid" 181 correct 182 if test "$mode" = roundtrip; then 183 bash "$driver" propose "$STATE" 6 1 0 2 7 0 $operand 0 0 184 printf '4 %s %s %s %s %s %s 2 3 2 7 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/3" 185 expected=14; target=3; guard=generation-match 186 fi 187 cp "$STATE/journal" "$STATE/before-stale" 188 rm "$STATE/paused" 189 local rc=0; wait "$pid" || rc=$? 190 semantic "$guard" test "$rc" = "$expected" 191 cmp "$STATE/journal" "$STATE/before-stale" 192 # Independently challenge canon with the saved generation1 wire receipt. 193 local dag; dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) 194 local trusted 195 { printf '1\n'; cat "$STATE/plan" "$STATE/journal"; } | "$RECOVERY" > "$STATE/stale.effective" 196 read -r -a trusted < "$STATE/stale.effective" 197 { 198 cat "$STATE/g1/document" "$STATE/g1/out/$dag.mjr1" "$STATE/g1/out/$dag.mjv" 199 printf '5 1 %s 1 20 5 %s %s %s %s %s\n' "$target" "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$(( $(wc -l < "$STATE/journal") + 1 ))" "${trusted[*]:2:4}" "${trusted[*]:35:4}" 200 } > "$STATE/stale.ingest" 201 rc=0; "$CANON" ingest < "$STATE/stale.ingest" > "$STATE/stale.events" 2> "$STATE/stale.err" || rc=$? 202 test "$rc" = "$expected" && test ! -s "$STATE/stale.events" 203 run_sequence 204 exactly_once "$target" 205 } 206 generation_probe() { stale roundtrip; } 207 publish_only() { 208 M1_PAUSE=published bash "$sequence" > "$STATE/first.log" 2>&1 & 209 local pid=$!; active_pid=$pid 210 wait_file "$STATE/paused" "$pid" 211 kill -KILL "$pid"; wait "$pid" || true 212 rm "$STATE/paused" 213 } 214 altered() { 215 new_state altered 216 publish_only 217 local dag; dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) 218 cp "$STATE/g1/out/$dag.mjr1" "$STATE/receipt.original" 219 # Signature-covered byte, not a malformed wire header. 220 local old; old=$(od -An -tu1 -j176 -N1 "$STATE/g1/out/$dag.mjr1") 221 printf '%b' "\\$(printf '%03o' "$((old ^ 1))")" | dd of="$STATE/g1/out/$dag.mjr1" bs=1 seek=176 conv=notrunc status=none 222 cp "$STATE/journal" "$STATE/before" 223 local rc=0; run_sequence > "$STATE/refusal.log" 2>&1 || rc=$? 224 printf 'altered signature expected_exit=12 observed_exit=%s\n' "$rc" 225 test "$rc" = 12 226 cmp "$STATE/journal" "$STATE/before" 227 cp "$STATE/receipt.original" "$STATE/g1/out/$dag.mjr1" 228 run_sequence 229 exactly_once 230 } 231 wrong_output() { 232 new_state signed-wrong-output 233 local rc=0; M1_MISBEHAVE=wrong-output run_sequence > "$STATE/refusal.log" 2>&1 || rc=$? 234 test "$rc" = 13 235 test "$(wc -l < "$STATE/journal")" = 1 236 test -z "$(compgen -G "$STATE/g1/out/*.mjv")" 237 } 238 duplicate() { 239 new_state duplicate 240 run_sequence 241 cp "$STATE/journal" "$STATE/before" 242 # Ingest the same signed artifacts again, then ask the kernel to admit the 243 # newly sequenced RESULT. The immutable journal must refuse with code 33. 244 local line rest rc dag 245 dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) 246 { 247 cat "$STATE/g1/document" "$STATE/g1/out/$dag.mjr1" "$STATE/g1/out/$dag.mjv" 248 printf '5 1 1 1 20 5 %s %s 4 %s %s\n' "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$objective" "$operand" 249 } | "$CANON" ingest > "$STATE/replayed.events" 250 read -r line < "$STATE/replayed.events" 251 read -r _ _ rest <<< "$line" 252 rc=0; bash "$driver" propose "$STATE" $rest || rc=$? 253 test "$rc" = 33 254 # A distinct, genuinely executor-signed completion from the test worker 255 # (different source_hash) is independently checked and also cannot commit. 256 mkdir "$STATE/second-out" 257 printf '%s\n' --connect "$LISTEN" --keys "$WKEYS" --pins "$WPINS" --state "$STATE/second-worker" --retry --connect-timeout 10 > "$STATE/second.args" 258 AN0_TEST_SERVE_ARGS="$STATE/second.args" AN0_TEST_PAUSE= \ 259 "$TEST_WORKER" --ignored --exact tests::serve_crash_worker --nocapture > "$STATE/second-worker.log" 2>&1 & 260 local second_pid=$!; active_pid=$second_pid 261 "$RUN" run --resend "$STATE/g1/job.an0b" --listen "$LISTEN" --keys "$KEYS" --pins "$PINS" --out "$STATE/second-out" \ 262 --recompute "$RECOMPUTE" --recompute-sha256 "$RECOMPUTE_SHA256" --accept-timeout 10 263 wait "$second_pid" 264 if cmp -s "$STATE/g1/out/$dag.mjr1" "$STATE/second-out/$dag.mjr1"; then echo SECOND_RECEIPT_NOT_DISTINCT >&2; return 1; fi 265 "$RUN" check --bundle "$STATE/second-out/$dag.an0b" --mjr1 "$STATE/second-out/$dag.mjr1" --mjv "$STATE/second-out/$dag.mjv" --keys "$KEYS" --pins "$PINS" 266 { 267 cat "$STATE/g1/document" "$STATE/second-out/$dag.mjr1" "$STATE/second-out/$dag.mjv" 268 printf '5 1 1 1 20 5 %s %s 4 %s %s\n' "$EXECUTOR_WORDS" "$VERIFIER_WORDS" "$objective" "$operand" 269 } | "$CANON" ingest > "$STATE/second.events" 270 read -r line < "$STATE/second.events" 271 read -r _ _ rest <<< "$line" 272 rc=0; bash "$driver" propose "$STATE" $rest || rc=$? 273 test "$rc" = 33 274 run_sequence 275 cmp "$STATE/journal" "$STATE/before" 276 exactly_once 277 } 278 # Signature-only AN0V mutation leaves binding hashes valid. canon deliberately 279 # does not verify P-256, so removing OH check must make this case accept falsely. 280 attestation_signature() { 281 new_state attestation-signature 282 publish_only 283 local dag; dag=$(sha256sum "$STATE/g1/document" | cut -d' ' -f1) 284 local old; old=$(od -An -tu1 -j235 -N1 "$STATE/g1/out/$dag.mjv") 285 printf '%b' "\\$(printf '%03o' "$((old ^ 1))")" | dd of="$STATE/g1/out/$dag.mjv" bs=1 seek=235 conv=notrunc status=none 286 cp "$STATE/journal" "$STATE/before" 287 local rc=0; run_sequence > "$STATE/refusal.log" 2>&1 || rc=$? 288 semantic check-before-ingest test "$rc" = 14 289 cmp "$STATE/journal" "$STATE/before" 290 } 291 pin_substitution() { 292 local mode=$1 guard=operand-pin expected=24 source_gen=1 target_gen=1 source_state source_dag 293 local other_objective old_operand target_dag pid rc=0 tag id st generation rest matches=0 294 case "$mode" in 295 objective) 296 guard=objective-pin; expected=23 297 other_objective=$(printf aienet-m1-other-objective | hash_words) 298 new_state foreign-objective 7 "$other_objective" 299 ;; 300 operand) new_state foreign-operand 8 ;; 301 after-correct) 302 new_state foreign-old-operand 8 303 old_operand=$(printf '`010002000300020000000000000007`' | xxd -r -p | hash_words) 304 bash "$driver" propose "$STATE" 6 1 0 1 7 0 $old_operand 0 0 305 printf '4 %s %s %s %s %s %s 2 3 2 7 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/2" 306 source_gen=2; target_gen=2 307 ;; 308 *) return 2 ;; 309 esac 310 run_sequence 311 exactly_once "$source_gen" 312 source_state=$STATE 313 source_dag=$(sha256sum "$STATE/g$source_gen/document" | cut -d' ' -f1) 314 new_state "substitute-$mode" 315 if test "$mode" = after-correct; then correct; fi 316 # The real sequencer is paused after authentic artifacts arrive but before 317 # its check/ingest. Replace the entire signed submission, not isolated bytes. 318 M1_PAUSE=published bash "$sequence" > "$STATE/first.log" 2>&1 & 319 pid=$!; active_pid=$pid 320 wait_file "$STATE/paused" "$pid" 321 target_dag=$(sha256sum "$STATE/g$target_gen/document" | cut -d' ' -f1) 322 local art="$STATE/g$target_gen" foreign="$source_state/g$source_gen" 323 mkdir "$STATE/original" 324 cp "$art/document" "$art/job.an0b" "$art/out/$target_dag.mjr1" "$art/out/$target_dag.mjv" "$STATE/original/" 325 cp "$foreign/document" "$art/document" 326 cp "$foreign/job.an0b" "$art/job.an0b" 327 cp "$foreign/out/$source_dag.mjr1" "$art/out/$target_dag.mjr1" 328 cp "$foreign/out/$source_dag.mjv" "$art/out/$target_dag.mjv" 329 "$RUN" check --bundle "$art/job.an0b" --mjr1 "$art/out/$target_dag.mjr1" --mjv "$art/out/$target_dag.mjv" --keys "$KEYS" --pins "$PINS" > "$STATE/substitute-check.log" 2>&1 330 cp "$STATE/journal" "$STATE/before-substitute" 331 rm "$STATE/paused" 332 wait "$pid" || rc=$? 333 active_pid= 334 printf '%s%s\t%s\t%s\n' "${CASE_PREFIX:-}" "$mode" "$expected" "$rc" >> "$E/pin-refusals.tsv" 335 semantic "$guard" test "$rc" = "$expected" 336 test ! -s "$art/events" 337 cmp "$STATE/journal" "$STATE/before-substitute" 338 bash "$driver" status "$STATE" > "$STATE/refused-status" 339 while read -r tag id st generation rest; do 340 if test "$tag/$id" = 101/1; then 341 matches=$((matches+1)) 342 test "$st/$generation" = "2/$target_gen" 343 fi 344 done < "$STATE/refused-status" 345 test "$matches" = 1 346 # Restore the originally checked bytes: the same dispatch can then complete. 347 cp "$STATE/original/document" "$art/document" 348 cp "$STATE/original/job.an0b" "$art/job.an0b" 349 cp "$STATE/original/$target_dag.mjr1" "$art/out/$target_dag.mjr1" 350 cp "$STATE/original/$target_dag.mjv" "$art/out/$target_dag.mjv" 351 run_sequence 352 exactly_once "$target_gen" 353 } 354 operand_substitution() { pin_substitution operand; } 355 objective_substitution() { pin_substitution objective; } 356 conflicting_result() { 357 new_state conflicting-result 358 M1_PAUSE=resulted bash "$sequence" > "$STATE/first.log" 2>&1 & 359 local pid=$!; active_pid=$pid 360 wait_file "$STATE/paused" "$pid" 361 kill -KILL "$pid"; wait "$pid" || true 362 rm "$STATE/paused" 363 local lines fields rc=0 364 mapfile -t lines < "$STATE/journal" 365 read -r -a fields <<< "${lines[1]}" 366 fields[13]=$((fields[13]+1)) 367 printf '%s\n%s\n' "${lines[0]}" "${fields[*]}" > "$STATE/journal" 368 bash "$driver" status "$STATE" > "$STATE/resulted-status" 369 cp "$STATE/journal" "$STATE/before-conflict" 370 run_sequence > "$STATE/conflict.log" 2>&1 || rc=$? 371 semantic result-conflict test "$rc" = 33 372 cmp "$STATE/journal" "$STATE/before-conflict" 373 } 374 history() { 375 local count=$1 gen=$(( $1+1 )) i current=1 changed expected seed effective 376 new_state "history-$count" 377 printf '`010002000300020000000000000008`' | xxd -r -p > "$STATE/payload2" 378 changed=$(hash_words < "$STATE/payload2") 379 for ((i=1;i<=count;i++)); do 380 if ((i%2)); then effective=$changed; else effective=$operand; fi 381 printf '3 %s 6 1 0 %s 7 0 %s 0 0\n' "$i" "$current" "$effective" >> "$STATE/journal" 382 current=$((current+1)) 383 done 384 if ((count%2)); then seed=8; expected=$changed; else seed=7; expected=$operand; fi 385 printf '4 %s %s %s %s %s %s 2 3 2 %s 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" "$seed" > "$STATE/bindings/$gen" 386 bash "$driver" status "$STATE" > "$STATE/history-status" 387 { printf '1\n'; cat "$STATE/plan" "$STATE/journal"; } | "$RECOVERY" > "$STATE/effective-probe" 388 read -r -a fields < "$STATE/effective-probe" 389 semantic latest-correct test "${fields[*]:35:4}" = "$expected" 390 run_sequence 391 exactly_once "$gen" 392 } 393 multiple_corrects() { history 2; } 394 correct_after_result() { 395 new_state correct-after-result 396 M1_PAUSE=resulted bash "$sequence" > "$STATE/first.log" 2>&1 & 397 local pid=$!; active_pid=$pid 398 wait_file "$STATE/paused" "$pid" 399 kill -KILL "$pid"; wait "$pid" || true 400 rm "$STATE/paused" 401 correct 402 bash "$driver" propose "$STATE" 6 1 0 2 7 0 $operand 0 0 403 printf '4 %s %s %s %s %s %s 2 3 2 7 1\n' "$objective" "$tenant" "$subject" "$approval" "$capability" "$expires" > "$STATE/bindings/3" 404 run_sequence 405 exactly_once 3 406 local tag seq type node attempt generation rest stale_verify=0 407 while read -r tag seq type node attempt generation rest; do 408 if test "$type/$node/$generation" = 3/1/1; then stale_verify=$((stale_verify+1)); fi 409 done < "$STATE/journal" 410 test "$stale_verify" = 0 411 } 412 capacity_boundaries() { 413 new_state capacity 414 # kernel.om:10,60-79: buffer length 262144, load refuses >= length-1. 415 local capacity=262144 size bytes expected kr hr 416 cat "$STATE/plan" "$STATE/journal" > "$STATE/base-input" 417 bytes=$(wc -c < "$STATE/base-input") 418 printf 'bytes\texpected_kernel\texpected_recovery\tobserved_kernel\tobserved_recovery\n' > "$STATE/capacity.tsv" 419 for size in "$((capacity-2))" "$((capacity-1))" "$capacity" "$((capacity+1))"; do 420 cp "$STATE/base-input" "$STATE/kernel-input" 421 printf '%*s' "$((size-bytes))" '' >> "$STATE/kernel-input" 422 expected=3; if test "$size" = "$((capacity-2))"; then expected=0; fi 423 kr=0; "$GM_KERNEL" < "$STATE/kernel-input" > "$STATE/capacity-status" || kr=$? 424 hr=0; { printf '1\n'; cat "$STATE/kernel-input"; } | "$RECOVERY" > "$STATE/capacity-fold" || hr=$? 425 printf '%s\t%s\t%s\t%s\t%s\n' "$size" "$expected" "$expected" "$kr" "$hr" >> "$STATE/capacity.tsv" 426 test "$kr" = "$expected"; test "$hr" = "$expected" 427 if test "$expected" = 0; then 428 { 429 cat "$STATE/capacity-fold" 430 while read -r tag rest; do if test "$tag" = 101; then printf '%s %s\n' "$tag" "$rest"; fi; done < "$STATE/capacity-status" 431 cat "$STATE/bindings/1" 432 } | "$CANON" emit > "$STATE/capacity-emission" 433 test "$(wc -c < "$STATE/capacity-emission")" = 687 434 else 435 test ! -s "$STATE/capacity-fold" 436 fi 437 done 438 } 439 omega_mutant() { 440 local name=$1 guard=$2 probe=$3 original=$RECOVERY line skip=0 441 local source="$E/recovery-$name.om" binary="$E/recovery-$name" 442 : > "$source" 443 while IFS= read -r line; do 444 if test "$skip" = 1; then skip=0; continue; fi 445 if test "$name" = conflict && test "$line" = 'note RECOVERY-GUARD result-conflict'; then skip=1; fi 446 printf '%s\n' "$line" >> "$source" 447 if test "$name" = first-correct && test "$line" = 'note RECOVERY-MUTANT first-correct-stop'; then printf 'break\n' >> "$source"; fi 448 done < "$repo/src/goal_microjobs/recovery.om" 449 OMEGA_OMC="$RECOMPUTE_OMC" sh "$repo/scripts/goal_microjobs/recovery-build.sh" "$binary" "$source" > "$E/recovery-$name-build.log" 2>&1 450 export RECOVERY="$binary" CASE_PREFIX="mutant-$name-" 451 local rc=0 452 set +e 453 (set -e; trap cleanup_case EXIT; "$probe") > "$E/mutant-$name.log" 2>&1 454 rc=$? 455 set -e 456 export RECOVERY=$original 457 unset CASE_PREFIX 458 test "$rc" = 1 459 local killed=0 460 while IFS= read -r line; do 461 if test "$line" = "M1_SEMANTIC $guard"; then killed=1; fi 462 done < "$E/mutant-$name.log" 463 test "$killed" = 1 464 printf '%s\tKILLED\t1\n' "$guard" >> "$E/mutants.tsv" 465 } 466 # Mutations are generated into evidence-local copies by removing exactly the 467 # named guard line. No candidate source, compiler or historical receipt changes. 468 mutant() { 469 local name=$1 guard=$2 probe=$3 470 local original=$sequence 471 sequence="$E/mutant-$name.sh" 472 local skip=0 line 473 : > "$sequence" 474 while IFS= read -r line; do 475 if test "$skip" = 1; then skip=0; continue; fi 476 if test "$line" = "# M1-GUARD $guard"; then skip=1; fi 477 printf '%s\n' "$line" >> "$sequence" 478 if test "$name" = persist && test "$line" = '# M1-MUTANT late-persist insertion point'; then printf 'persist\n' >> "$sequence"; fi 479 if test "$name/$line" = 'doc-objective/# M1-GUARD objective-pin'; then 480 printf 'objective_pin=$(od -An -tu8 --endian=big -j8 -N32 "$art/document")\n' >> "$sequence" 481 fi 482 if test "$name/$line" = 'doc-operand/# M1-GUARD operand-pin'; then 483 printf 'operand_pin=$(od -An -tu8 --endian=big -j488 -N32 "$art/document")\n' >> "$sequence" 484 fi 485 done < "$original" 486 # The copy is outside the repository; preserve its known adapter root. 487 export M1_REPO="$repo" 488 local rc=0 489 export CASE_PREFIX="mutant-$name-" 490 set +e 491 (set -e; trap cleanup_case EXIT; "$probe") > "$E/mutant-$name.log" 2>&1 492 rc=$? 493 set -e 494 unset CASE_PREFIX 495 sequence=$original 496 test "$rc" = 1 497 local killed=0 498 while IFS= read -r line; do 499 if test "$line" = "M1_SEMANTIC $guard"; then killed=1; fi 500 done < "$E/mutant-$name.log" 501 test "$killed" = 1 502 printf '%s\tKILLED\t%s\n' "$name" "$rc" >> "$E/mutants.tsv" 503 } 504 persist_probe() { crash dispatched; } 505 checks=0 failures=0 506 printf '# canon_source\t%s\n# canon_binary_sha256\t%s\ncase\texpected\tobserved\texit\n' "$canon_source" "$canon_binary" > "$E/summary.tsv" 507 printf '# oh_source\t%s\n# oh_run_sha256\t%s\n# oh_serve_sha256\t%s\n' "$oh_source" "$oh_run_sha" "$oh_serve_sha" > "$E/metadata.tsv" 508 cat "$E/summary.tsv" >> "$E/metadata.tsv" 509 mv "$E/metadata.tsv" "$E/summary.tsv" 510 printf 'case\texpected_refusal\tobserved_exit\n' > "$E/pin-refusals.tsv" 511 case_run() { 512 local name=$1; shift 513 local rc=0 514 set +e 515 (set -e; trap cleanup_case EXIT; "$@") > "$E/$name.log" 2>&1 516 rc=$? 517 set -e 518 checks=$((checks+1)) 519 if test "$rc" = 0; then 520 printf '%s\tPASS\tPASS\t0\n' "$name" >> "$E/summary.tsv" 521 else 522 failures=$((failures+1)) 523 printf '%s\tPASS\tFAIL\t%s\n' "$name" "$rc" >> "$E/summary.tsv" 524 fi 525 } 526 case_run done-reject-resulted done_negative resulted '101 1 3 1 1 0 0 0' 527 case_run done-reject-missing done_negative missing '100 1 1 0' 528 case_run done-reject-duplicate done_negative duplicate $'101 1 4 1 1 0 0 0\n101 1 4 1 1 0 0 0' 529 case_run result-conflict conflicting_result 530 case_run multiple-corrects multiple_corrects 531 case_run history-257 history 257 532 case_run history-1000 history 1000 533 case_run correct-after-result correct_after_result 534 case_run kernel-capacity-boundaries capacity_boundaries 535 case_run happy happy 536 for boundary in persisted dispatched published resulted; do case_run "crash-$boundary" crash "$boundary"; done 537 case_run crash-worker-admitted worker_crash 538 case_run crash-worker-done worker_crash done 539 case_run stale stale 540 case_run stale-restored-operand generation_probe 541 case_run altered altered 542 case_run signed-wrong-output wrong_output 543 case_run duplicate duplicate 544 case_run attestation-signature attestation_signature 545 case_run substitute-operand operand_substitution 546 case_run substitute-objective objective_substitution 547 case_run substitute-pre-correct pin_substitution after-correct 548 if test "$failures" != 0; then 549 cat "$E/summary.tsv" 550 echo 'mutants NOT_RUN: baseline cases must all pass' 551 exit 1 552 fi 553 printf 'mutant\tverdict\tprobe_exit\n' > "$E/mutants.tsv" 554 case_run mutant-persist mutant persist persist-before-dispatch persist_probe 555 case_run mutant-check mutant check check-before-ingest attestation_signature 556 case_run mutant-generation mutant generation generation-match generation_probe 557 case_run mutant-result-conflict omega_mutant conflict result-conflict conflicting_result 558 case_run mutant-first-correct omega_mutant first-correct latest-correct multiple_corrects 559 case_run mutant-doc-objective mutant doc-objective objective-pin objective_substitution 560 case_run mutant-doc-operand mutant doc-operand operand-pin operand_substitution 561 cat "$E/summary.tsv" "$E/mutants.tsv" 562 printf 'M1 cases=%s failures=%s evidence=%s\n' "$checks" "$failures" "$E" 563 test "$failures" = 0