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 / algebra / ma_digital_v1_gate.sh

151 lines · 6430 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# MIXED_ALGEBRA_DIGITAL_V1 closure gate (spec/mixed-algebra-digital-v1.md).
18# Run through `make gate-mixed-algebra-digital-v1` from the repository root.
19#
20# correctness leg -> timed bench leg (quiet flag held) -> selection over the
21# stored receipts (driver) -> separate-process reproduction -> wrapper
22# receipt evidence/MIXED_ALGEBRA/digital_v1/<sha256>.json (clean tree only).
23#
24# Environment: DV1_GATE, DV1_GATE_ASAN (driver binaries, set by make);
25# MA_DV1_REUSE_RUN=<run id> reuses evidence/MIXED_ALGEBRA/runs/<id>/
26# instead of running the bench (mode "reuse"); optional
27# MA_DV1_REUSE_SHA256="<run1 sha256> <run2 sha256>" pins those receipts to
28# externally recorded digests (e.g. from a published wrapper receipt).
29# Exit: 0 PASS, 3 FAIL (receipt written), 4 refused (quiet flag present),
30# other = error.
31set -u
32
33MAKE_CMD=${MAKE:-make}
34OUT=build/ma-dv1
35QUIET="$HOME/workspace/.spark-quiet"
36EV=evidence/MIXED_ALGEBRA
37CONT1=$EV/ma3_bench_run1.json
38CONT2=$EV/ma3_bench_run2.json
39
40[ -n "${DV1_GATE:-}" ] && [ -n "${DV1_GATE_ASAN:-}" ] || { echo "run via make gate-mixed-algebra-digital-v1"; exit 2; }
41[ -f spec/mixed-algebra-digital-v1.md ] || { echo "run from the omega repository root"; exit 2; }
42mkdir -p "$OUT" || exit 2
43STAMP=$(date -u +%Y%m%dT%H%M%SZ)
44WORK="$OUT/$STAMP"
45mkdir "$WORK" || exit 2
46
47dirty_now() {
48 a=$(git status --porcelain --untracked-files=no | grep -c .)
49 b=$(git status --porcelain -- src tests tools spec Makefile | grep -c .)
50 if [ "$a" = 0 ] && [ "$b" = 0 ]; then echo 0; else echo 1; fi
51}
52
53DIRTY0=$(dirty_now)
54COMMIT=$(git rev-parse HEAD)
55echo "gate: commit $COMMIT tree_dirty=$DIRTY0"
56
57# ---- correctness leg ------------------------------------------------------
58CORR="$WORK/correctness.txt"
59: > "$CORR"
60run_check() { # label target summary-grep
61 log="$WORK/$2.log"
62 if $MAKE_CMD --no-print-directory "$2" > "$log" 2>&1; then st=PASS; else st=FAIL; fi
63 line=$(grep -E "$3" "$log" | tr '\n' ';' | sed 's/;$//')
64 [ -n "$line" ] || { line="no summary line"; st=FAIL; }
65 echo "$st $1: $line" >> "$CORR"
66 echo "gate: $st $1: $line"
67}
68run_check "test-algebra" test-algebra "^OMA ALGEBRA:"
69run_check "test-algebra-asan" test-algebra-asan "^OMA ALGEBRA:"
70run_check "test-realize (plain+asan)" test-realize "^MA2 test-realize"
71run_check "test-turing (plain+asan)" test-turing "^test-turing:"
72run_check "bottom coverage (plain+asan)" test-ma-digital-bottom "^MA_DIGITAL_V1 bottom"
73
74# ---- measurement leg ------------------------------------------------------
75if [ -n "${MA_DV1_REUSE_RUN:-}" ]; then
76 MODE=reuse
77 RUN_ID=$MA_DV1_REUSE_RUN
78else
79 MODE=fresh
80 RUN_ID="$STAMP"
81 if [ -e "$QUIET" ]; then
82 echo "gate: REFUSED: $QUIET exists (another timed measurement). Wait and rerun; nothing written."
83 exit 4
84 fi
85 touch "$QUIET" || exit 2
86 trap 'rm -f "$QUIET"' EXIT INT TERM HUP
87 echo "gate: quiet flag held; bench-mixed-algebra MA2_RUN_ID=$RUN_ID"
88 $MAKE_CMD --no-print-directory bench-mixed-algebra MA2_RUN_ID="$RUN_ID" > "$WORK/bench.log" 2>&1
89 brc=$?
90 rm -f "$QUIET"
91 trap - EXIT INT TERM HUP
92 tail -3 "$WORK/bench.log"
93 if [ $brc -ne 0 ]; then
94 echo "FAIL bench-mixed-algebra: exit $brc (see $WORK/bench.log)" >> "$CORR"
95 fi
96fi
97R1=$EV/runs/$RUN_ID/ma2_bench_run1.json
98R2=$EV/runs/$RUN_ID/ma2_bench_run2.json
99[ -f "$R1" ] && [ -f "$R2" ] || { echo "gate: missing receipts in $EV/runs/$RUN_ID"; exit 2; }
100
101# Pin the receipt bytes now (right after the bench wrote them, or when a reuse
102# run is chosen). The driver re-hashes against these before ingest and before
103# writing the wrapper; any change in between is an error (exit 2), not a
104# verdict. Reuse mode may pin externally recorded digests instead with
105# MA_DV1_REUSE_SHA256="<run1 sha256> <run2 sha256>".
106if [ "$MODE" = reuse ] && [ -n "${MA_DV1_REUSE_SHA256:-}" ]; then
107 set -- $MA_DV1_REUSE_SHA256
108 [ $# -eq 2 ] || { echo "gate: MA_DV1_REUSE_SHA256 needs two digests"; exit 2; }
109 S1=$1; S2=$2
110else
111 S1=$(sha256sum "$R1" | cut -c1-64)
112 S2=$(sha256sum "$R2" | cut -c1-64)
113fi
114S3=$(sha256sum "$CONT1" | cut -c1-64)
115S4=$(sha256sum "$CONT2" | cut -c1-64)
116DV1_EXPECT_SHA256="$R1=$S1 $R2=$S2 $CONT1=$S3 $CONT2=$S4"
117export DV1_EXPECT_SHA256
118echo "gate: pinned receipts $R1=$S1 $R2=$S2"
119
120DIRTY1=$(dirty_now)
121DIRTY=0
122[ "$DIRTY0" = 0 ] && [ "$DIRTY1" = 0 ] && [ "$(git rev-parse HEAD)" = "$COMMIT" ] || DIRTY=1
123git status --porcelain --untracked-files=all | sed -n 's/^?? //p' > "$WORK/untracked.txt"
124
125# ---- selection reproduction in separate processes -------------------------
126"$DV1_GATE" digests "$R1" "$R2" > "$WORK/digests_proc1.txt" || exit 2
127"$DV1_GATE" digests "$R1" "$R2" > "$WORK/digests_proc2.txt" || exit 2
128"$DV1_GATE_ASAN" digests "$R1" "$R2" > "$WORK/digests_asan.txt" || exit 2
129
130# ---- decision + wrapper receipt -------------------------------------------
131RCPT="$WORK/receipt.json"
132DV1_COMMIT=$COMMIT DV1_TREE_DIRTY=$DIRTY DV1_MODE=$MODE DV1_RUN_ID=$RUN_ID DV1_CORRECTNESS="$CORR" \
133DV1_UNTRACKED="$WORK/untracked.txt" \
134DV1_REPRO_FILES="process_2=$WORK/digests_proc1.txt process_3=$WORK/digests_proc2.txt asan_process=$WORK/digests_asan.txt" \
135 "$DV1_GATE" receipt "$RCPT" "$R1" "$R2" "$CONT1" "$CONT2"
136grc=$?
137[ $grc -eq 0 ] || [ $grc -eq 3 ] || { echo "gate: driver error $grc"; exit 2; }
138
139if [ "$DIRTY" != 0 ]; then
140 echo "gate: tree dirty; receipt kept at $RCPT only (not published to evidence/)"
141 exit $grc
142fi
143H=$(sha256sum "$RCPT" | cut -c1-64)
144DEST=$EV/digital_v1/$H.json
145mkdir -p $EV/digital_v1
146if [ -e "$DEST" ]; then echo "gate: $DEST exists; refusing to overwrite"; exit 2; fi
147cp "$RCPT" "$DEST" || exit 2
148echo "gate: receipt $DEST"
149echo "gate: fresh receipts $R1 $R2"
150$MAKE_CMD --no-print-directory check-mixed-algebra-evidence || exit 2
151exit $grc