interplane.Get Omega
Read in your language

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

GitHub aien-dev/omega-mv#211 (code only)

closed derived ed713e7e427780f1 #211

Imported from GitHub aien-dev/omega-mv#211 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base e6298806f1c7ccd874d123350d639ad8bba6edc7 · Head b3ff1532cbd81f2102a84327d76e99b43870e3b0

Apply it

git checkout -b patch-ed713e7e427780f1 e6298806f1c7ccd874d123350d639ad8bba6edc7
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/ed713e7e427780f1.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/omega-mv
211
b3ff1532cbd81f2102a84327d76e99b43870e3b0
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":211,"url":"https://github.com/aien-dev/omega-mv/pull/211","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:47Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/tests/test_tensor_conversion_equiv.sh b/tests/test_tensor_conversion_equiv.sh
new file mode 100755
index 000000000..6596ee754
--- /dev/null
+++ b/tests/test_tensor_conversion_equiv.sh
@@ -0,0 +1,99 @@
+#!/bin/sh
+# Proof that tools/tensor_mutations.sh, now an adapter over
+# tools/mutation_runner.sh, behaves like the legacy sweep. Host only, CPU only.
+# Runs the OLD script (pinned commit ab66c17, omega#192, the last main commit
+# with the unconverted sweep and the current 27-row table) and the NEW script
+# on the same tree and requires identical stdout, identical exit code and an
+# identical per-mutant verdict list (name + KILLED/SURVIVED/ERROR). It also
+# requires the MUTATIONS and STORE_MUTATIONS tables to be identical in both
+# scripts. The old copy is written into tools/ of this tree, so old and new
+# both call this tree's own tools/m20_receipt_mutations.sh (already an adapter
+# on the runner since omega#207); only the tensor sweep itself differs between
+# old and new. The verdict list holds the main rows, the 11 M20 receipt rows
+# and the store rows (currently 27 + 11 + 6 = 44). The row counts the test
+# expects are read from the pinned script's own tables, never typed in here.
+# When a later PR adds table rows, the tables stop matching the pin: re-pin to
+# the newest main commit that still has the unconverted script.
+#
+# Normalised text: none. The sweeps print no temp paths or timings on stdout
+# (scratch dirs are only used internally), so stdout is compared byte for byte.
+# (The sweep has no JSON output; the c4 sweep is the only one that does.)
+set -u
+root=$(cd "$(dirname "$0")/.." && pwd)
+cd "$root" || exit 2
+PIN=ab66c171fd5b553d3910b47c3ecf9fecde117fd8
+old=tools/tensor_mutations_legacy.$$.sh
+tmp=$(mktemp -d "${TMPDIR:-/tmp}/tensor-equiv.XXXXXX") || exit 2
+trap 'rm -rf "$tmp" "$root/$old"' EXIT INT TERM
+git show "$PIN:tools/tensor_mutations.sh" > "$old" || { echo "FAIL cannot extract $PIN:tools/tensor_mutations.sh"; exit 2; }
+chmod +x "$old"
+fails=0
+ok() { if [ "$2" = 0 ]; then echo "ok   $1"; else echo "FAIL $1"; fails=$((fails + 1)); fi; }
+
+# verdicts FILE: "name VERDICT" per MUTATION line, in order.
+verdicts() {
+    sed -n 's/^MUTATION \([A-Za-z0-9_ ]*\): caught.*/\1 KILLED/p;
+            s/^MUTATION \([A-Za-z0-9_ ]*\): NOT CAUGHT.*/\1 SURVIVED/p;
+            s/^MUTATION \([A-Za-z0-9_ ]*\): \(NOT APPLIED\|does not build\).*/\1 ERROR/p;
+            s/^MUTATION \(store baseline\): .*/\1 ERROR/p' "$1"
+}
+
+# table_text NAME FILE: the NAME='...' table of a sweep script, one row per
+# line (the assignment ends at the first line that ends with a single quote).
+# table_rows NAME FILE: how many rows it holds (every row contains a '|').
+table_text() {
+    awk -v v="$1" 'index($0, v "=\047") == 1 { p = 1 } p { print } p && /\047$/ { exit }' "$2"
+}
+table_rows() { table_text "$1" "$2" | grep -c '|'; }
+main_rows=$(table_rows MUTATIONS "$old")
+store_rows=$(table_rows STORE_MUTATIONS "$old")
+new_main_rows=$(table_rows MUTATIONS tools/tensor_mutations.sh)
+table_text MUTATIONS "$old" > "$tmp/old.main.table"
+table_text MUTATIONS tools/tensor_mutations.sh > "$tmp/new.main.table"
+table_text STORE_MUTATIONS "$old" > "$tmp/old.store.table"
+table_text STORE_MUTATIONS tools/tensor_mutations.sh > "$tmp/new.store.table"
+
+sh "$old" > "$tmp/old.out" 2>/dev/null; echo $? > "$tmp/old.rc"
+tools/tensor_mutations.sh > "$tmp/new.out" 2>/dev/null; echo $? > "$tmp/new.rc"
+verdicts "$tmp/old.out" > "$tmp/old.v"
+verdicts "$tmp/new.out" > "$tmp/new.v"
+n=$(wc -l < "$tmp/new.v")
+
+cmp -s "$tmp/old.out" "$tmp/new.out"; ok "stdout identical old vs new" $?
+cmp -s "$tmp/old.rc" "$tmp/new.rc"; ok "exit code identical old vs new ($(cat "$tmp/old.rc") vs $(cat "$tmp/new.rc"))" $?
+cmp -s "$tmp/old.v" "$tmp/new.v"; ok "per-mutant verdict list identical" $?
+[ "$main_rows" -gt 0 ] && [ "$store_rows" -gt 0 ]; ok "found both tables in the pinned script ($main_rows main rows, $store_rows store rows)" $?
+cmp -s "$tmp/old.main.table" "$tmp/new.main.table"; ok "MUTATIONS table identical old vs new ($new_main_rows rows)" $?
+cmp -s "$tmp/old.store.table" "$tmp/new.store.table"; ok "STORE_MUTATIONS table identical old vs new" $?
+floor=$((main_rows + store_rows))
+[ "$n" -ge "$floor" ]; ok "compared at least $floor mutants ($main_rows main + $store_rows store), got $n" $?
+[ "$(wc -l < "$tmp/old.v")" = "$n" ]; ok "old and new list the same number of mutants" $?
+
+# Negative checks: the comparison must be able to fail.
+sed '0,/: caught/s//: NOT CAUGHT/' "$tmp/new.out" > "$tmp/alt.out"
+cmp -s "$tmp/old.out" "$tmp/alt.out"; [ $? -ne 0 ]; ok "negative: altered stdout is reported different" $?
+verdicts "$tmp/alt.out" > "$tmp/alt.v"
+cmp -s "$tmp/old.v" "$tmp/alt.v"; [ $? -ne 0 ]; ok "negative: altered verdict list is reported different" $?
+echo $(( $(cat "$tmp/old.rc") + 1 )) > "$tmp/alt.rc"
+cmp -s "$tmp/old.rc" "$tmp/alt.rc"; [ $? -ne 0 ]; ok "negative: altered exit code is reported different" $?
+{ cat "$tmp/new.main.table"; echo 'EXTRA_ROW|omega_tensor.c|s/a/b/'; } > "$tmp/alt.main.table"
+cmp -s "$tmp/old.main.table" "$tmp/alt.main.table"; [ $? -ne 0 ]; ok "negative: altered table is reported different" $?
+
+# Negative check for the adapter's row-count guard: a runner that dies reports
+# no verdicts, and the sweep must then FAIL, never print PASS (0 of 0). The
+# adapter does cd "$(dirname "$0")/..", so a scratch tree holding a copy of it
+# beside a stub runner that just exits 2 runs it against a dead runner. The M20
+# sweep is stubbed to succeed, so only the row-count guard can fail this run.
+dead="$tmp/dead"
+mkdir -p "$dead/tools"
+cp tools/tensor_mutations.sh "$dead/tools/tensor_mutations.sh"
+printf '#!/bin/sh\nexit 2\n' > "$dead/tools/mutation_runner.sh"
+printf '#!/bin/sh\nexit 0\n' > "$dead/tools/m20_receipt_mutations.sh"
+chmod +x "$dead/tools/tensor_mutations.sh" "$dead/tools/mutation_runner.sh" "$dead/tools/m20_receipt_mutations.sh"
+sh "$dead/tools/tensor_mutations.sh" > "$dead/out" 2>/dev/null; drc=$?
+[ "$drc" -ne 0 ]; ok "negative: dead runner makes the sweep exit nonzero (got $drc)" $?
+grep -q 'PASS' "$dead/out"; [ $? -ne 0 ]; ok "negative: dead runner never prints PASS" $?
+grep -q "runner reported 0 verdicts for $new_main_rows rows" "$dead/out"; ok "negative: dead runner reports the verdict shortfall (0 verdicts for $new_main_rows main rows)" $?
+
+if [ "$fails" -ne 0 ]; then echo "tensor conversion equivalence: FAIL ($fails)"; exit 1; fi
+echo "tensor conversion equivalence: PASS ($n mutants compared)"
diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh
index 871c36878..514932c32 100755
--- a/tools/tensor_mutations.sh
+++ b/tools/tensor_mutations.sh
@@ -1,9 +1,10 @@
 #!/bin/sh
-# M20 OMEGA_TENSOR mutation sweep. For each rule marked MUT:<name> in
-# src/tensor/*.c, copy src/tensor to a scratch directory, break that one rule,
-# rebuild the CPU test against the copy and require the test to FAIL.
-# A mutation that does not apply, or that the tests do not catch, fails the
-# sweep. CPU only, no device. Shell only (no Python).
+# M20 OMEGA_TENSOR mutation sweep, a thin adapter over tools/mutation_runner.sh.
+# For each rule marked MUT:<name> in src/tensor/*.c the runner copies the tree
+# to a scratch directory, breaks that one rule, rebuilds the CPU test there and
+# requires the test to FAIL. A mutation that does not apply, does not build or
+# is not caught fails the sweep. The adapter maps the runner verdicts back to
+# the legacy stdout lines. CPU only, no device. Shell only (no Python).
 set -u
 cd "$(dirname "$0")/.." || exit 2
 SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/tensor-mut.XXXXXX") || exit 2
@@ -43,87 +44,84 @@ REDUCE_AXES_DESCENDING|omega_tensor.c|s/for (uint32_t d = in.rank; d-- > 0;)/for
 REDUCE_AXES_KEEPDIMS|omega_tensor.c|s/keep\[n\] = keepdims;/keep[n] = keepdims \&\& false;/
 SUM_TO_SHAPE_SIZE1|omega_tensor.c|s/ax\[n\] = d; keep\[n\] = true; n++;/(void)0;/'
 
-# Baseline: the unmutated build must PASS, otherwise every mutant would
-# look "caught" (e.g. the test refusing an unsuitable FP environment).
-if ! gcc $FLAGS -Isrc -Isrc/tensor -o "$SCRATCH/base" tests/test_omega_tensor.c \
-    src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $DEPS \
-    > "$SCRATCH/base.log" 2>&1 || ! "$SCRATCH/base" > "$SCRATCH/base.run" 2>&1; then
-    head -5 "$SCRATCH/base.log" "$SCRATCH/base.run" 2>/dev/null
-    echo "tensor mutation sweep: FAIL (unmutated baseline does not pass)"; exit 1
-fi
+STORE_MUTATIONS='TSTORE_HASH_VERIFY|s/memcmp(dig, sl->payload_sha, 32) != 0 || memcmp(vid, sl->value_id, 32) != 0/0/
+TSTORE_SHORT_RECORD|s/len != HDR_BYTES + count \* REC_BYTES/0/
+TSTORE_GEN_RESET|s/sl->gen = r->gen + 1;/sl->gen = 1;/
+TSTORE_RENAME_BEFORE_WRITE|s/const char \*wpath = tmp;/const char *wpath = final;/
+TSTORE_RECORD_SUM|s/memcmp(sum, in + REC_SUM, 32) != 0/0/
+TSTORE_HEADER_SUM|s/memcmp(sum, st->jbuf + HDR_SUM, 32) != 0/0/'
+STORE_SRCS="src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c"
+# The runner reads its own env var ONLY; the legacy sweep never did.
+unset ONLY
 fail=0
 total=0
-old_ifs=$IFS
-IFS='
-'
-for m in $MUTATIONS; do
-    IFS=$old_ifs
-    IFS='|' read -r name file expr <<EOM
-$m
-EOM
-    total=$((total + 1))
-    rm -rf "$SCRATCH/tensor" && cp -r src/tensor "$SCRATCH/tensor"
-    sed -i "/MUT:$name/ $expr" "$SCRATCH/tensor/$file"
-    if cmp -s "src/tensor/$file" "$SCRATCH/tensor/$file"; then
-        echo "MUTATION $name: NOT APPLIED (marker or pattern missing)"; fail=1; continue
-    fi
-    if ! gcc $FLAGS -Isrc -I"$SCRATCH/tensor" -o "$SCRATCH/t" tests/test_omega_tensor.c \
-        "$SCRATCH/tensor/omega_tensor.c" "$SCRATCH/tensor/omega_tensor_cpu.c" \
-        "$SCRATCH/tensor/omega_tensor_reduce_seam.c" $DEPS > "$SCRATCH/build.log" 2>&1; then
-        head -5 "$SCRATCH/build.log"
-        echo "MUTATION $name: does not build (fix the sed expression)"; fail=1; continue
+
+# run_block ROWSFILE BUILDCMD TESTCMD: run the shared runner (marker reader,
+# baseline check on) and print one legacy "MUTATION <name>: ..." line per
+# mutant, in row order. Returns 3 if the unmutated baseline does not pass.
+# Sets fail=1 if the runner reported fewer or more verdict lines than rows.
+# Legacy notes that need no mapping beyond the verdict: KILLED note
+# "<N> failing case(s), first: ..." becomes "caught (<N> failing checks)",
+# "harness exit" (nonzero exit, no FAIL line) becomes "caught (0 failing
+# checks)". The 5-line build-log head the old script printed on a build error
+# is replaced by the runner's one-line build error note.
+run_block() {
+    rb_rows=$1
+    "tools/mutation_runner.sh" -k marker -m "$rb_rows" -t "$3" -b "$2" -c "src tests" -f FAIL -B \
+        > "$SCRATCH/rb.out" 2> "$SCRATCH/rb.err"
+    if grep -q 'unmutated baseline does not pass' "$SCRATCH/rb.out"; then
+        cat "$SCRATCH/rb.err"; return 3
     fi
-    if "$SCRATCH/t" > "$SCRATCH/run.log" 2>&1; then
-        echo "MUTATION $name: NOT CAUGHT (tests still pass)"; fail=1
-    else
-        echo "MUTATION $name: caught ($(grep -c '^FAIL' "$SCRATCH/run.log") failing checks)"
+    rb_seen=0
+    while IFS= read -r rb_l; do
+        rb_id=${rb_l%% *}; rb_r=${rb_l#* }; rb_st=${rb_r%% *}
+        rb_note=${rb_l#*\(}; rb_note=${rb_note%)}
+        total=$((total + 1)); rb_seen=$((rb_seen + 1))
+        case $rb_st in
+            KILLED)
+                rb_n=$(printf '%s\n' "$rb_note" | sed -n 's/^\([0-9][0-9]*\) failing case.*/\1/p')
+                echo "MUTATION $rb_id: caught (${rb_n:-0} failing checks)" ;;
+            SURVIVED*) echo "MUTATION $rb_id: NOT CAUGHT (tests still pass)"; fail=1 ;;
+            *)
+                case $rb_note in
+                    "build failed"*) echo "$rb_note"; echo "MUTATION $rb_id: does not build (fix the sed expression)" ;;
+                    *) echo "MUTATION $rb_id: NOT APPLIED (marker or pattern missing)" ;;
+                esac
+                fail=1 ;;
+        esac
+    done < "$SCRATCH/rb.err"
+    # The legacy sweep walked the rows itself, so a row could not be skipped.
+    # A runner that died, was killed or reported nothing must not pass silently:
+    # one verdict line per row is required.
+    rb_want=$(grep -c '|' "$rb_rows")
+    if [ "$rb_seen" -ne "$rb_want" ]; then
+        echo "MUTATION $rb_rows: runner reported $rb_seen verdicts for $rb_want rows (runner died or reported nothing)"
+        fail=1
     fi
-done
-IFS=$old_ifs
+}
+
+# Main block. Rows are name|file|sed expression; the file column is relative
+# to src/tensor, the runner wants it relative to the tree root.
+printf '%s\n' "$MUTATIONS" | sed 's#^\([A-Z0-9_]*\)|#\1|src/tensor/#' > "$SCRATCH/main.rows"
+# Baseline: the unmutated build must PASS, otherwise every mutant would
+# look "caught" (e.g. the test refusing an unsuitable FP environment).
+if ! run_block "$SCRATCH/main.rows" \
+    "gcc $FLAGS -Isrc -Isrc/tensor -o .tensor_t tests/test_omega_tensor.c src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $DEPS" \
+    ./.tensor_t; then
+    echo "tensor mutation sweep: FAIL (unmutated baseline does not pass)"; exit 1
+fi
 # M20 receipt writer mutants (MUT: markers in tools/m20_receipt.sh), own sweep.
 tools/m20_receipt_mutations.sh || fail=1
 
 # Crash-safe storage lifetime (omega_tensor_store.c): each mutant rebuilds
 # tests/test_omega_tensor_store.c against the mutated copy and must FAIL it.
 # (Skipping the fsync before rename is not observable without power loss, so
-# it is not a mutant here.)
-STORE_MUTATIONS='TSTORE_HASH_VERIFY|s/memcmp(dig, sl->payload_sha, 32) != 0 || memcmp(vid, sl->value_id, 32) != 0/0/
-TSTORE_SHORT_RECORD|s/len != HDR_BYTES + count \* REC_BYTES/0/
-TSTORE_GEN_RESET|s/sl->gen = r->gen + 1;/sl->gen = 1;/
-TSTORE_RENAME_BEFORE_WRITE|s/const char \*wpath = tmp;/const char *wpath = final;/
-TSTORE_RECORD_SUM|s/memcmp(sum, in + REC_SUM, 32) != 0/0/
-TSTORE_HEADER_SUM|s/memcmp(sum, st->jbuf + HDR_SUM, 32) != 0/0/'
-STORE_SRCS="src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c"
-if ! gcc $FLAGS -Isrc -Isrc/tensor -o "$SCRATCH/sbase" tests/test_omega_tensor_store.c \
-    src/tensor/omega_tensor_store.c $STORE_SRCS $DEPS > "$SCRATCH/sbase.log" 2>&1 \
-    || ! "$SCRATCH/sbase" > "$SCRATCH/sbase.run" 2>&1; then
-    head -5 "$SCRATCH/sbase.log" "$SCRATCH/sbase.run" 2>/dev/null
+# it is not a mutant here.) Rows are name|expr, the file is implied.
+printf '%s\n' "$STORE_MUTATIONS" | sed 's#^\([A-Z0-9_]*\)|#\1|src/tensor/omega_tensor_store.c|#' > "$SCRATCH/store.rows"
+if ! run_block "$SCRATCH/store.rows" \
+    "gcc $FLAGS -Isrc -Isrc/tensor -o .tstore_t tests/test_omega_tensor_store.c src/tensor/omega_tensor_store.c $STORE_SRCS $DEPS" \
+    ./.tstore_t; then
     echo "MUTATION store baseline: unmutated store test does not pass"; fail=1
-else
-    IFS='
-'
-    for m in $STORE_MUTATIONS; do
-        IFS=$old_ifs
-        name=${m%%|*}
-        expr=${m#*|}
-        total=$((total + 1))
-        cp src/tensor/omega_tensor_store.c "$SCRATCH/store.c"
-        sed -i "/MUT:$name/ $expr" "$SCRATCH/store.c"
-        if cmp -s src/tensor/omega_tensor_store.c "$SCRATCH/store.c"; then
-            echo "MUTATION $name: NOT APPLIED (marker or pattern missing)"; fail=1; continue
-        fi
-        if ! gcc $FLAGS -Isrc -Isrc/tensor -o "$SCRATCH/st" tests/test_omega_tensor_store.c \
-            "$SCRATCH/store.c" $STORE_SRCS $DEPS > "$SCRATCH/sbuild.log" 2>&1; then
-            head -5 "$SCRATCH/sbuild.log"
-            echo "MUTATION $name: does not build (fix the sed expression)"; fail=1; continue
-        fi
-        if "$SCRATCH/st" > "$SCRATCH/srun.log" 2>&1; then
-            echo "MUTATION $name: NOT CAUGHT (tests still pass)"; fail=1
-        else
-            echo "MUTATION $name: caught ($(grep -c '^FAIL' "$SCRATCH/srun.log") failing checks)"
-        fi
-    done
-    IFS=$old_ifs
 fi
 
 if [ "$fail" -ne 0 ]; then echo "tensor mutation sweep: FAIL"; exit 1; fi