aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-replay / mutations / run_mutants.sh
| 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 | # Prove the KV ownership checks catch realistic faults. |
| 18 | # |
| 19 | # usage: run_mutants.sh native apply each kv.mutants line, run the proptest, |
| 20 | # expect a FAILED test (KILLED) |
| 21 | # run_mutants.sh miri apply each miri.mutants line, expect native |
| 22 | # tests to still pass and `cargo miri test` to fail |
| 23 | # run_mutants.sh trn1 switch off each TRN1 check (trn1.mutants), expect |
| 24 | # the shared corpus test to fail; needs TRN1_VECTORS |
| 25 | # or the sibling ../aien-protocols checkout |
| 26 | # |
| 27 | # Works on a scratch copy; the real tree is never modified. Exit 0 only if |
| 28 | # every mutant is KILLED. A mutant that does not compile counts as BROKEN |
| 29 | # (a bad mutant, not a kill) and fails the run. |
| 30 | set -eu |
| 31 | |
| 32 | mode=${1:-native} |
| 33 | here=$(cd "$(dirname "$0")" && pwd) |
| 34 | root=$(cd "$here/../../.." && pwd) |
| 35 | case "$mode" in |
| 36 | native) table="$here/kv.mutants" ;; |
| 37 | miri) table="$here/miri.mutants" ;; |
| 38 | trn1) table="$here/trn1.mutants" ;; |
| 39 | *) echo "usage: $0 native|miri|trn1" >&2; exit 2 ;; |
| 40 | esac |
| 41 | |
| 42 | work=$(mktemp -d) |
| 43 | trap 'rm -rf "$work"' EXIT INT TERM |
| 44 | mkdir -p "$work/crates" |
| 45 | for c in aien-kv-cache aien-platform aien-platform-linux aien-replay; do |
| 46 | mkdir -p "$work/crates/$c" |
| 47 | (cd "$root/crates/$c" && tar cf - --exclude=./target .) | (cd "$work/crates/$c" && tar xf -) |
| 48 | done |
| 49 | # Minimal workspace root: same [workspace.package] values, only the three |
| 50 | # crates the test needs, so the copy builds without the aien-protocols sibling. |
| 51 | awk '/^members = \[/ { print "members = [\"crates/aien-kv-cache\", \"crates/aien-platform\", \"crates/aien-platform-linux\"]"; skip = 1; next } |
| 52 | skip && /^\]/ { skip = 0; next } |
| 53 | !skip { print }' "$root/Cargo.toml" >"$work/Cargo.toml" |
| 54 | |
| 55 | src="$work/crates/aien-kv-cache/src/lib.rs" |
| 56 | test=kv_ownership_props |
| 57 | if [ "$mode" = trn1 ]; then |
| 58 | src="$work/crates/aien-replay/src/lib.rs" |
| 59 | test=trn1_conformance |
| 60 | vectors=$(cd "${TRN1_VECTORS:-$root/../aien-protocols/specs/execution-transcript/vectors}" && pwd) |
| 61 | export TRN1_VECTORS="$vectors" TRN1_REQUIRE=1 |
| 62 | fi |
| 63 | cp "$src" "$work/lib.rs.orig" |
| 64 | manifest="$work/crates/aien-replay/Cargo.toml" |
| 65 | export CARGO_TARGET_DIR="${MUTANT_TARGET_DIR:-$work/target}" |
| 66 | cargo=${CARGO:-cargo} |
| 67 | |
| 68 | run_native() { $cargo test --offline --manifest-path "$manifest" --test "$test" >"$1" 2>&1; } |
| 69 | run_miri() { $cargo +nightly miri test --manifest-path "$manifest" --test "$test" >"$1" 2>&1; } |
| 70 | |
| 71 | fail=0 |
| 72 | killed=0 |
| 73 | total=0 |
| 74 | tab=$(printf '\t') |
| 75 | while IFS="$tab" read -r id expr what; do |
| 76 | case "$id" in '' | '#'*) continue ;; esac |
| 77 | total=$((total + 1)) |
| 78 | cp "$work/lib.rs.orig" "$src" |
| 79 | sed -i "$expr" "$src" |
| 80 | if cmp -s "$src" "$work/lib.rs.orig"; then |
| 81 | echo "BROKEN $id: sed expression matched nothing" |
| 82 | fail=1 |
| 83 | continue |
| 84 | fi |
| 85 | log="$work/$id.log" |
| 86 | if [ "$mode" != miri ]; then |
| 87 | if run_native "$log"; then |
| 88 | echo "SURVIVED $id ($what)" |
| 89 | fail=1 |
| 90 | elif grep -q "test result: FAILED" "$log"; then |
| 91 | echo "KILLED $id ($what)" |
| 92 | killed=$((killed + 1)) |
| 93 | else |
| 94 | echo "BROKEN $id: did not compile" |
| 95 | tail -n 20 "$log" |
| 96 | fail=1 |
| 97 | fi |
| 98 | else |
| 99 | if ! run_native "$log.native"; then |
| 100 | echo "NOTE $id: native tests also fail, so this is not a Miri-only catch" |
| 101 | fi |
| 102 | if run_miri "$log"; then |
| 103 | echo "SURVIVED $id under Miri ($what)" |
| 104 | fail=1 |
| 105 | elif grep -q "Undefined Behavior" "$log"; then |
| 106 | echo "KILLED $id under Miri ($what)" |
| 107 | killed=$((killed + 1)) |
| 108 | else |
| 109 | echo "BROKEN $id: Miri run failed without reporting UB" |
| 110 | tail -n 20 "$log" |
| 111 | fail=1 |
| 112 | fi |
| 113 | fi |
| 114 | done <"$table" |
| 115 | |
| 116 | echo "mode=$mode killed=$killed total=$total" |
| 117 | exit "$fail" |