Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/one_layer/acceptance/selftest.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / one_layer / acceptance / selftest.sh` 463 lines ยท 38380 bytes Raw Blame History 1 #!/usr/bin/env bash 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 # tests/one_layer/acceptance/selftest.sh -- selftest of the stage-1 harness (and its v2 18 # extension, section 7: kind oscir, score-v2, the experiment task corpus, omega#445) on 19 # the PUBLIC sample corpus (sample/). It never touches the sealed corpus. Every check has a 20 # counterexample or a mutant of the harness that must make it fail; nothing prints PASS by itself. 21 # Env from mk/one-layer-acceptance.mk: CC, OLA_CFLAGS, OLA_RUNNER_SRCS (for the mutants). 22 set -euo pipefail 23 BIN="${1:?usage: selftest.sh }" 24 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25 ROOT="$(cd "$HERE/../../.." && pwd)" 26 cd "$ROOT" 27 CC="${CC:-cc}" 28 OLA_CFLAGS="${OLA_CFLAGS:--std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -Isrc -Isrc/compiler}" 29 T="$(mktemp -d "${TMPDIR:-/tmp}/ola-selftest.XXXXXXXX")" 30 DIRTY_MARK="$HERE/.selftest-dirty-probe" 31 trap 'rm -rf "$T" "$DIRTY_MARK"' EXIT 32 fails=0 33 ok() { echo "ok $*"; } 34 bad() { echo "FAIL $*"; fails=$((fails + 1)); } 35 S="$HERE/sample" 36 37 # ---- 0. the frozen contract is the one pinned in RULES ------------------------------------------- 38 pin="$(awk -F= '$1=="interface_sha256"{print $2}' "$HERE/RULES")" 39 if [ "$pin" = `a9e7e2aae27ff43d0e09e6dcd9173ad1f19776007c1a24496b102e830290de5e` ] && 40 [ "$(sha256sum "$HERE/HARNESS_INTERFACE.md" | cut -d' ' -f1)" = "$pin" ]; then ok "contract v1 hash pinned and matching" 41 else bad "contract hash"; fi 42 43 # ---- 0b. dependency inventory: every entry has a removal stage 2..7 (no permanent one) -------------- 44 inv_ok() { awk -F" [|] " '/^#/ || NF == 0 { next } { n++; if (NF != 4 || $3 !~ /^removal_stage=[2-7]$/) bad++ } END { exit (n >= 10 && !bad) ? 0 : 1 }' "$1"; } 45 cp "$ROOT/evidence/ONE-LAYER-1/INVENTORY.txt" "$T/inv"; echo "new libfoo | ola.c | removal_stage=never | permanent" >> "$T/inv" 46 if inv_ok "$ROOT/evidence/ONE-LAYER-1/INVENTORY.txt" && ! inv_ok "$T/inv"; then ok "inventory: $(grep -vc '^#' "$ROOT/evidence/ONE-LAYER-1/INVENTORY.txt") dependencies, each with a removal stage (an entry without one is caught)" 47 else bad "inventory"; fi 48 49 # ---- 1. sample OmegaProgram IR bytes are reproducible from the repo's own encoder ---------------- 50 $CC $OLA_CFLAGS -o "$T/mkopir" "$S/mkopir.c" $OLA_PROG_SRCS 51 "$T/mkopir" "$T/p8.opir" 8 add 200 > "$T/p8.id" 52 "$T/mkopir" "$T/p16.opir" 16 add 200 > /dev/null 53 head -c 100 "$T/p8.opir" > "$T/p8.trunc" 54 if cmp -s "$T/p8.opir" "$S/cases/s04/candidate.opir" && cmp -s "$T/p16.opir" "$S/cases/s11/candidate.opir" && 55 cmp -s "$T/p8.trunc" "$S/cases/s10/candidate.opir" && 56 grep -q "program_id $(sed 's/program_id=//' "$T/p8.id")" "$S/cases/s04/requirement"; then ok "sample .opir bytes and program_id reproducible" 57 else bad "sample .opir bytes drifted from mkopir"; fi 58 59 # ---- corpus builder: sample cases + generated oversize case s15 ------------------------------------ 60 # mkcorpus [hook]: dir/corpus.tar + dir/SEALED.sha256; hook runs inside dir before tar 61 mkcorpus() { 62 local d="$1" hook="${2:-}" 63 mkdir -p "$d/corpus" 64 cp -r "$S/cases" "$d/corpus/" 65 cp "$S/LABELS" "$d/corpus/LABELS" 66 mkdir -p "$d/corpus/cases/s15/hidden" 67 printf 'kind osc\nentry add\nparams u32 u32\nret u32\n' > "$d/corpus/cases/s15/requirement" 68 printf '1 2\n' > "$d/corpus/cases/s15/hidden/inputs"; printf '3\n' > "$d/corpus/cases/s15/hidden/expected" 69 { cat "$S/cases/s01/candidate.osc"; head -c `1048577` /dev/zero | tr '\0' '/'; echo; } > "$d/corpus/cases/s15/candidate.osc" 70 echo "s15 DEFECT oversize_candidate" >> "$d/corpus/LABELS" 71 if [ -n "$hook" ]; then (cd "$d" && eval "$hook"); fi 72 (cd "$d" && tar --format=ustar --sort=name --owner=0 --group=0 --numeric-owner --mtime=@0 ${TAROPT:-} -cf corpus.tar corpus && 73 sha256sum corpus.tar > SEALED.sha256) 74 } 75 { grep -v '^#' "$S/EXPECTED_VERDICTS"; echo "s15 REJECT oversize"; } > "$T/expected" 76 # verdicts_match : same cases, same verdict and reason as $T/expected 77 verdicts_match() { diff <(awk '{print $1, $2, $3}' "$1") "$T/expected" > "$T/vdiff" 2>&1; } 78 79 mkcorpus "$T/good" 80 81 # ---- 2. end to end: ola.sh score twice --------------------------------------------------------------- 82 E="$T/evid" 83 # run 2 carries OLA_PROBE_ONLY (a selftest knob for `ola probes`): ola.sh must clear it and run every probe 84 for i in 1 2; do 85 only=""; [ "$i" = 2 ] && only=read_key 86 OLA_PROBE_ONLY="$only" OLA_ALLOW_DIRTY=1 OLA_EVIDENCE_ROOT="$E" "$HERE/ola.sh" score "$T/good/corpus.tar" "$T/good/SEALED.sha256" > "$T/score$i.out" 2> "$T/score$i.err" || 87 { bad "ola.sh score run $i exited non-zero"; tail -5 "$T/score$i.err"; } 88 done 89 runs=( $(ls -d "$E"/runs/* | LC_ALL=C sort) ) 90 [ "${#runs[@]}" -eq 2 ] && ok "two run directories, none overwritten" || bad "expected 2 run dirs, got ${#runs[@]}" 91 R1="${runs[0]}"; R2="${runs[1]}" 92 if verdicts_match "$R1/verdicts.txt"; then ok "every sample case gets its expected verdict and reason (15 cases)" 93 else bad "sample verdicts"; cat "$T/vdiff"; fi 94 cmp -s "$R1/verdicts.txt" "$R1/replay/verdicts.txt" && cmp -s "$R1/verdicts.txt" "$R2/verdicts.txt" && 95 ok "verdicts identical across the in-run clean replay and a second run" || bad "replays differ" 96 nrec=0; recbad=0 97 while read -r id v r h; do 98 f="$E/receipts/$h"; nrec=$((nrec + 1)) 99 if [ ! -f "$f" ] || [ "$(sha256sum "$f" | cut -d' ' -f1)" != "$h" ] || ! grep -qx "case=$id" "$f" || 100 ! grep -qx "verdict=$v" "$f" || ! grep -qx "reason=$r" "$f" || grep -q "$T" "$f"; then recbad=$((recbad + 1)); fi 101 for k in schema commit harness_sha256 rules_sha256 corpus_sha256 case kind candidate_sha256 requirement_sha256 \ 102 inputs_sha256 expected_sha256 verdict reason detail; do grep -q "^$k=" "$f" || recbad=$((recbad + 1)); done 103 done < "$R1/verdicts.txt" 104 [ "$nrec" -eq 15 ] && [ "$recbad" -eq 0 ] && [ "$(ls "$E/receipts" | wc -l)" -eq 15 ] && 105 ok "15 receipts: content-addressed, all contract keys, no paths, replay reused identical bytes" || bad "receipts ($recbad problems)" 106 if [ "$(grep -c ' result=PASS$' "$R1/probes.log")" -eq 15 ] && grep -qx 'PROBES PASS count=15' "$R1/probes.log"; then 107 ok "15 isolation probes: each blocked in the sandbox, each control escaped, scratch positive control allowed" 108 else bad "probes"; cat "$R1/probes.log"; fi 109 if grep -qx 'PROBES PASS count=15' "$R2/probes.log" && grep -q "OLA_PROBE_ONLY is a selftest knob" "$T/score2.err"; then 110 ok "OLA_PROBE_ONLY set on a scoring run: cleared, all 15 probes still ran, the gate cannot pass" 111 else bad "OLA_PROBE_ONLY honoured on a scoring run"; tail -2 "$R2/probes.log"; fi 112 if [ ! -w "$R1/verdicts.txt" ] && [ ! -w "$R1/replay/verdicts.txt" ]; then 113 ok "verdicts.txt read-only after the passes; the write_evidence probe (and its control) aimed at a private copy" 114 else bad "verdicts.txt still writable after the run"; fi 115 printf 'defects_rejected=10/30 controls_accepted=4/10 errors=1\nlabelled_defects=11 labelled_controls=4 verdicts_matched=15 unlabelled_verdicts=0\nreplay_identical=yes probes=PASS clean_tree=no\nGATE FAIL\n' > "$T/score.want" 116 cmp -s "$R1/score.txt" "$T/score.want" && ok "score.txt: sample tally exact, gate FAIL (sample is not the 30/10 corpus; selftest tree flagged)" || 117 { bad "score.txt"; cat "$R1/score.txt"; } 118 119 # a dirty tree is refused (counterexample for the clean-tree rule) 120 touch "$DIRTY_MARK" 121 if OLA_EVIDENCE_ROOT="$T/evid-dirty" "$HERE/ola.sh" score "$T/good/corpus.tar" "$T/good/SEALED.sha256" > /dev/null 2> "$T/dirty.err"; then 122 bad "dirty tree accepted"; else grep -q "refusing a dirty git tree" "$T/dirty.err" && ok "dirty tree refused" || bad "dirty refusal reason"; fi 123 rm -f "$DIRTY_MARK" 124 # not sealed yet 125 if "$HERE/ola.sh" score "$T/good/corpus.tar" "$T/nonexistent.sha256" > /dev/null 2> "$T/unsealed.err"; then bad "unsealed corpus scored" 126 else grep -q "not sealed yet" "$T/unsealed.err" && ok "missing SEALED.sha256 refused" || bad "unsealed refusal reason"; fi 127 128 # ---- 3. hostile corpora are refused whole, nothing extracted --------------------------------------- 129 refused() { # refused