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 / searchtrace / run_m23_corpus_gate.sh

96 lines · 5255 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# M23 G1 search-trace corpus gate (lane 7). Correctness only: no timing is measured.
18# 1. refuses a dirty tree (tracked or untracked changes outside build/)
19# 2. builds the searchtrace tool and runs test-searchtrace (unit, refusal, ASan/UBSan, G3 format)
20# 3. generates the corpus from the frozen task set twice and compares byte for byte
21# 4. strict verify + replay; hooks-off equivalence on the frozen set
22# 5. M9 and M14 gates on omegatool built from this tree (hooks compiled in, not installed)
23# 6. stores the corpus as evidence/M23/corpus/corpus-<digest>.txt and writes a
24# content-addressed receipt evidence/M23/receipts/m23-corpus-<sha256>.json
25# Never overwrites existing evidence: an existing file must hold identical bytes.
26set -eu
27ROOT=$(cd "$(dirname "$0")/../.." && pwd -P)
28cd "$ROOT"
29TASKSET=tests/searchtrace/frozen_taskset_v1.txt
30TOOL=build/searchtrace/searchtrace
31EVD=evidence/M23
32PHYSICS_DIR=${PHYSICS_DIR:-../physics}
33
34die() { echo "m23-corpus-gate: REFUSED: $*" >&2; exit 2; }
35
36[ -z "$(git status --porcelain --untracked-files=all)" ] || die "dirty tree; commit first (receipts record an exact commit)"
37COMMIT=$(git rev-parse HEAD)
38case "$COMMIT" in *[!0-9a-f]*|"") die "cannot read HEAD";; esac
39
40make -s searchtrace test-searchtrace >/tmp/m23gate.$$.unit 2>&1 || { tail -20 /tmp/m23gate.$$.unit; die "test-searchtrace failed"; }
41UNIT=$(grep -c '^st_corpus: .* PASS$\|^st_holdout: .* PASS$' /tmp/m23gate.$$.unit || true)
42[ "$UNIT" = 4 ] || die "expected 4 unit PASS lines (plain+asan x corpus+holdout), got $UNIT"
43
44T1=$(mktemp -d)
45trap 'rm -rf "$T1" /tmp/m23gate.$$.*' EXIT
46"$TOOL" run "$TASKSET" "$T1/run1.txt" >"$T1/run1.log"
47"$TOOL" run "$TASKSET" "$T1/run2.txt" >"$T1/run2.log"
48cmp -s "$T1/run1.txt" "$T1/run2.txt" || die "corpus differs between two runs"
49VER=$("$TOOL" verify "$T1/run1.txt" "$TASKSET")
50case "$VER" in "verify PASS digest="*) ;; *) die "verify: $VER";; esac
51DIGEST=$(echo "$VER" | sed 's/.*digest=\([0-9a-f]*\).*/\1/')
52STEPS=$(echo "$VER" | sed 's/.* steps=\([0-9]*\).*/\1/')
53REPLAY=$("$TOOL" replay "$TASKSET" "$T1/run1.txt") || die "replay: $REPLAY"
54HOOK=$("$TOOL" hookcheck "$TASKSET") || die "hookcheck: $HOOK"
55
56make -s PHYSICS_DIR="$PHYSICS_DIR" build/omegatool >/dev/null 2>"$T1/build.err" || { tail -5 "$T1/build.err"; die "omegatool build failed"; }
57./build/omegatool --run-m9-gates >"$T1/m9.log" 2>&1 || { tail -15 "$T1/m9.log"; die "M9 gates failed"; }
58./build/omegatool --run-m14-gates >"$T1/m14.log" 2>&1 || { tail -15 "$T1/m14.log"; die "M14 gates failed"; }
59tot() { sed -n 's/.*TOTAL GATES: *\([0-9]*\) *| *PASSED: *\([0-9]*\) *| *FAILED: *\([0-9]*\).*/\1 \2 \3/p' "$1" | tail -1; }
60set -- $(tot "$T1/m9.log"); M9T=${1:-0}; M9P=${2:-0}; M9F=${3:-x}
61set -- $(tot "$T1/m14.log"); M14T=${1:-0}; M14P=${2:-0}; M14F=${3:-x}
62[ "$M9F" = 0 ] && [ "$M9P" = "$M9T" ] && [ "$M9T" -gt 0 ] || die "M9 totals not all PASS ($M9P/$M9T)"
63[ "$M14F" = 0 ] && [ "$M14P" = "$M14T" ] && [ "$M14T" -gt 0 ] || die "M14 totals not all PASS ($M14P/$M14T)"
64
65mkdir -p "$EVD/corpus" "$EVD/receipts"
66CORPUS="$EVD/corpus/corpus-$DIGEST.txt"
67if [ -e "$CORPUS" ]; then cmp -s "$CORPUS" "$T1/run1.txt" || die "$CORPUS exists with different bytes"
68else cp "$T1/run1.txt" "$CORPUS"; fi
69CFILE=$(sha256sum "$CORPUS" | cut -d' ' -f1)
70TSHA=$(sha256sum "$TASKSET" | cut -d' ' -f1)
71EST=$(pgrep -c est_load || true)
72
73R="$T1/receipt.json"
74{
75 printf '{\n'
76 printf ' "schema": "omega.m23.searchtrace.corpus.receipt.v1",\n'
77 printf ' "verdict": "PASS",\n'
78 printf ' "repo_commit": "%s",\n' "$COMMIT"
79 printf ' "tree_clean": true,\n'
80 printf ' "host_arch": "%s",\n' "$(uname -m)"
81 printf ' "taskset": {"path": "%s", "sha256": "%s"},\n' "$TASKSET" "$TSHA"
82 printf ' "corpus": {"path": "%s", "end_digest": "%s", "file_sha256": "%s", "steps": %s},\n' "$CORPUS" "$DIGEST" "$CFILE" "$STEPS"
83 printf ' "two_runs_byte_identical": true,\n'
84 printf ' "replay": "%s",\n' "$(echo "$REPLAY" | cut -d' ' -f2)"
85 printf ' "hook_equivalence": "%s",\n' "$(echo "$HOOK" | cut -d' ' -f2)"
86 printf ' "unit_and_refusal_tests": "PASS (plain + ASan/UBSan, corpus + G3 holdout)",\n'
87 printf ' "m9_gates": {"exit": 0, "total": %s, "passed": %s, "failed": %s},\n' "$M9T" "$M9P" "$M9F"
88 printf ' "m14_gates": {"exit": 0, "total": %s, "passed": %s, "failed": %s},\n' "$M14T" "$M14P" "$M14F"
89 printf ' "timing_measured": false,\n'
90 printf ' "est_load_processes_at_run": %s\n' "$EST"
91 printf '}\n'
92} >"$R"
93RSHA=$(sha256sum "$R" | cut -d' ' -f1)
94OUT="$EVD/receipts/m23-corpus-$RSHA.json"
95[ -e "$OUT" ] || cp "$R" "$OUT"
96echo "m23-corpus-gate: PASS corpus=$DIGEST steps=$STEPS receipt=$OUT"