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/omega-mv/blob/main/tools/test_m19r_qualify.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tools / test_m19r_qualify.sh` 204 lines ยท 12562 bytes Raw Blame History 1 #!/bin/bash 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 # test_m19r_qualify.sh -- negative tests for candidate binding, immutable 18 # qualification emission and gate counting in tools/m19r_qualify.sh, plus 19 # golden tests for the canonical JSON helper tools/json_canon.c. 20 # Host only (no GPU). Run: make test-m19r-qualify (or run this file). 21 set -u 22 HERE=$(cd -P "$(dirname "$0")/.." && pwd) 23 # shellcheck source=tools/m19r_qualify.sh 24 . "$HERE/tools/m19r_qualify.sh" 25 m19r_build_canon || { echo "FAIL: cannot build tools/json_canon.om"; exit 1; } 26 TMP=$(mktemp -d) 27 trap 'rm -rf "$TMP" "$M19R_TMP"' EXIT 28 fails=0 passes=0 29 ok() { echo " [PASS] $1"; passes=$((passes + 1)); } 30 bad() { echo " [FAIL] $1"; fails=$((fails + 1)); } 31 check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; } 32 33 echo "candidate mismatch and dirty tree" 34 repo=$TMP/repo 35 git init -q "$repo" 36 echo candidate > "$repo/source.txt" 37 git -C "$repo" add source.txt 38 git -C "$repo" -c user.name=Test -c user.email=test@example.invalid commit -qm candidate 39 sha=$(git -C "$repo" rev-parse HEAD) 40 check "all-zero SHA rejected" '! m19r_must_candidate "$repo" `0000000000000000000000000000000000000000`' 41 check " with the HEAD message" '[ "$M19R_ERR" = "repo HEAD differs from supplied candidate" ]' 42 check "short SHA rejected" '! m19r_must_candidate "$repo" "${sha:0:12}"' 43 check " with the full-SHA message" '[ "$M19R_ERR" = "candidate must be an explicit full 40-hex SHA" ]' 44 check "exact clean candidate accepted" 'm19r_must_candidate "$repo" "$sha"' 45 check "upper-case candidate accepted" 'm19r_must_candidate "$repo" "${sha^^}"' 46 echo dirty > "$repo/source.txt" 47 check "dirty tree rejected" '! m19r_must_candidate "$repo" "$sha"' 48 check " with the dirty message" '[ "$M19R_ERR" = "repo candidate tree is dirty" ]' 49 git -C "$repo" checkout -q source.txt 50 echo new > "$repo/untracked.txt" 51 check "untracked file counts as dirty" '! m19r_must_candidate "$repo" "$sha"' 52 53 echo "exclusive receipt and canonical digest" 54 body='{"count": 2, "candidate": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}' 55 h=$(printf '%s' "$body" | "$JSON_CANON" --sha256) 56 check "digest of the canonical body" '[ "$h" = "$(printf "%s" "{\"candidate\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"count\":2}" | sha256sum | cut -d" " -f1)" ]' 57 receipt="{\"receipt_digest\":\"$h\",${body#\{}" 58 path=$TMP/M19R/$h.json 59 check "first write succeeds" 'printf "%s" "$receipt" | m19r_write_immutable_receipt "$path"' 60 original=$(sha256sum < "$path") 61 check "file is read-only (0444)" '[ "$(stat -c %a "$path")" = 444 ]' 62 check "second write refused" '! printf "%s" "$receipt" | m19r_write_immutable_receipt "$path"' 63 check " as an existing file" '[ "$(cat "$M19R_TMP/error")" = "[Errno 17] File exists: '"'"'$path'"'"'" ]' 64 check "original bytes unchanged" '[ "$(sha256sum < "$path")" = "$original" ]' 65 66 echo "failed gate and derived final count" 67 printf ' [PASS] GATE_ONE\n [FAIL] GATE_TWO\n' > "$TMP/gates.log" 68 m19r_events "$TMP/gates.log" suite > "$TMP/seen.tsv" 69 check "counts derived from observed lines" '[ "$(m19r_observed_counts < "$TMP/seen.tsv")" = "{\"completed\":2,\"failed\":1,\"passed\":1}" ]' 70 check "a failed gate fails the run" '! m19r_require_passed < "$TMP/seen.tsv"' 71 check "no observed gates fails the run" '! m19r_require_passed < /dev/null' 72 head -n 1 "$TMP/seen.tsv" > "$TMP/one.tsv" 73 check "first gate alone counts 1" '[ "$(m19r_observed_counts < "$TMP/one.tsv")" = "{\"completed\":1,\"failed\":0,\"passed\":1}" ]' 74 check "first gate alone passes" 'm19r_require_passed < "$TMP/one.tsv"' 75 printf 'SILICON_PASS: FAIL\nOTHER_PASS: measured true\n' > "$TMP/named.log" 76 m19r_events "$TMP/named.log" named > "$TMP/named.tsv" 77 check "named lines: FAIL word wins" '[ "$(cut -f3 "$TMP/named.tsv" | paste -sd, -)" = "FAIL,PASS" ]' 78 check "named FAIL fails the run" '! m19r_require_passed < "$TMP/named.tsv"' 79 printf 'XY_PASS: y\n [PASS]\n\n LATE_ID trailing\n[PASS]FOO\n[PASS] a:b-c(d)\n A__PASS: FAILED\nA_PASS: x\n' > "$TMP/order.log" 80 check "gate lines first, id after blank lines, then named lines" '[ "$(m19r_events "$TMP/order.log" s | m19r_events_json)" = "[{\"suite\":\"s\",\"id\":\"LATE_ID\",\"status\":\"PASS\"},{\"suite\":\"s\",\"id\":\"a:b-c\",\"status\":\"PASS\"},{\"suite\":\"s\",\"id\":\"XY_PASS\",\"status\":\"PASS\"}]" ]' 81 82 echo "tagged observations" 83 printf 'M19_OBSERVED_JSON:{"a":1}\nnoise\nM19_OBSERVED_JSON:{"a":2}\n' > "$TMP/tag.log" 84 check "every tagged line returned" '[ "$(m19r_tagged_json "$TMP/tag.log" M19_OBSERVED_JSON | tail -n 1)" = "{\"a\":2}" ]' 85 check "missing tag fails" '! m19r_tagged_json "$TMP/tag.log" M19R_SOAK_JSON > /dev/null' 86 printf 'M19R_SOAK_JSON:{"a":\n' > "$TMP/badtag.log" 87 check "malformed tagged JSON fails" '! m19r_tagged_json "$TMP/badtag.log" M19R_SOAK_JSON > /dev/null' 88 89 echo "canonical JSON matches Python json.dumps" 90 trap_doc='{"z":[84.830,85.000,1e3,0,-0,-0.0,`18446744073709551615`,1e16,1e-05,0.0001,1.5e-7],"b":{"e":{},"f":[]},"s":"q\"b\\s\u0001\n\u00e9\u007f\ud83d\ude00","a":1,"a":"dup-last"}' 91 compact=$(printf '%s' "$trap_doc" | "$JSON_CANON") 92 want=$(printf '{"a":"dup-last","b":{"e":{},"f":[]},"s":"q\\"b\\\\s\\u0001\\n\xc3\xa9\x7f\xf0\x9f\x98\x80","z":[84.83,85.0,1000.0,0,0,-0.0,`18446744073709551615`,1e+16,1e-05,0.0001,1.5e-07]}') 93 check "compact form (numbers, escapes, raw UTF-8, dup key)" '[ "$compact" = "$want" ]' 94 pretty=$(printf '%s' "$trap_doc" | "$JSON_CANON" --pretty) 95 want_pretty='{ 96 "a": "dup-last", 97 "b": { 98 "e": {}, 99 "f": [] 100 }, 101 "s": "q\"b\\s\u0001\n\u00e9\u007f\ud83d\ude00", 102 "z": [ 103 84.83, 104 85.0, 105 1000.0, 106 0, 107 0, 108 -0.0, 109 `18446744073709551615`, 110 1e+16, 111 1e-05, 112 0.0001, 113 1.5e-07 114 ] 115 }' 116 check "pretty form (indent 2, ASCII escapes)" '[ "$pretty" = "$want_pretty" ]' 117 check "invalid JSON rejected" '! printf "{\"a\":1,}" | "$JSON_CANON" > /dev/null 2>&1' 118 rec=$(ls "$HERE"/evidence/M19R/*.json | head -n 1) 119 name=$(basename "$rec" .json) 120 check "recorded M19R receipt digest reproduced" '[ "$(jq "del(.receipt_digest)" "$rec" | "$JSON_CANON" --sha256)" = "$name" ]' 121 check "recorded M19R receipt pretty form reproduced" '"$JSON_CANON" --pretty < "$rec" | cmp -s - "$rec"' 122 123 echo "evidence retention across runs (stubbed qualification, no hardware)" 124 check "make clean removes only the build directory" '[ "$(make --no-print-directory -C "$HERE" -n clean | tr -d "\n")" = "rm -rf ${OUT_DIR:-build}" ]' 125 fake=$TMP/fakeomega 126 mkdir -p "$fake/tools" "$fake/build" 127 ln -s "$HERE/seed" "$fake/seed"; cp "$HERE/tools/json_canon.om" "$fake/tools/" 128 printf "/qual-runs/\nseed\n" > "$fake/.gitignore" 129 printf 'clean:\n\trm -rf build\n' > "$fake/Makefile" 130 git init -q "$fake" 131 fake_run() { # fake_run EXTRA_ARGS... ; runs m19r_main with a stubbed qualify 132 ( 133 M19R_OMEGA=$fake 134 m19r_qualify() { # like the real flow: make clean, then write evidence into the run dir 135 m19r_cmd "$M19R_OMEGA" - make clean || return 1 136 mkdir -p "$M19R_OMEGA/build"; echo product > "$M19R_OMEGA/build/omegatool" 137 printf ' [PASS] GATE_A\n' > "$M19R_RUN_DIR/m19.log" 138 echo "stub stdout line"; echo "stub stderr line" >&2 139 R_STATUS=$STUB_STATUS R_EVENTS='[]' R_M19='{}' 140 [ "$STUB_STATUS" = PASS ] || { m19r_fail "stub failure"; return 1; } 141 } 142 m19r_main --omega-candidate "$(printf 'a%.0s' {1..40})" --physics-candidate "$(printf 'b%.0s' {1..40})" \ 143 --physics-dir "$TMP/nophysics" "$@" 144 ) > "$TMP/fake.out" 2> "$TMP/fake.err" 145 } 146 STUB_STATUS=PASS fake_run --run-id run1; rc1=$? 147 r1=$fake/qual-runs/run1 148 check "run 1 exits 0 and writes under /qual-runs (default root)" '[ "$rc1" = 0 ] && [ -f "$r1/run.json" ]' 149 check "run 1 has command, environment, logs, verdict, hashes" 'for f in command.txt environment.json stdout.log stderr.log verdict.json hashes.sha256 m19.log; do [ -f "$r1/$f" ] || exit 1; done' 150 check "stdout.log/stderr.log captured the run" 'grep -q "stub stdout line" "$r1/stdout.log" && grep -q "stub stderr line" "$r1/stderr.log"' 151 check "environment.json has the six fields" '[ "$(jq -r "[.hostname,.date_utc,.omega_sha,.physics_sha,.uname_r,.user] | map(length > 0) | all" "$r1/environment.json")" = true ]' 152 check "verdict.json says PASS, exit 0" '[ "$(jq -r "[.status,.exit_code,.run_id] | @tsv" "$r1/verdict.json")" = "$(printf "PASS\t0\trun1")" ]' 153 check "hashes.sha256 verifies and omits itself" '(cd "$r1" && sha256sum -c --quiet hashes.sha256) && ! grep -q hashes.sha256 "$r1/hashes.sha256"' 154 count1=$(find "$r1" -type f | wc -l) 155 sums1=$(cd "$r1" && find . -type f -print0 | sort -z | xargs -0 sha256sum) 156 STUB_STATUS=PASS fake_run --run-id run2; rc2=$? 157 check "run 2 (which runs make clean) exits 0" '[ "$rc2" = 0 ] && [ -f "$fake/qual-runs/run2/run.json" ]' 158 check "run 2 cleanup removed build products but not run 1" '[ -d "$r1" ] && [ -f "$fake/build/omegatool" ]' 159 check "run 1 hashes still verify after run 2" '(cd "$r1" && sha256sum -c --quiet hashes.sha256)' 160 check "run 1 file count unchanged" '[ "$(find "$r1" -type f | wc -l)" = "$count1" ]' 161 check "run 1 bytes identical (every file)" '[ "$(cd "$r1" && find . -type f -print0 | sort -z | xargs -0 sha256sum)" = "$sums1" ]' 162 STUB_STATUS=PASS fake_run --run-id run1; rcx=$? 163 check "reusing an existing run id exits 2" '[ "$rcx" = 2 ] && grep -q "never reused" "$TMP/fake.err"' 164 check " and leaves run 1 untouched" '(cd "$r1" && sha256sum -c --quiet hashes.sha256) && [ "$(find "$r1" -type f | wc -l)" = "$count1" ]' 165 STUB_STATUS=PASS fake_run --run-id inbuild --evidence-root "$fake/build/qual"; rcb=$? 166 check "evidence root inside build/ refused (exit 2)" '[ "$rcb" = 2 ]' 167 STUB_STATUS=FAILED fake_run --run-id run3; rc3=$? 168 check "failed run exits 1 with FAILED verdict and exit code" '[ "$rc3" = 1 ] && [ "$(jq -r "[.status,.exit_code,.failing_step,.failing_gate_or_exit] | @tsv" "$fake/qual-runs/run3/verdict.json")" = "$(printf "FAILED\t1\tstub failure\texit:1")" ]' 169 check "command.txt records the exact argv" 'grep -q -- "--run-id run3" "$fake/qual-runs/run3/command.txt"' 170 171 echo "campaign verdicts (tools/m19r_campaign.sh)" 172 CAMP=$HERE/tools/m19r_campaign.sh 173 mkrun() { # mkrun DIR ID STATUS -- a sealed run directory 174 local d=$1/$2 175 mkdir -p "$d" 176 printf '{"status":"%s"}' "$3" > "$d/run.json" 177 printf '{"run_id":"%s","status":"%s","exit_code":0}' "$2" "$3" > "$d/verdict.json" 178 echo "log $2" > "$d/m19.log" 179 m19r_seal "$d" 180 } 181 verdict() { "$CAMP" --campaign-dir "$1" --runs "$2" > /dev/null 2>&1; jq -r .verdict "$1/final-verdict.json"; } 182 c=$TMP/c_pass; mkdir "$c"; mkrun "$c" r1 PASS; mkrun "$c" r2 PASS 183 check "PASS: 2 of 2 runs PASS" '[ "$(verdict "$c" 2)" = PASS ]' 184 check " campaign.json written with sha, rule, created_at" '[ "$(jq -r "[.sha,.rule,.created_at] | map(length > 0) | all" "$c/campaign.json")" = true ]' 185 check " exits 0" '"$CAMP" --campaign-dir "$c" --runs 2 > /dev/null' 186 check "INCOMPLETE: 2 usable runs but 3 required" '[ "$(verdict "$c" 3)" = INCOMPLETE ]' 187 check " exits 1" '! "$CAMP" --campaign-dir "$c" --runs 3 > /dev/null' 188 c=$TMP/c_fail; mkdir "$c"; mkrun "$c" r1 PASS; mkrun "$c" r2 FAILED 189 check "FAIL: one run FAILED" '[ "$(verdict "$c" 2)" = FAIL ]' 190 c=$TMP/c_inv; mkdir "$c"; mkrun "$c" r1 PASS; mkrun "$c" r2 PASS 191 chmod u+w "$c/r2/m19.log"; printf 'log r3' > "$c/r2/m19.log" 192 check "INVALID: one altered byte in a run file" '[ "$(verdict "$c" 2)" = INVALID ]' 193 c=$TMP/c_inv2; mkdir "$c"; mkrun "$c" r1 PASS; mkrun "$c" r2 PASS; rm "$c/r2/verdict.json" 194 check "INVALID: run lacks verdict.json" '[ "$(verdict "$c" 2)" = INVALID ]' 195 c=$TMP/c_inv3; mkdir "$c"; mkrun "$c" r1 PASS; mkrun "$c" r2 FAILED; chmod u+w "$c/r1/m19.log"; echo x >> "$c/r1/m19.log" 196 check "INVALID takes precedence over FAIL" '[ "$(verdict "$c" 2)" = INVALID ]' 197 check "bad arguments exit 2" '"$CAMP" --campaign-dir "$TMP/nonexistent" --runs 2 > /dev/null 2>&1; [ $? = 2 ]' 198 199 printf 'TOTAL GATES: %d | PASSED: %d | FAILED: %d\n' "$((passes + fails))" "$passes" "$fails" 200 if [ "$fails" -ne 0 ]; then 201 echo "M19R qualifier tests: $fails FAILED" 202 exit 1 203 fi 204 echo "M19R qualifier tests: all passed"