interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / omega-reference / check.sh

78 lines · 4028 bytes Raw Blame History
1#!/bin/sh
2# Host orchestration only. page.om (seeded Omega) writes main.html from the
3# vendored omega-harness guide and examples; this script checks the inputs,
4# gates every example with the pinned omc and publishes the page.
5# check.sh full check; needs OMEGA_OMC, the omc pinned in vendor.pin
6# check.sh --hashes inputs and output against their recorded hashes only
7# Optional OMEGA_HARNESS=<omega-harness clone> also compares vendor/ with
8# git archive of the pinned commit.
9set -eu
10cd "$(dirname "$0")"
11vendor_ok() {
12 (cd vendor && sha256sum --quiet -c ../vendor.sha256) || { echo 'vendor/ differs from vendor.sha256' >&2; exit 3; }
13 [ "$(find vendor -type f | wc -l)" -eq "$(wc -l < vendor.sha256)" ] || { echo 'vendor/ holds a file vendor.sha256 does not list' >&2; exit 3; }
14}
15vendor_ok
16if [ "${1:-}" = --hashes ]; then
17 sha256sum --quiet -c main.html.sha256
18 printf 'OMEGA-REFERENCE HASHES PASS files=%s main=%s\n' "$(wc -l < vendor.sha256)" "$(cut -d' ' -f1 main.html.sha256)"
19 exit 0
20fi
21[ $# -eq 0 ] || { echo 'usage: check.sh [--hashes]' >&2; exit 2; }
22omc=${OMEGA_OMC:?set OMEGA_OMC to the omc pinned in vendor.pin}
23pin=$(awk '$1 == "omc-sha256" { print $2 }' vendor.pin)
24commit=$(awk '$1 == "omega-harness" { print $2 }' vendor.pin)
25[ "$(sha256sum "$omc" | cut -d' ' -f1)" = "$pin" ] || { echo 'Compiler pin mismatch' >&2; exit 3; }
26work=$(mktemp -d)
27trap 'rm -rf "$work"' EXIT HUP INT TERM
28if [ -n "${OMEGA_HARNESS:-}" ]; then
29 mkdir "$work/h"
30 git -C "$OMEGA_HARNESS" archive "$commit" examples skills/writing-omega/SKILL.md skills/omega-encoding/examples | tar -x -C "$work/h"
31 rm -f "$work/h/examples/WOLFRAM.md"
32 diff -r "$work/h" vendor > /dev/null || { echo "vendor/ differs from omega-harness $commit" >&2; exit 3; }
33 echo "vendor/ equals omega-harness $commit"
34fi
35# Every worked example on the page: compiled and run by the harness gate.
36bash vendor/examples/gate.sh "$omc" > "$work/gate.log" 2>&1 || { cat "$work/gate.log" >&2; exit 5; }
37gate=$(grep '^GATE PASS' "$work/gate.log")
38echo "$gate"
39# Negative control: one changed expected exit code must fail the gate.
40cp -R vendor "$work/mut"
41printf 'compile 0\nexit 9\n' > "$work/mut/examples/hello.expect"
42if bash "$work/mut/examples/gate.sh" "$omc" > "$work/mut.log" 2>&1; then
43 echo 'Mutated example wrongly passed the gate' >&2; exit 5
44fi
45echo "negative control: $(grep '^GATE FAIL' "$work/mut.log")"
46# Error 24 has no example file: the recipe in the guide, run at both sizes.
47e24() {
48 { printf 'fn main to int\nx = ulong 0\nc = true\nwhile c bound 1\n'
49 yes 'x = add x 1' | head -n "$1"
50 printf 'c = false\nend\nret int and x 1\nend\n'; } > "$work/e24.om"
51 rc=0; "$omc" < "$work/e24.om" > "$work/e24" 2> "$work/e24.err" || rc=$?
52}
53e24 270000
54[ "$rc" = 24 ] && [ "$(cat "$work/e24.err")" = 'omc: line 270006: error 24' ] || { echo "error 24 recipe: rc $rc" >&2; exit 5; }
55e24 140000
56[ "$rc" = 0 ] || { echo "error 24 recipe, short loop: rc $rc" >&2; exit 5; }
57echo 'error 24 recipe: 270000 lines refused with error 24 at line 270006, 140000 lines compiled'
58"$omc" < page.om > "$work/page"
59chmod +x "$work/page"
60"$work/page" > "$work/first.html"
61"$work/page" > "$work/second.html"
62cmp "$work/first.html" "$work/second.html"
63[ -s "$work/first.html" ]
64# Negative control: a missing pin must refuse, not publish links to no commit.
65mkdir "$work/nopin"
66cp vendor.sha256 "$work/nopin/"
67ln -s "$PWD/vendor" "$work/nopin/vendor"
68if (cd "$work/nopin" && "$work/page" > refused.html 2>/dev/null); then
69 echo 'Missing vendor.pin wrongly accepted' >&2; exit 5
70fi
71stale=0
72if [ ! -f main.html ] || ! cmp -s "$work/first.html" main.html; then stale=1; fi
73cp "$work/first.html" main.html
74sha256sum main.html > main.html.sha256
75if [ "$stale" = 1 ] && [ "${OMEGA_ACCEPT_CHANGE:-0}" != 1 ]; then
76 echo 'main.html changed; commit it with its Omega source and vendor/' >&2; exit 4
77fi
78printf 'OMEGA-REFERENCE PASS compiler=%s harness=%s main=%s\n' "$pin" "$commit" "$(cut -d' ' -f1 main.html.sha256)"