diff --git a/evidence/max-cpu-evidence-path/2026-10-31/README.md b/evidence/max-cpu-evidence-path/2026-10-31/README.md new file mode 100644 index 0000000..3c6a0d4 --- /dev/null +++ b/evidence/max-cpu-evidence-path/2026-10-31/README.md @@ -0,0 +1,90 @@ +# MAX CPU evidence destination regression + +Status: EXERCISED host filesystem behavior, Linux x86_64, Python 3.12.14. +Base: `6ec6dab7668a0ca60835f8ac26996544c90b16f0` (merged #47). +Date: 2026-10-31 UTC. Related coordination: #5. + +## Exact source identity + +SHA256: + +```text +793996f12bde5ffa2b3e3ecd552dd23074da2b0188383d5c33edbb12377cd98c max-cpu/run.sh +800ef073631b70e10926a30ab1b916b0c04458395e1771a079f11ce806ebda68 max-cpu/test_run_evidence.py +9ea29b5a6f9f6281c65a7412535d7388aa153e1e27d623814b02eaf202b34df3 max-cpu/README.md +dd2f5f2d832f2d2088c6172896b92eab94f4f6d48b9b387fa08289ca2596df49 baseline run.sh +``` + +MEASURED: `python3 max-cpu/test_run_evidence.py` passed all 11 test methods. +The identical tests against the original source failed 17 subcases. A private +mutant disabling only the containment predicate failed eight subcases. Raw +outputs and exit statuses are adjacent; no earlier evidence was rewritten. +The two red logs are losslessly compressed with `gzip -n` to preserve unittest's +trailing spaces without introducing whitespace errors into the source diff. +`gzip -dc baseline-red.log.gz` recovers the raw log with SHA256 +`041943afab73d5176ca1caf516453b68a68aa5d74ee4adebfcb8d1d8500c87b1`; +`gzip -dc no-overlap-mutant-red.log.gz` recovers SHA256 +`2883ca95a3b893556222653bfc0f8af921dc5a8eb7acfbe3dbea58bf1ee1aa4a`. +Both decoded streams were compared byte-for-byte with the original logs. + +The test executes an unchanged copy of the selected shell script in a private +temporary fixture. `git`, `sha256sum`, and `tools/native` are explicit test +doubles. The native double exits 73 so the tests can observe the first output +redirection even when a build fails. This does not exercise or change compiler +admission, a MAX graph, an Omega unit, or a device. + +## Reproduction + +From the repository root with the source identities above: + +```sh +python3 max-cpu/test_run_evidence.py +sh -n max-cpu/run.sh +python3 -m py_compile max-cpu/test_run_evidence.py +git diff --check +``` + +The recorded red/green run used byte-identical copies under a fresh generic +temporary directory so failure traces contain no private workspace paths: + +```sh +T=$(mktemp -d /tmp/bridge-max-cpu-public.XXXXXXXX) +mkdir "$T/max-cpu" +cp max-cpu/run.sh max-cpu/test_run_evidence.py "$T/max-cpu/" +git show 6ec6dab7668a0ca60835f8ac26996544c90b16f0:max-cpu/run.sh >"$T/base-run.sh" +python3 - "$T" <<'PY' +from pathlib import Path +import sys +p = Path(sys.argv[1]) +s = (p / 'max-cpu/run.sh').read_text() +old = ' case "$1/" in "${2%/}/"*) return 0 ;; *) return 1 ;; esac' +assert s.count(old) == 1 +(p / 'no-overlap-mutant.sh').write_text(s.replace(old, ' return 1')) +PY +(cd "$T"; RUN_SCRIPT="$T/base-run.sh" python3 max-cpu/test_run_evidence.py) +# Expected exit 1: baseline-red.log +(cd "$T"; RUN_SCRIPT="$T/no-overlap-mutant.sh" python3 max-cpu/test_run_evidence.py) +# Expected exit 1: no-overlap-mutant-red.log +(cd "$T"; python3 max-cpu/test_run_evidence.py) +# Expected exit 0: patched-green.log +``` + +Source review was performed independently of the writer, including containment, +outward symlinks, dangling symlinks and missing-parent handling. It was a static +review with inspection of execution receipts, not a second independent runtime +execution. The exact source-only patch also passed a clean-base archive replay. + +## Limits + +- `sh tools/bootstrap.sh`: exit 1, `bootstrap requires Linux AArch64`. +- `env -u OMEGA_SEED sh tools/test.sh`: exit 1, missing pinned bootstrap compiler. + The native aggregate suite is NOT_RUN, not PASS. +- Full MAX CPU reproduction and device execution: NOT_RUN. No MAX installation + or required AArch64 environment was used. This is not a numeric, performance, + GPU, qualification or deployment receipt. +- Paths must remain stable during the run, and BUILD remains caller-owned, + disposable build storage. This is not a concurrent-filesystem security sandbox. +- The regression has an explicit documented host-only command. It is not added + to the native aggregate suite or recursively invoked from its own fixture. +- Compiler pins, gates, MAX glue, Omega kernel and original MAX-CPU records are + unchanged. Runtime shape-binding concerns are outside this patch. diff --git a/evidence/max-cpu-evidence-path/2026-10-31/baseline-red.log.gz b/evidence/max-cpu-evidence-path/2026-10-31/baseline-red.log.gz new file mode 100644 index 0000000..58eb90f Binary files /dev/null and b/evidence/max-cpu-evidence-path/2026-10-31/baseline-red.log.gz differ diff --git a/evidence/max-cpu-evidence-path/2026-10-31/bootstrap-not-run.log b/evidence/max-cpu-evidence-path/2026-10-31/bootstrap-not-run.log new file mode 100644 index 0000000..cb476be --- /dev/null +++ b/evidence/max-cpu-evidence-path/2026-10-31/bootstrap-not-run.log @@ -0,0 +1 @@ +bootstrap requires Linux AArch64 diff --git a/evidence/max-cpu-evidence-path/2026-10-31/exits.txt b/evidence/max-cpu-evidence-path/2026-10-31/exits.txt new file mode 100644 index 0000000..900d9f2 --- /dev/null +++ b/evidence/max-cpu-evidence-path/2026-10-31/exits.txt @@ -0,0 +1,5 @@ +baseline=1 +no_overlap_mutant=1 +patched=0 +bootstrap=1 +full_suite=1 diff --git a/evidence/max-cpu-evidence-path/2026-10-31/full-suite-not-run.log b/evidence/max-cpu-evidence-path/2026-10-31/full-suite-not-run.log new file mode 100644 index 0000000..64685c6 --- /dev/null +++ b/evidence/max-cpu-evidence-path/2026-10-31/full-suite-not-run.log @@ -0,0 +1,2 @@ +sha256sum: build/bootstrap/omc: No such file or directory +seed fingerprint mismatch diff --git a/evidence/max-cpu-evidence-path/2026-10-31/no-overlap-mutant-red.log.gz b/evidence/max-cpu-evidence-path/2026-10-31/no-overlap-mutant-red.log.gz new file mode 100644 index 0000000..db9c20b Binary files /dev/null and b/evidence/max-cpu-evidence-path/2026-10-31/no-overlap-mutant-red.log.gz differ diff --git a/evidence/max-cpu-evidence-path/2026-10-31/patched-green.log b/evidence/max-cpu-evidence-path/2026-10-31/patched-green.log new file mode 100644 index 0000000..163e3f3 --- /dev/null +++ b/evidence/max-cpu-evidence-path/2026-10-31/patched-green.log @@ -0,0 +1,16 @@ +test_dangling_explicit_evidence_link_refuses_before_reset (__main__.EvidenceDestinationTests.test_dangling_explicit_evidence_link_refuses_before_reset) ... ok +test_default_does_not_overwrite_original_even_when_build_fails (__main__.EvidenceDestinationTests.test_default_does_not_overwrite_original_even_when_build_fails) ... ok +test_default_rerun_keeps_previous_evidence (__main__.EvidenceDestinationTests.test_default_rerun_keeps_previous_evidence) ... ok +test_default_tmpdir_inside_build_refuses_including_alias (__main__.EvidenceDestinationTests.test_default_tmpdir_inside_build_refuses_including_alias) ... ok +test_existing_explicit_evidence_refuses_before_build_reset (__main__.EvidenceDestinationTests.test_existing_explicit_evidence_refuses_before_build_reset) ... ok +test_explicit_evidence_ancestor_of_build_refuses_without_creating_it (__main__.EvidenceDestinationTests.test_explicit_evidence_ancestor_of_build_refuses_without_creating_it) ... ok +test_explicit_outward_alias_uses_resolved_destination_after_reset (__main__.EvidenceDestinationTests.test_explicit_outward_alias_uses_resolved_destination_after_reset) ... ok +test_explicit_overlap_aliases_refuse_before_reset (__main__.EvidenceDestinationTests.test_explicit_overlap_aliases_refuse_before_reset) ... ok +test_missing_explicit_parent_refuses_before_build_reset (__main__.EvidenceDestinationTests.test_missing_explicit_parent_refuses_before_build_reset) ... ok +test_new_explicit_evidence_directory_is_used (__main__.EvidenceDestinationTests.test_new_explicit_evidence_directory_is_used) ... ok +test_new_explicit_evidence_under_build_refuses_before_reset (__main__.EvidenceDestinationTests.test_new_explicit_evidence_under_build_refuses_before_reset) ... ok + +---------------------------------------------------------------------- +Ran 11 tests in 0.156s + +OK diff --git a/max-cpu/README.md b/max-cpu/README.md index c44ce5d..5b80ab7 100644 --- a/max-cpu/README.md +++ b/max-cpu/README.md @@ -6,3 +6,16 @@ - `run.sh` — the single reproduce target; `mogg-cache-repro.sh` — the MAX cache observation. Status EXERCISED(host CPU). Evidence, pins, results and gaps: [../evidence/MAX-CPU/README.md](../evidence/MAX-CPU/README.md). + +Each `run.sh` invocation writes fresh evidence to a new directory under +`$TMPDIR` (or `/tmp`) and prints `evidence=`. To select a destination, +set `EV` to a path that does not yet exist, with an existing writable parent. +`EV` must not contain or be inside `BUILD`; the default evidence parent +(`TMPDIR` or `/tmp`) must be outside `BUILD`. Checks resolve symlink and `..` +aliases with GNU `realpath` before any build reset. An existing destination is +also refused. Paths must be stable during the run; this is not a sandbox +against concurrent filesystem renames. The committed +`evidence/MAX-CPU/raw` directory remains the immutable original run of record. + +Host-only filesystem regression, without Omega, MAX or devices: +`python3 max-cpu/test_run_evidence.py`. diff --git a/max-cpu/run.sh b/max-cpu/run.sh index 31b2ae9..5e1baa1 100755 --- a/max-cpu/run.sh +++ b/max-cpu/run.sh @@ -7,7 +7,6 @@ cd "$(dirname "$0")/.." MAXPY=${MAXPY:-$HOME/workspace/maxinterop/venv/bin/python} OMEGA_REPO=${OMEGA_REPO:-$HOME/workspace/omega} BUILD=${BUILD:-/dev/shm/omega-max-cpu} -EV=${EV:-$PWD/evidence/MAX-CPU/raw} ITERS=${ITERS:-300} OMC1_REV=55f9b0af OMC1_SHA=734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61 OMC2_REV=ec07d25d OMC2_SHA=499236398aabc652e2dae27fe4bdc4c5db3d3726314356e0dbef23e3345803ec @@ -17,8 +16,52 @@ GLUE_CALL='process.get_function[UInt32]("omega2_omatmul")(' MUT_FROM='ai = mul i k' MUT_TO='ai = mul i n' +# Never replay into the committed run of record or an earlier evidence directory. +# Resolve aliases before checking containment. These are caller-owned paths on a +# stable local filesystem, not a sandbox against concurrent namespace changes. +inside() { + case "$1/" in "${2%/}/"*) return 0 ;; *) return 1 ;; esac +} +build_path=$(realpath -m -- "$BUILD") || exit 2 +if [ -n "${EV:-}" ]; then + evidence_path=$(realpath -m -- "$EV") || exit 2 + if inside "$evidence_path" "$build_path" || inside "$build_path" "$evidence_path"; then + echo 'run.sh: EV must not overlap BUILD' >&2 + exit 2 + fi + # Check the supplied path before resolving away a dangling leaf symlink. + evidence_input=$EV + while [ "$evidence_input" != / ] && [ "${evidence_input%/}" != "$evidence_input" ]; do + evidence_input=${evidence_input%/} + done + evidence_input_parent=$(dirname -- "$evidence_input") + if [ -e "$evidence_input" ] || [ -L "$evidence_input" ] || + [ ! -d "$evidence_input_parent" ] || [ ! -w "$evidence_input_parent" ]; then + echo 'run.sh: EV must name a new directory with an existing writable parent' >&2 + exit 2 + fi + # A lexical path may traverse a BUILD symlink that the reset removes. + EV=$evidence_path +else + evidence_parent=$(realpath -e -- "${TMPDIR:-/tmp}") || exit 2 + if [ ! -d "$evidence_parent" ] || inside "$evidence_parent" "$build_path"; then + echo 'run.sh: default evidence TMPDIR must be a directory outside BUILD' >&2 + exit 2 + fi +fi +# Refuse before resetting BUILD or opening any output log. rm -rf "$BUILD" -mkdir -p "$BUILD/omc" "$EV" +mkdir -p "$BUILD/omc" +# Atomic creation refuses a destination that appeared after the preflight. +if [ -n "${EV:-}" ]; then + if ! mkdir -- "$EV"; then + echo 'run.sh: EV must name a new directory with an existing writable parent' >&2 + exit 2 + fi +else + EV=$(mktemp -d "$evidence_parent/omega-max-cpu-evidence.XXXXXXXX") +fi +printf 'evidence=%s\n' "$EV" for v in 1 2; do eval rev=\$OMC${v}_REV sha=\$OMC${v}_SHA git -C "$OMEGA_REPO" show "$rev:seed/out/omc" >"$BUILD/omc/omc$v" diff --git a/max-cpu/test_run_evidence.py b/max-cpu/test_run_evidence.py new file mode 100644 index 0000000..8f8c1f4 --- /dev/null +++ b/max-cpu/test_run_evidence.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python3 +"""Host-only evidence-path regression for run.sh, no Omega or MAX execution. + +Run: python3 max-cpu/test_run_evidence.py +RUN_SCRIPT may select an unchanged baseline or private source mutant. +The exact shell script runs in a private fixture. git, sha256sum and +tools/native are explicit test doubles; this does not test compiler admission. +""" +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +SCRIPT = Path(os.environ.get("RUN_SCRIPT", Path(__file__).with_name("run.sh"))) + + +class EvidenceDestinationTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory(prefix="bridge-max-evidence-test-") + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + for directory in ("max-cpu", "tools", "bin", "tmp", "evidence/MAX-CPU/raw"): + (self.root / directory).mkdir(parents=True) + shutil.copyfile(SCRIPT, self.root / "max-cpu/run.sh") + self.record = self.root / "evidence/MAX-CPU/raw/build-lib.log" + self.record.write_text("IMMUTABLE_ORIGINAL\n") + for name, text in { + "bin/git": "#!/bin/sh\nprintf 'compiler-placeholder\\n'\n", + "bin/sha256sum": "#!/bin/sh\ncat >/dev/null\nexit 0\n", + "tools/native": "#!/bin/sh\nprintf 'TEST_BUILD_FAILURE\\n'\nexit 73\n", + }.items(): + path = self.root / name + path.write_text(text) + path.chmod(0o755) + self.build = self.root / "build" + self.env = dict(os.environ, PATH=str(self.root / "bin") + ":" + os.environ["PATH"], + BUILD=str(self.build), TMPDIR=str(self.root / "tmp"), + OMEGA_REPO=str(self.root / "unused-repo")) + self.env.pop("EV", None) + + def run_script(self, ev=None): + env = self.env.copy() + if ev is not None: + env["EV"] = str(ev) + return subprocess.run(["sh", "max-cpu/run.sh"], cwd=self.root, env=env, + text=True, capture_output=True, timeout=10) + + def test_default_does_not_overwrite_original_even_when_build_fails(self): + result = self.run_script() + self.assertEqual(result.returncode, 73, result.stderr) + self.assertEqual(self.record.read_text(), "IMMUTABLE_ORIGINAL\n") + paths = [line.removeprefix("evidence=") for line in result.stdout.splitlines() + if line.startswith("evidence=")] + self.assertEqual(len(paths), 1, result.stdout) + self.assertEqual((Path(paths[0]) / "build-lib.log").read_text(), "TEST_BUILD_FAILURE\n") + + def test_existing_explicit_evidence_refuses_before_build_reset(self): + self.build.mkdir() + marker = self.build / "keep" + marker.write_text("existing build\n") + result = self.run_script(self.record.parent) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("EV must name a new directory", result.stderr) + self.assertEqual(self.record.read_text(), "IMMUTABLE_ORIGINAL\n") + self.assertEqual(marker.read_text(), "existing build\n") + + def test_new_explicit_evidence_directory_is_used(self): + ev = self.root / "new-evidence" + result = self.run_script(ev) + self.assertEqual(result.returncode, 73, result.stderr) + self.assertEqual((ev / "build-lib.log").read_text(), "TEST_BUILD_FAILURE\n") + self.assertEqual(self.record.read_text(), "IMMUTABLE_ORIGINAL\n") + + def test_new_explicit_evidence_under_build_refuses_before_reset(self): + self.build.mkdir() + marker = self.build / "keep" + marker.write_text("existing build\n") + ev = self.build / "evidence" + result = self.run_script(ev) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("EV must not overlap BUILD", result.stderr) + self.assertEqual(marker.read_text(), "existing build\n") + self.assertEqual(self.record.read_text(), "IMMUTABLE_ORIGINAL\n") + + def test_explicit_outward_alias_uses_resolved_destination_after_reset(self): + self.build.mkdir() + outside = self.root / "outside" + outside.mkdir() + alias = self.build / "link" + alias.symlink_to(outside, target_is_directory=True) + result = self.run_script(alias / "new-evidence") + self.assertEqual(result.returncode, 73, result.stderr) + self.assertFalse(alias.exists()) + self.assertEqual((outside / "new-evidence/build-lib.log").read_text(), + "TEST_BUILD_FAILURE\n") + self.assertIn(f"evidence={outside / 'new-evidence'}\n", result.stdout) + self.assertEqual(self.record.read_text(), "IMMUTABLE_ORIGINAL\n") + + def test_dangling_explicit_evidence_link_refuses_before_reset(self): + for index, suffix in enumerate(("", "/", "///", "/.")): + with self.subTest(suffix=suffix): + self.build.mkdir(exist_ok=True) + marker = self.build / "keep" + marker.write_text("existing build\n") + target = self.root / f"missing-target-{index}" + alias = self.root / f"dangling-{index}" + alias.symlink_to(target, target_is_directory=True) + result = self.run_script(str(alias) + suffix) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("EV must name a new directory", result.stderr) + self.assertTrue(alias.is_symlink()) + self.assertFalse(target.exists()) + self.assertEqual(marker.read_text(), "existing build\n") + + def test_missing_explicit_parent_refuses_before_build_reset(self): + self.build.mkdir() + marker = self.build / "keep" + marker.write_text("existing build\n") + result = self.run_script(self.root / "missing-parent/evidence") + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("EV must name a new directory", result.stderr) + self.assertEqual(marker.read_text(), "existing build\n") + + def test_explicit_overlap_aliases_refuse_before_reset(self): + self.build.mkdir() + marker = self.build / "keep" + marker.write_text("existing build\n") + alias = self.root / "alias" + alias.symlink_to(self.build, target_is_directory=True) + for ev in (alias / "evidence", self.build / ".." / "build" / "evidence", self.build): + with self.subTest(ev=ev): + result = self.run_script(ev) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("EV must not overlap BUILD", result.stderr) + self.assertEqual(marker.read_text(), "existing build\n") + + def test_default_tmpdir_inside_build_refuses_including_alias(self): + temp = self.build / "tmp" + temp.mkdir(parents=True) + marker = temp / "previous-evidence" + marker.write_text("previous evidence\n") + alias = self.root / "tmp-alias" + alias.symlink_to(temp, target_is_directory=True) + for parent in (temp, alias, self.build / ".." / "build" / "tmp"): + with self.subTest(parent=parent): + self.env["TMPDIR"] = str(parent) + result = self.run_script() + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("TMPDIR must be a directory outside BUILD", result.stderr) + self.assertEqual(marker.read_text(), "previous evidence\n") + + def test_explicit_evidence_ancestor_of_build_refuses_without_creating_it(self): + ev = self.root / "new-evidence" + self.env["BUILD"] = str(ev / "build") + result = self.run_script(ev) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("EV must not overlap BUILD", result.stderr) + self.assertFalse(ev.exists()) + + def test_default_rerun_keeps_previous_evidence(self): + first = self.run_script() + self.assertEqual(first.returncode, 73, first.stderr) + paths = list((self.root / "tmp").glob("omega-max-cpu-evidence.*")) + self.assertEqual(len(paths), 1) + marker = paths[0] / "keep" + marker.write_text("previous evidence\n") + second = self.run_script() + self.assertEqual(second.returncode, 73, second.stderr) + self.assertEqual(marker.read_text(), "previous evidence\n") + self.assertEqual(len(list((self.root / "tmp").glob("omega-max-cpu-evidence.*"))), 2) + + +if __name__ == "__main__": + unittest.main(verbosity=2)