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 / test_chipwait_campaign.sh

155 lines · 8786 bytes Raw Blame History
1#!/bin/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# test_chipwait_campaign.sh -- host-only tests of tools/chipwait_campaign.sh
18# with a STUB qualify script (CHIPWAIT_QUALIFY). No GPU, no real qualifier.
19# Run: make test-chipwait-campaign (or run this file).
20set -u
21HERE=$(cd -P "$(dirname "$0")/.." && pwd)
22CW=$HERE/tools/chipwait_campaign.sh
23TMP=$(mktemp -d)
24trap 'rm -rf "$TMP"' EXIT
25fails=0
26ok() { echo " [PASS] $1"; }
27bad() { echo " [FAIL] $1"; fails=$((fails + 1)); }
28check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; }
29
30# Stub qualify. Per-run behaviour from env STUB_STATUS_<n> (default PASS):
31# PASS/FAIL write a valid verified run dir; NODIR writes nothing; both exit
32# nonzero for FAIL/NODIR. STUB_NEED_CAMPAIGN_JSON=1 records whether
33# campaign.json existed at invocation time.
34STUB=$TMP/stub_qualify.sh
35cat > "$STUB" <<'STUBEOF'
36#!/bin/bash
37root= id=
38while [ $# -gt 0 ]; do
39 case $1 in --evidence-root) root=$2;; --run-id) id=$2;; esac
40 shift
41done
42n=${id#run-}; n=$((10#$n))
43# STUB_CLEAN=1: what m19r_qualify.sh does to build/ (make clean), on CHIPWAIT_BUILD_DIR.
44[ "${STUB_CLEAN:-0}" = 1 ] && rm -rf "$CHIPWAIT_BUILD_DIR"
45[ -e "$root/campaign.json" ] && echo "$id saw campaign.json" >> "$root/../stub-order.log" ||
46 echo "$id NO campaign.json" >> "$root/../stub-order.log"
47echo "stub stdout $id"; echo "stub stderr $id" >&2
48v=STUB_STATUS_$n; s=${!v:-PASS}
49[ "$s" = NODIR ] && exit 3
50mkdir "$root/$id" || exit 2
51echo '{"stub":true}' > "$root/$id/run.json"
52printf '{"status":"%s"}\n' "$s" > "$root/$id/verdict.json"
53(cd "$root/$id" && sha256sum run.json verdict.json > hashes.sha256)
54[ "$s" = PASS ]
55STUBEOF
56chmod +x "$STUB"
57export CHIPWAIT_QUALIFY=$STUB
58# The build directory the lane receipt guard inspects (never the real build/ here).
59export CHIPWAIT_BUILD_DIR=$TMP/build; unset WINDOW_LANE_OUT
60S40=$(printf 'a%.0s' $(seq 40)); P40=$(printf 'b%.0s' $(seq 40))
61run() { # run <dir> [extra args]; sets rc
62 local d=$1; shift
63 "$CW" --omega-candidate "$S40" --physics-candidate "$P40" --physics-dir "$TMP/phys" --campaign-dir "$d" "$@" \
64 > "$TMP/out.log" 2> "$TMP/err.log"
65 rc=$?
66}
67verdict() { jq -r .verdict "$1/final-verdict.json"; }
68
69echo "PASS: three PASS runs"
70c=$TMP/pass; run "$c"
71check "exit 0" '[ $rc = 0 ]'
72check "final-verdict PASS" '[ "$(verdict "$c")" = PASS ]'
73check "three run dirs" '[ "$(ls -d "$c"/run-00?/ | wc -l)" = 3 ]'
74check "campaign.json written before the first run" '[ "$(head -n1 "$TMP/stub-order.log")" = "run-001 saw campaign.json" ] && ! grep -q NO "$TMP/stub-order.log"'
75check "campaign.json fields" 'jq -e --arg o "$S40" --arg p "$P40" ".omega_candidate_sha==\$o and .physics_candidate_sha==\$p and .rule==\"3/3 PASS, predeclared\" and .runs_required==3 and (.created_at|test(\"Z\$\")) and (.host|length>0) and (.uname|length>0) and has(\"runner_sha\")" "$c/campaign.json" > /dev/null'
76check "stdout log captured" 'grep -q "stub stdout run-002" "$c/runner-run-002.stdout.log"'
77check "stderr log captured" 'grep -q "stub stderr run-002" "$c/runner-run-002.stderr.log"'
78check "output also shown on terminal" 'grep -q "stub stdout run-003" "$TMP/out.log" && grep -q "stub stderr run-003" "$TMP/err.log"'
79check "exit codes recorded" '[ "$(cat "$c/runner-run-001.exit")" = 0 ]'
80
81echo "FAIL: run 2 fails, campaign continues"
82c=$TMP/fail; STUB_STATUS_2=FAIL run "$c"
83check "exit 1" '[ $rc = 1 ]'
84check "final-verdict FAIL" '[ "$(verdict "$c")" = FAIL ]'
85check "run 3 still ran" '[ -d "$c/run-003" ] && [ "$(cat "$c/runner-run-003.exit")" = 0 ]'
86check "failing exit code recorded" '[ "$(cat "$c/runner-run-002.exit")" = 1 ]'
87
88echo "INCOMPLETE: run 3 writes no run dir (m19r_campaign.sh mechanically gives INCOMPLETE)"
89c=$TMP/inc; STUB_STATUS_3=NODIR run "$c"
90check "exit nonzero (1)" '[ $rc = 1 ]'
91check "final-verdict INCOMPLETE" '[ "$(verdict "$c")" = INCOMPLETE ]'
92check "exit code 3 recorded" '[ "$(cat "$c/runner-run-003.exit")" = 3 ]'
93
94echo "runs count"
95c=$TMP/two; run "$c" --runs 2
96check "--runs 2 passes with 2 runs, rule text derived" '[ $rc = 0 ] && [ "$(jq -r .rule "$c/campaign.json")" = "2/2 PASS, predeclared" ] && [ ! -d "$c/run-003" ]'
97
98echo "refusal to reuse a campaign dir"
99find "$TMP/pass" -type f | sort | xargs sha256sum > "$TMP/before.sums"
100run "$TMP/pass"
101check "exit 2" '[ $rc = 2 ]'
102check "existing files byte-identical" 'find "$TMP/pass" -type f | sort | xargs sha256sum | cmp -s - "$TMP/before.sums"'
103mkdir -p "$TMP/partial/run-001"; echo keep > "$TMP/partial/run-001/x"
104run "$TMP/partial"
105check "lone run-001 dir refused (exit 2) and untouched" '[ $rc = 2 ] && [ "$(cat "$TMP/partial/run-001/x")" = keep ] && [ ! -e "$TMP/partial/campaign.json" ]'
106
107echo "bad arguments"
108check "no arguments" '"$CW" > /dev/null 2>&1; [ $? = 2 ]'
109check "runs 0" 'run "$TMP/b1" --runs 0; [ $rc = 2 ]'
110check "runs abc" 'run "$TMP/b2" --runs abc; [ $rc = 2 ]'
111check "runs -1" 'run "$TMP/b3" --runs -1; [ $rc = 2 ]'
112check "missing candidate" '"$CW" --physics-candidate x --physics-dir y --campaign-dir "$TMP/b4" > /dev/null 2>&1; [ $? = 2 ]'
113check "unknown flag" '"$CW" --bogus > /dev/null 2>&1; [ $? = 2 ]'
114check "error text on stderr" '"$CW" --runs 0 2>&1 >/dev/null | grep -q usage'
115check "bad usage created no campaign dir" '[ ! -e "$TMP/b1" ] && [ ! -e "$TMP/b2" ]'
116
117echo "lane receipt guard (omega #315): R11 evidence is archived before the make-clean lane"
118B=$CHIPWAIT_BUILD_DIR; WD=$TMP/window
119mkdir -p "$B/qual-runs/r16/R11" "$B/qual-runs/r11/R11"
120printf '{"gate":"PASS","from":"R16 ladder rung"}\n' > "$B/qual-runs/r16/R11/rx_aien_faculty_receipt.json"
121printf '{"gate":"PASS","from":"r11 lane"}\n' > "$B/qual-runs/r11/R11/rx_aien_faculty_receipt.json"
122s16=$(sha256sum "$B/qual-runs/r16/R11/rx_aien_faculty_receipt.json" | cut -c1-64)
123s11=$(sha256sum "$B/qual-runs/r11/R11/rx_aien_faculty_receipt.json" | cut -c1-64)
124c=$TMP/g1; STUB_CLEAN=1 run "$c"
125check "no WINDOW_LANE_OUT, R11 receipts in build: refused (exit 2)" '[ $rc = 2 ]'
126check "refusal names the R11 receipt" 'grep -q "REFUSED: lane chipwait would clean .* R11 receipt" "$TMP/err.log"'
127check "refused before anything ran: no campaign dir, receipts intact" '[ ! -e "$c" ] && [ -s "$B/qual-runs/r16/R11/rx_aien_faculty_receipt.json" ] && [ -s "$B/qual-runs/r11/R11/rx_aien_faculty_receipt.json" ]'
128( . "$HERE/tools/window_lane_guard.sh"; wl_begin "$WD" r11; wl_r11_archive "$WD" "$B" )
129c=$TMP/g2; WINDOW_LANE_OUT=$WD STUB_CLEAN=1 run "$c"
130check "only the newest R11 receipt archived: still refused" '[ $rc = 2 ] && [ ! -e "$c" ] && [ -d "$B" ]'
131( . "$HERE/tools/window_lane_guard.sh"; wl_begin "$WD" ladder )
132( . "$HERE/tools/window_lane_guard.sh"; wl_r11_archive_all "$WD" "$B" )
133c=$TMP/g3; WINDOW_LANE_OUT=$WD STUB_CLEAN=1 run "$c"
134check "a pending ladder lane is refused by name" '[ $rc = 2 ] && grep -q "lane ladder has an unarchived receipt" "$TMP/err.log"'
135( . "$HERE/tools/window_lane_guard.sh"; wl_no_receipt "$WD" ladder )
136c=$TMP/g4; WINDOW_LANE_OUT=$WD STUB_CLEAN=1 run "$c"
137check "everything archived: the campaign runs (exit 0)" '[ $rc = 0 ] && [ "$(verdict "$c")" = PASS ]'
138check "the campaign's clean removed build/" '[ ! -e "$B" ]'
139check "both R11 receipts survive under their sha256 names" 'cmp -s "$WD/R11-living/rx_aien_faculty_receipt.$s16.json" <(printf "{\"gate\":\"PASS\",\"from\":\"R16 ladder rung\"}\n") && cmp -s "$WD/R11-living/rx_aien_faculty_receipt.$s11.json" <(printf "{\"gate\":\"PASS\",\"from\":\"r11 lane\"}\n")'
140mkdir -p "$B/qual-runs/r11/R11"; printf '{"gate":"FAIL","from":"a later r11 run"}\n' > "$B/qual-runs/r11/R11/rx_aien_faculty_receipt.json"
141c=$TMP/g5; WINDOW_LANE_OUT=$WD STUB_CLEAN=1 run "$c"
142check "a new, different R11 receipt is not covered by an old archive: refused" '[ $rc = 2 ] && [ ! -e "$c" ] && [ -s "$B/qual-runs/r11/R11/rx_aien_faculty_receipt.json" ]'
143rm -rf "$B"
144
145echo "nothing deleted"
146find "$TMP" -type f | sort > "$TMP/files.before"
147run "$TMP/after-all" ; run "$TMP/fail" ; run "$TMP/inc"
148find "$TMP" -type f | sort > "$TMP/files.after"
149check "file list before is a subset of after" '[ -z "$(comm -23 "$TMP/files.before" "$TMP/files.after")" ]'
150
151if [ "$fails" -ne 0 ]; then
152 echo "chipwait campaign tests: $fails FAILED"
153 exit 1
154fi
155echo "chipwait campaign tests: all passed"