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 / tests / physics0 / learner / test_pd0b_run.sh

69 lines · 4349 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# Test of pd0b_run.sh law-record retention and validity, with a fake harness in a throw-away git repo.
18set -eu
19SRC=$(pwd); T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
20fail=0; check() { if ! eval "$1"; then echo "FAIL: $1"; fail=1; fi; }
21mkdir -p "$T/tests/physics0/learner" "$T/src/physics0/learner" "$T/src/physics0/ladder" "$T/src/physics0/score" "$T/src/physics0/controls" "$T/tests/physics0/verify"
22cp tests/physics0/learner/pd0b_run.sh tests/physics0/learner/pd0b_freeze.sh "$T/tests/physics0/learner/"
23for d in learner ladder score controls; do echo x > "$T/src/physics0/$d/f.c"; done; echo x > "$T/tests/physics0/verify/f.c"
24cat > "$T/harness" <<'EOS'
25#!/bin/sh
26# fake harness: world - level seed outdir. FAKE=nolaw: REPLICATED but no law record; FAKE=reject: law file but verifier rejected
27L=$3; S=$4; O=$5; [ "$L" = null ] || L=L$L; [ "$L" = nullL ] && L=null
28st=REPLICATED; lrc=0
29[ "${FAKE:-}" != nolaw ] || lrc=-1
30[ "${FAKE:-}" != reject ] || lrc=3
31if [ "$lrc" != -1 ]; then echo "law-bytes-$L-$S" > "$O/pd0l-$L-s$S.law"; fi
32echo ledger > "$O/pd0l-$L-s$S.ledger"
33echo "PD0L level=$L seed=$S state=$st code=0 law=$lrc score=PASS score_code=0"
34echo "PD0F level=$L seed=$S final=00 final_status=0 score_before_final=0 shape_before_final=0 play_after_final=0 dup_final=0 audit_ok=1 mode=SEALED s_star=2 n_vars=2 n_latent=0 n_channels=1 valid=VALID"
35EOS
36chmod +x "$T/harness"; printf '#!/bin/sh\nexit 0\n' > "$T/world"; chmod +x "$T/world"
37for s in 1 2 3 4 5; do echo "0 $s"; done > "$T/seeds.txt"
38( cd "$T" && git init -q && git add -A && git -c user.email=t@t -c user.name=t commit -q -m t )
39run() { ( cd "$T" && env PD0B_LEDGER_ARCHIVE="$T/archive" "$@" sh tests/physics0/learner/pd0b_run.sh ./harness ./world seeds.txt note ) > "$T/out.txt" 2>&1; }
40# good run
41run FAKE=none; rc=$?; R=$(ls "$T"/evidence/physics0/pd0b/PD0B_RUN-*.txt | head -1)
42check "[ -f '$R' ]"; check "grep -q '^run_validity: VALID' '$R'"
43check "grep -q '^validity_rule:.*law=1' '$R'"
44D="${R%.txt}-laws"; check "[ -d '$D' ]"
45check "[ -f '$D/pd0l-L0-s1.law' ] && [ ! -e '$D/pd0l-L0-s1.ledger' ]"
46A="$T/archive/$(basename "${R%.txt}")-ledgers"; check "[ -f '$A/pd0l-L0-s1.ledger' ]"
47nled=$(ls "$A" | wc -l); nman=$(wc -l < "$D/LEDGERS.sha256")
48check "[ $nled -eq 5 ] && [ $nman -eq 5 ]"
49check "(cd '$A' && sha256sum -c '$D/LEDGERS.sha256' >/dev/null)"
50check "grep -q '^ledger_archive: $A\$' '$R'"
51msha=$(sha256sum "$D/LEDGERS.sha256" | cut -d' ' -f1)
52check "grep -q '^ledgers_manifest_sha256: $msha' '$R'"
53sha=$(sha256sum "$D/pd0l-L0-s1.law" | cut -d' ' -f1)
54check "grep -q '^level=L0 seed=1 state=REPLICATED code=0 score=PASS score_code=0 law=1 law_sha256=$sha\$' '$R'"
55check "[ \$(grep -c ' law=1 law_sha256=' '$R') -eq 5 ]"
56# the laws directory is never overwritten, nor the receipt
57run FAKE=none && { echo "FAIL: second run succeeded"; fail=1; } || true
58check "grep -q 'refusing to overwrite' '$T/out.txt'"
59rm -rf "$T/evidence" "$T/archive"
60# REPLICATED without a law record: INVALID, law=0, law_sha256=-
61run FAKE=nolaw && { echo "FAIL: nolaw run succeeded"; fail=1; } || true
62R=$(ls "$T"/evidence/physics0/pd0b/PD0B_RUN-*.txt | head -1)
63check "grep -q '^run_validity: INVALID' '$R'"; check "grep -q 'seed=1 state=REPLICATED code=0 score=PASS score_code=0 law=0 law_sha256=-\$' '$R'"
64rm -rf "$T/evidence" "$T/archive"
65# law bytes present but the verifier rejected them: law=0, INVALID
66run FAKE=reject && { echo "FAIL: reject run succeeded"; fail=1; } || true
67R=$(ls "$T"/evidence/physics0/pd0b/PD0B_RUN-*.txt | head -1)
68check "grep -q '^run_validity: INVALID' '$R'"; check "grep -q 'seed=2 state=REPLICATED.* law=0 law_sha256=-\$' '$R'"
69[ "$fail" = 0 ] && echo "PD0B_RUN_TEST: PASS" || { echo "PD0B_RUN_TEST: FAIL"; exit 1; }