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 / visor / qualification / run_qualification.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 | # Omega Visor V1 -- lane 8 qualification runner (user-perspective / adversarial). |
| 18 | # |
| 19 | # usage: tests/visor/qualification/run_qualification.sh [OMEGA_BINARY] |
| 20 | # OMEGA_BINARY default: build/q8/omega (build it with |
| 21 | # make OUT_DIR=build/q8 PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 build/q8/omega) |
| 22 | # env QUAL_WORK scratch dir (default build/q8/qual-work; wiped at start) |
| 23 | # |
| 24 | # Every assertion of the console campaign lives here or in the *.omega-session / |
| 25 | # *.expected files next to this script. Output lines: |
| 26 | # QUAL <section> <case> PASS|FAIL [detail] |
| 27 | # QUAL_SECTION <section> run=<n> failed=<n> |
| 28 | # QUAL_HOSTILE run=<n> failed_closed=<n> crashed=<n> noop=<n> |
| 29 | # QUAL_DETERMINISM runs=<n> identical=<yes|no> |
| 30 | # Exit: 0 when every case passed, 1 otherwise. |
| 31 | set -u |
| 32 | LC_ALL=C |
| 33 | export LC_ALL |
| 34 | |
| 35 | ROOT=$(cd "$(dirname "$0")/../../.." && pwd) |
| 36 | cd "$ROOT" || exit 2 |
| 37 | Q=tests/visor/qualification |
| 38 | OMEGA=${1:-${OMEGA:-build/q8/omega}} |
| 39 | WORK=${QUAL_WORK:-build/q8/qual-work} |
| 40 | EVROOT=tests/visor/fixtures/evidence |
| 41 | rm -rf "$WORK" |
| 42 | mkdir -p "$WORK" |
| 43 | |
| 44 | if [ ! -x "$OMEGA" ]; then |
| 45 | echo "QUAL setup binary FAIL not executable: $OMEGA" |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | # Strict JSON line checker (tools/json_canon.om: pure OM-2, Python json.loads rules, strict |
| 50 | # UTF-8) for the --json scriptability checks; Omega + jq, no Python. |
| 51 | JSONC=$WORK/json_canon |
| 52 | if ! { seed/out/omc < tools/json_canon.om > "$JSONC" && chmod +x "$JSONC"; }; then |
| 53 | echo "QUAL setup json_canon FAIL build" |
| 54 | exit 1 |
| 55 | fi |
| 56 | # json_envelope_check FILE: every line is one JSON object with exactly the keys |
| 57 | # command/status/class/result/error, status ok|error, and error non-null |
| 58 | # exactly when status is error. Prints one reason per problem; rc 1 if any. |
| 59 | json_envelope_check() { |
| 60 | local bad reasons |
| 61 | bad=$("$JSONC" --check-lines <"$1") |
| 62 | reasons=$(jq -nrR --arg bad "$bad" ' |
| 63 | def py: if . == true then "True" elif . == false then "False" |
| 64 | elif . == null then "None" elif type == "string" then . else tojson end; |
| 65 | ($bad | split("\n") | map(select(length > 0) | tonumber)) as $badn |
| 66 | | [inputs] | to_entries[] | (.key + 1) as $n |
| 67 | | if ($badn | index($n)) != null then "line \($n) not JSON" |
| 68 | else (.value | try fromjson catch "\u0000") as $o |
| 69 | | if $o == "\u0000" then "line \($n) not JSON" |
| 70 | elif ($o | type) != "object" then "line \($n) not an object" |
| 71 | else |
| 72 | (if ($o | keys) != ["class", "command", "error", "result", "status"] |
| 73 | then "line \($n) envelope keys [\($o | keys | map("'"'"'\(.)'"'"'") | join(", "))]" else empty end), |
| 74 | (if ($o | has("status") and has("error")) | not then "line \($n) missing status or error" |
| 75 | else |
| 76 | (if $o.status != "ok" and $o.status != "error" then "line \($n) status \($o.status | py)" else empty end), |
| 77 | (if ($o.status == "error") != ($o.error != null) then "line \($n) status/error mismatch" else empty end) |
| 78 | end) |
| 79 | end |
| 80 | end' "$1") || return 1 |
| 81 | [ -z "$reasons" ] || { printf '%s\n' "$reasons"; return 1; } |
| 82 | [ -z "$bad" ] |
| 83 | } |
| 84 | |
| 85 | declare -A RUN FAILED |
| 86 | SECTIONS="semantic determinism realize hostile authority scriptability usability" |
| 87 | for s in $SECTIONS; do RUN[$s]=0; FAILED[$s]=0; done |
| 88 | H_RUN=0; H_CLOSED=0; H_CRASH=0; H_NOOP=0 |
| 89 | |
| 90 | pass() { RUN[$1]=$(( ${RUN[$1]} + 1 )); echo "QUAL $1 $2 PASS${3:+ $3}"; } |
| 91 | fail() { RUN[$1]=$(( ${RUN[$1]} + 1 )); FAILED[$1]=$(( ${FAILED[$1]} + 1 )); echo "QUAL $1 $2 FAIL${3:+ $3}"; } |
| 92 | check() { # check <section> <case> <condition-exit-code> [detail] |
| 93 | if [ "$3" -eq 0 ]; then pass "$1" "$2" "${4:-}"; else fail "$1" "$2" "${4:-}"; fi |
| 94 | } |
| 95 | |
| 96 | # om <outfile> <args...> : run omega with stdin closed, capture stdout+stderr, echo rc |
| 97 | om() { |
| 98 | local out=$1; shift |
| 99 | "$OMEGA" --evidence-root "$EVROOT" "$@" </dev/null >"$out" 2>&1 |
| 100 | echo $? |
| 101 | } |
| 102 | |
| 103 | # jid <cmds...> : fresh process, --json, print the "id" of the LAST output line |
| 104 | jid() { |
| 105 | local args=() c |
| 106 | for c in "$@"; do args+=(--command "$c"); done |
| 107 | "$OMEGA" --evidence-root "$EVROOT" --json "${args[@]}" </dev/null 2>/dev/null | tail -n 1 | |
| 108 | sed -n 's/.*"id":"\(sha256:[0-9a-f]\{64\}\)".*/\1/p' |
| 109 | } |
| 110 | # jfield <field> <cmds...> : string field of the LAST output line |
| 111 | jfield() { |
| 112 | local f=$1; shift |
| 113 | local args=() c |
| 114 | for c in "$@"; do args+=(--command "$c"); done |
| 115 | "$OMEGA" --evidence-root "$EVROOT" --json "${args[@]}" </dev/null 2>/dev/null | tail -n 1 | |
| 116 | sed -n "s/.*\"$f\":\"\\([^\"]*\\)\".*/\\1/p" |
| 117 | } |
| 118 | |
| 119 | # mask host-dependent content of a text transcript (machine block, machine name/id, estimates) |
| 120 | mask() { # mask <in> <out> |
| 121 | local name mid |
| 122 | name=$("$OMEGA" --json --command machine </dev/null 2>/dev/null | sed -n 's/.*"result":{"name":"\([^"]*\)".*/\1/p') |
| 123 | mid=$("$OMEGA" --json --command machine </dev/null 2>/dev/null | sed -n 's/.*"result":{"name":"[^"]*","id":"sha256:\([0-9a-f]*\)".*/\1/p') |
| 124 | awk -v name="$name" -v mid="$mid" ' |
| 125 | /^\xce\xa9> / { inmach = ($0 == "\xce\xa9> machine"); print; if (inmach) print "<machine block masked>"; next } |
| 126 | inmach { next } |
| 127 | { |
| 128 | if (name != "") gsub(name, "<HOST_MACHINE>") |
| 129 | if (mid != "") gsub(mid, "<HOST_MACHINE_ID>") |
| 130 | gsub(/estimated cycles=[0-9]+/, "estimated cycles=<N>") |
| 131 | gsub(/estimated A=[0-9]+ B=[0-9]+ \((equal|A lower|B lower|differ)[^)]*\)/, "estimated A=<N> B=<N> (<cmp>)") |
| 132 | |
| 133 | }' "$1" >"$2" |
| 134 | } |
| 135 | |
| 136 | # ---------------------------------------------------------------- 1. semantic |
| 137 | S=semantic |
| 138 | v7=$(jid '7: u64') |
| 139 | for f in '07: u64' '0x07: u64' '0b111: u64' '(7: u64)' '0x7: u64' '/* c */ 7: u64 // tail'; do |
| 140 | got=$(jid "$f") |
| 141 | [ -n "$v7" ] && [ "$got" = "$v7" ]; check $S "literal-spelling[$f]" $? "id=$got" |
| 142 | done |
| 143 | u32=$(jid '7: u32') |
| 144 | [ -n "$u32" ] && [ "$u32" != "$v7" ]; check $S "width-is-identity[u32!=u64]" $? |
| 145 | u8=$(jid '7: u8'); u16=$(jid '7: u16') |
| 146 | [ -n "$u8" ] && [ -n "$u16" ] && [ "$u8" != "$u16" ] && [ "$u8" != "$u32" ] && [ "$u16" != "$v7" ]; check $S "width-is-identity[u8,u16,u32,u64 distinct]" $? |
| 147 | P1='let x: u64 = 7'; P2='let y: u64 = 11' |
| 148 | a1=$(jid "$P1" "$P2" 'x + y') |
| 149 | for f in 'x+y' 'x + /* c */ y' 'x + y // trailing comment' '(x + y)' ' x + y ' '(x) + (y)'; do |
| 150 | got=$(jid "$P1" "$P2" "$f") |
| 151 | [ -n "$a1" ] && [ "$got" = "$a1" ]; check $S "whitespace-comments[$f]" $? "id=$got" |
| 152 | done |
| 153 | b1=$(jid "$P1" "$P2" 'y + x') |
| 154 | [ -n "$b1" ] && [ "$b1" != "$a1" ]; check $S "operand-order-is-identity[y+x!=x+y]" $? |
| 155 | la=$(jid 'let a: u64 = 7' 'let b: u64 = 7' 'id a'); lb=$(jid 'let a: u64 = 7' 'let b: u64 = 7' 'id b') |
| 156 | [ -n "$la" ] && [ "$la" = "$lb" ] && [ "$la" = "$v7" ]; check $S "binding-name-not-in-id[let a/let b]" $? |
| 157 | # second let adds no object: graph size of the session is identical with and without it |
| 158 | ga=$("$OMEGA" --command 'let a: u64 = 7' --command 'verify a' </dev/null 2>&1 | sed -n 's/.*(\([0-9]*\) object(s)).*/\1/p' | head -n 1) |
| 159 | gb=$("$OMEGA" --command 'let a: u64 = 7' --command 'let b: u64 = 7' --command 'verify a' </dev/null 2>&1 | sed -n 's/.*(\([0-9]*\) object(s)).*/\1/p' | head -n 1) |
| 160 | [ -n "$ga" ] && [ "$ga" = "$gb" ]; check $S "dedupe[second let adds no object]" $? "objects=$ga/$gb" |
| 161 | for bl in true false; do |
| 162 | t=$(jfield type "$bl" "type _") |
| 163 | [ "$t" = "bool" ]; check $S "bool-literal-type[$bl]" $? "type=$t" |
| 164 | done |
| 165 | t=$(jfield type "$P1" "$P2" 'x + y' 'type _'); [ "$t" = "u64" ]; check $S "apply-type[x+y:u64]" $? "type=$t" |
| 166 | t=$(jfield type '(7: u32) + (1: u32)' 'type _'); [ "$t" = "u32" ]; check $S "apply-type[u32+u32:u32]" $? "type=$t" |
| 167 | # values the language reports (evaluation of canonical applies) |
| 168 | val() { jfield value "$@"; } |
| 169 | [ "$(val "$P1" "$P2" 'x + y')" = 18 ]; check $S "value[x+y=18]" $? |
| 170 | [ "$(val 'let m: u64 = 18446744073709551615' 'm + (1: u64)')" = 0 ]; check $S "value[u64 wrap max+1=0]" $? |
| 171 | [ "$(val '(0: u64) - (1: u64)')" = 18446744073709551615 ]; check $S "value[u64 wrap 0-1=max]" $? |
| 172 | [ "$(val '(255: u8) + (1: u8)')" = 0 ]; check $S "value[u8 wrap 255+1=0]" $? |
| 173 | [ "$(val "$P1" '(x + x) * x')" = 98 ]; check $S "value[(x+x)*x=98]" $? |
| 174 | [ "$(val "$P1" 'x & (3: u64)')" = 3 ]; check $S "value[7&3=3]" $? |
| 175 | [ "$(val "$P1" 'x | (8: u64)')" = 15 ]; check $S "value[7|8=15]" $? |
| 176 | [ "$(val "$P1" 'x / (2: u64)')" = 3 ]; check $S "value[7/2=3]" $? |
| 177 | p1=$(jfield program_id 'fn f(x: u64) -> u64 { x * 2 + 1 }' 'id f'); p2=$(jfield program_id 'fn f(n: u64) -> u64 { 1 + 2 * n }' 'id f') |
| 178 | [ -n "$p1" ] && [ "$p1" = "$p2" ]; check $S "program-id[param name + commutative side]" $? |
| 179 | # program identity v2 (spec/program-identity.md): the id binds the canonical body, so |
| 180 | # redefining a name with a different body gives a distinct id and rebinds the name. |
| 181 | p1=$(jfield program_id 'fn t(x: u64) -> u64 { x + 1 }' 'id t'); p2=$(jfield program_id 'fn t(x: u64) -> u64 { x + 1 }' 'clear' 'fn t(x: u64) -> u64 { x + 2 }' 'id t') |
| 182 | [ -n "$p1" ] && [ -n "$p2" ] && [ "$p1" != "$p2" ]; check $S "program-id[body-bound: x+1 != x+2 after clear]" $? |
| 183 | rc=$(om "$WORK/coll.out" --command 'fn f(x: u64) -> u64 { x * 2 + 1 }' --command 'fn f(x: u64) -> u64 { x * 3 + 1 }') |
| 184 | [ "$rc" = 0 ] && ! grep -q 'collision' "$WORK/coll.out"; check $S "program-id-redefine-distinct" $? |
| 185 | # golden transcript: exact text of a pure, host-independent semantic session |
| 186 | rc=$(om "$WORK/semantic.out" --script $Q/semantic.omega-session) |
| 187 | cmp -s "$WORK/semantic.out" $Q/semantic.expected; check $S "golden[semantic.omega-session]" $? "rc=$rc" |
| 188 | [ "$rc" = "$(cat $Q/semantic.exit)" ]; check $S "golden-exit[semantic.omega-session]" $? "rc=$rc" |
| 189 | |
| 190 | # ---------------------------------------------------------------- 1b. realize / run / cost |
| 191 | S=realize |
| 192 | # realize -> run agrees with the language value (machine code executed natively) |
| 193 | runv() { jfield result "$@"; } |
| 194 | for e in 'x + y' 'x - y' 'x * y' 'x & y' 'x | y' 'y - x' '(x + x) * x'; do |
| 195 | v=$(val "$P1" "$P2" "$e"); r=$(runv "$P1" "$P2" "$e" 'realize _' 'run _') |
| 196 | [ -n "$v" ] && [ "$v" = "$r" ]; check $S "realize-run-agrees[$e]" $? "value=$v run=$r" |
| 197 | done |
| 198 | r=$(runv 'let m: u64 = 18446744073709551615' 'm + (1: u64)' 'realize _' 'run _'); [ "$r" = 0 ]; check $S "realize-run-wrap[max+1=0]" $? "run=$r" |
| 199 | FN='fn f(x: u64) -> u64 requires true ensures result >= 1 { x * 2 + 1 }' |
| 200 | r=$(runv "$FN" 'realize f' 'run _ 5'); [ "$r" = 11 ]; check $S "program-run[f(5)=11]" $? "run=$r" |
| 201 | r=$(runv "$FN" 'run f 0'); [ "$r" = 1 ]; check $S "program-run[f(0)=1]" $? "run=$r" |
| 202 | out=$("$OMEGA" --json --command "$P1" --command "$P2" --command 'x + y' --command 'realize _' </dev/null 2>&1 | tail -n 1) |
| 203 | echo "$out" | grep -q '"disasm":\["8b010000 add x0, x0, x1","d65f03c0 ret"\]'; check $S "realize-code[x+y = add;ret]" $? |
| 204 | echo "$out" | grep -q '"compatible":true,"runnable":true'; check $S "realize-compatible-runnable" $? |
| 205 | echo "$out" | grep -q '"measured":{"present":false' && echo "$out" | grep -q '"qualified":{"present":false'; check $S "cost-measured-qualified-absent" $? |
| 206 | echo "$out" | grep -q '"predicted":{"present":true' && echo "$out" | grep -q '"estimated":{"present":true'; check $S "cost-predicted-estimated-present" $? |
| 207 | out=$("$OMEGA" --json --command "$P1" --command "$P2" --command 'x + y' --command 'cost _' </dev/null 2>&1 | tail -n 1) |
| 208 | echo "$out" | grep -q '"status":"error"'; check $S "cost-before-realize-refused" $? |
| 209 | # arity: running with the wrong number of arguments must be refused, not silently defaulted or ignored |
| 210 | arity() { # arity <case> <cmds...> : the LAST command must be an error |
| 211 | local name=$1; shift |
| 212 | local args=() c last |
| 213 | for c in "$@"; do args+=(--command "$c"); done |
| 214 | last=$("$OMEGA" --json "${args[@]}" </dev/null 2>&1 | tail -n 1) |
| 215 | echo "$last" | grep -q '"status":"error"' |
| 216 | check $S "$name" $? "$(echo "$last" | cut -c1-120)" |
| 217 | } |
| 218 | arity "run-arity[unary fn, 0 args refused]" "$FN" 'run f' |
| 219 | arity "run-arity[unary fn, 2 args refused]" "$FN" 'run f 5 6' |
| 220 | arity "run-arity[binary apply realization, 1 arg refused]" "$P1" "$P2" 'x + y' 'realize _' 'run _ 1' |
| 221 | arity "run-arity[binary apply realization, 3 args refused]" "$P1" "$P2" 'x + y' 'realize _' 'run _ 1 2 3' |
| 222 | arity "realize-u8-refused" '(1: u8) + (2: u8)' 'realize _' |
| 223 | arity "realize-div-refused" "$P1" 'x / (2: u64)' 'realize _' |
| 224 | out=$("$OMEGA" --command "$FN" --command 'alternatives f' </dev/null 2>&1) |
| 225 | echo "$out" | grep -q '^direct@'; check $S "alternatives-lists-direct" $? |
| 226 | |
| 227 | # ---------------------------------------------------------------- 2. determinism |
| 228 | S=determinism |
| 229 | DET_RUNS=3; DET_OK=yes |
| 230 | for i in 1 2 3; do |
| 231 | om "$WORK/det-text-$i.out" --script $Q/usability.omega-session >/dev/null |
| 232 | om "$WORK/det-json-$i.out" --json --script $Q/usability.omega-session >/dev/null |
| 233 | om "$WORK/det-sem-$i.out" --json --script $Q/semantic.omega-session >/dev/null |
| 234 | done |
| 235 | for k in text json sem; do |
| 236 | cmp -s "$WORK/det-$k-1.out" "$WORK/det-$k-2.out" && cmp -s "$WORK/det-$k-1.out" "$WORK/det-$k-3.out" |
| 237 | r=$?; [ $r -eq 0 ] || DET_OK=no |
| 238 | check $S "byte-identical-x3[$k]" $r |
| 239 | done |
| 240 | r1=$(jfield realization_id "$P1" "$P2" 'x + y' 'realize _'); r2=$(jfield realization_id "$P1" "$P2" 'x + y' 'realize _') |
| 241 | r3=$(jfield realization_id "$P1" "$P2" 'x + y' 'realize _') |
| 242 | [ -n "$r1" ] && [ "$r1" = "$r2" ] && [ "$r1" = "$r3" ]; r=$?; [ $r -eq 0 ] || DET_OK=no |
| 243 | check $S "realization-id-identical-x3-fresh-processes" $r "id=$r1" |
| 244 | i1=$(jid "$P1" "$P2" 'x * y'); i2=$(jid "$P1" "$P2" 'x * y') |
| 245 | [ -n "$i1" ] && [ "$i1" = "$i2" ]; r=$?; [ $r -eq 0 ] || DET_OK=no |
| 246 | check $S "apply-id-identical-fresh-processes" $r |
| 247 | # the ids the golden file pins must equal the ids fresh processes compute |
| 248 | grep -q "${v7#sha256:}" $Q/semantic.expected; check $S "golden-pins-fresh-id[7:u64]" $? |
| 249 | |
| 250 | # ---------------------------------------------------------------- 3. hostile |
| 251 | S=hostile |
| 252 | HD="$WORK/hostile"; mkdir -p "$HD" |
| 253 | # hcase <name> <expect: E=error|N=no-op|A=any non-crash> <script-file> |
| 254 | # The script's LAST line is always `help quit` (needs no table space); the process must still answer it. |
| 255 | hcase() { |
| 256 | local name=$1 exp=$2 f=$3 rc out |
| 257 | out="$HD/$name.out" |
| 258 | rc=$(om "$out" --script "$f") |
| 259 | H_RUN=$((H_RUN + 1)) |
| 260 | local alive=1 crashed=0 |
| 261 | tail -n 1 "$out" | grep -q '^ quit ' || alive=0 |
| 262 | case "$rc" in 0|1|2) ;; *) crashed=1 ;; esac |
| 263 | if [ $crashed -eq 1 ]; then |
| 264 | H_CRASH=$((H_CRASH + 1)); fail $S "$name" "CRASH rc=$rc"; return |
| 265 | fi |
| 266 | case "$exp" in |
| 267 | E) if [ "$rc" = 1 ] && [ $alive -eq 1 ] && grep -q '^error: ' "$out"; then |
| 268 | H_CLOSED=$((H_CLOSED + 1)); pass $S "$name" "rc=1 failed closed: $(grep -m1 '^error: ' "$out" | cut -c1-110)" |
| 269 | else fail $S "$name" "rc=$rc alive=$alive expected error+rc1"; fi ;; |
| 270 | N) if [ "$rc" = 0 ] && [ $alive -eq 1 ]; then H_NOOP=$((H_NOOP + 1)); pass $S "$name" "rc=0 no-op (spec: blank/comment line)" |
| 271 | else fail $S "$name" "rc=$rc alive=$alive expected no-op"; fi ;; |
| 272 | A) if [ $alive -eq 1 ]; then pass $S "$name" "rc=$rc alive"; else fail $S "$name" "rc=$rc not alive"; fi ;; |
| 273 | esac |
| 274 | } |
| 275 | # mk <name> <printf-format> [args] : write a hostile script: prelude + hostile line + sentinel |
| 276 | PRE='let x: u64 = 7\nlet y: u64 = 11\nx + y\n' |
| 277 | mk() { local n=$1 fmt=$2; shift 2; printf "$PRE$fmt\\nhelp quit\\n" "$@" >"$HD/$n.s"; echo "$HD/$n.s"; } |
| 278 | rep() { local i out=""; for ((i = 0; i < $2; i++)); do out="$out$1"; done; printf '%s' "$out"; } |
| 279 | Z64=$(rep 0 64); H63=$(rep a 63); H65=$(rep b 65) |
| 280 | TY=037a444b0f120fd4bbabd0c16ae143599b231d2469827fccbf9bc79c57bab822 |
| 281 | hcase empty-line N "$(mk empty-line '')" |
| 282 | hcase only-spaces N "$(mk only-spaces ' \t ')" |
| 283 | hcase comment-only N "$(mk comment-only '// just a comment')" |
| 284 | hcase block-comment-only N "$(mk block-comment-only '/* only a block comment */')" |
| 285 | hcase token-300 E "$(mk token-300 'let %s: u64 = 1' "$(rep a 300)")" |
| 286 | hcase line-5000 E "$(mk line-5000 '%s' "$(rep z 5000)")" |
| 287 | hcase line-5000-valid-prefix E "$(mk line-5000-valid-prefix 'let v: u64 = 1 %s' "$(rep ' ' 4990)")" |
| 288 | hcase invalid-utf8-name E "$(mk invalid-utf8-name 'let \377\376: u64 = 1')" |
| 289 | hcase invalid-utf8-cmd E "$(mk invalid-utf8-cmd 'inspect \303\050')" |
| 290 | hcase invalid-utf8-bare E "$(mk invalid-utf8-bare '\200\201\202')" |
| 291 | hcase nul-in-name E "$(mk nul-in-name 'let a\000b: u64 = 1')" |
| 292 | hcase nul-after-valid E "$(mk nul-after-valid 'let n: u64 = 5\000 junk that must not be ignored')" |
| 293 | hcase nul-only A "$(mk nul-only '\000')" |
| 294 | hcase id-63-hex E "$(mk id-63-hex 'id %s' "$H63")" |
| 295 | hcase id-65-hex E "$(mk id-65-hex 'id %s' "$H65")" |
| 296 | hcase id-non-hex E "$(mk id-non-hex 'id %sg' "$(rep 0 63)")" |
| 297 | hcase id-sha-junk E "$(mk id-sha-junk 'inspect sha256:not-a-hash')" |
| 298 | hcase id-sha-empty E "$(mk id-sha-empty 'inspect sha256:')" |
| 299 | hcase id-sha-64-plus-junk E "$(mk id-sha-64-plus-junk 'inspect sha256:%szz' "$Z64")" |
| 300 | hcase id-uppercase-prefix A "$(mk id-uppercase-prefix 'inspect SHA256:%s' "$Z64")" |
| 301 | hcase unknown-command E "$(mk unknown-command 'frobnicate the graph')" |
| 302 | hcase unknown-command-2 E "$(mk unknown-command-2 'delete x')" |
| 303 | hcase unterminated-paren E "$(mk unterminated-paren '(x + y')" |
| 304 | hcase unbalanced-close E "$(mk unbalanced-close 'x + y)')" |
| 305 | hcase overflow-2p64 E "$(mk overflow-2p64 '18446744073709551616: u64')" |
| 306 | hcase overflow-2p65 E "$(mk overflow-2p65 '36893488147419103232: u64')" |
| 307 | hcase overflow-hex-65bit E "$(mk overflow-hex-65bit '0x1ffffffffffffffff: u64')" |
| 308 | hcase overflow-u8-256 E "$(mk overflow-u8-256 '256: u8')" |
| 309 | hcase overflow-u16 E "$(mk overflow-u16 'let w: u16 = 65536')" |
| 310 | hcase overflow-u32 E "$(mk overflow-u32 '4294967296: u32')" |
| 311 | hcase nest-40 E "$(mk nest-40 '%s7: u64%s' "$(rep '(' 40)" "$(rep ')' 40)")" |
| 312 | hcase nest-100 E "$(mk nest-100 '%s7: u64%s' "$(rep '(' 100)" "$(rep ')' 100)")" |
| 313 | hcase nest-1000-open E "$(mk nest-1000-open '%s' "$(rep '(' 1000)")" |
| 314 | hcase chain-200-adds E "$(mk chain-200-adds 'x%s' "$(rep ' + x' 200)")" |
| 315 | hcase chain-2000-adds E "$(mk chain-2000-adds 'x%s' "$(rep '+x' 2000)")" |
| 316 | hcase inspect-absent-id E "$(mk inspect-absent-id 'inspect %s' "$Z64")" |
| 317 | hcase graph-absent-id E "$(mk graph-absent-id 'graph sha256:%s' "$Z64")" |
| 318 | hcase verify-absent-id E "$(mk verify-absent-id 'verify %s' "$Z64")" |
| 319 | hcase run-too-many-args E "$(mk run-too-many-args 'realize _\nrun _ 1 2 3 4 5 6 7 8')" |
| 320 | hcase run-no-args E "$(mk run-no-args 'run')" |
| 321 | hcase compare-one-arg E "$(mk compare-one-arg 'compare x')" |
| 322 | hcase compare-three-args E "$(mk compare-three-args 'compare x y x')" |
| 323 | hcase realize-bool E "$(mk realize-bool 'let b: bool = true\nrealize b')" |
| 324 | hcase realize-no-arg E "$(mk realize-no-arg 'realize')" |
| 325 | hcase realize-bad-machine E "$(mk realize-bad-machine 'realize _ for other.machine')" |
| 326 | hcase run-a-type E "$(mk run-a-type 'run sha256:%s' "$TY")" |
| 327 | hcase run-a-value E "$(mk run-a-value 'run x')" |
| 328 | hcase run-u8-apply E "$(mk run-u8-apply '(1: u8) + (2: u8)\nrealize _')" |
| 329 | hcase mixed-width E "$(mk mixed-width '(1: u32) + (1: u64)')" |
| 330 | hcase bool-arith E "$(mk bool-arith 'true + false')" |
| 331 | hcase ambiguous-width E "$(mk ambiguous-width '1 + 2')" |
| 332 | hcase div-const-zero E "$(mk div-const-zero 'x / (0: u64)')" |
| 333 | hcase comparison-op E "$(mk comparison-op 'x == y')" |
| 334 | hcase signed-type E "$(mk signed-type 'let s: i64 = 1')" |
| 335 | hcase fn-body-not-chain E "$(mk fn-body-not-chain 'fn g(x: u64) -> u64 { x * x }')" |
| 336 | hcase fn-recursion E "$(mk fn-recursion 'fn g(x: u64) -> u64 { g + 1 }')" |
| 337 | hcase fn-wide-const E "$(mk fn-wide-const 'fn g(x: u64) -> u64 { x + 4294967296 }')" |
| 338 | hcase name-64-chars E "$(mk name-64-chars 'let %s: u64 = 1' "$(rep n 64)")" |
| 339 | hcase help-unknown E "$(mk help-unknown 'help nosuchcommand')" |
| 340 | hcase crlf-line A "$(mk crlf-line 'let c: u64 = 1\r')" |
| 341 | hcase tab-separated A "$(mk tab-separated 'let\tt:\tu64\t=\t1')" |
| 342 | # capacity: 300 distinct lets (binding table is 64) -> must fail closed, not crash |
| 343 | { for ((i = 0; i < 300; i++)); do echo "let v$i: u64 = $i"; done; echo 'help quit'; } >"$HD/binding-table-300.s" |
| 344 | hcase binding-table-300 E "$HD/binding-table-300.s" |
| 345 | # capacity: graph (256 objects) exhaustion |
| 346 | { echo 'let x: u64 = 7'; for ((i = 1; i < 400; i++)); do echo "x + ($i: u64)"; done; echo 'help quit'; } >"$HD/graph-full-400.s" |
| 347 | hcase graph-full-400 E "$HD/graph-full-400.s" |
| 348 | # capacity: 20 distinct programs (table is 16) |
| 349 | { for ((i = 1; i <= 20; i++)); do echo "fn p$i(x: u64) -> u64 { x + $i }"; done; echo 'help quit'; } >"$HD/program-table-20.s" |
| 350 | hcase program-table-20 E "$HD/program-table-20.s" |
| 351 | # capacity: 40 realizations |
| 352 | { echo 'let x: u64 = 7'; for ((i = 1; i <= 40; i++)); do echo "fn r$i(x: u64) -> u64 { x * $i }"; echo "realize r$i"; done; echo 'help quit'; } >"$HD/realization-table-40.s" |
| 353 | hcase realization-table-40 A "$HD/realization-table-40.s" |
| 354 | # --command mode hostile arguments (argv cannot carry NUL) |
| 355 | rc=$(om "$HD/cmd-huge.out" --command "$(rep q 5000)" --command 'let alive: u64 = 42'); H_RUN=$((H_RUN + 1)) |
| 356 | if [ "$rc" = 1 ] && tail -n 1 "$HD/cmd-huge.out" | grep -qx 42; then H_CLOSED=$((H_CLOSED + 1)); pass $S cmd-5000-byte-arg "rc=1"; else |
| 357 | case "$rc" in 0|1|2) ;; *) H_CRASH=$((H_CRASH + 1)) ;; esac; fail $S cmd-5000-byte-arg "rc=$rc"; fi |
| 358 | rc=$(om "$HD/cmd-bad-flag.out" --no-such-flag); H_RUN=$((H_RUN + 1)) |
| 359 | if [ "$rc" = 2 ]; then H_CLOSED=$((H_CLOSED + 1)); pass $S bad-flag "rc=2 usage"; else |
| 360 | case "$rc" in 0|1|2) ;; *) H_CRASH=$((H_CRASH + 1)) ;; esac; fail $S bad-flag "rc=$rc"; fi |
| 361 | rc=$(om "$HD/cmd-missing-arg.out" --command); H_RUN=$((H_RUN + 1)) |
| 362 | if [ "$rc" = 2 ]; then H_CLOSED=$((H_CLOSED + 1)); pass $S flag-missing-value "rc=2"; else |
| 363 | case "$rc" in 0|1|2) ;; *) H_CRASH=$((H_CRASH + 1)) ;; esac; fail $S flag-missing-value "rc=$rc"; fi |
| 364 | rc=$(om "$HD/cmd-script-dir.out" --script /); H_RUN=$((H_RUN + 1)) |
| 365 | if [ "$rc" = 1 ] || [ "$rc" = 2 ]; then H_CLOSED=$((H_CLOSED + 1)); pass $S script-is-directory "rc=$rc"; else |
| 366 | case "$rc" in 0) ;; *) H_CRASH=$((H_CRASH + 1)) ;; esac; fail $S script-is-directory "rc=$rc (a directory given as a script must not succeed)"; fi |
| 367 | # golden: the full hostile transcript text (error wording is part of the contract) |
| 368 | rc=$(om "$WORK/hostile.out" --script $Q/hostile.omega-session) |
| 369 | cmp -s "$WORK/hostile.out" $Q/hostile.expected; check $S "golden[hostile.omega-session]" $? "rc=$rc" |
| 370 | [ "$rc" = "$(cat $Q/hostile.exit)" ]; check $S "golden-exit[hostile.omega-session]" $? "rc=$rc" |
| 371 | |
| 372 | # ---------------------------------------------------------------- 4. authority (console side) |
| 373 | S=authority |
| 374 | for w in 'authorize x' 'authorize' 'submit' 'submit _' 'execute _' 'execute' 'mint cap' 'mint' 'grant x' 'revoke x' 'publish x' 'promote _' 'capability' 'effect x' 'syscall' 'admin'; do |
| 375 | rc=$(om "$WORK/auth.out" --command 'let x: u64 = 7' --command "$w" --command 'let alive: u64 = 42') |
| 376 | { [ "$rc" = 1 ] && grep -q '^error: ' "$WORK/auth.out" && tail -n 1 "$WORK/auth.out" | grep -qx 42; } |
| 377 | check $S "escalation-word-refused[$w]" $? "$(grep -m1 '^error: ' "$WORK/auth.out" | cut -c1-100)" |
| 378 | done |
| 379 | out=$("$OMEGA" --json --command "$P1" --command "$P2" --command 'x + y' --command 'verify _' </dev/null 2>&1 | tail -n 1) |
| 380 | echo "$out" | grep -q '"name":"AUTHORITY","status":"PASS"[^}]*"detail":"NONE:' && |
| 381 | echo "$out" | grep -q '"authority":{"required":false,"effects":0,"capability_refs":0,"granted":false}' |
| 382 | check $S "verify-authority-NONE[pure apply]" $? |
| 383 | out=$("$OMEGA" --json --command 'fn f(x: u64) -> u64 { x * 2 + 1 }' --command 'verify f' </dev/null 2>&1 | tail -n 1) |
| 384 | echo "$out" | grep -q '"granted":false'; check $S "verify-authority-not-granted[program]" $? |
| 385 | out=$("$OMEGA" --command 'effects' </dev/null 2>&1) |
| 386 | [ "$out" = "$(printf '[effect-request]\nno effect objects in session')" ]; check $S "effects-empty-session" $? |
| 387 | rc=$(om "$WORK/eff.out" --command "$P1" --command 'effects x'); grep -q "is not an EFFECT object" "$WORK/eff.out" && [ "$rc" = 1 ] |
| 388 | check $S "effects-on-value-refused" $? |
| 389 | out=$("$OMEGA" --json --command "$P1" --command "$P2" --command 'x + y' --command 'realize _' --command 'run _' </dev/null 2>&1 | tail -n 1) |
| 390 | echo "$out" | grep -q '"class":"pure-execution"' && ! echo "$out" | grep -qi 'authorized":true' |
| 391 | check $S "run-pure-is-pure-execution-class" $? |
| 392 | out=$("$OMEGA" --command 'world' </dev/null 2>&1) |
| 393 | echo "$out" | grep -q 'unattached' && echo "$out" | grep -q 'holds no authority'; check $S "world-unattached-no-authority" $? |
| 394 | # no command anywhere in help is an authority/grant verb |
| 395 | "$OMEGA" --command help </dev/null 2>&1 | grep -Eiq '^ (authorize|grant|mint|submit|execute|promote|publish|revoke)\b' |
| 396 | [ $? -ne 0 ]; check $S "help-lists-no-grant-verb" $? |
| 397 | |
| 398 | # ---------------------------------------------------------------- 5. scriptability |
| 399 | S=scriptability |
| 400 | rc=$(om "$WORK/s1.out" --command 'let a: u64 = 1'); [ "$rc" = 0 ] && [ "$(cat "$WORK/s1.out")" = 1 ]; check $S "single-command-rc0" $? |
| 401 | rc=$(om "$WORK/s2.out" --command 'let a: u64 = 2' --command 'let b: u64 = 3' --command 'a * b'); [ "$rc" = 0 ] && [ "$(tail -n 1 "$WORK/s2.out")" = 6 ] |
| 402 | check $S "repeated-command-share-session" $? |
| 403 | printf 'let a: u64 = 4\nlet b: u64 = 5\na + b\n' >"$WORK/s3.omega-session" |
| 404 | rc=$(om "$WORK/s3.out" --script "$WORK/s3.omega-session"); [ "$rc" = 0 ] && [ "$(tail -n 1 "$WORK/s3.out")" = 9 ]; check $S "script-file-rc0" $? |
| 405 | "$OMEGA" --evidence-root "$EVROOT" --script - <"$WORK/s3.omega-session" >"$WORK/s4.out" 2>&1; rc=$? |
| 406 | [ "$rc" = 0 ] && cmp -s "$WORK/s3.out" "$WORK/s4.out"; check $S "script-stdin-equals-file" $? |
| 407 | "$OMEGA" --evidence-root "$EVROOT" <"$WORK/s3.omega-session" >"$WORK/s5.out" 2>&1; rc=$? |
| 408 | [ "$rc" = 0 ] && ! grep -q $'\xce\xa9>' "$WORK/s5.out" && [ "$(tail -n 1 "$WORK/s5.out")" = 9 ]; check $S "no-prompt-when-stdin-not-tty" $? |
| 409 | rc=$(om "$WORK/s6.out" --command 'let a: u64 = 1' --command 'nosuch'); [ "$rc" = 1 ]; check $S "any-error-rc1" $? "rc=$rc" |
| 410 | rc=$(om "$WORK/s7.out" --script "$WORK/does-not-exist.omega-session"); [ "$rc" = 2 ]; check $S "missing-script-rc2" $? "rc=$rc" |
| 411 | rc=$(om "$WORK/s8.out" --bogus); [ "$rc" = 2 ] && grep -q '^usage: ' "$WORK/s8.out"; check $S "bad-flag-rc2-usage" $? "rc=$rc" |
| 412 | rc=$(om "$WORK/s9.out" --command 'let a: u64 = 1' --command quit --command 'let b: u64 = 2'); [ "$rc" = 0 ] && ! grep -qx 2 "$WORK/s9.out" |
| 413 | check $S "quit-stops-processing" $? |
| 414 | # --json: exactly one parseable object per non-blank command, with the fixed envelope |
| 415 | "$OMEGA" --evidence-root "$EVROOT" --json --script $Q/usability.omega-session </dev/null >"$WORK/j.out" 2>"$WORK/j.err"; rc=$? |
| 416 | ncmd=$(grep -cv -e '^[[:space:]]*$' $Q/usability.omega-session) # comment lines answer too; blank lines do not |
| 417 | nl=$(wc -l <"$WORK/j.out") |
| 418 | [ "$nl" = "$ncmd" ]; check $S "json-one-line-per-command" $? "lines=$nl commands=$ncmd" |
| 419 | json_envelope_check "$WORK/j.out" |
| 420 | check $S "json-every-line-parses-with-envelope" $? |
| 421 | "$OMEGA" --evidence-root "$EVROOT" --json --script $Q/hostile.omega-session </dev/null >"$WORK/jh.out" 2>/dev/null |
| 422 | "$JSONC" --check-lines <"$WORK/jh.out" >/dev/null |
| 423 | check $S "json-hostile-lines-still-valid-json" $? |
| 424 | [ ! -s "$WORK/j.err" ]; check $S "json-mode-no-stderr-noise" $? |
| 425 | # stderr/stdout: errors in text mode go to stdout together with the transcript (documented behaviour check) |
| 426 | "$OMEGA" --command nosuch </dev/null >"$WORK/so.out" 2>"$WORK/se.out" |
| 427 | { grep -q '^error:' "$WORK/so.out" || grep -q '^error:' "$WORK/se.out"; }; check $S "error-text-emitted" $? |
| 428 | |
| 429 | # ---------------------------------------------------------------- 6. usability (help-only discovery trace) |
| 430 | S=usability |
| 431 | rc=$(om "$WORK/usability.raw" --script $Q/usability.omega-session) |
| 432 | mask "$WORK/usability.raw" "$WORK/usability.out" |
| 433 | cmp -s "$WORK/usability.out" $Q/usability.expected; r=$? |
| 434 | [ $r -ne 0 ] && diff $Q/usability.expected "$WORK/usability.out" | head -n 20 |
| 435 | check $S "golden[usability.omega-session masked]" $r "rc=$rc" |
| 436 | [ "$rc" = "$(cat $Q/usability.exit)" ]; check $S "golden-exit[usability.omega-session]" $? "rc=$rc" |
| 437 | # discovery questions answered by the trace (structure, host-independent) |
| 438 | q() { grep -q -- "$2" "$WORK/usability.raw"; check $S "$1" $?; } |
| 439 | q "what-is-it[inspect shows kind]" '^kind: OPERATION' |
| 440 | q "why-valid[verify verdict]" '^VERDICT PASS' |
| 441 | q "where-runs[machine targets]" '^ target aarch64-v8a ' |
| 442 | q "where-runs[realize compatible]" '^ compatible yes' |
| 443 | q "what-costs[four classes]" '^cost (four separate classes; never merged)' |
| 444 | q "what-costs[measured absent, not invented]" '^ measured ABSENT' |
| 445 | q "evidence[scope reported]" '^ scope HOST' |
| 446 | q "run-result[18]" '^18$' |
| 447 | # machine view structure via JSON (host-dependent values not asserted) |
| 448 | out=$("$OMEGA" --json --command machine </dev/null 2>&1) |
| 449 | for k in '"name":' '"provenance":"assumed' '"observed":false' '"pipeline":' '"registers":' '"caches":' '"targets":' '"physics_seal_is_placeholder":true'; do |
| 450 | echo "$out" | grep -q -- "$k"; check $S "machine-json-has[$k]" $? |
| 451 | done |
| 452 | |
| 453 | # ---------------------------------------------------------------- sanitizer reports (meaningful when OMEGA is an ASan/UBSan build) |
| 454 | SAN=$(grep -rl -e 'ERROR: AddressSanitizer' -e 'runtime error:' -e 'ERROR: LeakSanitizer' "$WORK" 2>/dev/null | wc -l) |
| 455 | [ "$SAN" = 0 ]; check hostile "no-sanitizer-reports-in-any-transcript" $? "files_with_reports=$SAN" |
| 456 | |
| 457 | # ---------------------------------------------------------------- summary |
| 458 | TOTAL_FAIL=0 |
| 459 | for s in $SECTIONS; do |
| 460 | echo "QUAL_SECTION $s run=${RUN[$s]} failed=${FAILED[$s]}" |
| 461 | TOTAL_FAIL=$((TOTAL_FAIL + ${FAILED[$s]})) |
| 462 | done |
| 463 | echo "QUAL_HOSTILE run=$H_RUN failed_closed=$H_CLOSED crashed=$H_CRASH noop=$H_NOOP" |
| 464 | echo "QUAL_DETERMINISM runs=$DET_RUNS identical=$DET_OK" |
| 465 | echo "QUAL_BINARY $(sha256sum "$OMEGA" | cut -d' ' -f1) $OMEGA" |
| 466 | if [ $TOTAL_FAIL -eq 0 ]; then echo "QUAL_RESULT PASS"; exit 0; fi |
| 467 | echo "QUAL_RESULT FAIL failed=$TOTAL_FAIL" |
| 468 | exit 1 |