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
omega-mv / tests / one_layer / acceptance / ola.sh
| 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/ola.sh -- one-layer hostile acceptance harness (stage 1 omega#443, stage 2 omega#445). |
| 18 | # Contracts: HARNESS_INTERFACE.md (v1) and HARNESS_INTERFACE_V2.md (v2) next to this file; their sha256 |
| 19 | # are pinned in RULES and checked here. |
| 20 | # |
| 21 | # ola.sh score <corpus.tar> <SEALED.sha256> v1, unchanged (evidence/ONE-LAYER-1) |
| 22 | # ola.sh score-v2 <corpus.tar> <SEALED.sha256> v2 corpus with kind oscir (evidence/ONE-LAYER-2) |
| 23 | # ola.sh tasks-public <tasks.tar> <TASKS.sha256> <outdir> only requirement + prompt of every task |
| 24 | # ola.sh experiment <tasks.tar> <TASKS.sha256> <candidates_dir> score candidate sets, no LABELS, RUN VALID|INVALID |
| 25 | # ola.sh tasks-check <tasks.tar> <TASKS.sha256> experiment with no sets: references only |
| 26 | # |
| 27 | # Refuses a dirty git tree. Writes evidence/ONE-LAYER-<1|2>/runs/<run_id>/ (never overwritten) with |
| 28 | # verdicts.txt, probes.log, score.txt (+ replay/verdicts.txt, meta.txt) and content-addressed receipts |
| 29 | # under evidence/ONE-LAYER-<1|2>/receipts/. Steps: |
| 30 | # 1 clean tree, contract hash, build ola + ola_runner from this commit |
| 31 | # 2 ola untar: sealed hash check, member validation, extract WITHOUT corpus/LABELS (private dir) |
| 32 | # 3 pass A: every case run in the sandbox (ola_runner), verdict + receipt |
| 33 | # 4 pass B: a second clean extraction and execution; verdicts must be byte-identical |
| 34 | # 5 LABELS extracted only now; isolation probes (each blocked AND logged, each with a control; |
| 35 | # the evidence probe aims at a private copy of verdicts.txt, the real one is made read-only) |
| 36 | # 6 rules and harness re-hashed (unchanged), tally -> score.txt (GATE PASS|FAIL) |
| 37 | # experiment (V2 section 3.3) follows the same steps with sets/<set_id>/ instead of one verdicts.txt, |
| 38 | # the task references as set `references`, the read_labels probe aimed at a hidden/reference.osc, and |
| 39 | # score.txt ending RUN VALID|INVALID. |
| 40 | # Untracked output allowed by the clean-tree check: evidence/ONE-LAYER-1/(runs|receipts)/ and |
| 41 | # evidence/ONE-LAYER-2/(runs|receipts|generations)/ (generations = the exp445 driver's request logs). |
| 42 | # Selftest-only knobs (each forces GATE FAIL / RUN INVALID): OLA_ALLOW_DIRTY=1, OLA_EVIDENCE_ROOT=<dir>. |
| 43 | # OLA_PROBE_ONLY (a probe subset for `ola probes`) is cleared here and also forces GATE FAIL; tally |
| 44 | # independently requires every probe in probes.log. The sandbox is aarch64-only: other machines are refused. |
| 45 | set -euo pipefail |
| 46 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 47 | ROOT="$(cd "$HERE/../../.." && pwd)" |
| 48 | cd "$ROOT" |
| 49 | |
| 50 | die() { echo "ola.sh: $*" >&2; exit 2; } |
| 51 | kv() { awk -F= -v k="$1" '$1 == k { print substr($0, length(k) + 2); exit }' "$HERE/RULES"; } |
| 52 | sha() { sha256sum "$1" | awk '{print $1}'; } |
| 53 | |
| 54 | # harness identity: every tracked file of the harness and its make fragment, in name order |
| 55 | harness_sha() { |
| 56 | { git ls-files -z -- tests/one_layer/acceptance mk/one-layer-acceptance.mk | sort -z | xargs -0 sha256sum; } | sha256sum | awk '{print $1}' |
| 57 | } |
| 58 | |
| 59 | # common start of every scoring command: sets clean, commit, rules_sha, harness, bin, evid ($1 = 1|2) |
| 60 | prepare() { |
| 61 | [ "$(uname -m)" = aarch64 ] || die "the sandbox (seccomp allow-list) is aarch64-only; refusing to score on $(uname -m)" |
| 62 | # 1. clean tree: no change to tracked files, nothing untracked except earlier harness output |
| 63 | clean=1 |
| 64 | local dirty |
| 65 | dirty="$(git status --porcelain=v1 --untracked-files=all | |
| 66 | grep -Ev '^\?\? evidence/(ONE-LAYER-1/(runs|receipts)|ONE-LAYER-2/(runs|receipts|generations))/' || true)" |
| 67 | if [ -n "$dirty" ]; then |
| 68 | if [ "${OLA_ALLOW_DIRTY:-0}" = 1 ]; then clean=0; echo "ola.sh: DIRTY tree allowed for a selftest: the gate cannot pass" >&2 |
| 69 | else echo "$dirty" | head -20 >&2; die "refusing a dirty git tree (commit or stash first)"; fi |
| 70 | fi |
| 71 | evid="$ROOT/evidence/ONE-LAYER-$1" |
| 72 | if [ -n "${OLA_EVIDENCE_ROOT:-}" ]; then evid="$OLA_EVIDENCE_ROOT"; clean=0; fi |
| 73 | if [ -n "${OLA_PROBE_ONLY:-}" ]; then |
| 74 | echo "ola.sh: OLA_PROBE_ONLY is a selftest knob: cleared, every probe runs, the gate cannot pass" >&2 |
| 75 | clean=0 |
| 76 | fi |
| 77 | unset OLA_PROBE_ONLY |
| 78 | [ "$(sha "$HERE/HARNESS_INTERFACE.md")" = "$(kv interface_sha256)" ] || die "HARNESS_INTERFACE.md does not match the pinned v1 hash" |
| 79 | if [ "$1" = 2 ]; then |
| 80 | [ "$(sha "$HERE/HARNESS_INTERFACE_V2.md")" = "$(kv interface_v2_sha256)" ] || die "HARNESS_INTERFACE_V2.md does not match the pinned v2 hash" |
| 81 | fi |
| 82 | commit="$(git rev-parse HEAD)" |
| 83 | [ "$clean" = 1 ] || commit="$commit-dirty" |
| 84 | make -s PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 one-layer-acceptance-tools >&2 |
| 85 | bin="$ROOT/${OUT_DIR:-build}/one_layer" # mk/one-layer-acceptance.mk: OLA_DIR = $(OUT_DIR)/one_layer |
| 86 | rules_sha="$(sha "$HERE/RULES")" |
| 87 | harness="$(harness_sha)" |
| 88 | # 2. private directory (never inside the repo, never visible to a candidate) |
| 89 | priv="$(mktemp -d "${TMPDIR:-/tmp}/ola-priv.XXXXXXXX")" # global: the EXIT trap removes it |
| 90 | chmod 700 "$priv" |
| 91 | trap 'rm -rf "${priv:-}"' EXIT |
| 92 | mkdir "$priv/A" "$priv/B" "$priv/scratch" "$priv/keys" "$priv/outside" |
| 93 | head -c 32 /dev/urandom > "$priv/keys/decoy.key" # a key-shaped secret the probes try to read |
| 94 | } |
| 95 | |
| 96 | write_meta() { # write_meta <corpus_sha> <run dir> |
| 97 | { |
| 98 | echo "commit=$commit"; echo "harness_sha256=$harness"; echo "rules_sha256=$rules_sha" |
| 99 | echo "corpus_sha256=$1"; echo "time_ms=$(kv time_ms)"; echo "mem_mb=$(kv mem_mb)" |
| 100 | } > "$priv/meta" |
| 101 | cp "$priv/meta" "$2/meta.txt" |
| 102 | } |
| 103 | |
| 104 | new_run() { # new_run <corpus_sha> -> sets run, run_id |
| 105 | run_id="$(date -u +%Y%m%dT%H%M%SZ)-${1:0:12}-$$" |
| 106 | mkdir -p "$evid/runs" "$evid/receipts" |
| 107 | run="$evid/runs/$run_id" |
| 108 | mkdir "$run" || die "run directory $run exists: never overwritten" |
| 109 | } |
| 110 | |
| 111 | probes() { # probes <dir holding hidden/inputs + hidden/expected> <labels target> <tar> <evidence copy> |
| 112 | echo "isolation probes:" >&2 |
| 113 | "$bin/ola" probes "$bin/ola_runner" "$priv/scratch" "$run/probes.log" "$(kv time_ms)" "$(kv mem_mb)" \ |
| 114 | hidden_inputs="$1/hidden/inputs" expected="$1/hidden/expected" \ |
| 115 | labels="$2" tar="$3" key="$priv/keys/decoy.key" evidence="$4" \ |
| 116 | scorer="$HERE/ola.sh" rules="$HERE/RULES" outside="$priv/outside/escape" || |
| 117 | echo "ola.sh: isolation probes did not all pass" >&2 |
| 118 | } |
| 119 | |
| 120 | unchanged() { # step 6: nothing the candidates could reach changed the rules or the harness |
| 121 | [ "$(sha "$HERE/RULES")" = "$rules_sha" ] || { echo "ola.sh: RULES changed during the run" >&2; clean=0; } |
| 122 | [ "$(harness_sha)" = "$harness" ] || { echo "ola.sh: harness changed during the run" >&2; clean=0; } |
| 123 | } |
| 124 | |
| 125 | score() { # score <1|2> <corpus.tar> <SEALED.sha256> |
| 126 | local V="$1"; shift |
| 127 | local cmd=score; [ "$V" = 2 ] && cmd=score-v2 |
| 128 | [ $# -eq 2 ] || die "usage: ola.sh $cmd <corpus.tar> <SEALED.sha256>" |
| 129 | local tar sealed; tar="$(realpath -e "$1")" || die "no corpus tarball $1" |
| 130 | sealed="$(realpath -m "$2")" |
| 131 | [ -f "$sealed" ] || die "$sealed does not exist: the corpus is not sealed yet; nothing scored" |
| 132 | local sfx="" pass=pass tally=tally |
| 133 | [ "$V" = 2 ] && { sfx=2; pass=pass2; tally=tally2; } |
| 134 | prepare "$V" |
| 135 | local corpus_sha |
| 136 | corpus_sha="$("$bin/ola" untar "$tar" "$sealed" "$priv/A" "cases$sfx" | sed -n 's/^corpus_sha256=//p')" |
| 137 | [ ${#corpus_sha} -eq 64 ] || die "untar gave no corpus hash" |
| 138 | new_run "$corpus_sha" |
| 139 | mkdir "$run/replay" |
| 140 | write_meta "$corpus_sha" "$run" |
| 141 | echo "ola.sh: run $run_id corpus $corpus_sha" >&2 |
| 142 | |
| 143 | # 3. pass A |
| 144 | echo "pass A:" >&2 |
| 145 | "$bin/ola" "$pass" "$priv/A/corpus" "$run/verdicts.txt" "$evid/receipts" "$priv/scratch" "$bin/ola_runner" "$priv/meta" |
| 146 | # 4. pass B from a fresh extraction |
| 147 | echo "pass B (clean replay):" >&2 |
| 148 | "$bin/ola" untar "$tar" "$sealed" "$priv/B" "cases$sfx" >/dev/null |
| 149 | "$bin/ola" "$pass" "$priv/B/corpus" "$run/replay/verdicts.txt" "$evid/receipts" "$priv/scratch" "$bin/ola_runner" "$priv/meta" |
| 150 | local replay=0 |
| 151 | "$bin/ola" cmp "$run/verdicts.txt" "$run/replay/verdicts.txt" && replay=1 |
| 152 | chmod a-w "$run/verdicts.txt" "$run/replay/verdicts.txt" # written once; the probes aim at a copy |
| 153 | local verdicts_sha; verdicts_sha="$(sha "$run/verdicts.txt")" |
| 154 | mkdir "$priv/evidence" && cp "$run/verdicts.txt" "$priv/evidence/verdicts.txt" && chmod u+w "$priv/evidence/verdicts.txt" |
| 155 | |
| 156 | # 5. LABELS only now; then the isolation probes against the real private files |
| 157 | "$bin/ola" untar "$tar" "$sealed" "$priv/A" "labels$sfx" >/dev/null |
| 158 | local first; first="$(ls "$priv/A/corpus/cases" | LC_ALL=C sort | head -n 1)" |
| 159 | probes "$priv/A/corpus/cases/$first" "$priv/A/corpus/LABELS" "$tar" "$priv/evidence/verdicts.txt" |
| 160 | |
| 161 | # 6. nothing the candidates could reach changed the rules or the harness |
| 162 | unchanged |
| 163 | [ "$(sha "$run/verdicts.txt")" = "$verdicts_sha" ] || { echo "ola.sh: verdicts.txt changed during the probes" >&2; clean=0; } |
| 164 | if [ "$V" = 2 ]; then |
| 165 | "$bin/ola" tally2 "$run/verdicts.txt" "$priv/A/corpus/LABELS" "$replay" "$run/probes.log" "$clean" "$priv/A/corpus" > "$run/score.txt" |
| 166 | else |
| 167 | "$bin/ola" tally "$run/verdicts.txt" "$priv/A/corpus/LABELS" "$replay" "$run/probes.log" "$clean" > "$run/score.txt" |
| 168 | fi |
| 169 | cat "$run/score.txt" |
| 170 | echo "ola.sh: evidence in ${run#"$ROOT"/}" >&2 |
| 171 | } |
| 172 | |
| 173 | tasks_public() { |
| 174 | [ $# -eq 3 ] || die "usage: ola.sh tasks-public <tasks.tar> <TASKS.sha256> <outdir>" |
| 175 | local tar sealed out; tar="$(realpath -e "$1")" || die "no task tarball $1" |
| 176 | sealed="$(realpath -m "$2")" |
| 177 | [ -f "$sealed" ] || die "$sealed does not exist: the tasks are not sealed yet" |
| 178 | [ "$(sha "$HERE/HARNESS_INTERFACE_V2.md")" = "$(kv interface_v2_sha256)" ] || die "HARNESS_INTERFACE_V2.md does not match the pinned v2 hash" |
| 179 | mkdir -p "$3"; out="$(realpath -e "$3")" |
| 180 | [ -z "$(ls -A "$out")" ] || die "$out is not empty" |
| 181 | make -s PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 one-layer-acceptance-tools >&2 |
| 182 | "$ROOT/${OUT_DIR:-build}/one_layer/ola" untar "$tar" "$sealed" "$out" public |
| 183 | } |
| 184 | |
| 185 | # check_sets <candidates_dir> <tasks/cases dir>: the whole run is refused unless every path is |
| 186 | # <set_id>/, <set_id>/<task_id>/ or <set_id>/<task_id>/candidate.osc|candidate.oscir (regular files and |
| 187 | # directories only, known task ids, at most one candidate per task). ola xpass checks it again. |
| 188 | check_sets() { |
| 189 | local c="$1" cases="$2" p rel set task n |
| 190 | while IFS= read -r -d '' p; do |
| 191 | rel="${p#"$c"/}" |
| 192 | if [ -L "$p" ] || { [ ! -f "$p" ] && [ ! -d "$p" ]; }; then die "refused: $rel is not a regular file or directory"; fi |
| 193 | IFS=/ read -r set task n <<< "$rel" |
| 194 | [[ "$set" =~ ^[a-z0-9_-]{1,40}$ ]] && [ "$set" != references ] || die "refused: set id '$set'" |
| 195 | [ -n "${task:-}" ] || { [ -d "$p" ] || die "refused: $rel is not a set directory"; continue; } |
| 196 | [ -d "$cases/$task" ] || die "refused: $rel: '$task' is not a task of the corpus" |
| 197 | if [ -z "${n:-}" ]; then |
| 198 | [ -d "$p" ] || die "refused: $rel is not a task directory" |
| 199 | [ "$(find "$p" -mindepth 1 | wc -l)" -le 1 ] || die "refused: $rel has more than one entry" |
| 200 | else |
| 201 | [ -f "$p" ] && { [ "$n" = candidate.osc ] || [ "$n" = candidate.oscir ]; } || die "refused: $rel is not a candidate file" |
| 202 | fi |
| 203 | done < <(find "$c" -mindepth 1 -print0) |
| 204 | } |
| 205 | |
| 206 | # experiment <tasks.tar> <TASKS.sha256> <candidates_dir|-> (- = tasks-check: references only) |
| 207 | experiment() { |
| 208 | local tar sealed cands=""; tar="$(realpath -e "$1")" || die "no task tarball $1" |
| 209 | sealed="$(realpath -m "$2")" |
| 210 | [ -f "$sealed" ] || die "$sealed does not exist: the tasks are not sealed yet; nothing scored" |
| 211 | if [ "$3" != - ]; then cands="$(realpath -e "$3")" || die "no candidates dir $3"; [ -d "$cands" ] || die "$3 is not a directory"; fi |
| 212 | prepare 2 |
| 213 | local corpus_sha |
| 214 | corpus_sha="$("$bin/ola" untar "$tar" "$sealed" "$priv/A" tasks | sed -n 's/^corpus_sha256=//p')" |
| 215 | [ ${#corpus_sha} -eq 64 ] || die "untar gave no task corpus hash" |
| 216 | # frozen private copy of the candidates, checked before anything is written |
| 217 | mkdir "$priv/sets" |
| 218 | if [ -n "$cands" ]; then |
| 219 | check_sets "$cands" "$priv/A/tasks/cases" |
| 220 | cp -R --no-dereference "$cands/." "$priv/sets/" |
| 221 | check_sets "$priv/sets" "$priv/A/tasks/cases" |
| 222 | fi |
| 223 | local sets=(); local s |
| 224 | while IFS= read -r s; do [ -n "$s" ] && sets+=("$s"); done < <(ls "$priv/sets" | LC_ALL=C sort) |
| 225 | new_run "$corpus_sha" |
| 226 | write_meta "$corpus_sha" "$run" |
| 227 | (cd "$priv/sets" && find . -type f -print0 | LC_ALL=C sort -z | xargs -0 -r sha256sum) > "$run/candidates.sha256" |
| 228 | echo "ola.sh: run $run_id tasks $corpus_sha sets ${#sets[@]}" >&2 |
| 229 | local replay=1 L |
| 230 | for L in A B; do |
| 231 | if [ "$L" = B ]; then "$bin/ola" untar "$tar" "$sealed" "$priv/B" tasks >/dev/null; fi |
| 232 | for s in references "${sets[@]}"; do |
| 233 | local out="$run/sets/$s/verdicts.txt" arg="$priv/sets/$s" |
| 234 | [ "$s" = references ] && arg=REFERENCES |
| 235 | [ "$L" = B ] && out="$run/sets/$s/replay/verdicts.txt" |
| 236 | mkdir -p "$(dirname "$out")" |
| 237 | echo "pass $L set $s:" >&2 |
| 238 | "$bin/ola" xpass "$priv/$L/tasks" "$arg" "$out" "$evid/receipts" "$priv/scratch" "$bin/ola_runner" "$priv/meta" |
| 239 | if [ "$L" = B ]; then |
| 240 | "$bin/ola" cmp "$run/sets/$s/verdicts.txt" "$out" || replay=0 |
| 241 | chmod a-w "$run/sets/$s/verdicts.txt" "$out" |
| 242 | fi |
| 243 | done |
| 244 | done |
| 245 | local verdicts_sha; verdicts_sha="$(sha "$run/sets/references/verdicts.txt")" |
| 246 | mkdir "$priv/evidence" && cp "$run/sets/references/verdicts.txt" "$priv/evidence/verdicts.txt" && chmod u+w "$priv/evidence/verdicts.txt" |
| 247 | local first; first="$(ls "$priv/A/tasks/cases" | LC_ALL=C sort | head -n 1)" |
| 248 | probes "$priv/A/tasks/cases/$first" "$priv/A/tasks/cases/$first/hidden/reference.osc" "$tar" "$priv/evidence/verdicts.txt" |
| 249 | unchanged |
| 250 | [ "$(sha "$run/sets/references/verdicts.txt")" = "$verdicts_sha" ] || { echo "ola.sh: verdicts changed during the probes" >&2; clean=0; } |
| 251 | "$bin/ola" xscore "$run/sets" "$replay" "$run/probes.log" "$clean" > "$run/score.txt" |
| 252 | awk '$2 != "ACCEPT" { print "ola.sh: reference not accepted: " $1 " " $2 " " $3 }' "$run/sets/references/verdicts.txt" >&2 |
| 253 | cat "$run/score.txt" |
| 254 | echo "ola.sh: evidence in ${run#"$ROOT"/}" >&2 |
| 255 | } |
| 256 | |
| 257 | usage="usage: ola.sh score|score-v2 <corpus.tar> <SEALED.sha256> | tasks-public <tasks.tar> <TASKS.sha256> <outdir> | experiment <tasks.tar> <TASKS.sha256> <candidates_dir> | tasks-check <tasks.tar> <TASKS.sha256>" |
| 258 | case "${1:-}" in |
| 259 | score) shift; score 1 "$@" ;; |
| 260 | score-v2) shift; score 2 "$@" ;; |
| 261 | tasks-public) shift; tasks_public "$@" ;; |
| 262 | experiment) shift; [ $# -eq 3 ] || die "usage: ola.sh experiment <tasks.tar> <TASKS.sha256> <candidates_dir>"; [ "$3" != - ] || die "candidates_dir '-'"; experiment "$@" ;; |
| 263 | tasks-check) shift; [ $# -eq 2 ] || die "usage: ola.sh tasks-check <tasks.tar> <TASKS.sha256>"; experiment "$1" "$2" - ;; |
| 264 | *) die "$usage" ;; |
| 265 | esac |