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/physics-mv/blob/main/tests/test_forge_gates_receipt.sh # physics-mv FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence. 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 `physics-mv / tests / test_forge_gates_receipt.sh` 129 lines ยท 10523 bytes Raw Blame History 1 #!/bin/bash 2 # tests/test_forge_gates_receipt.sh -- host-only tests (no GPU) for the Gate 3 # 3/4 receipt writer in tests/run_forge_gates.sh. 4 # 5 # tests/test_forge_gates_receipt.sh [OMEGA_DIR] 6 # 7 # Needs jq. The receipt writer itself uses no omega code. When OMEGA_DIR (an 8 # omega checkout) is given, the test also builds omega's tools/json_canon.c 9 # and checks that every digest the writer makes equals json_canon --sha256 10 # on the same content (the check the Gate 14 combiner does). Without it, 11 # the same equality is checked with jq -S -c plus a fixed known digest. 12 # The PASS fixture tests/fixtures/forge_gates_pass.log is the unedited Gate 13 # 3/4 log of the Gate 14 legs run on omega `62f5ba5` + physics `f63a6ef`. 14 set -u 15 HERE=$(cd -P "$(dirname "$0")/.." && pwd) 16 OMEGA_DIR=${1:-${OMEGA_DIR:-}} 17 # shellcheck source=tests/run_forge_gates.sh 18 . "$HERE/tests/run_forge_gates.sh" 19 TMP=$(mktemp -d) 20 trap 'rm -rf "$TMP"' EXIT 21 JSON_CANON= 22 if [ -n "$OMEGA_DIR" ]; then 23 [ -f "$OMEGA_DIR/tools/json_canon.c" ] || { echo "usage: $0 [OMEGA_DIR] (an omega checkout with tools/json_canon.c)"; exit 2; } 24 JSON_CANON=$TMP/json_canon 25 # omega moved SHA-256 into a generated Omega unit (`450bbefd4`, OM-2): the 26 # implementation is src/omega_om_units.c now and src/sha256.c is gone. 27 # Use the unit when the checkout has it, else the hand-written file. 28 if [ -f "$OMEGA_DIR/src/omega_om_units.c" ]; then 29 SHA256_IMPL=$OMEGA_DIR/src/omega_om_units.c 30 else 31 SHA256_IMPL=$OMEGA_DIR/src/sha256.c 32 fi 33 gcc -std=gnu11 -O2 -Wall -Wextra -Werror -I"$OMEGA_DIR/src" -o "$JSON_CANON" \ 34 "$OMEGA_DIR/tools/json_canon.c" "$SHA256_IMPL" -lm || { echo "FAIL: cannot build json_canon"; exit 1; } 35 fi 36 fails=0 passes=0 37 ok() { echo " [PASS] $1"; passes=$((passes + 1)); } 38 bad() { echo " [FAIL] $1"; fails=$((fails + 1)); } 39 check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; } 40 # jq_canon -- stdin JSON to sorted compact bytes (no trailing newline) 41 jq_canon() { jq -S -c -j .; } 42 # ref_digest -- digest of stdin JSON the way the Gate 14 combiner computes it 43 ref_digest() { if [ -n "$JSON_CANON" ]; then "$JSON_CANON" --sha256; else jq_canon | sha256sum | cut -d' ' -f1; fi; } 44 FIX=$HERE/tests/fixtures/forge_gates_pass.log 45 # digest of the PASS body built below (fixed repos, run id and time), made by 46 # omega tools/json_canon.c --sha256 at omega `3875223` 47 KAT_DIGEST=`b1a2f42cb95ba7246c71addb3e87f98c94aad95ea61e0c2930462fabe5667573` 48 # mkrepo DIR CONTENT -- one-commit repo whose commit id is the same on every 49 # host. The commit id feeds the PASS body and so KAT_DIGEST: identity, dates 50 # and signing are fixed here, so the caller's GIT_AUTHOR_*/GIT_COMMITTER_* 51 # environment and global/system git config cannot change it (issue #93). 52 mkrepo() { 53 git init -q "$1" && echo "$2" > "$1/f" && git -C "$1" add f && 54 GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_COUNT=0 \ 55 GIT_AUTHOR_NAME=T GIT_AUTHOR_EMAIL=t@example.invalid GIT_AUTHOR_DATE=2026-09-30T00:00:00Z \ 56 GIT_COMMITTER_NAME=T GIT_COMMITTER_EMAIL=t@example.invalid GIT_COMMITTER_DATE=2026-09-30T00:00:00Z \ 57 git -C "$1" -c commit.gpgsign=false commit -qm c && 58 git -C "$1" rev-parse HEAD 59 } 60 O=$TMP/omega; P=$TMP/physics 61 osha=$(mkrepo "$O" omega); psha=$(mkrepo "$P" physics) 62 BIN3=$(printf 3 | sha256sum | cut -d' ' -f1); BIN4=$(printf 4 | sha256sum | cut -d' ' -f1) 63 body_of() { forge_body "$1" "${2:-0}" "${3:-0}" "$BIN3" "$BIN4" "$O" "$osha" "$P" "$psha" 20260930T000000Z-`000000000000` 2026-09-30T00:00:00.000000Z; } 64 field() { printf '%s' "$1" | jq -r "$2"; } 65 variant() { sed -E "$1" "$FIX" > "$TMP/v.log"; echo "$TMP/v.log"; } 66 67 echo "gate verdicts on the real PASS log" 68 check "gate 3 PASS" '[ "$(forge_gate_verdict "$FIX" 3 0 "$FORGE_G3_IDS")" = PASS ]' 69 check "gate 4 PASS" '[ "$(forge_gate_verdict "$FIX" 4 0 "$FORGE_G4_IDS")" = PASS ]' 70 check "gate 3 has 11 events" '[ "$(forge_events "$FIX" 3 | wc -l)" = 11 ]' 71 check "gate 4 has 10 events" '[ "$(forge_events "$FIX" 4 | wc -l)" = 10 ]' 72 check "nonzero exit status fails" '[ "$(forge_gate_verdict "$FIX" 3 1 "$FORGE_G3_IDS")" = "FAIL: gate 3 binary exit status 1" ]' 73 check "a FAIL line fails" 'v=$(variant "s/^\[PASS\] NEG_NULL_NVRM_REJECTED$/[FAIL] NEG_NULL_NVRM_REJECTED/"); [ "$(forge_gate_verdict "$v" 3 0 "$FORGE_G3_IDS")" = "FAIL: gate 3 printed a FAIL line" ]' 74 check "a missing id fails" 'v=$(variant "/^\[PASS\] DESCRIPTOR_DIGEST_BOUND$/d"); forge_gate_verdict "$v" 4 0 "$FORGE_G4_IDS" | grep -q "^FAIL"' 75 check "an unexpected id fails" 'v=$(variant "s/^\[PASS\] AEGIS_VERIFY_API_NAMED$/[PASS] SOMETHING_ELSE/"); [ "$(forge_gate_verdict "$v" 3 0 "$FORGE_G3_IDS")" = "FAIL: gate 3 observed ids differ from the expected ids" ]' 76 check "FAILED=1 in results fails" 'v=$(variant "s/^Gate 3 Results: .*/Gate 3 Results: TOTAL=11 PASSED=10 FAILED=1/"); forge_gate_verdict "$v" 3 0 "$FORGE_G3_IDS" | grep -q "^FAIL: gate 3 results"' 77 check "missing results line fails" 'v=$(variant "/^Gate 4 Results:/d"); forge_gate_verdict "$v" 4 0 "$FORGE_G4_IDS" | grep -q "results line missing"' 78 check "repeated results line fails" 'v=$(variant "s/^(Gate 4 Results: .*)/\1\n\1/"); forge_gate_verdict "$v" 4 0 "$FORGE_G4_IDS" | grep -q "results line missing or repeated"' 79 check "a truncated log (no gate 3) fails" 'v=$(variant "/Running Gate 3:/,\$d"); forge_gate_verdict "$v" 3 0 "$FORGE_G3_IDS" | grep -q "^FAIL"' 80 81 echo "receipt body and digest" 82 body=$(body_of "$FIX") 83 check "body is valid JSON" 'printf "%s" "$body" | jq -e . > /dev/null' 84 check "PASS body is already canonical (sorted keys, compact)" '[ "$(printf "%s" "$body" | jq_canon)" = "$body" ]' 85 check "PASS body digest equals the reference canonical digest" '[ "$(printf "%s" "$body" | ref_digest)" = "$(printf "%s" "$body" | sha256sum | cut -d" " -f1)" ]' 86 check "status PASS" '[ "$(field "$body" .status)" = PASS ]' 87 check "schema" '[ "$(field "$body" .schema)" = AIEN_M19R_FORGE_GATES_V1 ]' 88 check "candidate_git_commit is the omega commit" '[ "$(field "$body" .candidate_git_commit)" = "$osha" ]' 89 check "physics_candidate_git_commit is the physics commit" '[ "$(field "$body" .physics_candidate_git_commit)" = "$psha" ]' 90 check "both trees clean" '[ "$(field "$body" "[.candidate_trees_clean.omega, .candidate_trees_clean.physics] | all")" = true ]' 91 check "per-gate PASS" '[ "$(field "$body" "[.gates[].status] | join(\",\")")" = PASS,PASS ]' 92 check "observed 21 pass, 0 fail" '[ "$(field "$body" "[.observed_test_count,.observed_pass_count,.observed_fail_count] | join(\",\")")" = 21,21,0 ]' 93 check "descriptor digest from the log" '[ "$(field "$body" .hardware_descriptor_digest)" = `1ce23d57112901c414ddc75ba35b65bc8c38fc0bb5e85f3a995634af456bf24b` ]' 94 check "log sha256 bound" '[ "$(field "$body" .gate_log_sha256)" = `2c139d36a055dc1e7bfa1e6074d8b14a23d90f74b13216d8d70b529c0f66e805` ]' 95 forge_receipt "$body"; receipt=$FORGE_RECEIPT 96 check "receipt digest recomputes from the body" '[ "$(printf "%s" "$receipt" | jq -c "del(.receipt_digest)" | ref_digest)" = "$FORGE_DIGEST" ]' 97 check "receipt with receipt_digest is itself canonical" '[ "$(printf "%s" "$receipt" | jq_canon)" = "$receipt" ]' 98 check "PASS body digest is the known value" '[ "$FORGE_DIGEST" = "$KAT_DIGEST" ]' 99 fb=$(body_of "$FIX" 3 1) 100 check "FAIL body with error is canonical" 'field "$fb" .error | grep -q . && [ "$(printf "%s" "$fb" | jq_canon)" = "$fb" ]' 101 check "FAIL body digest equals the reference canonical digest" '[ "$(printf "%s" "$fb" | ref_digest)" = "$(printf "%s" "$fb" | sha256sum | cut -d" " -f1)" ]' 102 check "gate 4 exit 1 gives status FAIL with error" 'b=$(body_of "$FIX" 0 1); [ "$(field "$b" .status)" = FAIL ] && [ "$(field "$b" .gates.GATE_4_FORGE_HWID.status)" = FAIL ] && field "$b" .error | grep -q "gate 4 binary exit status 1"' 103 echo dirty > "$P/f" 104 check "dirty physics tree gives FAIL" 'b=$(body_of "$FIX"); [ "$(field "$b" .status)" = FAIL ] && [ "$(field "$b" .candidate_trees_clean.physics)" = false ]' 105 git -C "$P" checkout -q f 106 echo new > "$O/untracked" 107 check "untracked file in omega gives FAIL" 'b=$(body_of "$FIX"); [ "$(field "$b" .status)" = FAIL ] && [ "$(field "$b" .candidate_trees_clean.omega)" = false ]' 108 rm -f "$O/untracked" 109 check "wrong omega candidate gives FAIL" 'b=$(forge_body "$FIX" 0 0 "$BIN3" "$BIN4" "$O" "$psha" "$P" "$psha" r t); [ "$(field "$b" .status)" = FAIL ]' 110 check "candidate check refuses short SHA" '! forge_candidate "$O" "${osha:0:12}"' 111 check "candidate check refuses other HEAD" '! forge_candidate "$O" "$psha"' 112 check "candidate check accepts HEAD of clean tree" 'forge_candidate "$O" "$osha"' 113 114 echo "permanent receipt" 115 EV=$TMP/evidence 116 check "record writes digest-named receipt" 'forge_record "$receipt" "$FIX" "$EV" "$O" "$P" && [ -f "$EV/$FORGE_DIGEST.json" ]' 117 check "receipt is 0444" '[ "$(stat -c %a "$EV/$FORGE_DIGEST.json")" = 444 ]' 118 check "log blob kept by sha256" '[ -f "$EV/blobs/`2c139d36a055dc1e7bfa1e6074d8b14a23d90f74b13216d8d70b529c0f66e805`.log" ]' 119 check "on-disk receipt digest verifies" '[ "$(jq -c "del(.receipt_digest)" "$EV/$FORGE_DIGEST.json" | ref_digest)" = "$FORGE_DIGEST" ]' 120 check "second write refused" '! forge_record "$receipt" "$FIX" "$EV" "$O" "$P" 2>/dev/null' 121 check "evidence dir inside a candidate tree refused" '! forge_record "$receipt" "$FIX" "$P/evidence" "$O" "$P" && [ ! -e "$P/evidence" ]' 122 check "empty binary hash gives FAIL" 'b=$(forge_body "$FIX" 0 0 "" "$BIN4" "$O" "$osha" "$P" "$psha" r t); [ "$(field "$b" .status)" = FAIL ] && field "$b" .error | grep -q "gate 3 binary hash missing"' 123 check "blobs symlink into a candidate tree refused" 'mkdir -p "$TMP/ev3" "$P/planted" && ln -s "$P/planted" "$TMP/ev3/blobs" && ! forge_record "$receipt" "$FIX" "$TMP/ev3" "$O" "$P" && [ -z "$(ls "$P/planted")" ]; rm -rf "$P/planted"' 124 check "existing writable blob made read-only" 'mkdir -p "$TMP/ev4/blobs" && cp "$FIX" "$TMP/ev4/blobs/`2c139d36a055dc1e7bfa1e6074d8b14a23d90f74b13216d8d70b529c0f66e805`.log" && chmod 0666 "$TMP/ev4/blobs/"*.log && forge_record "$receipt" "$FIX" "$TMP/ev4" "$O" "$P" && [ "$(stat -c %a "$TMP/ev4/blobs/"*.log)" = 444 ]' 125 check "existing blob that is a symlink refused" 'mkdir -p "$TMP/ev5/blobs" && ln -s "$FIX" "$TMP/ev5/blobs/`2c139d36a055dc1e7bfa1e6074d8b14a23d90f74b13216d8d70b529c0f66e805`.log" && ! forge_record "$receipt" "$FIX" "$TMP/ev5" "$O" "$P"' 126 check "receipt is 0444 under umask 077" 'mkdir -p "$TMP/ev6" && ( umask 077; forge_record "$receipt" "$FIX" "$TMP/ev6" "$O" "$P" ) && [ "$(stat -c %a "$TMP/ev6/$FORGE_DIGEST.json")" = 444 ]' 127 128 echo "Gate 3/4 receipt tests: $passes passed, $fails failed" 129 [ "$fails" -eq 0 ]