interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / doctrine / corpus.sh

131 lines · 11135 bytes Raw Blame History
1#!/usr/bin/env bash
2# corpus.sh: parity corpus for tools/doctrine/doctrine.om against the retired bash oracle.
3# Builds mutated copies of the doctrine tree under a scratch directory, runs the oracle and
4# the .om binary on each, and compares stdout and exit code byte for byte.
5#
6# usage: tools/doctrine/corpus.sh ORACLE.sh DOCTRINE-BINARY [REPO-ROOT]
7# ORACLE.sh the bash script (git show <sha>:scripts/check_doctrine.sh > /tmp/oracle.sh)
8# DOCTRINE-BINARY the compiled doctrine.om
9# Exit 0 when every case is identical, 1 otherwise. Scratch dir: $CORPUS_DIR or mktemp.
10set -u
11export LC_ALL=C
12ORACLE="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
13BIN="$(cd "$(dirname "$2")" && pwd)/$(basename "$2")"
14ROOT="${3:-$(cd "$(dirname "$0")/../.." && pwd)}"
15WORK="${CORPUS_DIR:-$(mktemp -d)}"
16mkdir -p "$WORK"
17HB='<!-- HISTORICAL-PROVENANCE:BEGIN -->'
18HE='<!-- HISTORICAL-PROVENANCE:END -->'
19
20n=0; bad=0
21# fresh <name>: a copy of the real tree (only the files in scope) at $D
22fresh() { D="$WORK/$1"; rm -rf "$D"; mkdir -p "$D/doctrine" "$D/docs"
23 cp "$ROOT"/doctrine/*.md "$D/doctrine/"; cp "$ROOT"/docs/milestone-*-spec.md "$D/docs/"; }
24# app <file> <text...>: append one line
25app() { f="$1"; shift; printf '%s\n' "$*" >> "$D/$f"; }
26# run <name>: oracle vs .om on $D (or on a literal path when $2 is given)
27run() { n=$((n + 1)); t="${2:-$D}"
28 (cd / && env PATH=/usr/bin:/bin bash "$ORACLE" "$t") > "$WORK/$1.sh.out" 2> "$WORK/$1.sh.err"; a=$?
29 (cd / && "$BIN" "$t") > "$WORK/$1.om.out" 2> "$WORK/$1.om.err"; b=$?
30 if [ "$a" = "$b" ] && cmp -s "$WORK/$1.sh.out" "$WORK/$1.om.out"; then
31 printf 'ok %-28s exit %s, %s line(s)\n' "$1" "$a" "$(wc -l < "$WORK/$1.om.out")"
32 else
33 bad=$((bad + 1)); printf 'DIFF %-28s exit sh=%s om=%s\n' "$1" "$a" "$b"
34 diff "$WORK/$1.sh.out" "$WORK/$1.om.out" | head -20
35 fi; }
36
37fresh real; run real "$ROOT"
38
39fresh c01-status-tag; app doctrine/AIEN.md 'The ledger is [COMPLETE] and [IN PROGRESS] and [QEMU QUALIFIED] here.'
40app doctrine/TRUST.md ' [COMPLETE / QEMU QUALIFIED]'; app doctrine/TRUST.md '[REOPENED anything at all]'; app doctrine/TRUST.md '[REOPENED without close'; run c01-status-tag
41
42fresh c02-wrong-number; app doctrine/OMEGA.md 'See Milestone 3 (`DOCTRINE_V1`) and `OMEGA_VERIFY` (M8) later.'
43app doctrine/OMEGA.md 'Milestones 12 - OMEGA_LIVING_MATVEC is fine but MILESTONE 11 — OMEGA_LIVING_MATVEC is not.'
44app doctrine/OMEGA.md 'Correct: Milestone 7 (`OMEGA_VERIFY`); and `PHYSICS_BOOT` (Milestone 2).'
45app docs/milestone-5-spec.md 'M27: AIEN_HUMAN_INTERFACE'; app docs/milestone-5-spec.md 'PHYSICS_EFFECTS (MILESTONE 4)'; run c02-wrong-number
46
47fresh c03-unbalanced-begin; app doctrine/TRUST.md "$HB"; app doctrine/TRUST.md 'ALPHA inside the open block is blanked'; run c03-unbalanced-begin
48fresh c04-unbalanced-end; app doctrine/FORGE.md 'ALPHA before'; app doctrine/FORGE.md "$HE"; app doctrine/FORGE.md 'ALPHA after'; run c04-unbalanced-end
49fresh c05-nested-begin; app doctrine/FORGE.md "$HB"; app doctrine/FORGE.md "$HB"; app doctrine/FORGE.md "$HE"; app doctrine/FORGE.md "$HE"; run c05-nested-begin
50
51fresh c06-row-deleted; sed -i '/^| \*\*M5\*\* |/d' "$D/doctrine/ROADMAP.md"; run c06-row-deleted
52fresh c07-28-milestone; app doctrine/OMEGA.md 'The old 28-milestone plan, a 31-Milestone list, and the 128-milestone joke.'
53app doctrine/OMEGA.md 'Twenty-eight precise milestones; twenty-eight milestones; Thirty-one milestones; thirty-one milestones.'; run c07-28-milestone
54
55fresh c08-alpha; app doctrine/ATLAS.md 'ALPHA release and the Alpha stage and alpha.bin and alpha.memory-map.'
56app doctrine/ATLAS.md 'alphabet alpha.binary ALPHA_X xAlpha alpha.audit. alpha.sha256)'; app doctrine/ATLAS.md 'éALPHA ALPHAé _ALPHA'; run c08-alpha
57
58fresh c09-el1; app doctrine/PHYSICS.md 'Monotonic Handoff (EL1) and EL1 handoff and at EL1 privilege level'
59app doctrine/PHYSICS.md 'EL1 Jump; strictly at **EL1**; EL1 HANDOFF (no)'; run c09-el1
60
61fresh c10-m27-closure; app doctrine/SOVEREIGNTY.md 'Milestone 27 — SOVEREIGN_MACHINE_CLOSURE'
62app doctrine/SOVEREIGNTY.md '| M27 | SOVEREIGN_CLOSURE |'; app doctrine/SOVEREIGNTY.md 'SOVEREIGN_CLOSURE lands at M 27.'
63app doctrine/SOVEREIGNTY.md 'XM27 AIEN_HUMAN_INTERFACE'; app doctrine/SOVEREIGNTY.md 'XM27 SOVEREIGN_CLOSURE'; app doctrine/SOVEREIGNTY.md 'M270 SOVEREIGN_CLOSURE'; run c10-m27-closure
64
65fresh c11-retired; app doctrine/ATLAS.md 'SENTINEL_GATE_3 and SENTINEL_GATE_12 and ATLAS_BOOT and PHYSICS_CORE_MEMBRANE.'
66app doctrine/ATLAS.md 'xBOOTSTRAP_SEED_ATLAS AIEN_SEED_TOPOLOGYx (AIEN_SEED_TRAINING)'; run c11-retired
67
68fresh c12-physics-zero; app doctrine/DISCOVERY.md 'Physics Zero spans M26-M35.'
69app doctrine/DISCOVERY.md 'M27-M35 (Physics Zero) is right; M27-M36 (physics zero) is not.'
70app doctrine/DISCOVERY.md 'Physics Zero M27–M35 with an en dash never matches gawk in C.'
71app doctrine/DISCOVERY.md 'Physics Zero runs M27 - M35 exactly.'
72app doctrine/DISCOVERY.md 'Physics Zero (see M1-M2) M27-M35 takes the longest match.'
73app doctrine/DISCOVERY.md 'Physics Zero. M26-M35 after a dot is out of reach.'
74app doctrine/DISCOVERY.md 'physics zero M27-M35 and then physics zero M27-M34.'; run c12-physics-zero
75
76fresh c13-roadmap-status; sed -i 's/^\(| \*\*M30\*\* | \)Physics Zero Discovery/\1Foundational/; s/^\(| \*\*M10\*\* | \)[^|]*|/\1General AIEN |/; s/^\(| \*\*M8\*\* | \)[^|]*|/\1Physics Zero Discovery |/' "$D/doctrine/ROADMAP.md"
77sed -i '/^| \*\*M12\*\* |/ s/| [^|]*|$/| DONE |/' "$D/doctrine/ROADMAP.md"; run c13-roadmap-status
78
79fresh c14-dup-table; app doctrine/INDEX.md '| **M3** | x |'; app doctrine/INDEX.md ' M12: OMEGA_X'; app doctrine/INDEX.md 'M123: ABCD'; app docs/milestone-3-spec.md ' M4: PHYSICS_EFFECTS'; run c14-dup-table
80
81fresh c15-roadmap-missing; rm "$D/doctrine/ROADMAP.md"; app doctrine/OMEGA.md 'Milestone 3 (`DOCTRINE_V1`)'; run c15-roadmap-missing
82fresh c16-roadmap-is-dir; rm "$D/doctrine/ROADMAP.md"; mkdir "$D/doctrine/ROADMAP.md"; run c16-roadmap-is-dir
83
84fresh c17-historical-blanked; app doctrine/TRUST.md "$HB"; app doctrine/TRUST.md 'ALPHA [COMPLETE] 28-milestone Milestone 3 (`DOCTRINE_V1`)'; app doctrine/TRUST.md "$HE"; app doctrine/TRUST.md 'clean after'; run c17-historical-blanked
85
86fresh c18-strip-and-cut; app doctrine/OMEGA.md "$(printf '\t \r ALPHA %0300d' 0)"; app doctrine/OMEGA.md "$(printf '%0170dALPHA' 0)"; run c18-strip-and-cut
87fresh c19-crlf; sed -i 's/$/\r/' "$D/docs/milestone-2-spec.md"; app docs/milestone-2-spec.md $'[COMPLETE]\r'; sed -i 's/$/\r/' "$D/doctrine/ROADMAP.md"; run c19-crlf
88
89fresh c20-extra-files; app doctrine/zz.md 'ALPHA'; app doctrine/Aa.md 'ALPHA'; app doctrine/.hidden.md 'ALPHA'; mkdir "$D/doctrine/sub.md"; app doctrine/sub.md/x.md 'ALPHA'
90app docs/milestone--spec.md 'ALPHA'; app docs/milestone-x-spec.md.txt 'ALPHA'; app docs/milestone-spec.md 'ALPHA'; app docs/Milestone-9-spec.md 'ALPHA'
91ln -s AIEN.md "$D/doctrine/link.md"; ln -s nowhere "$D/doctrine/dangling.md"; app doctrine/_under.md 'ALPHA'; app doctrine/ZZ.md 'ALPHA'; app doctrine/a.md 'ALPHA'; run c20-extra-files
92
93fresh c21-no-trailing-newline; printf 'x\nALPHA at the very end' >> "$D/doctrine/TRUST.md"; run c21-no-trailing-newline
94fresh c22-empty-file; : > "$D/doctrine/EMPTY.md"; printf '\n' > "$D/doctrine/NL.md"; run c22-empty-file
95
96fresh c23-milestone-emdash; app doctrine/OMEGA.md 'MILESTONE 12 — foo'; app doctrine/OMEGA.md ' MILESTONE 12 — x'; app doctrine/OMEGA.md 'MILESTONE 12 —x'; run c23-milestone-emdash
97fresh c24-m-range-m27; app doctrine/OMEGA.md 'M1-M27 and M1 – M27 and M1–M27 and M1-M270 and xM1-M27 and M1-M27x'; run c24-m-range-m27
98fresh c25-physics-boot; app doctrine/PHYSICS.md 'PHYSICS_BOOTSTRAP is COMPLETE'; app doctrine/PHYSICS.md 'PHYSICS_BOOT | COMPLETE'; app doctrine/PHYSICS.md 'PHYSICS_BOOT_COMPLETE and PHYSICS_BOOT COMPLETED'; run c25-physics-boot
99
100fresh c26-roadmap-leading-zero; sed -i 's/^| \*\*M5\*\* |/| **M05** |/' "$D/doctrine/ROADMAP.md"; app doctrine/OMEGA.md 'Milestone 5 (`OMEGA_AARCH64`) and `OMEGA_AARCH64` (M05)'; run c26-roadmap-leading-zero
101
102fresh c27-two-per-line; app doctrine/OMEGA.md 'Milestone 7 (`OMEGA_VERIFY`) then Milestone 9 (`OMEGA_VERIFY`) then Milestone 10 (`OMEGA_VERIFY`)'
103app doctrine/OMEGA.md '`OMEGA_VERIFY` (M7) then `OMEGA_VERIFY` (M9) and Milestone 9 (`DOCTRINE_V1`)'; run c27-two-per-line
104
105fresh c28-roadmap-historical; sed -i "/^| \*\*M38\*\* |/i $HB" "$D/doctrine/ROADMAP.md"; sed -i "/^| \*\*M40\*\* |/a $HE" "$D/doctrine/ROADMAP.md"; run c28-roadmap-historical
106
107fresh c29-identifier-edges; app doctrine/OMEGA.md 'M5_OMEGA_AARCH64 and M5 _OMEGA_AARCH64 and M6__OMEGA_AARCH64 and MILESTONE 6 ___ OMEGA_AARCH64'
108app doctrine/OMEGA.md 'THE OMEGA_AARCH64 (M6) and ABC_ (M5) and OMEGA_AARCH64` (Milestones 6) and OMEGA_AARCH64 ((M6)'
109app doctrine/OMEGA.md 'OMEGA_AARCH64`----(M6) and OMEGA_AARCH64-----(M6) and OMEGA_AARCH64 (M 6) and OMEGA_AARCH64 (Milestone6)'; run c29-identifier-edges
110
111fresh c30-roadmap-short-row; sed -i 's/^| \*\*M20\*\* |.*/| **M20** | Physics Zero Discovery |/' "$D/doctrine/ROADMAP.md"; run c30-roadmap-short-row
112fresh c31-roadmap-dup-code; sed -i 's/^\(| \*\*M39\*\* | [^|]*| \)`[^`]*`/\1`OMEGA_VERIFY`/' "$D/doctrine/ROADMAP.md"; app doctrine/OMEGA.md 'Milestone 7 (`OMEGA_VERIFY`)'; run c31-roadmap-dup-code
113fresh c32-row-with-space-status; sed -i '/^| \*\*M3\*\* |/ s/| [^|]*|$/| COMPLETE |/' "$D/doctrine/ROADMAP.md"; sed -i '/^| \*\*M4\*\* |/ s/| [^|]*|$/| COMPLETE |/' "$D/doctrine/ROADMAP.md"; run c32-row-with-space-status
114
115fresh c33-many-rows; for i in $(seq 41 45); do app doctrine/ROADMAP.md "| **M$i** | General AIEN | \`EXTRA_$i\` | x | PLANNED |"; done; run c33-many-rows
116fresh c34-both-markers-one-line; app doctrine/TRUST.md "$HB $HE"; app doctrine/TRUST.md 'ALPHA blanked (BEGIN wins)'; run c34-both-markers-one-line
117fresh c35-second-begin-then-end; app doctrine/INDEX.md "$HB"; app doctrine/INDEX.md "$HE"; app doctrine/INDEX.md "$HB"; app doctrine/INDEX.md 'x'; app doctrine/INDEX.md "$HB"; run c35-second-begin-then-end
118fresh c36-relative-root; run c36-relative-root "$(realpath --relative-to=/ "$D")"
119fresh c37-row-digits-only; sed -i 's/^| \*\*M0\*\* |/| **M** |/' "$D/doctrine/ROADMAP.md"; app doctrine/ROADMAP.md '| **M41** |'; run c37-row-digits-only
120fresh c39-roadmap-no-rows; sed -i '/^| \*\*M[0-9]*\*\* |/d' "$D/doctrine/ROADMAP.md"; app doctrine/OMEGA.md 'Milestone 3 (`DOCTRINE_V1`)'; run c39-roadmap-no-rows
121
122# missing ROOT: exit 2, empty stdout, and the script's own stderr line (bash prints its own
123# "cd: ... No such file or directory" diagnostic first; that shell line is not reproduced)
124n=$((n + 1)); (cd / && env PATH=/usr/bin:/bin bash "$ORACLE" "$WORK/does-not-exist") > "$WORK/c38.sh.out" 2> "$WORK/c38.sh.err"; a=$?
125(cd / && "$BIN" "$WORK/does-not-exist") > "$WORK/c38.om.out" 2> "$WORK/c38.om.err"; b=$?
126if [ "$a" = "$b" ] && cmp -s "$WORK/c38.sh.out" "$WORK/c38.om.out" && [ "$(tail -n 1 "$WORK/c38.sh.err")" = "$(cat "$WORK/c38.om.err")" ]; then
127 printf 'ok %-28s exit %s (script stderr line identical)\n' c38-missing-root "$a"
128else bad=$((bad + 1)); printf 'DIFF %-28s exit sh=%s om=%s\n' c38-missing-root "$a" "$b"; fi
129
130echo "corpus: $n cases, $bad differ (work dir $WORK)"
131[ "$bad" = 0 ]