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 / test_m20_receipt.sh
| 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 | # tests/test_m20_receipt.sh -- tests for tools/m20_receipt.sh (M20 receipt writer). |
| 18 | # Fixture logs and tables under tests/fixtures/m20_receipt/. Each scenario |
| 19 | # commits a fixture table as docs/tensor/M20_OMEGA_TENSOR.md in a throwaway git |
| 20 | # repo under a temp dir and writes evidence outside it. Covers reproducibility |
| 21 | # (two runs, same hash, byte-identical), every refusal path and every |
| 22 | # NOT QUALIFIED rule. M20_RECEIPT_WRITER selects the writer (used by |
| 23 | # tools/m20_receipt_mutations.sh to run mutants). Host only, no device. |
| 24 | # Shell + coreutils + git + jq. No Python. Exit 0 only if every check passes. |
| 25 | set -u |
| 26 | cd "$(dirname "$0")/.." || exit 2 |
| 27 | ROOT=$(pwd) |
| 28 | W=${M20_RECEIPT_WRITER:-$ROOT/tools/m20_receipt.sh} |
| 29 | FX=$ROOT/tests/fixtures/m20_receipt |
| 30 | T=$(mktemp -d "${TMPDIR:-/tmp}/m20-receipt-test.XXXXXX") || exit 2 |
| 31 | trap 'chmod -R u+w "$T" 2> /dev/null; rm -rf "$T"' EXIT INT TERM |
| 32 | G="git -c user.name=m20-test -c user.email=m20-test@invalid -c commit.gpgsign=false -c init.defaultBranch=main" |
| 33 | PASSLOG=$FX/tensor_pass.log; FAILLOG=$FX/tensor_fail.log; MUTLOG=$FX/mutations_pass.log |
| 34 | fail=0; total=0 |
| 35 | check() { # NAME CONDITION-EXIT-STATUS |
| 36 | total=$((total + 1)) |
| 37 | if [ "$2" = 0 ]; then echo "PASS $1"; else echo "FAIL $1"; fail=1; fi |
| 38 | } |
| 39 | mkrepo() { # NAME TABLE (fixture tests/fixtures/m20_receipt/table_<TABLE>) -> prints the repo path |
| 40 | local r=$T/repo-$1 |
| 41 | mkdir -p "$r/docs/tensor" && cp "$FX/table_$2" "$r/docs/tensor/M20_OMEGA_TENSOR.md" \ |
| 42 | && $G -C "$r" init -q && $G -C "$r" add -A && $G -C "$r" commit -qm fixture \ |
| 43 | || { echo "FATAL: cannot create fixture repo $1"; exit 2; } |
| 44 | echo "$r" |
| 45 | } |
| 46 | # run NAME REPO EVID TENSOR-LOG [writer args...] -> sets RC, OUT, REC |
| 47 | run() { |
| 48 | local name=$1 repo=$2 evid=$3 tlog=$4; shift 4 |
| 49 | OUT=$T/$name.out |
| 50 | "$W" --repo "$repo" --evidence-dir "$evid" --tensor-log "$tlog" --mutations-log "$MUTLOG" "$@" > "$OUT" 2>&1 |
| 51 | RC=$? |
| 52 | REC=$(sed -n 's/^receipt: \([^ ]*\) .*/\1/p' "$OUT") |
| 53 | } |
| 54 | nojson() { ! ls "$1"/*.json > /dev/null 2>&1; } |
| 55 | jqok() { jq -e "$2" "$1" > /dev/null 2>&1; } |
| 56 | sha() { sha256sum "$1" | cut -d' ' -f1; } |
| 57 | |
| 58 | # 1. All rows host PASS (+ REFERENCE rows), no GB10 parity row: host-only |
| 59 | # evidence never qualifies -> NOT QUALIFIED; sealed, content-addressed. |
| 60 | R=$(mkrepo all all_pass.md) |
| 61 | run all1 "$R" "$T/ev-a" "$PASSLOG" --binary "$FX/binary_stub.txt"; A=$REC |
| 62 | [ "$RC" = 1 ]; check "all host PASS: exit 1 (NOT QUALIFIED)" $? |
| 63 | [ -n "$A" ] && jqok "$A" '.verdict == "NOT QUALIFIED" and .hardware == "host" and .gate == "M20_OMEGA_TENSOR" and (.verdict_reasons | any(test("GB10 parity")))'; check "all host PASS: NOT QUALIFIED, hardware host, GB10 parity reason" $? |
| 64 | [ -n "$A" ] && [ "$(basename "$A" .json)" = "$(sha "$A")" ]; check "receipt name is its sha256" $? |
| 65 | [ -n "$A" ] && [ "$(stat -c %a "$A")" = 444 ]; check "receipt mode 0444" $? |
| 66 | [ -f "$T/ev-a/blobs/$(sha "$PASSLOG").log" ] && [ -f "$T/ev-a/blobs/$(sha "$MUTLOG").log" ] \ |
| 67 | && [ -f "$T/ev-a/blobs/$(sha "$FX/binary_stub.txt").bin" ]; check "log and binary blobs stored by digest" $? |
| 68 | [ -n "$A" ] && jqok "$A" "(.logs.test_tensor_sha256 == \"$(sha "$PASSLOG")\") and (.binaries[0].sha256 == \"$(sha "$FX/binary_stub.txt")\") and (.omega_commit == \"$($G -C "$R" rev-parse HEAD)\") and .omega_tree_clean_after and .omega_commit_unchanged_after and ([.rows[] | select(.label == \"host PASS\")] | length) == 3 and ([.rows[] | select(.label == \"REFERENCE\")] | length) == 2 and (has(\"started_utc\") | not)" |
| 69 | check "receipt fields: log/binary/commit hashes, clean after, row labels, no clock" $? |
| 70 | |
| 71 | # 2. Reproducibility: same inputs, second evidence dir -> same hash, same bytes. |
| 72 | run all2 "$R" "$T/ev-b" "$PASSLOG" --binary "$FX/binary_stub.txt"; B=$REC |
| 73 | [ "$RC" = 1 ] && [ -n "$A" ] && [ "$(basename "$A")" = "$(basename "$B")" ] && cmp -s "$A" "$B"; check "reproducible: two runs give the same hash and bytes" $? |
| 74 | run ts1 "$R" "$T/ev-ts1" "$PASSLOG" --started-utc 2026-10-01T00:00:00Z --finished-utc 2026-10-01T00:01:00Z; T1=$REC |
| 75 | run ts2 "$R" "$T/ev-ts2" "$PASSLOG" --started-utc 2026-10-01T00:00:00Z --finished-utc 2026-10-01T00:01:00Z; T2=$REC |
| 76 | run ts3 "$R" "$T/ev-ts3" "$PASSLOG" --started-utc 2026-10-01T00:00:01Z --finished-utc 2026-10-01T00:01:00Z; T3=$REC |
| 77 | [ -n "$T1" ] && [ "$(basename "$T1")" = "$(basename "$T2")" ] && [ "$(basename "$T1")" != "$(basename "$T3")" ] \ |
| 78 | && jqok "$T1" '.started_utc == "2026-10-01T00:00:00Z"'; check "timestamps only when passed in, and they are hashed" $? |
| 79 | |
| 80 | # 3. Never overwritten: rerun into the same dir, and a squatter with the same name. |
| 81 | run again "$R" "$T/ev-a" "$PASSLOG" --binary "$FX/binary_stub.txt" |
| 82 | [ "$RC" = 2 ] && grep -q 'already exists' "$OUT"; check "rerun into same evidence dir refused" $? |
| 83 | mkdir -p "$T/ev-sq" && [ -n "$A" ] && echo squatter > "$T/ev-sq/$(basename "$A")" && chmod 0644 "$T/ev-sq/$(basename "$A")" |
| 84 | run squat "$R" "$T/ev-sq" "$PASSLOG" --binary "$FX/binary_stub.txt" |
| 85 | [ "$RC" = 2 ] && [ "$(cat "$T/ev-sq/$(basename "$A")" 2> /dev/null)" = squatter ]; check "existing writable receipt name not overwritten" $? |
| 86 | |
| 87 | # 4. NOT_RUN / MISSING_IMPLEMENTATION (GB10 parity PASS, so only that rule |
| 88 | # can fail them) / nothing counted -> NOT QUALIFIED (receipt written). |
| 89 | R=$(mkrepo notrun not_run.md); run notrun "$R" "$T/ev-nr" "$PASSLOG" --chip-evidence "$FX/chip_evidence.json" |
| 90 | [ "$RC" = 1 ] && [ -n "$REC" ] && jqok "$REC" '.verdict == "NOT QUALIFIED" and (.verdict_reasons | any(test("NOT_RUN")))'; check "NOT_RUN row forces NOT QUALIFIED" $? |
| 91 | R=$(mkrepo missing missing.md); run missing "$R" "$T/ev-mi" "$PASSLOG" --chip-evidence "$FX/chip_evidence.json" |
| 92 | [ "$RC" = 1 ] && [ -n "$REC" ] && jqok "$REC" '.verdict == "NOT QUALIFIED" and (.verdict_reasons | any(test("MISSING_IMPLEMENTATION")))'; check "MISSING_IMPLEMENTATION row forces NOT QUALIFIED" $? |
| 93 | R=$(mkrepo refonly reference_only.md); run refonly "$R" "$T/ev-ro" "$PASSLOG" |
| 94 | [ "$RC" = 1 ] && [ -n "$REC" ] && jqok "$REC" '.verdict == "NOT QUALIFIED"'; check "only REFERENCE rows -> NOT QUALIFIED" $? |
| 95 | |
| 96 | # 5. Refusals: exit 2 and no receipt. |
| 97 | R=$(mkrepo dirty all_pass.md); echo stray > "$R/stray.txt"; run dirty "$R" "$T/ev-di" "$PASSLOG" |
| 98 | [ "$RC" = 2 ] && nojson "$T/ev-di"; check "dirty tree refused" $? |
| 99 | R=$(mkrepo inside all_pass.md); echo "evidence/" > "$R/.git/info/exclude"; run inside "$R" "$R/evidence" "$PASSLOG" |
| 100 | [ "$RC" = 2 ] && nojson "$R/evidence"; check "evidence dir inside the tree refused" $? |
| 101 | R=$(mkrepo unknown unknown.md); run unknown "$R" "$T/ev-un" "$PASSLOG" |
| 102 | [ "$RC" = 2 ] && nojson "$T/ev-un"; check "unknown row label refused" $? |
| 103 | R=$(mkrepo hostfail all_pass.md); run hostfail "$R" "$T/ev-hf" "$FAILLOG" |
| 104 | [ "$RC" = 2 ] && nojson "$T/ev-hf"; check "host PASS rows with a failing host log refused" $? |
| 105 | |
| 106 | # 6. GB10 PASS rows: need the chip evidence file and its hash in the row. |
| 107 | R=$(mkrepo gb10 gb10.md) |
| 108 | run gb10ok "$R" "$T/ev-g1" "$PASSLOG" --chip-evidence "$FX/chip_evidence.json" |
| 109 | [ "$RC" = 0 ] && [ -n "$REC" ] && jqok "$REC" ".verdict == \"QUALIFIED\" and .hardware == \"GB10\" and .chip_evidence_sha256 == \"$(sha "$FX/chip_evidence.json")\"" \ |
| 110 | && [ -f "$T/ev-g1/blobs/$(sha "$FX/chip_evidence.json").json" ]; check "GB10 PASS with matching chip evidence -> QUALIFIED, hardware GB10" $? |
| 111 | run gb10none "$R" "$T/ev-g2" "$PASSLOG" |
| 112 | [ "$RC" = 2 ] && nojson "$T/ev-g2"; check "GB10 PASS without chip evidence refused" $? |
| 113 | run gb10other "$R" "$T/ev-g3" "$PASSLOG" --chip-evidence "$FX/chip_evidence_other.json" |
| 114 | [ "$RC" = 2 ] && nojson "$T/ev-g3"; check "GB10 PASS with non-matching chip evidence refused" $? |
| 115 | R=$(mkrepo gb10nh gb10_nohash.md); run gb10nh "$R" "$T/ev-g4" "$PASSLOG" |
| 116 | [ "$RC" = 2 ] && nojson "$T/ev-g4"; check "GB10 PASS row naming no evidence, no chip file, refused" $? |
| 117 | |
| 118 | # 7. Tree changes during the run (test-only hook) -> NOT QUALIFIED with the reason. |
| 119 | R=$(mkrepo middirty all_pass.md) |
| 120 | M20_RECEIPT_TEST_MIDRUN="echo x > '$R/late.txt'" run middirty "$R" "$T/ev-md" "$PASSLOG" |
| 121 | [ "$RC" = 1 ] && [ -n "$REC" ] && jqok "$REC" '(.omega_tree_clean_after | not) and (.verdict_reasons | any(test("dirty after")))'; check "tree dirtied mid-run -> NOT QUALIFIED" $? |
| 122 | R=$(mkrepo midcommit all_pass.md) |
| 123 | M20_RECEIPT_TEST_MIDRUN="$G -C '$R' commit -q --allow-empty -m moved" run midcommit "$R" "$T/ev-mc" "$PASSLOG" |
| 124 | [ "$RC" = 1 ] && [ -n "$REC" ] && jqok "$REC" '(.omega_commit_unchanged_after | not) and (.verdict_reasons | any(test("HEAD moved")))'; check "HEAD moved mid-run -> NOT QUALIFIED" $? |
| 125 | |
| 126 | if [ "$fail" -ne 0 ]; then echo "test-m20-receipt: FAIL"; exit 1; fi |
| 127 | echo "test-m20-receipt: PASS ($total of $total checks)" |