From 35cc1f8eb1f15c60e3157612d449f1bb28c4c3f1 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 5 Nov 2026 07:43:46 -0600 Subject: [PATCH] fix(om-units): preserve absolute and hosted-only unit overrides --- .crumb | 36 +++--- CONTRIBUTORS.md | 1 + om/units.sh | 12 +- tests/.crumb | 78 ++++++------- tests/test_om_units_overrides.py | 189 +++++++++++++++++++++++++++++++ 5 files changed, 257 insertions(+), 59 deletions(-) create mode 100644 tests/test_om_units_overrides.py diff --git a/.crumb b/.crumb index 622707972..d06084acd 100644 --- a/.crumb +++ b/.crumb @@ -42,80 +42,80 @@ "children": [ { "digest": "9f19f11674ca5dfc3c9c3ae35fe6106557aee9583210da13d257e1b9d88e052c", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "calibration", "purpose": "Directory calibration. Purpose not yet described by a human." }, { "digest": "6eb2ceac3cd92a2107ced5ad4ad3023ef3b79c05816063572c180600465deacf", - "last_commit": "e673cbb52", + "last_commit": "e673cbb5", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { "digest": "536f7b8db9a92a1f586bad4379d47544a30d1b8e83c2d799c18e66cf8660c9ae", - "last_commit": "30bb116cc", + "last_commit": "30bb116c", "name": "doctrine", "purpose": "Directory doctrine. Purpose not yet described by a human." }, { "digest": "1d027cfb699f8ebe4ad85158dff7d7c3b1539b5eb2b53f39ec8fdd593017fb31", - "last_commit": "e673cbb52", + "last_commit": "e673cbb5", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, { "digest": "58fa9ff7fa255befd7b2f7ff95f5be838c5797faa8c231b64dbe39ea15d80b01", - "last_commit": "e6d145055", + "last_commit": "e6d14505", "name": "native", "purpose": "Handwritten .om units of omega-mv that are not part of the seed ladder: the ORIG-4 shadow adviso" }, { "digest": "012dce5a57d2e546d47b2e676789550aaf4c84f898c3373cdba9d77eca71dad5", - "last_commit": "882e93c0f", + "last_commit": "882e93c0", "name": "neuralese", "purpose": "Bounded untrusted representation envelopes and explicit checked Omega decoding; learned extensio" }, { "digest": "16bd56102894984869d56d0ee92a56ccc51adf6d28ce2be40c39b3b35a3dd0c1", - "last_commit": "bd77148a4", + "last_commit": "bd77148a", "name": "research", "purpose": "Directory research. Purpose not yet described by a human." }, { "digest": "a242049489d69509b31f11fb24201b86a111cdc27b6282b8ecea4f5d4c6fd243", - "last_commit": "326c414f3", + "last_commit": "326c414f", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { "digest": "6e250e32fb5f61a07916ccf914680d344504b4130d4d11aac6186ada2c0db788", - "last_commit": "e673cbb52", + "last_commit": "e673cbb5", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "58f22402d9b0849093ddae0c364872f3623adca238d3a07362b3b2367970de72", - "last_commit": "e673cbb52", + "digest": "c15a88cef7c4ef186a02ebe366999aa33e51b2b64050e03fcf1933a895d18d3a", + "last_commit": "96693b8e", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "c380fc34fc2b67641cb15154ccfae807e45b0c5408f244c17b51096ba9586c18", - "last_commit": "e6d145055", + "last_commit": "e6d14505", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:aa8991b5ca6aab1084402a0675a7734db8ff47a5964a1957a806c83d450e8807", - "compiled_at": "2026-11-05T13:04:30Z", + "children_root": "sha256:c39b99afaeddd0f3572e45cd97ddf27ffa7caac4f10de01740b1e2bbe7505e35", + "compiled_at": "2026-11-05T13:41:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:aac0e0cc7eb6abbd6887a3471e6f3d5db5a4c7aa49d2d72410f60a034ccfea14", + "digest": "sha256:6a26880b4aea02a63b9f8e9935d3ac6193c1644fd2ad1fdba1d6d5cad2bcd6d0", "evidence_files": 15321, "evidence_root": "sha256:e4e83d089b086dd1dcab0cfd4babe338eab359310746dbddc14edd655012c33f", - "files": 23689, - "generated_at_commit": "e673cbb52742e8a54ca64653faa61fffbd324fd7", - "source_tree": "sha256:3994895183f3ad2ca608b43366d6212ef0f27a939d3a0c1332a3e0dc6755c859" + "files": 23690, + "generated_at_commit": "37fa50340345bbecd702e3ce49c95e9df24529d7", + "source_tree": "sha256:637afebec7c4ee5c0b37e7b53611e7c4b398b3e78e937a339dfa91b55b528c3e" }, "owner_lane": "", "provenance": { diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 05fc8203a..820c68676 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -7,6 +7,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE | Model | What it did | |---|---| +| OpenAI Codex | Restored absolute-path and hosted-only OMEGA_UNITS overrides after the freestanding binding cutover, with host-only shell orchestration regression controls. | | Claude Opus 5.5 (via omp) | #1015 review fixes. `tests/x86efi/run.sh` checks the exit status only inside the boot branch, after a serial log exists and the disk check passed; with main's omc `be8c5130` the old script printed `PASS exit e1: returned without a trap` after `cannot open .../exit-e1/serial.log`, the new one does not (SUMMARY pass=2 fail=5), and omc `b4f45121` gives SUMMARY pass=11 fail=0 under QEMU q35 + OVMF (EMULATED). `tools/x86efi/corpus_diff.sh` is NOT_RUN (exit 3) without `file`, and a compiler killed by a signal (exit 129 or above, 139 SIGSEGV under qemu-user) gets verdict `signal` plus a `CORPUS_DIFF_SIGNAL` stderr line instead of counting as a refusal; native AArch64 reruns reproduce both committed TSVs byte for byte. Error 25 meaning in `seed/omc/error-codes.reg` and OMEGESE covers the x86efi refusals; OMEGESE states efi OP outside 0..13 is error 25 and a non-literal OP error 16 (both observed with omc `b4f45121`). Recorded the native tape suite (`checks=302`) and native float parity. omc bytes unchanged. | | Grok 4.7 (via Cursor Agent) | Repinned `native/prefetch/compiler.sha256` to omc `b4f45121` and `omc.om` `16b4ca40`. `tools/run_gpu_l2d_prefetch_chip.sh --host-qualification` PASS, `prefetch_cases` 53, classifier `b527a20c5b93e98f109e0cfe1974b8eeff246f6ff7551005796ab89d7c5cb25d`. | | Grok 4.7 (via Cursor Agent) | `tools/x86efi/corpus_diff.sh` on the 1305 tracked `.om` files, omc `b4f45121` against `be8c5130`: as stored, 663 identical, 638 same-refusal, 4 differ. The earlier 664/637 count came from a reader with universal newlines, which turned CR LF and a lone CR into LF: `seed/omc/om2/s1/bad-fmt-cr.om` and `seed/qualification/om2/sec/s0s2/s2fmt/bad-cr.om` (CR LF line ends, refused error 6 and 16 as stored) then compiled, and `bad-crtext.om` (a lone CR inside a `text` literal, compiles as stored) was refused error 22. x86linux mode: 647 identical, 654 same-refusal, 4 differ. Native AArch64 run NOT_RUN (host was x86_64, qemu-user). | diff --git a/om/units.sh b/om/units.sh index 69a40b65f..8bc8513ad 100755 --- a/om/units.sh +++ b/om/units.sh @@ -22,6 +22,8 @@ # A unit, compiler or profile that changes without regenerating these files fails --check. # OMEGA_UNITS (the unit list, repo-relative or absolute) and OMEGA_UNITS_DEST (output directory, default src) # override the defaults; mk/om-encoder.mk uses them to build mutant encoders beside the real binding. +# Freestanding selection follows source-file identity, so absolute paths and aliases of FS_UNITS work. +# With no selected freestanding unit, omega_om_units_fs.c contains only a comment (no stale binding). set -eu OMC_PIN=b4f45121f6c6d5d8a6ed0f5c4f3934b7cc4bec369bfa89523699bd33928f9b55 NATIVE_PIN=2c1bf63798336e899704217d98f909b31e567289650751a55d83255c7eb8f27d @@ -48,13 +50,19 @@ for u in $UNITS; do { cat "$src"; printf '\0'; printf '%08d' "$(wc -c < "$T/u.bin")"; cat "$T/u.bin" [ $abi = 1 ] || printf 'omega-unit %s %s\n' "$name" "$OMC_PIN"; } > "$T/u.in" cat "$T/u.in" >> "$T/units.in" - case " $FS_UNITS " in *" $u "*) cat "$T/u.in" >> "$T/fs.in";; esac + for fs in $FS_UNITS; do + if [ "$src" -ef "$ROOT/$fs" ]; then cat "$T/u.in" >> "$T/fs.in"; break; fi + done echo "omega-ident 1 unit=$name abi=$abi profile=$prof src=$(sha256sum < "$src" | cut -c1-64) omc=$OMC_PIN path=$u" >> "$T/omega_om_units.ident" done { "$T/native" c < "$T/units.in"; "$T/native" apic < "$T/units.in"; } > "$T/omega_om_units.c" "$T/native" h < "$T/units.in" > "$T/omega_native.h" "$T/native" apih < "$T/units.in" > "$T/omega_api_decl.h" -{ "$T/native" freest < "$T/fs.in"; "$T/native" fapic < "$T/fs.in"; } > "$T/omega_om_units_fs.c" +if [ -s "$T/fs.in" ]; then + { "$T/native" freest < "$T/fs.in"; "$T/native" fapic < "$T/fs.in"; } > "$T/omega_om_units_fs.c" +else + printf '/* No freestanding units selected by OMEGA_UNITS. */\n' > "$T/omega_om_units_fs.c" +fi if [ "${1:-}" = --check ]; then bad=0 for f in $OUTS; do cmp -s "$T/$f" "$DEST/$f" || { echo "FAIL $DEST/$f differs from the pinned tools' output"; bad=1; }; done diff --git a/tests/.crumb b/tests/.crumb index 3fd5f2d6a..efd0f17b8 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -110,218 +110,218 @@ "children": [ { "digest": "2c1deaaa1bae6257789749edde641df61413250fe91ce6aa61a99dfb3b271306", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "algebra", "purpose": "Directory tests/algebra. Purpose not yet described by a human." }, { "digest": "63f086b68bb9ffc032cbd74931309ab34df3c8c341b57935e5db43d8bf475800", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "ans", "purpose": "Tests 1-10 for ANS (docs/ans/INERTIAL_ALIGNMENT_SPEC_V1.md): freeze/digest, hostile reference mu" }, { "digest": "2224a2d78038ae3d43c15bcbebe6636cb1327d58384c610d5de4210c002e1d88", - "last_commit": "965fb7627", + "last_commit": "965fb762", "name": "autodiff664", "purpose": "Native tape tests: differential checks, refusals, no-FMA control, compiled source mutants of nat" }, { "digest": "7b69a19958c5a5f55bba4fbc33bc6f26423358efd46311b0eacfe83bb665d4c1", - "last_commit": "450bbefd4", + "last_commit": "450bbefd", "name": "brownian", "purpose": "Directory tests/brownian. Purpose not yet described by a human." }, { "digest": "1cd97575b2b10d9313ca0df4997391612056754778bb2851bf052c146144f15e", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "canonicalization", "purpose": "Directory tests/canonicalization. Purpose not yet described by a human." }, { "digest": "e83c52ffc46da0e9df448bc5d28a70b08a8cbcd6858e8adea7a842791717c024", - "last_commit": "f5c9bd89a", + "last_commit": "f5c9bd89", "name": "compiler", "purpose": "Directory tests/compiler. Purpose not yet described by a human." }, { "digest": "9e372cfc9747befacdcf31bc8643356aaff861e81ee6640b4866170be67b5e6c", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "constraints", "purpose": "Directory tests/constraints. Purpose not yet described by a human." }, { "digest": "87a3efa5cd0aefa7821046f9a31594bfa0a109e95005a1e12f40c99a1bc6cd3d", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "crumbline", "purpose": "Directory tests/crumbline. Purpose not yet described by a human." }, { "digest": "10aa3424eded7768fee0bae0eedd062b9deac3279d2e5721439fd024493bc42b", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "dual_experiment", "purpose": "Tests for the DUAL applicability experiment: determinism (same seed, byte-identical results dige" }, { "digest": "758dde696afa847d9347fad76b0c4935e968f8af4551f0f9810ec2a37ad9847a", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "effect", "purpose": "Directory tests/effect. Purpose not yet described by a human." }, { "digest": "23e559d13ff664995baca31dc157a8cf5a860615f3ecb07a9a40fe4626b57ae3", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "estimation", "purpose": "Directory tests/estimation. Purpose not yet described by a human." }, { "digest": "b7b6391caf653c76707a21f9969126abcbc730d1243259219225fdb9bc0084e0", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "fabric", "purpose": "Directory tests/fabric. Purpose not yet described by a human." }, { "digest": "defc52a44ea0f65ba5de3468de786148ba58d292ffa217fb95629a28a569a977", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "identity", "purpose": "Directory tests/identity. Purpose not yet described by a human." }, { "digest": "6ba43d622b712a4215767cab29425016f29cce4b28eb9e4961fc67fd20e9d765", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "language", "purpose": "Directory tests/language. Purpose not yet described by a human." }, { "digest": "54f43a3416595ff5d4e64bd12afe013359e706651c39c78e2896a5799638d263", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "malformed", "purpose": "Directory tests/malformed. Purpose not yet described by a human." }, { "digest": "a03a4dd9a72f7b449342e562f6d9df1a3348fb03fb640b662956caf163dcd7e9", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "numeric_native", "purpose": "Simulated M16 driver for numeric resource-lifecycle tests. No device execution or numeric parity" }, { "digest": "a4e1544a88e0b71ced2340ed880985b6ceaad797023b74a683d470971a8d47d4", - "last_commit": "f5c9bd89a", + "last_commit": "f5c9bd89", "name": "orig4", "purpose": "ORIG-4 shadow advisor tests: shadow-test.om (in-process checks over the SYNTHETIC fixture and th" }, { "digest": "628d85f858a9ed11e4502064192aeb797bf9fe6f73a3932db520d5b9c22d43f1", - "last_commit": "f5c9bd89a", + "last_commit": "f5c9bd89", "name": "osh", "purpose": "osh lexer host driver, vendored aien-protocols PR#16 draft vectors (5ae5292)" }, { "digest": "65e84051bb8dc00b180c6b06bec58103773785eebd6d6c69c9783de5fd0e2ba9", - "last_commit": "450bbefd4", + "last_commit": "450bbefd", "name": "path", "purpose": "Directory tests/path. Purpose not yet described by a human." }, { "digest": "51f14936b27d3d21379cf05ea1b6b532cf3175a40844dac85f023a61e7a0912c", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "physics0", "purpose": "PD-0 gates: world self-test, oracle calibration, learner L0/L1/NULL, mutations, OSC differential" }, { "digest": "c8524317c751fa8f464cabc31b760cef262abba822f1843482a02e239daa81b3", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "polyglot", "purpose": "Directory tests/polyglot. Purpose not yet described by a human." }, { "digest": "6569e2cd6dbf6f792edb5d83bf0715df9dece42ca7bd9b3a291535de0492d3aa", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "program", "purpose": "Directory tests/program. Purpose not yet described by a human." }, { "digest": "c549b5b82fd026d664b35e4b1a5d7fd2aaafa13b60b541cfbba87d7522517b1d", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "r16_inventory", "purpose": "Directory tests/r16_inventory. Purpose not yet described by a human." }, { "digest": "855bd23e4c526fb49eeb430c4ea5967d3f2f9da3a5b3aa3ec9dae5b814b11a21", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "r16_negative", "purpose": "Directory tests/r16_negative. Purpose not yet described by a human." }, { "digest": "f21be04969cbf51de17118c4f81b103f712db56fd517a1f12dd0d3ac4ff3afe4", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "r16_surface", "purpose": "Directory tests/r16_surface. Purpose not yet described by a human." }, { "digest": "b0ba3448394d5f27958c38b7233ae389e5e437e327f0859749a774fb252d6b02", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "realize", "purpose": "Directory tests/realize. Purpose not yet described by a human." }, { "digest": "157018d66de5bfd149015654cf0bda1346a9cfcefe5fd552c1d54859cd9ece81", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "relations", "purpose": "Directory tests/relations. Purpose not yet described by a human." }, { "digest": "e5f68362c083510e34c41f65de3ba2d553eac8a52fbc3e4cc1f69314eac9cc32", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "reservoir", "purpose": "Reservoir tests (omega#440): Gate 1 simulator and readout checks against an independent binary64" }, { "digest": "64deb95447cff39505fbebe02d4f46ead44c223df5bf25e6e7cb24c8a4aa1312", - "last_commit": "3c73e8c8e", + "last_commit": "3c73e8c8", "name": "runtime", "purpose": "Directory tests/runtime. Purpose not yet described by a human." }, { "digest": "467652c09505ecbd82d96a5e0e7ea24b19d9216cfd1dad7c60fa8258e47594c0", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "searchtrace", "purpose": "Directory tests/searchtrace. Purpose not yet described by a human." }, { "digest": "e69616ad471704066a86bf2796776301179eada5c0aa36a7166b9aca788619f4", - "last_commit": "ed8de5736", + "last_commit": "ed8de573", "name": "synapse", "purpose": "J1 parity driver for syn_codec.osc against the sealed Rust A1 corpus (aien-dev/synapse j1-codec-" }, { "digest": "5c97916fbf20310eff2e502c526337cb093e912cb48f18d44b0345ed8a3c3240", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "train", "purpose": "Directory tests/train. Purpose not yet described by a human." }, { "digest": "7679bd1c49c7e89d8c26ccf8dfb91478f4e6e2f584745806fa8d26061dbdbb9c", - "last_commit": "d863780eb", + "last_commit": "d863780e", "name": "turing", "purpose": "Directory tests/turing. Purpose not yet described by a human." }, { "digest": "aad47a6f37231afcd415798fcd7f18cbcb541066bb958c09d44cb755ce385057", - "last_commit": "f5c9bd89a", + "last_commit": "f5c9bd89", "name": "visor", "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], "children_root": "sha256:b6f336a041665f568ae78afdb1e2c888d6dae86ba9062e01734587b55fc95806", - "compiled_at": "2026-11-05T13:04:30Z", + "compiled_at": "2026-11-05T13:41:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:58f22402d9b0849093ddae0c364872f3623adca238d3a07362b3b2367970de72", + "digest": "sha256:c15a88cef7c4ef186a02ebe366999aa33e51b2b64050e03fcf1933a895d18d3a", "evidence_files": 74, "evidence_root": "sha256:9aa38bf7dcfa5eb3499356a0a2a1dd7704fedfae2d16822a7c9e1400f3a72723", - "files": 2076, - "generated_at_commit": "e673cbb52742e8a54ca64653faa61fffbd324fd7", - "source_tree": "sha256:5a2544d2d4f13db54849a08dcfb809292bde9a30db3800cb0e06999d4a274039" + "files": 2077, + "generated_at_commit": "37fa50340345bbecd702e3ce49c95e9df24529d7", + "source_tree": "sha256:3717e2371cbb7d4ad0386cec67e9e2b867e293c48e81e82eb3e32ba73d1fee6f" }, "owner_lane": "", "provenance": { diff --git a/tests/test_om_units_overrides.py b/tests/test_om_units_overrides.py new file mode 100644 index 000000000..38b4cf956 --- /dev/null +++ b/tests/test_om_units_overrides.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python3 +"""Host-only shell orchestration checks, not Omega compilation or ABI evidence. + +Run with python3 tests/test_om_units_overrides.py. To exercise an old script, +set OM_UNITS_TEST_SCRIPT to a saved om/units.sh. Only the disposable copy's +compiler/generator pins are replaced with the hashes of explicit test doubles. +Production pins and generated files are never changed by this test. +""" +import hashlib +import os +from pathlib import Path +import re +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +SCRIPT = Path(os.environ.get("OM_UNITS_TEST_SCRIPT", ROOT / "om/units.sh")) +OUTPUTS = ( + "omega_om_units.c", "omega_native.h", "omega_api_decl.h", + "omega_om_units.ident", "omega_om_units_fs.c", +) +SHA = "om/sha256/sha256-om2.om" +B3 = "om/blake3/b3unit.om" +ENC = "om/encoder/bw_enc_sm121.om" +NATIVE_DOUBLE = b'''#!/usr/bin/env python3 +import hashlib +import os +import sys +data = sys.stdin.buffer.read() +mode = sys.argv[1] +with open(os.environ["STUB_LOG"], "a") as log: + log.write(mode + "\\n") +if not data: + print("test double: zero units refused", file=sys.stderr) + sys.exit(10) +if mode == os.environ.get("STUB_FAIL_MODE"): + print("test double: generator failure", file=sys.stderr) + sys.exit(77) +print(mode + ":" + hashlib.sha256(data).hexdigest()) +''' + + +class UnitOverrides(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory(prefix="omega-units-test-") + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + self.dest = self.root / "dest" + self.dest.mkdir() + self.bridge = self.root / "bridge" + (self.bridge / "src").mkdir(parents=True) + (self.bridge / "src/native.om").write_bytes(b"explicit generator test double\n") + self.omc = self.root / "omc" + self.omc.write_text( + "#!/usr/bin/env python3\nimport os\nimport sys\n" + "data = sys.stdin.buffer.read()\n" + "mode = 'native' if data == b'explicit generator test double\\n' else 'unit'\n" + "if mode == os.environ.get('STUB_COMPILE_FAIL'): sys.exit(76)\n" + f"sys.stdout.buffer.write({NATIVE_DOUBLE!r} if data == " + "b'explicit generator test double\\n' else b'unit-code')\n" + ) + self.omc.chmod(0o755) + script = SCRIPT.read_text() + for key, path in (("OMC_PIN", self.omc), + ("NATIVE_PIN", self.bridge / "src/native.om")): + digest = hashlib.sha256(path.read_bytes()).hexdigest() + script, count = re.subn(rf"^{key}=[0-9a-f]{{64}}$", f"{key}={digest}", + script, flags=re.MULTILINE) + self.assertEqual(count, 1, f"expected one {key} pin") + for unit in (SHA, B3, ENC): + dest = self.root / unit + dest.parent.mkdir(parents=True, exist_ok=True) + dest.write_bytes((ROOT / unit).read_bytes()) + self.script = self.root / "om/units.sh" + self.script.write_text(script) + self.log = self.root / "calls" + self.env = os.environ.copy() + for key in ("OMEGA_UNITS", "OMEGA_UNITS_DEST", "STUB_FAIL_MODE", "STUB_COMPILE_FAIL"): + self.env.pop(key, None) + self.env.update(OMEGA_OMC=str(self.omc), OMEGA_BRIDGE=str(self.bridge), + OMEGA_UNITS_DEST=str(self.dest), STUB_LOG=str(self.log)) + + def run_units(self, units=None, check=False, expected=0, **extra): + env = self.env.copy() + if units is not None: + env["OMEGA_UNITS"] = units + env.update(extra) + args = ["sh", str(self.script)] + (["--check"] if check else []) + result = subprocess.run(args, cwd=self.root, env=env, capture_output=True, text=True) + self.assertEqual(result.returncode, expected, result.stdout + result.stderr) + return result + + def fs(self): + return (self.dest / OUTPUTS[-1]).read_bytes() + + def test_default_and_check(self): + self.run_units() + self.assertEqual(set(p.name for p in self.dest.iterdir()), set(OUTPUTS)) + fs = self.fs() + self.assertTrue(fs.startswith(b"freest:")) + self.assertIn(b"\nfapic:", fs) + self.run_units(check=True) + self.run_units(SHA) + self.assertEqual(self.fs(), fs, "default freestanding output must contain only SHA") + + def test_absolute_sha(self): + self.run_units(SHA) + expected = self.fs() + self.run_units(str(self.root / SHA)) + self.assertEqual(self.fs(), expected) + self.run_units(str(self.root / SHA), check=True) + + def test_relative_dot_sha(self): + self.run_units(SHA) + expected = self.fs() + self.run_units("./om/sha256/../sha256/sha256-om2.om") + self.assertEqual(self.fs(), expected) + + def test_symlink_alias(self): + self.run_units(SHA) + expected = self.fs() + alias = self.root / "alias/sha256-om2.om" + alias.parent.mkdir() + alias.symlink_to(self.root / SHA) + self.run_units(str(alias)) + self.assertEqual(self.fs(), expected) + + def test_hosted_only_replaces_stale_fs(self): + self.run_units() + self.log.write_text("") + self.run_units(B3) + self.assertEqual(self.fs(), b"/* No freestanding units selected by OMEGA_UNITS. */\n") + self.assertEqual(self.log.read_text().splitlines(), ["c", "apic", "h", "apih"]) + self.run_units(B3, check=True) + (self.dest / OUTPUTS[-1]).write_text("stale freestanding binding\n") + self.run_units(B3, check=True, expected=1) + + def test_copied_sha_is_not_canonical_fs(self): + copied = self.root / "copy/sha256-om2.om" + copied.parent.mkdir() + copied.write_bytes((self.root / SHA).read_bytes()) + self.run_units(str(copied)) + self.assertEqual(self.fs(), b"/* No freestanding units selected by OMEGA_UNITS. */\n") + + def test_encoder_mutant_shape(self): + custom = self.root / "mutant/bw_enc_sm121.om" + custom.parent.mkdir() + custom.write_bytes((self.root / ENC).read_bytes() + b"note test mutation\n") + self.run_units() + expected = self.fs() + self.run_units(f"{SHA} {B3} {custom}") + self.assertEqual(self.fs(), expected) + + def test_generator_failures_propagate_without_copying(self): + for mode in ("c", "apic", "h", "apih", "freest", "fapic"): + with self.subTest(mode=mode): + self.run_units() + before = {p.name: p.read_bytes() for p in self.dest.iterdir()} + self.run_units(SHA, expected=77, STUB_FAIL_MODE=mode) + self.assertEqual({p.name: p.read_bytes() for p in self.dest.iterdir()}, before) + + def test_compiler_failures_propagate_without_copying(self): + for mode in ("native", "unit"): + with self.subTest(mode=mode): + self.run_units() + before = {p.name: p.read_bytes() for p in self.dest.iterdir()} + self.run_units(SHA, expected=76, STUB_COMPILE_FAIL=mode) + self.assertEqual({p.name: p.read_bytes() for p in self.dest.iterdir()}, before) + + def test_missing_sha_input_still_refuses(self): + (self.root / SHA).unlink() + self.run_units(SHA, expected=2) + self.assertEqual(list(self.dest.iterdir()), []) + + def test_pin_checks_remain_enforced(self): + self.omc.write_text(self.omc.read_text() + "# changed compiler\n") + self.run_units(expected=3) + self.assertFalse(self.log.exists()) + + def test_generator_pin_check_remains_enforced(self): + (self.bridge / "src/native.om").write_text("changed generator\n") + self.run_units(expected=3) + self.assertFalse(self.log.exists()) + + +if __name__ == "__main__": + unittest.main(verbosity=2)