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 / estimation / test_est5_tools.sh

151 lines · 11152 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 v5 tool tests (synthetic data only; never opens D1 or D2).
18# tools/estimation/test_est5_tools.sh <est5-test-build> <workdir>
19# The test build (-DE5_TEST_BUILD) takes the dirty flag, protocol SHA and the
20# D1/D2/params identities from E5_TEST_* environment variables.
21set -u
22T=${1:?test build}
23W=${2:?workdir}
24JV=${3:-} # optional strict-JSON validator (test_est_json --validate FILE)
25pass=0; fail=0
26ok() { pass=$((pass + 1)); }
27bad() { fail=$((fail + 1)); echo "FAIL: $*" >&2; }
28# expect <rc> <stderr-substring> <cmd...>
29expect() {
30 want=$1; pat=$2; shift 2
31 "$@" > "$W/out.txt" 2> "$W/err.txt"; rc=$?
32 if [ "$rc" -ne "$want" ]; then bad "rc $rc (want $want): $*"; cat "$W/err.txt" >&2; return; fi
33 if [ -n "$pat" ] && ! grep -q -- "$pat" "$W/err.txt" "$W/out.txt"; then bad "missing '$pat': $*"; cat "$W/err.txt" >&2; return; fi
34 ok
35}
36rm -rf "$W"; mkdir -p "$W"
37S=$W/syn-a; S2=$W/syn-b
38expect 0 "" "$T" make-synthetic "$S" --seed 7 --lines 2400
39expect 0 "" "$T" make-synthetic "$S2" --seed 11 --lines 2400
40expect 0 "VALID" "$T" precheck --dir "$S2"
41
42# 0. v5 window rule: a void or missing WINDOW makes the folder INCONCLUSIVE everywhere
43V=$W/syn-void; cp -r "$S2" "$V"; echo "WINDOW_VOID 3 foreign build/test/gate process samples" > "$V/WINDOW"
44expect 3 "INCONCLUSIVE: window not clean" "$T" precheck --dir "$V"
45N=$W/syn-nowin; cp -r "$S2" "$N"; rm "$N/WINDOW"
46expect 3 "no WINDOW file" "$T" precheck --dir "$N"
47
48# 1. synthetic fit runs, fast and pmf scores agree for every family
49expect 0 "EST5_FIT" "$T" fit --raw "$S/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/p.txt" --synthetic-test --grid-stride 3
50for g in G1 G2 G3; do
51 if grep -q "^family $g available 1 .* agree 1$" "$W/p.txt"; then ok; else bad "family $g not available+agreeing"; fi
52done
53grep -q '^phase_a ' "$W/p.txt" && ok || bad "no phase_a line"
54grep -q '^e0_count ' "$W/p.txt" && ok || bad "no E0 histogram"
55grep -q '^baseline F1 available 1 ' "$W/p.txt" && ok || bad "no F1 baseline"
56# never overwrites
57expect 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
58
59# 2. held-out guard: refused before any file is opened (paths do not exist)
60for tag in est5-heldout est4-heldout est3c-heldout; do
61 H=$W/x-$tag-silicon
62 expect 2 "held-out" "$T" fit --raw "$H/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/h.txt" --synthetic-test
63 expect 2 "held-out" "$T" fit --raw "$S/machine-state.ndjson" --marks "$H/machine-state-marks.txt" --out "$W/h.txt" --synthetic-test
64done
65# a symlink whose target carries the tag is refused too
66mkdir -p "$W/r-est5-heldout-silicon"; cp "$S"/* "$W/r-est5-heldout-silicon/"; ln -s "$(cd "$W" && pwd)/r-est5-heldout-silicon" "$W/innocent"
67expect 2 "held-out" "$T" fit --raw "$W/innocent/machine-state.ndjson" --marks "$W/innocent/machine-state-marks.txt" --out "$W/h2.txt" --synthetic-test
68
69# 3. purity: a fit opens only its own inputs (strace, when available)
70if command -v strace > /dev/null 2>&1; then
71 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
72 if grep -E 'heldout|syn-b|-est5-fit-|est3c-fit' "$W/trace.txt" > /dev/null; then bad "fit opened a foreign data path"; else ok; fi
73 if grep -q 'syn-a/machine-state.ndjson' "$W/trace.txt"; then ok; else bad "strace saw no input open"; fi
74 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
75 if grep -E 'machine-state' "$W/trace2.txt" > /dev/null; then bad "held-out refusal opened data"; else ok; fi
76else
77 echo "test_est5_tools: strace absent, open-trace purity skipped" >&2
78fi
79
80# 4. binding-mode refusals
81F1=$W/d-est5-fit-silicon; mkdir -p "$F1"; cp "$S"/* "$F1/"
82RS=$(sha256sum "$F1/machine-state.ndjson" | cut -c1-64); MS=$(sha256sum "$F1/machine-state-marks.txt" | cut -c1-64)
83PS=$(sha256sum docs/estimation/protocols/est-v5.md 2>/dev/null | cut -c1-64)
84fitb() { "$T" fit --raw "$1/machine-state.ndjson" --marks "$1/machine-state-marks.txt" --out "$2"; }
85expect 2 "--grid-stride only" "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt" --grid-stride 3
86expect 2 "clean tree" env E5_TEST_DIRTY=1 "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt"
87expect 2 "protocol SHA" env E5_TEST_DIRTY=0 E5_TEST_PROTOCOL_SHA=0000 "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt"
88if [ -n "$PS" ]; then
89 expect 2 "no D1 identity" env E5_TEST_DIRTY=0 E5_TEST_PROTOCOL_SHA="$PS" "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt"
90 expect 2 "-est5-fit-" env E5_TEST_DIRTY=0 E5_TEST_PROTOCOL_SHA="$PS" E5_TEST_D1_RAW_SHA="$RS" E5_TEST_D1_MARKS_SHA="$MS" "$T" fit --raw "$S/machine-state.ndjson" --marks "$S/machine-state-marks.txt" --out "$W/b.txt"
91 expect 2 "differs from the compiled D1" env E5_TEST_DIRTY=0 E5_TEST_PROTOCOL_SHA="$PS" E5_TEST_D1_RAW_SHA="$MS" E5_TEST_D1_MARKS_SHA="$MS" "$T" fit --raw "$F1/machine-state.ndjson" --marks "$F1/machine-state-marks.txt" --out "$W/b.txt"
92 [ ! -e "$W/b.txt" ] && ok || bad "refused binding fit left an output"
93else
94 echo "test_est5_tools: protocol doc absent, binding identity refusals skipped" >&2
95fi
96
97# 5. recorded: refuses PHASE_A_FAIL params, a held-out dir in synthetic mode, binding without D2 identity
98mkdir -p "$W/rc"
99if grep -q '^phase_a PHASE_A_FAIL' "$W/p.txt"; then
100 expect 2 "NOT_RUN" "$T" recorded --dir "$S2" --params "$W/p.txt" --outdir "$W/rc" --synthetic-test
101fi
102expect 2 "no D2 identity" env E5_TEST_DIRTY=0 "$T" recorded --dir "$S2" --params "$W/p.txt" --outdir "$W/rc"
103expect 2 "never runs on D1" "$T" recorded --dir "$W/r-est5-heldout-silicon" --params "$W/p.txt" --outdir "$W/rc" --synthetic-test
104# a params file marked as a G1 screen pass exercises the scored path end to end
105sed -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"
106mkdir -p "$W/rcw"; expect 3 "D2 is INCONCLUSIVE" "$T" recorded --dir "$V" --params "$W/pp.txt" --outdir "$W/rcw" --synthetic-test
107expect 0 "EST5_RECORDED" "$T" recorded --dir "$S2" --params "$W/pp.txt" --outdir "$W/rc" --synthetic-test
108n=$(ls "$W/rc" | grep -c '^receipt-.*\.json$'); [ "$n" -eq 1 ] && ok || bad "want one receipt, have $n"
109r=$(ls "$W/rc"/receipt-*.json | head -1); h=$(sha256sum "$r" | cut -c1-64)
110case "$r" in *"receipt-$h.json") ok ;; *) bad "receipt name is not its SHA-256" ;; esac
111grep -q '"same_steps": true' "$r" && ok || bad "S, F1, E0 not on the same steps"
112# est-json-1: the receipt is strict JSON; unbounded and unavailable values are explicit
113if [ -n "$JV" ]; then "$JV" --validate "$r" && ok || bad "synthetic receipt is not strict JSON"; else bad "no strict-JSON validator given (the check is never skipped)"; fi
114if grep -Eq '(^|[^A-Za-z"])(inf|nan)([^A-Za-z"]|$)' "$r"; then bad "receipt holds a bare inf or nan token"; else ok; fi
115grep -q '"json_rules": "est-json-1"' "$r" && ok || bad "receipt lacks json_rules"
116grep -q '"invalid_measurements": 0' "$r" && ok || bad "invalid_measurements not 0 on a finite run"
117grep -q '"n_scored": {"value": [0-9]*, "value_status": "ok", "lo": [0-9]*, "lo_unbounded": false, "hi": null, "hi_unbounded": true' "$r" && ok || bad "n_scored threshold not null + hi_unbounded"
118n=$(grep -c '"ten_log_score": null, "ten_log_score_status": "unavailable"' "$r"); [ "$n" -eq 2 ] && ok || bad "want 2 unavailable baseline ten-step scores, have $n"
119expect 2 "already holds a receipt" "$T" recorded --dir "$S2" --params "$W/pp.txt" --outdir "$W/rc" --synthetic-test
120# selection mismatch is refused
121sed -e 's/^selected .*/selected G3/' "$W/pp.txt" > "$W/pm.txt"; mkdir -p "$W/rc2"
122expect 2 "the rule gives" "$T" recorded --dir "$S2" --params "$W/pm.txt" --outdir "$W/rc2" --synthetic-test
123
124
125# 6. binding recorded end to end (identities from the environment), and the
126# synthetic path refusing D2 bytes under another name
127if [ -n "$PS" ]; then
128 RD=$W/repo; RO=$RD/docs/estimation/receipts/est-v5; mkdir -p "$RO"
129 D2=$W/z-est5-heldout-silicon; mkdir -p "$D2"; cp "$S2"/* "$D2/"
130 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)
131 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/" \
132 -e "s/^fit_raw_sha256 .*/fit_raw_sha256 $RS/" -e "s/^fit_marks_sha256 .*/fit_marks_sha256 $MS/" \
133 -e "s|^fit_raw_path .*|fit_raw_path $F1/machine-state.ndjson|" "$W/pp.txt" > "$2"; }
134 mkpb "$PS" "$W/pb.txt"; mkpb 1111 "$W/pbx.txt"
135 rec() { env E5_TEST_DIRTY=0 E5_TEST_PROTOCOL_SHA="$PS" E5_TEST_D1_RAW_SHA="$RS" E5_TEST_D1_MARKS_SHA="$MS" \
136 E5_TEST_D2_RAW_SHA="$R2" E5_TEST_D2_MARKS_SHA="$M2" E5_TEST_D2_SCHED_SHA="$C2" \
137 E5_TEST_PARAMS_SHA="$(sha256sum "$1" | cut -c1-64)" E5_TEST_REPO_ROOT="$RD" \
138 "$T" recorded --dir "$D2" --params "$1" --outdir "$RO"; }
139 expect 2 "another protocol SHA" rec "$W/pbx.txt"
140 expect 2 "receipt goes only" env E5_TEST_DIRTY=0 E5_TEST_PROTOCOL_SHA="$PS" E5_TEST_D2_RAW_SHA="$R2" E5_TEST_D2_MARKS_SHA="$M2" E5_TEST_D2_SCHED_SHA="$C2" \
141 E5_TEST_PARAMS_SHA="$(sha256sum "$W/pb.txt" | cut -c1-64)" E5_TEST_REPO_ROOT="$RD" "$T" recorded --dir "$D2" --params "$W/pb.txt" --outdir "$W/rc2"
142 expect 0 "EST5_RECORDED" rec "$W/pb.txt"
143 n=$(ls "$RO" | grep -c '^receipt-.*\.json$'); [ "$n" -eq 1 ] && ok || bad "binding: want one receipt, have $n"
144 grep -q "\"protocol_sha256\": \"$PS\"" "$RO"/receipt-*.json && ok || bad "binding receipt lacks the protocol SHA"
145 if [ -n "$JV" ]; then for br in "$RO"/receipt-*.json; do "$JV" --validate "$br" && ok || bad "binding receipt is not strict JSON"; done; fi
146 expect 2 "already holds a receipt" rec "$W/pb.txt"
147 mkdir -p "$W/rc3"
148 expect 2 "(D2 bytes)" env E5_TEST_D2_RAW_SHA="$R2" "$T" recorded --dir "$S2" --params "$W/pp.txt" --outdir "$W/rc3" --synthetic-test
149fi
150echo "test_est5_tools: $pass passed, $fail failed"
151[ "$fail" -eq 0 ]