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 / c4_requal_mutants.sh

76 lines · 7265 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# C4 mutant check: each mutant weakens one recovery check in a COPY of the
18# runtime, rebuilds the C4 harness against it and runs it. A mutant is KILLED
19# when the harness fails (exit nonzero, FAIL cases listed), SURVIVED when it
20# still passes (a recovery check no test bites on), ERROR when it did not build
21# or the edit did not apply. Exit 0 only if every mutant is KILLED.
22# usage: tools/c4_requal_mutants.sh [out.json]
23# Extra make args via MAKE_ARGS (e.g. AIENOS_LOCK_REPO=...).
24# Thin adapter over tools/mutation_runner.sh (one mutation runner). This file
25# holds only the mutant rows (data) and the C4 build and test commands; the
26# runner copies the tree, applies each edit, runs them and writes the receipt.
27set -u
28root=$(git rev-parse --show-toplevel)
29out=${1:-"$root/build/c4_mutants.json"}
30# The authority cache for the FULL aienos.lock commit, proven to hold that commit's
31# native/capability (tools/aienos_lock_source.sh); never "the first directory found".
32lock=$(head -n 1 "$root/aienos.lock")
33auth="$root/build/aienos-authority/$lock"
34[ -d "$auth" ] || { echo "run 'make test-c4-requal' first (builds the authority library for $lock)" >&2; exit 2; }
35AIENOS_R7_DIR= bash "$root/tools/aienos_lock_source.sh" verify-dir "$auth" native/capability || {
36 echo "build/aienos-authority/$lock is not the aienos.lock source; delete it and rebuild" >&2; exit 2; }
37phys=${PHYSICS_DIR:-$(cd "$root/../physics" && pwd)}
38
39# M03 retired: cx_open is the single integrity seam; rx_compose no longer re-walks the chain.
40# id~file~sed expression~what the original check does[~class~rationale]
41# class is redundant or gap for a known-equivalent or untested-check mutant, with the
42# rationale in the last column; rows with four columns have no justification.
43MUTANTS='
44M01~src/runtime/rx_compose.c~s/ || !aien_mid_equal(&stored, self))/ || 0)/~machine identity must match the stored one
45M02~src/runtime/rx_compose.c~s/n_units > 1) return RX_ERR_REPLAY;/n_units > 100000) return RX_ERR_REPLAY;/~refuse durable history when the Cortex journal has no state record
46M04~src/runtime/rx_compose.c~s/js_branch_info(&c->js, r, &bi) == JS_OK \&\& !bi.staged/js_branch_info(\&c->js, r, \&bi) == JS_OK/~recovered state branch must be sealed, not staged~redundant~no injection can leave a staged branch in the durable checkpoint (staged branches are never persisted, rx_compose.h recovery note), candidate equivalent mutant, UNVERIFIED
47M05~src/runtime/rx_compose.c~s/if (!o || o->id <= chosen) continue;/continue;/~answer newer, non-durable state records with a rollback admission
48M06~src/runtime/rx_compose.c~s/for (uint32_t i = l->n; i-- > 0;) {/for (uint32_t i = 0; i < l->n; i++) {/~choose the NEWEST durable state record
49M07~src/runtime/rx_compose.c~s/if (n < 0) return RX_ERR_REPLAY;/(void)n;/~an interrupted composition record that cannot be completed refuses~gap~no injection leaves a composition record that cannot be completed
50M08~src/runtime/rx_compose.c~s/int n = compose_records(c, S, V, NULL, 0, \&tmp);/int n = 0; (void)S; (void)V; (void)tmp;/~complete every interrupted composition record at open
51M09~src/runtime/rx_cortex.c~s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (CX_R_FIXED + n), 32) != 0) {/if (0) {/~each journal record digest is checked at load
52M10~src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint body digest~redundant~header digest, body digest and the restore-time content check overlap; each alone is covered by the others and by structural validation
53M11~src/runtime/rx_jspace.c~s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint header digest~redundant~header digest, body digest and the restore-time content check overlap; each alone is covered by the others and by structural validation
54M12~src/runtime/rx_compose.c~s/if (commit_js(c) != JS_OK) return RX_ERR_REPLAY;/;/~recovered state is made durable before the World starts
55M13~src/runtime/rx_cortex.c,src/runtime/rx_cortex.c~s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (CX_R_FIXED + n), 32) != 0) {/if (0) {/@@s/return memcmp(chain, s->chain, 32) == 0 ? CX_OK : CX_ERR_DIGEST;/return CX_OK;/~Cortex integrity (open-time record digest and the audit chain compare both removed)
56M14~src/runtime/rx_jspace.c,src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint integrity (header and body digests both removed)~gap~with every J-Space integrity digest removed all 820 single-byte flips of the task checkpoint are still refused structurally or benign, so the digests are not shown to bite
57M15~src/runtime/rx_jspace.c,src/runtime/rx_jspace.c,src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(chk, r->content, 32)) { s->stats.corrupt_restores++; return JS_ERR_CORRUPT; }/;/~J-Space integrity, all three layers (header digest, body digest, restore-time content check) removed~gap~with every J-Space integrity digest removed all 820 single-byte flips of the task checkpoint are still refused structurally or benign, so the digests are not shown to bite
58M16~src/runtime/rx_compose.c~s/if (pp \&\& state_ref_promoted(s, pp\[CX_WREC_FIELD0 + RXC_S_REF\])) return RX_ERR_REPLAY;/(void)pp; (void)state_ref_promoted;/~refuse a J-Space checkpoint that lost a state Cortex already promoted
59M17~src/runtime/rx_compose.c~s/if (c->cx.n < cnt || (cnt > 0 && (!head || memcmp(head->digest, an + 8, 32) != 0))) {/(void)head; if (0) {/~refuse a Cortex journal cut behind the checkpoint anchor
60'
61# Same copy list as before: the source dirs plus the one authority library.
62copy="src tests tools Makefile mk aienos.lock physics.lock build/aienos-authority/$lock build/aienos-cap/$lock"
63lockrepo=$(AIENOS_R7_DIR= bash "$root/tools/aienos_lock_source.sh" identity | sed -n 's/.*"repo": "\([^"]*\)".*/\1/p')
64build="nice -n 10 make PHYSICS_DIR=\"$phys\" AIENOS_LOCK_REPO=\"$lockrepo\" ${MAKE_ARGS:-} c4-requal-bin"
65test_cmd='./build/rx_c4_requal "$PWD/r.json"'
66
67# The runner prints the per-mutant lines on stderr as before. -e keeps the old
68# note for a build that failed with an empty make log. It FAILS an empty
69# sweep (ONLY matching nothing); the legacy script exited 0 then, so map it back.
70res=$(printf '%s\n' "$MUTANTS" | "$root/tools/mutation_runner.sh" -k table -m - -t "$test_cmd" \
71 -d "$root" -b "$build" -e "empty make log (make killed or never started)" \
72 -c "$copy" -o "$out" -f FAIL)
73rc=$?
74printf '%s\n' "$res"
75case $res in "mutants: 0 total,"*) rc=0;; esac
76exit $rc