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

branch main Branches Tags History

omega-mv / tools / m20_receipt_mutations.sh

83 lines · 4299 bytes Raw Blame History
1#!/bin/sh
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# M20 receipt writer mutation sweep (sibling of tools/tensor_mutations.sh,
18# which calls it). For each rule marked MUT:<name> at the end of a line in
19# tools/m20_receipt.sh, copy the writer to a scratch directory, break that one
20# rule, run tests/test_m20_receipt.sh against the copy and require it to FAIL.
21# A mutation that does not apply, or that the tests do not catch, fails the
22# sweep. Host only, no device. Shell only (no Python).
23#
24# Thin adapter over tools/mutation_runner.sh (marker reader). The rows below
25# are the mutant set; the runner copies the tree, applies each edit and runs
26# the test. The sed address stays /MUT:<name>$/ (end of line): the runner adds
27# its own unanchored /MUT:<name>/ address, and each row nests the anchored one
28# inside a { } block so only the line ENDING in the marker is edited. This
29# script maps the runner's per-mutant stderr lines back to the legacy stdout
30# lines and keeps the legacy exit codes.
31set -u
32cd "$(dirname "$0")/.." || exit 2
33SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/m20-receipt-mut.XXXXXX") || exit 2
34trap 'rm -rf "$SCRATCH"' EXIT INT TERM
35
36# Rows: name|file|sed expression (anchored to the end-of-line marker).
37cat > "$SCRATCH/rows" <<'ROWS'
38DIRTY_REFUSED|tools/m20_receipt.sh|{/MUT:DIRTY_REFUSED$/ s/|| refuse/|| :/}
39EVID_OUTSIDE|tools/m20_receipt.sh|{/MUT:EVID_OUTSIDE$/ s/) refuse/) :/}
40UNKNOWN_LABEL|tools/m20_receipt.sh|{/MUT:UNKNOWN_LABEL$/ s/refuse "row/: "row/}
41NOTRUN_FORCES_NQ|tools/m20_receipt.sh|{/MUT:NOTRUN_FORCES_NQ$/ s/add_nq/:/}
42GB10_NEEDS_EVIDENCE|tools/m20_receipt.sh|{/MUT:GB10_NEEDS_EVIDENCE$/ s/|| refuse/|| :/}
43GB10_HASH_MATCH|tools/m20_receipt.sh|{/MUT:GB10_HASH_MATCH$/ s/|| refuse/|| :/}
44HOST_LOG_PASS|tools/m20_receipt.sh|{/MUT:HOST_LOG_PASS$/ s/|| refuse/|| :/}
45GB10_PARITY_REQUIRED|tools/m20_receipt.sh|{/MUT:GB10_PARITY_REQUIRED$/ s/|| add_nq/|| :/}
46CLEAN_AFTER|tools/m20_receipt.sh|{/MUT:CLEAN_AFTER$/ s/|| add_nq/|| :/}
47COMMIT_UNCHANGED|tools/m20_receipt.sh|{/MUT:COMMIT_UNCHANGED$/ s/|| add_nq/|| :/}
48NO_OVERWRITE|tools/m20_receipt.sh|{/MUT:NO_OVERWRITE$/ s/set -o noclobber; //}
49ROWS
50
51# Baseline: the unmutated writer must pass, otherwise every mutant would
52# look "caught".
53if ! tests/test_m20_receipt.sh > "$SCRATCH/base.log" 2>&1; then
54 grep '^FAIL' "$SCRATCH/base.log" | head -5
55 echo "m20 receipt mutation sweep: FAIL (unmutated baseline does not pass)"; exit 1
56fi
57
58# The test command runs inside the runner's scratch tree and points the test
59# at that tree's (mutated) writer through M20_RECEIPT_WRITER.
60tools/mutation_runner.sh -k marker -m "$SCRATCH/rows" \
61 -t 'M20_RECEIPT_WRITER=$PWD/tools/m20_receipt.sh tests/test_m20_receipt.sh' \
62 -c "tools/m20_receipt.sh tests/test_m20_receipt.sh tests/fixtures" \
63 -f FAIL -o "$SCRATCH/out.json" > "$SCRATCH/runner.out" 2> "$SCRATCH/runner.err"
64rrc=$?
65
66fail=0
67total=0
68while IFS= read -r line; do
69 name=${line%% *}; rest=${line#* }; status=${rest%% *}
70 total=$((total + 1))
71 case $status in
72 KILLED)
73 n=$(echo "$line" | sed -n 's/.*(\([0-9][0-9]*\) failing case(s).*/\1/p'); : "${n:=0}"
74 echo "MUTATION $name: caught ($n failing checks)" ;;
75 ERROR) echo "MUTATION $name: NOT APPLIED (marker or pattern missing)"; fail=1 ;;
76 *) echo "MUTATION $name: NOT CAUGHT (tests still pass)"; fail=1 ;;
77 esac
78done < "$SCRATCH/runner.err"
79# Runner usage error or a row it never reported must not pass silently.
80[ "$total" -eq "$(grep -c '|' "$SCRATCH/rows")" ] || fail=1
81[ "$rrc" -eq 0 ] || fail=1
82if [ "$fail" -ne 0 ]; then echo "m20 receipt mutation sweep: FAIL"; exit 1; fi
83echo "m20 receipt mutation sweep: PASS ($total of $total mutations caught)"