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/tools/estimation/test_est4_tools.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 / tools / estimation / test_est4_tools.sh` 135 lines ยท 9504 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 # ESTIMATION v4 tool tests (synthetic data only; never opens D1 or D2). 18 # tools/estimation/test_est4_tools.sh 19 # The test build (-DE4_TEST_BUILD) takes the dirty flag, protocol SHA and the 20 # D1/D2/params identities from E4_TEST_* environment variables. 21 set -u 22 T=${1:?test build} 23 W=${2:?workdir} 24 pass=0; fail=0 25 ok() { pass=$((pass + 1)); } 26 bad() { fail=$((fail + 1)); echo "FAIL: $*" >&2; } 27 # expect 28 expect() { 29 want=$1; pat=$2; shift 2 30 "$@" > "$W/out.txt" 2> "$W/err.txt"; rc=$? 31 if [ "$rc" -ne "$want" ]; then bad "rc $rc (want $want): $*"; cat "$W/err.txt" >&2; return; fi 32 if [ -n "$pat" ] && ! grep -q -- "$pat" "$W/err.txt" "$W/out.txt"; then bad "missing '$pat': $*"; cat "$W/err.txt" >&2; return; fi 33 ok 34 } 35 rm -rf "$W"; mkdir -p "$W" 36 S=$W/syn-a; S2=$W/syn-b 37 expect 0 "" "$T" make-synthetic "$S" --seed 7 --lines 2400 38 expect 0 "" "$T" make-synthetic "$S2" --seed 11 --lines 2400 39 expect 0 "VALID" "$T" precheck --dir "$S2" 40 41 # 1. synthetic fit runs, fast and pmf scores agree for every family 42 expect 0 "EST4_FIT" "$T" fit --raw "$S/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/p.txt" --synthetic-test --grid-stride 3 43 for g in G1 G2 G3; do 44 if grep -q "^family $g available 1 .* agree 1$" "$W/p.txt"; then ok; else bad "family $g not available+agreeing"; fi 45 done 46 grep -q '^phase_a ' "$W/p.txt" && ok || bad "no phase_a line" 47 grep -q '^e0_count ' "$W/p.txt" && ok || bad "no E0 histogram" 48 grep -q '^baseline F1 available 1 ' "$W/p.txt" && ok || bad "no F1 baseline" 49 # never overwrites 50 expect 1 "never overwritten" "$T" fit --raw "$S/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/p.txt" --synthetic-test --grid-stride 3 51 52 # 2. held-out guard: refused before any file is opened (paths do not exist) 53 for tag in est4-heldout est3c-heldout; do 54 H=$W/x-$tag-silicon 55 expect 2 "held-out" "$T" fit --raw "$H/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/h.txt" --synthetic-test 56 expect 2 "held-out" "$T" fit --raw "$S/machine-state.ndjson" --marks "$H/machine-state-marks.txt" --out "$W/h.txt" --synthetic-test 57 done 58 # a symlink whose target carries the tag is refused too 59 mkdir -p "$W/r-est4-heldout-silicon"; cp "$S"/* "$W/r-est4-heldout-silicon/"; ln -s "$(cd "$W" && pwd)/r-est4-heldout-silicon" "$W/innocent" 60 expect 2 "held-out" "$T" fit --raw "$W/innocent/machine-state.ndjson" --marks "$W/innocent/machine-state-marks.txt" --out "$W/h2.txt" --synthetic-test 61 62 # 3. purity: a fit opens only its own inputs (strace, when available) 63 if command -v strace > /dev/null 2>&1; then 64 strace -f -e trace=open,openat -o "$W/trace.txt" "$T" fit --raw "$S/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/p2.txt" --synthetic-test --grid-stride 5 > /dev/null 2>&1 65 if grep -E 'heldout|syn-b|-est4-fit-|est3c-fit' "$W/trace.txt" > /dev/null; then bad "fit opened a foreign data path"; else ok; fi 66 if grep -q 'syn-a/machine-state.ndjson' "$W/trace.txt"; then ok; else bad "strace saw no input open"; fi 67 strace -f -e trace=open,openat -o "$W/trace2.txt" "$T" fit --raw "$W/innocent/machine-state.ndjson" --marks "$W/innocent/machine-state-marks.txt" --out "$W/h3.txt" --synthetic-test > /dev/null 2>&1 68 if grep -E 'machine-state' "$W/trace2.txt" > /dev/null; then bad "held-out refusal opened data"; else ok; fi 69 else 70 echo "test_est4_tools: strace absent, open-trace purity skipped" >&2 71 fi 72 73 # 4. binding-mode refusals 74 F1=$W/d-est4-fit-silicon; mkdir -p "$F1"; cp "$S"/* "$F1/" 75 RS=$(sha256sum "$F1/machine-state.ndjson" | cut -c1-64); MS=$(sha256sum "$F1/machine-state-marks.txt" | cut -c1-64) 76 PS=$(sha256sum docs/estimation/protocols/est-v4.md 2>/dev/null | cut -c1-64) 77 fitb() { "$T" fit --raw "$1/machine-state.ndjson" --marks "$1/machine-state-marks.txt" --out "$2"; } 78 expect 2 "--grid-stride only" "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt" --grid-stride 3 79 expect 2 "clean tree" env E4_TEST_DIRTY=1 "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt" 80 expect 2 "protocol SHA" env E4_TEST_DIRTY=0 E4_TEST_PROTOCOL_SHA=0000 "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt" 81 if [ -n "$PS" ]; then 82 expect 2 "no D1 identity" env E4_TEST_DIRTY=0 E4_TEST_PROTOCOL_SHA="$PS" "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt" 83 expect 2 "-est4-fit-" env E4_TEST_DIRTY=0 E4_TEST_PROTOCOL_SHA="$PS" E4_TEST_D1_RAW_SHA="$RS" E4_TEST_D1_MARKS_SHA="$MS" "$T" fit --raw "$S/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/b.txt" 84 expect 2 "differs from the compiled D1" env E4_TEST_DIRTY=0 E4_TEST_PROTOCOL_SHA="$PS" E4_TEST_D1_RAW_SHA="$MS" E4_TEST_D1_MARKS_SHA="$MS" "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt" 85 [ ! -e "$W/b.txt" ] && ok || bad "refused binding fit left an output" 86 else 87 echo "test_est4_tools: protocol doc absent, binding identity refusals skipped" >&2 88 fi 89 90 # 5. recorded: refuses PHASE_A_FAIL params, a held-out dir in synthetic mode, binding without D2 identity 91 mkdir -p "$W/rc" 92 if grep -q '^phase_a PHASE_A_FAIL' "$W/p.txt"; then 93 expect 2 "NOT_RUN" "$T" recorded --dir "$S2" --params "$W/p.txt" --outdir "$W/rc" --synthetic-test 94 fi 95 expect 2 "no D2 identity" env E4_TEST_DIRTY=0 "$T" recorded --dir "$S2" --params "$W/p.txt" --outdir "$W/rc" 96 expect 2 "never runs on D1" "$T" recorded --dir "$W/r-est4-heldout-silicon" --params "$W/p.txt" --outdir "$W/rc" --synthetic-test 97 # a params file marked as a G1 screen pass exercises the scored path end to end 98 sed -e 's/^screen_result G1 pass 0/screen_result G1 pass 1/' -e 's/^selected .*/selected G1/' -e 's/^phase_a .*/phase_a PASS/' "$W/p.txt" > "$W/pp.txt" 99 expect 0 "EST4_RECORDED" "$T" recorded --dir "$S2" --params "$W/pp.txt" --outdir "$W/rc" --synthetic-test 100 n=$(ls "$W/rc" | grep -c '^receipt-.*\.json$'); [ "$n" -eq 1 ] && ok || bad "want one receipt, have $n" 101 r=$(ls "$W/rc"/receipt-*.json | head -1); h=$(sha256sum "$r" | cut -c1-64) 102 case "$r" in *"receipt-$h.json") ok ;; *) bad "receipt name is not its SHA-256" ;; esac 103 grep -q '"same_steps": true' "$r" && ok || bad "S, F1, E0 not on the same steps" 104 expect 2 "already holds a receipt" "$T" recorded --dir "$S2" --params "$W/pp.txt" --outdir "$W/rc" --synthetic-test 105 # selection mismatch is refused 106 sed -e 's/^selected .*/selected G3/' "$W/pp.txt" > "$W/pm.txt"; mkdir -p "$W/rc2" 107 expect 2 "the rule gives" "$T" recorded --dir "$S2" --params "$W/pm.txt" --outdir "$W/rc2" --synthetic-test 108 109 110 # 6. binding recorded end to end (identities from the environment), and the 111 # synthetic path refusing D2 bytes under another name 112 if [ -n "$PS" ]; then 113 RD=$W/repo; RO=$RD/docs/estimation/receipts/est-v4; mkdir -p "$RO" 114 D2=$W/z-est4-heldout-silicon; mkdir -p "$D2"; cp "$S2"/* "$D2/" 115 R2=$(sha256sum "$D2/machine-state.ndjson" | cut -c1-64); M2=$(sha256sum "$D2/machine-state-marks.txt" | cut -c1-64); C2=$(sha256sum "$D2/schedule.txt" | cut -c1-64) 116 mkpb() { sed -e 's/^synthetic_test .*/synthetic_test 0/' -e 's/^tool_dirty .*/tool_dirty 0/' -e "s/^protocol_doc_sha256 .*/protocol_doc_sha256 $1/" \ 117 -e "s/^fit_raw_sha256 .*/fit_raw_sha256 $RS/" -e "s/^fit_marks_sha256 .*/fit_marks_sha256 $MS/" \ 118 -e "s|^fit_raw_path .*|fit_raw_path $F1/machine-state.ndjson|" "$W/pp.txt" > "$2"; } 119 mkpb "$PS" "$W/pb.txt"; mkpb 1111 "$W/pbx.txt" 120 rec() { env E4_TEST_DIRTY=0 E4_TEST_PROTOCOL_SHA="$PS" E4_TEST_D1_RAW_SHA="$RS" E4_TEST_D1_MARKS_SHA="$MS" \ 121 E4_TEST_D2_RAW_SHA="$R2" E4_TEST_D2_MARKS_SHA="$M2" E4_TEST_D2_SCHED_SHA="$C2" \ 122 E4_TEST_PARAMS_SHA="$(sha256sum "$1" | cut -c1-64)" E4_TEST_REPO_ROOT="$RD" \ 123 "$T" recorded --dir "$D2" --params "$1" --outdir "$RO"; } 124 expect 2 "another protocol SHA" rec "$W/pbx.txt" 125 expect 2 "receipt goes only" env E4_TEST_DIRTY=0 E4_TEST_PROTOCOL_SHA="$PS" E4_TEST_D2_RAW_SHA="$R2" E4_TEST_D2_MARKS_SHA="$M2" E4_TEST_D2_SCHED_SHA="$C2" \ 126 E4_TEST_PARAMS_SHA="$(sha256sum "$W/pb.txt" | cut -c1-64)" E4_TEST_REPO_ROOT="$RD" "$T" recorded --dir "$D2" --params "$W/pb.txt" --outdir "$W/rc2" 127 expect 0 "EST4_RECORDED" rec "$W/pb.txt" 128 n=$(ls "$RO" | grep -c '^receipt-.*\.json$'); [ "$n" -eq 1 ] && ok || bad "binding: want one receipt, have $n" 129 grep -q "\"protocol_sha256\": \"$PS\"" "$RO"/receipt-*.json && ok || bad "binding receipt lacks the protocol SHA" 130 expect 2 "already holds a receipt" rec "$W/pb.txt" 131 mkdir -p "$W/rc3" 132 expect 2 "(D2 bytes)" env E4_TEST_D2_RAW_SHA="$R2" "$T" recorded --dir "$S2" --params "$W/pp.txt" --outdir "$W/rc3" --synthetic-test 133 fi 134 echo "test_est4_tools: $pass passed, $fail failed" 135 [ "$fail" -eq 0 ]