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 / dgraph_receipt / run.sh
| 1 | #!/bin/sh |
| 2 | # tests/dgraph_receipt/run.sh TOOL JSON_CANON WORKDIR: host-only tests of tools/dgraph_receipt.c |
| 3 | # (aien-architecture#233 P1, spec docs/perf/DECODE_GRAPH_RECEIPT.md). No GPU, reads evidence/ only. |
| 4 | # 1. regenerate each golden receipt from its evidence run and compare byte for byte with fixtures/ |
| 5 | # 2. the checker accepts every golden receipt (and the hand-written NOT_RUN one), json_canon agrees |
| 6 | # it is strict JSON, and every evidence path exists in this tree |
| 7 | # 3. every negative fixture in negatives.txt is refused, for the reason named there, and differs |
| 8 | # from the good receipt it was cut from (a negative identical to a good one proves nothing) |
| 9 | # 4. the generator refuses bad input (missing flag, log without settings, stats/log from two runs) |
| 10 | # 5. a receipt written under umask 000 is mode 644, never world-writable |
| 11 | # Run from the repo root (the Makefile does). Exit 0 only when every case holds. |
| 12 | set -u |
| 13 | TOOL="${1:?tool}"; CANON="${2:?json_canon}"; WORK="${3:?workdir}" |
| 14 | T=tests/dgraph_receipt; F=$T/fixtures |
| 15 | rm -rf "$WORK"; mkdir -p "$WORK" |
| 16 | fails=0; cases=0 |
| 17 | ok() { cases=$((cases + 1)); echo "ok: $*"; } |
| 18 | bad() { cases=$((cases + 1)); fails=$((fails + 1)); echo "FAIL: $*"; } |
| 19 | |
| 20 | MODEL="synthetic Qwen3-30B-A3B-shaped decode step, random weights" |
| 21 | PREC="FP8 e4m3 weights (qkv, o, gate_up, down), BF16 lm_head, f32 activations" |
| 22 | MODE="decode, one token per command list (omega_gpu_decode_graph_token), batch 1" |
| 23 | |
| 24 | # golden 1: decode_graph main at omega main 710d438c (clean tree), uncached weights, prefetch off |
| 25 | R1=evidence/OWN30B-REQUAL-MAIN-710d438c-20261015/gates/decode_graph |
| 26 | gen_main() { |
| 27 | "$TOOL" --run-dir "$R1" --stats "$R1/receipt-main.json" --log "$R1/main.log" --status HISTORICAL --repo aien-spark/omega \ |
| 28 | --model "$MODEL" --precision "$PREC" --mode "$MODE" --runner "tools/run_gpu_decode_graph_chip.sh EVIDENCE_DIR main" \ |
| 29 | --evidence evidence/OWN30B-REQUAL-MAIN-710d438c-20261015/NOTES.md "$@" |
| 30 | } |
| 31 | # golden 2: the same base, GPU-cached weights with the W-L2d prefetch on (independent launches) |
| 32 | R2=evidence/OWN30B-REQUAL-MAIN-710d438c-20261015/gates/l2d_prefetch |
| 33 | gen_prefetch() { |
| 34 | "$TOOL" --run-dir "$R2" --stats "$R2/receipt-4-cached-prefetch.json" --log "$R2/4-cached-prefetch.log" --status HISTORICAL \ |
| 35 | --repo aien-spark/omega --model "$MODEL" --precision "$PREC" --mode "$MODE" \ |
| 36 | --runner "tools/run_gpu_l2d_prefetch_chip.sh EVIDENCE_DIR (run 4-cached-prefetch: --cached-weights --prefetch --reps 10)" \ |
| 37 | --evidence evidence/OWN30B-REQUAL-MAIN-710d438c-20261015/NOTES.md "$@" |
| 38 | } |
| 39 | |
| 40 | # 1 + 2: golden receipts |
| 41 | for g in main prefetch; do |
| 42 | golden="$F/good-historical-710d438c-$g.json" |
| 43 | if "gen_$g" --out "$WORK/$g.json" 2> "$WORK/$g.err"; then |
| 44 | if cmp -s "$WORK/$g.json" "$golden"; then ok "golden $g regenerated byte for byte from evidence"; else bad "golden $g differs from $golden"; diff "$golden" "$WORK/$g.json" | head -20; fi |
| 45 | else bad "generator failed on golden $g: $(cat "$WORK/$g.err")"; fi |
| 46 | done |
| 47 | for good in "$F"/good-*.json; do |
| 48 | if out=$("$TOOL" --check "$good" --evidence-root .); then ok "checker accepts $good"; else bad "checker refused $good: $out"; fi |
| 49 | if "$CANON" --check < "$good"; then ok "json_canon: $good is strict JSON"; else bad "json_canon refused $good"; fi |
| 50 | done |
| 51 | # the receipts carry the evidence numbers unchanged (independent of the tool: grep both files) |
| 52 | for pair in "C_total:graph total_ns" "C_chip:graph chip_ns" "span_ns:stamped span_ns"; do |
| 53 | key=${pair%%:*} |
| 54 | want=$(grep -o "\"$key\":[0-9]*" "$R1/receipt-main.json" | head -n 1 | cut -d: -f2) |
| 55 | case "$key" in C_total) f=total_ns ;; C_chip) f=chip_ns ;; *) f=span_ns ;; esac |
| 56 | got=$(grep -o "\"$f\": [0-9]*" "$F/good-historical-710d438c-main.json" | head -n 1 | cut -d' ' -f2) |
| 57 | if [ -n "$want" ] && [ "$want" = "$got" ]; then ok "${pair#*:} $got equals evidence $key"; else bad "${pair#*:} $got vs evidence $key $want"; fi |
| 58 | done |
| 59 | |
| 60 | # 3: negative fixtures (file, the good receipt it was cut from, expected reason) |
| 61 | while IFS='|' read -r name base reason; do |
| 62 | case "$name" in ''|'#'*) continue ;; esac |
| 63 | n="$F/$name" |
| 64 | if [ ! -f "$n" ]; then bad "negative $name missing"; continue; fi |
| 65 | if cmp -s "$n" "$F/$base"; then bad "negative $name is identical to $base"; continue; fi |
| 66 | out=$("$TOOL" --check "$n" --evidence-root .); rc=$? |
| 67 | if [ $rc = 1 ] && printf '%s' "$out" | grep -qF -- "$reason"; then ok "refused $name ($reason)" |
| 68 | else bad "negative $name: exit $rc, wanted 1 with \"$reason\", got: $out"; fi |
| 69 | done < "$T/negatives.txt" |
| 70 | |
| 71 | # 4: generator refusals (nothing written) |
| 72 | "$TOOL" --run-dir "$R1" --stats "$R1/receipt-main.json" --log "$R1/main.log" --repo aien-spark/omega --model m --precision p --mode d \ |
| 73 | --runner r --out "$WORK/x1.json" 2> /dev/null |
| 74 | rc=$?; if [ $rc = 2 ] && [ ! -e "$WORK/x1.json" ]; then ok "generator: missing --status is a usage error"; else bad "generator: missing --status gave exit $rc"; fi |
| 75 | head -n 0 "$R1/main.log" > "$WORK/empty.log" |
| 76 | "$TOOL" --run-dir "$R1" --stats "$R1/receipt-main.json" --log "$WORK/empty.log" --status HISTORICAL --repo aien-spark/omega --model m \ |
| 77 | --precision p --mode d --runner r --out "$WORK/x3.json" 2> "$WORK/x3.err" |
| 78 | rc=$?; if [ $rc = 2 ] && [ ! -e "$WORK/x3.json" ] && grep -q 'dgraph prefetch' "$WORK/x3.err"; then ok "generator: log without the run's settings refused"; else bad "generator: settings-less log gave exit $rc"; fi |
| 79 | "$TOOL" --run-dir "$R1" --stats "$R1/receipt-main.json" --log "$R2/4-cached-prefetch.log" --status HISTORICAL --repo aien-spark/omega \ |
| 80 | --model m --precision p --mode d --runner r --out "$WORK/x4.json" 2> "$WORK/x4.err" |
| 81 | rc=$?; if [ $rc = 2 ] && [ ! -e "$WORK/x4.json" ] && grep -q 'not the same run' "$WORK/x4.err"; then ok "generator: stats and log from two runs refused"; else bad "generator: mixed runs gave exit $rc"; fi |
| 82 | gen_main --status TBD --out "$WORK/x5.json" 2> /dev/null |
| 83 | rc=$? |
| 84 | if [ $rc = 2 ]; then ok "generator: a repeated --status is a usage error"; else bad "generator: repeated --status gave exit $rc"; fi |
| 85 | "$TOOL" --run-dir "$R1" --stats "$R1/receipt-main.json" --log "$R1/main.log" --status DONE --repo aien-spark/omega --model m \ |
| 86 | --precision p --mode d --runner r --out "$WORK/x6.json" 2> "$WORK/x6.err" |
| 87 | rc=$?; if [ $rc = 1 ] && [ ! -e "$WORK/x6.json" ] && grep -q 'fails its own check' "$WORK/x6.err"; then ok "generator: status outside the enum never written"; else bad "generator: status DONE gave exit $rc"; fi |
| 88 | # 5: a written receipt is never world-writable, even under umask 000 (CodeQL cpp/world-writable-file-creation) |
| 89 | ( umask 000; gen_main --out "$WORK/mode.json" 2> "$WORK/mode.err" ) |
| 90 | rc=$?; mode=$(stat -c %a "$WORK/mode.json" 2> /dev/null) |
| 91 | if [ $rc = 0 ] && [ "$mode" = 644 ]; then ok "generator: receipt created mode 644 under umask 000"; else bad "generator: receipt mode '$mode' (exit $rc) under umask 000, wanted 644"; fi |
| 92 | |
| 93 | echo "dgraph_receipt tests: $cases cases, $fails failed" |
| 94 | [ $fails = 0 ] |