From 66b7b1f4954ef0ec4e94115d236746cf49e2cc38 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:33:17 -0500 Subject: [PATCH 01/10] Expose omitted elder sources and symlinked object directories --- tests/test_cbz_source514_hosted.py | 56 +++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index 6c037c594..2bddc8c2f 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -130,6 +130,30 @@ def test_unused_dependency_object_root_absence_is_explicit(self): self.assertFalse(snapshot["root_presence"][".lake/packages/Unused/.lake/build"]) self.assertTrue(snapshot["root_presence"][".lake/build"]) + def test_symlinked_build_root_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + outside=Path(temporary)/"outside" + package.joinpath(".lake").mkdir(parents=True) + outside.mkdir() + (outside/"hidden.olean").write_bytes(b"object") + package.joinpath(".lake","build").symlink_to(outside,target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + + def test_symlinked_nested_directory_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + outside=Path(temporary)/"outside" + build=package/".lake/build/lib/lean" + build.mkdir(parents=True) + outside.mkdir() + (build/"Owned.olean").write_bytes(b"owned") + (outside/"hidden.olean").write_bytes(b"hidden") + (build/"Shadow").symlink_to(outside,target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + def test_dependency_object_root_appearance_is_rejected(self): with tempfile.TemporaryDirectory() as temporary: package=Path(temporary) @@ -194,23 +218,47 @@ def setUp(self): self.root=Path(self.temporary.name) self.production=["Production"+str(i) for i in range(67)] self.support=["Support"+str(i) for i in range(25)] - self.plan={"production":self.production,"support":self.support,"schema":"cbz-source514-exact-domain-v1","source_commit":subject.SOURCE_COMMIT} + self.elder=["SuperlevelBar","ElderClearance","ReusedCompactFrontier","ClosedSuperlevel","OrdinaryH0","ElderInterval","ElderBridge"] + self.plan={"production":self.production,"support":self.support,"elder":self.elder,"schema":"cbz-source514-exact-domain-v1","source_commit":subject.SOURCE_COMMIT} (self.root/"inputs").mkdir() for name in self.production: (self.root/(name+".lean")).write_text("-- finite source fixture\n") for name in self.support: (self.root/"inputs"/(name+".lean")).write_text("-- finite input fixture\n") + (self.root/"inputs"/"elder").mkdir() + for name in self.elder: + (self.root/"inputs"/"elder"/(name+".lean")).write_text("-- consumed elder input fixture\n") for name in ["lake-manifest.json","lean-toolchain"]: (self.root/name).write_text("finite configuration fixture\n") self.write_configuration() def write_configuration(self): - (self.root/"lakefile.toml").write_text("defaultTargets = "+json.dumps(self.production)+"\n[[lean_lib]]\nname = \"SourceDerivativeInputs\"\nroots = "+json.dumps(self.support)+"\n") + (self.root/"lakefile.toml").write_text("defaultTargets = "+json.dumps(self.production)+"\n[[lean_lib]]\nname = \"SourceDerivativeInputs\"\nroots = "+json.dumps(self.support)+"\n[[lean_lib]]\nname = \"SourceElderInputs\"\nsrcDir = \"inputs/elder\"\nroots = "+json.dumps(self.elder)+"\n") def test_complete_registered_domain(self): modules,sources=subject.checked_domain(self.root,self.plan) - self.assertEqual(len(modules),92) - self.assertEqual(len(sources),95) + self.assertEqual(len(modules),99) + self.assertEqual(len(set(modules)),99) + self.assertEqual(len(sources),102) + for name in self.elder: + self.assertIn("inputs/elder/"+name+".lean",sources) + + def test_omitted_registered_elder_root_rejected(self): + plan = dict(self.plan, elder=self.elder[:-1]) + with self.assertRaisesRegex(ValueError, "domain differs"): + subject.checked_domain(self.root, plan) + + def test_missing_imported_elder_source_rejected(self): + (self.root/(self.production[0]+".lean")).write_text("import "+self.elder[-1]+"\n") + (self.root/"inputs"/"elder"/(self.elder[-1]+".lean")).unlink() + with self.assertRaisesRegex(ValueError,"registered source is absent"): + subject.checked_domain(self.root,self.plan) + + def test_plan_and_configuration_cannot_jointly_omit_elder_root(self): + self.elder.pop() + self.write_configuration() + with self.assertRaisesRegex(ValueError,"expected exactly"): + subject.checked_domain(self.root,self.plan) def test_reordered_domain_rejected(self): plan=dict(self.plan,production=self.production[::-1]) From 24769d4a0511ea82586a7699299bdca7253cca89 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:36:58 -0500 Subject: [PATCH 02/10] Bind all imported elder sources and compiled-object directories Preserve actual adverse controls and require fresh 99-module replay; no mathematical statement or bound is changed. --- .github/workflows/cbz-source514-hosted.yml | 4 +- cbz/source514-hosted/README.md | 12 +- cbz/source514-hosted/domain.json | 11 +- .../99-domain-local-partial-green-normal.log | 21 + .../evidence/99-domain-local-red-normal.log | 91 +++++ .../evidence/99-domain-local-red-tests.py.txt | 377 ++++++++++++++++++ tests/test_cbz_source514_hosted.py | 45 ++- tools/cbz_source514_hosted.py | 38 +- tools/cbz_source514_mutations.py | 11 +- 9 files changed, 589 insertions(+), 21 deletions(-) create mode 100644 cbz/source514-hosted/evidence/99-domain-local-partial-green-normal.log create mode 100644 cbz/source514-hosted/evidence/99-domain-local-red-normal.log create mode 100644 cbz/source514-hosted/evidence/99-domain-local-red-tests.py.txt diff --git a/.github/workflows/cbz-source514-hosted.yml b/.github/workflows/cbz-source514-hosted.yml index 1b4b34ab4..c3e0bc684 100644 --- a/.github/workflows/cbz-source514-hosted.yml +++ b/.github/workflows/cbz-source514-hosted.yml @@ -48,7 +48,7 @@ jobs: print('RETAINED_ORIGINAL_RED_STREAM',item.filename) print(archive.read(item).decode('utf-8')) PY - - name: Verify recorder contracts and all three reason-bound source mutations + - name: Verify recorder contracts and all six reason-bound source mutations run: | python -B -S tools/cbz_source514_mutations.py --output "$RUNNER_TEMP/cbz-source514-recorder-tests" - name: Obtain immutable mathematical source @@ -96,7 +96,7 @@ jobs: cd "$GITHUB_WORKSPACE" python -B -S replay/cbz/evidence/kernel/additional/replay-tool/run_lean_selftest.py --lean "$LEAN_BIN" --collector collector/formal/gate_helper.py --collector-sha256 ff8a5374597772b2d37054fd722c2243c4b552a63802c69f7c605519832be6c4 --output "$RUNNER_TEMP/cbz-source514-lean-selftest-normal" python -B -S -O replay/cbz/evidence/kernel/additional/replay-tool/run_lean_selftest.py --lean "$LEAN_BIN" --collector collector/formal/gate_helper.py --collector-sha256 ff8a5374597772b2d37054fd722c2243c4b552a63802c69f7c605519832be6c4 --output "$RUNNER_TEMP/cbz-source514-lean-selftest-optimized" - - name: Build exact 92 modules and replay complete owned proof closure into an empty kernel + - name: Build exact 99 modules and replay complete owned proof closure into an empty kernel run: | python -B -S tools/cbz_source514_hosted.py --source candidate --replay replay --collector collector --plan cbz/source514-hosted/domain.json --output "$RUNNER_TEMP/cbz-source514-observation" --carrier . --carrier-head "${{ github.sha }}" - name: Preserve every raw result and source, including unsuccessful attempts diff --git a/cbz/source514-hosted/README.md b/cbz/source514-hosted/README.md index dbe0dafb5..4a62947f8 100644 --- a/cbz/source514-hosted/README.md +++ b/cbz/source514-hosted/README.md @@ -1,18 +1,18 @@ # Frozen source514 qualification -This narrow execution carrier serves CBZ criteria3,6,7,9 and11. It does not change mathematical sources or claim a federation baseline. The historical PR514 source is checked out at86c00d4c08c6c2af0529ec1744693de3ca6ac6e4; all67 production and25 consumed support modules are built serially. The seven unconsumed elder source copies remain preserved and outside this proof-closure claim. +This narrow execution carrier serves CBZ criteria3,6,7,9 and11. It does not change mathematical sources or claim a federation baseline. The historical PR514 source is checked out at86c00d4c08c6c2af0529ec1744693de3ca6ac6e4; all 67 production, 25 derivative-support and seven actually imported elder modules are built serially and included in source binding and the owned-declaration census. Model application and premise inhabitation remain outside the claim. -`tools/cbz_source514_hosted.py` reuses the published self-tested bounded Lean replay generator from main66c54f8c161c3af467e5d1d715066c96b3a0561b and the existing C297 raw execution recorder from Math8151f592918a845bf19eb8eafaf8444540a32734. The collector's full SHA256 isff8a5374597772b2d37054fd722c2243c4b552a63802c69f7c605519832be6c4. Source HEAD and exact working bytes are compared with immutable Git blobs before and after execution, including files hidden by assume-unchanged flags. Every dependency additionally binds the exact complete index, working modes and bytes to the frozen tree; visible untracked paths and ignored Lean shadows outside .lake are rejected. All actual owned and dependency olean/ilean/dynamic-library objects are bound before and after census and kernel replay. Locked dependencies with no compiled object directory are recorded explicitly as absent; their later appearance also fails the stability check. Loaded recorder/tool bytes are hashed before compilation and executed from those same immutable bytes. The registered67+25 domain must equal the frozen TOML. Loaded launcher bytes are compiled from an immutable Git blob and compared with its declared source identity; the plan is parsed from the same immutable bytes whose identity is recorded. Both carrier inputs are rebound after execution. +`tools/cbz_source514_hosted.py` reuses the published self-tested bounded Lean replay generator from main66c54f8c161c3af467e5d1d715066c96b3a0561b and the existing C297 raw execution recorder from Math8151f592918a845bf19eb8eafaf8444540a32734. The collector's full SHA256 isff8a5374597772b2d37054fd722c2243c4b552a63802c69f7c605519832be6c4. Source HEAD and exact working bytes are compared with immutable Git blobs before and after execution, including files hidden by assume-unchanged flags. Every dependency additionally binds the exact complete index, working modes and bytes to the frozen tree; visible untracked paths and ignored Lean shadows outside .lake are rejected. All actual owned and dependency olean/ilean/dynamic-library objects are bound before and after census and kernel replay. Locked dependencies with no compiled object directory are recorded explicitly as absent; their later appearance also fails the stability check. Loaded recorder/tool bytes are hashed before compilation and executed from those same immutable bytes. The registered 67+25+7 domain must equal the frozen TOML and exact elder roots. Loaded launcher bytes are compiled from an immutable Git blob and compared with its declared source identity; the plan is parsed from the same immutable bytes whose identity is recorded. Both carrier inputs are rebound after execution. The independent census enumerates compiled module-table constants (with all code-generator ownership metadata explicitly recorded outside the kernel census), records every owned constant's literal type, kind and source-range origin, and is compared with the replay program's separate full environment ownership enumeration. The existing verified program checks every selected module, every owned declaration and its complete transitive type/value closure, rejects unsafe/partial constants and nonstandard axioms, and calls pinned Lean4.34.1's empty trust-level-zero Kernel.Environment.replay. Only Classical.choice, Quot.sound and propext are admitted. Mathematical model adequacy, satisfiability of all hypotheses and prose applications are outside this claim. -Run the recorder contracts and all three source mutations in both Python modes: +Run the recorder contracts and all six source mutations in both Python modes: ```sh python3.11 -B -S tools/cbz_source514_mutations.py --output /new/recorder-selftest ``` -The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of three uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. +The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of six uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. Prepare clean source/replay/collector checkouts at the above exact commits, install the package's pinned Lean/Mathlib dependencies, then run: @@ -29,3 +29,7 @@ Preserved test-first RED: b841fcc18ad7ebbe136ff7d237c8b61455e8e02f, native run40 Additional observed RED: native run40946268822/job123702332184 at source787ad73c42805155a50afca5a30b02e48e39726e ran43 cases and observed one real Git-replacement false acceptance plus one inherited-GIT_DIR redirect error. The repair reuses main701's no-replacement/sanitized-Git environment pattern for every command, including cat-file batch. Existing fixed-scope guard mutation thresholds are unchanged. Original all92-module build: run40943603468/job123693053386 compiled every selected module with exit0. Its census then failed because it demanded a kernel declaration for `_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter._boxed`. Pinned Lean4.34.1's `ModuleData` explicitly defines extraConstNames as code-generator ownership metadata absent from the ConstantInfo mapping. The repaired census retains and prints every such extra name as NON_KERNEL_CODE_GENERATOR_OWNERSHIP and fails if it unexpectedly has a kernel declaration. Every actual kernel declaration remains checked by the independent full module-table census and the separate complete environment ownership enumeration; no mathematical theorem, bound, failed proof or test is dropped. The original failed diagnostic stream is retained, checksum-verified and printed by subsequent hosted attempts. This is a precise kernel/IR boundary, not a weakened proof obligation. + +## Corrected source and object boundary + +Independent review showed that seven SourceElderInputs roots are transitively imported by the production modules. The previous 92-module report omitted those source bindings and their owned-module census; prior runs remain historical and do not certify complete source custody. The revised carrier binds and replays all 99 roots and rejects symlinked compiled-object roots, ancestors, and nested entries. Inherited LEAN_PATH and LEAN_SRC_PATH are removed before execution. The in-memory Python 3.11 normal-mode adverse fixture run observed 10 failures among 16 tests on the prior source and no errors; the exact source and raw output are retained in this directory. A subsequent 16-case normal-mode run on the candidate before the separate environment-guard addition observed exit0; it is not a full suite or kernel qualification. Fresh native tests, all six mutations in both modes and actual 99-module replay remain required. Observation recorded 2026-10-29 20:36:47 UTC. diff --git a/cbz/source514-hosted/domain.json b/cbz/source514-hosted/domain.json index a03242da4..ecba205af 100644 --- a/cbz/source514-hosted/domain.json +++ b/cbz/source514-hosted/domain.json @@ -97,5 +97,14 @@ ], "schema": "cbz-source514-exact-domain-v1", "source_commit": "86c00d4c08c6c2af0529ec1744693de3ca6ac6e4", - "boundary": "67 registered production modules plus exactly25 consumed support modules; inputs/elder/{SuperlevelBar,ElderClearance,ReusedCompactFrontier,ClosedSuperlevel,OrdinaryH0,ElderInterval,ElderBridge}.lean are preserved but not imported by any production module and have no proof-closure admission in this run." + "boundary": "67 registered production modules plus exactly 25 SourceDerivativeInputs and 7 SourceElderInputs modules, including the consumed elder import chain. Model application and premise inhabitation are outside this literal replay.", + "elder": [ + "SuperlevelBar", + "ElderClearance", + "ReusedCompactFrontier", + "ClosedSuperlevel", + "OrdinaryH0", + "ElderInterval", + "ElderBridge" + ] } diff --git a/cbz/source514-hosted/evidence/99-domain-local-partial-green-normal.log b/cbz/source514-hosted/evidence/99-domain-local-partial-green-normal.log new file mode 100644 index 000000000..37dc141ea --- /dev/null +++ b/cbz/source514-hosted/evidence/99-domain-local-partial-green-normal.log @@ -0,0 +1,21 @@ +test_complete_registered_domain (isolated_test.RegisteredDomainTests.test_complete_registered_domain) ... ok +test_duplicate_modules_rejected (isolated_test.RegisteredDomainTests.test_duplicate_modules_rejected) ... ok +test_elder_source_directory_is_exact (isolated_test.RegisteredDomainTests.test_elder_source_directory_is_exact) ... ok +test_missing_imported_elder_source_rejected (isolated_test.RegisteredDomainTests.test_missing_imported_elder_source_rejected) ... ok +test_missing_source_rejected (isolated_test.RegisteredDomainTests.test_missing_source_rejected) ... ok +test_omitted_registered_elder_root_rejected (isolated_test.RegisteredDomainTests.test_omitted_registered_elder_root_rejected) ... ok +test_plan_and_configuration_cannot_jointly_omit_elder_root (isolated_test.RegisteredDomainTests.test_plan_and_configuration_cannot_jointly_omit_elder_root) ... ok +test_plan_and_configuration_cannot_replace_elder_root (isolated_test.RegisteredDomainTests.test_plan_and_configuration_cannot_replace_elder_root) ... ok +test_reordered_domain_rejected (isolated_test.RegisteredDomainTests.test_reordered_domain_rejected) ... ok +test_dangling_nested_symlink_is_rejected (isolated_test.CompiledObjectCustodyTests.test_dangling_nested_symlink_is_rejected) ... ok +test_dependency_object_change_rejected_while_owned_object_is_stable (isolated_test.CompiledObjectCustodyTests.test_dependency_object_change_rejected_while_owned_object_is_stable) ... ok +test_dependency_object_root_appearance_is_rejected (isolated_test.CompiledObjectCustodyTests.test_dependency_object_root_appearance_is_rejected) ... ok +test_symlinked_build_ancestor_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_build_ancestor_is_rejected) ... ok +test_symlinked_build_root_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_build_root_is_rejected) ... ok +test_symlinked_nested_directory_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected) ... ok +test_unused_dependency_object_root_absence_is_explicit (isolated_test.CompiledObjectCustodyTests.test_unused_dependency_object_root_absence_is_explicit) ... ok + +---------------------------------------------------------------------- +Ran 16 tests in 0.030s + +OK diff --git a/cbz/source514-hosted/evidence/99-domain-local-red-normal.log b/cbz/source514-hosted/evidence/99-domain-local-red-normal.log new file mode 100644 index 000000000..d92116ee0 --- /dev/null +++ b/cbz/source514-hosted/evidence/99-domain-local-red-normal.log @@ -0,0 +1,91 @@ +test_complete_registered_domain (isolated_test.RegisteredDomainTests.test_complete_registered_domain) ... FAIL +test_duplicate_modules_rejected (isolated_test.RegisteredDomainTests.test_duplicate_modules_rejected) ... ok +test_elder_source_directory_is_exact (isolated_test.RegisteredDomainTests.test_elder_source_directory_is_exact) ... FAIL +test_missing_imported_elder_source_rejected (isolated_test.RegisteredDomainTests.test_missing_imported_elder_source_rejected) ... FAIL +test_missing_source_rejected (isolated_test.RegisteredDomainTests.test_missing_source_rejected) ... ok +test_omitted_registered_elder_root_rejected (isolated_test.RegisteredDomainTests.test_omitted_registered_elder_root_rejected) ... FAIL +test_plan_and_configuration_cannot_jointly_omit_elder_root (isolated_test.RegisteredDomainTests.test_plan_and_configuration_cannot_jointly_omit_elder_root) ... FAIL +test_plan_and_configuration_cannot_replace_elder_root (isolated_test.RegisteredDomainTests.test_plan_and_configuration_cannot_replace_elder_root) ... FAIL +test_reordered_domain_rejected (isolated_test.RegisteredDomainTests.test_reordered_domain_rejected) ... ok +test_dangling_nested_symlink_is_rejected (isolated_test.CompiledObjectCustodyTests.test_dangling_nested_symlink_is_rejected) ... FAIL +test_dependency_object_change_rejected_while_owned_object_is_stable (isolated_test.CompiledObjectCustodyTests.test_dependency_object_change_rejected_while_owned_object_is_stable) ... ok +test_dependency_object_root_appearance_is_rejected (isolated_test.CompiledObjectCustodyTests.test_dependency_object_root_appearance_is_rejected) ... ok +test_symlinked_build_ancestor_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_build_ancestor_is_rejected) ... FAIL +test_symlinked_build_root_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_build_root_is_rejected) ... FAIL +test_symlinked_nested_directory_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected) ... FAIL +test_unused_dependency_object_root_absence_is_explicit (isolated_test.CompiledObjectCustodyTests.test_unused_dependency_object_root_absence_is_explicit) ... ok + +====================================================================== +FAIL: test_complete_registered_domain (isolated_test.RegisteredDomainTests.test_complete_registered_domain) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 261, in test_complete_registered_domain +AssertionError: 92 != 99 + +====================================================================== +FAIL: test_elder_source_directory_is_exact (isolated_test.RegisteredDomainTests.test_elder_source_directory_is_exact) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 294, in test_elder_source_directory_is_exact +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_missing_imported_elder_source_rejected (isolated_test.RegisteredDomainTests.test_missing_imported_elder_source_rejected) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 275, in test_missing_imported_elder_source_rejected +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_omitted_registered_elder_root_rejected (isolated_test.RegisteredDomainTests.test_omitted_registered_elder_root_rejected) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 269, in test_omitted_registered_elder_root_rejected +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_plan_and_configuration_cannot_jointly_omit_elder_root (isolated_test.RegisteredDomainTests.test_plan_and_configuration_cannot_jointly_omit_elder_root) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 281, in test_plan_and_configuration_cannot_jointly_omit_elder_root +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_plan_and_configuration_cannot_replace_elder_root (isolated_test.RegisteredDomainTests.test_plan_and_configuration_cannot_replace_elder_root) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 288, in test_plan_and_configuration_cannot_replace_elder_root +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_dangling_nested_symlink_is_rejected (isolated_test.CompiledObjectCustodyTests.test_dangling_nested_symlink_is_rejected) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 175, in test_dangling_nested_symlink_is_rejected +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_symlinked_build_ancestor_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_build_ancestor_is_rejected) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 165, in test_symlinked_build_ancestor_is_rejected +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_symlinked_build_root_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_build_root_is_rejected) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 141, in test_symlinked_build_root_is_rejected +AssertionError: ValueError not raised + +====================================================================== +FAIL: test_symlinked_nested_directory_is_rejected (isolated_test.CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/tmp/isolated_test.py", line 154, in test_symlinked_nested_directory_is_rejected +AssertionError: ValueError not raised + +---------------------------------------------------------------------- +Ran 16 tests in 0.029s + +FAILED (failures=10) diff --git a/cbz/source514-hosted/evidence/99-domain-local-red-tests.py.txt b/cbz/source514-hosted/evidence/99-domain-local-red-tests.py.txt new file mode 100644 index 000000000..160a7da9a --- /dev/null +++ b/cbz/source514-hosted/evidence/99-domain-local-red-tests.py.txt @@ -0,0 +1,377 @@ +from __future__ import annotations +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest +from unittest import mock + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) +import cbz_source514_hosted as subject + +class SourceBindingTests(unittest.TestCase): + def setUp(self): + self.temporary = tempfile.TemporaryDirectory() + self.addCleanup(self.temporary.cleanup) + self.root = Path(self.temporary.name) + subprocess.run(["git","init","-q",str(self.root)],check=True) + subprocess.run(["git","-C",str(self.root),"config","user.email","fixture@example.invalid"],check=True) + subprocess.run(["git","-C",str(self.root),"config","user.name","Finite fixture"],check=True) + (self.root/"Proof.lean").write_text("theorem exactFixture : True := True.intro\n") + subprocess.run(["git","-C",str(self.root),"add","Proof.lean"],check=True) + subprocess.run(["git","-C",str(self.root),"commit","-qm","finite fixture"],check=True) + self.previous_head=subject.git(self.root,"rev-parse","HEAD").decode().strip() + (self.root/"Metadata.txt").write_text("second commit; unchanged proof blob\n") + subprocess.run(["git","-C",str(self.root),"add","Metadata.txt"],check=True) + subprocess.run(["git","-C",str(self.root),"commit","-qm","metadata successor"],check=True) + self.head=subject.git(self.root,"rev-parse","HEAD").decode().strip() + + def test_exact_source_is_bound(self): + result=subject.bind(self.root,self.head,["Proof.lean"]) + self.assertEqual(result["commit"],self.head) + self.assertEqual(result["files"]["Proof.lean"]["sha256"],subject.sha((self.root/"Proof.lean").read_bytes())) + + def test_wrong_head_rejected(self): + with self.assertRaisesRegex(ValueError,"source HEAD differs"): + subject.bind(self.root,self.previous_head,["Proof.lean"]) + + def test_dirty_bytes_rejected_even_assume_unchanged(self): + subprocess.run(["git","-C",str(self.root),"update-index","--assume-unchanged","Proof.lean"],check=True) + (self.root/"Proof.lean").write_text("theorem changedFixture : True := True.intro\n") + with self.assertRaisesRegex(ValueError,"source bytes differ"): + subject.bind(self.root,self.head,["Proof.lean"]) + + def test_unsafe_relative_path_rejected(self): + with self.assertRaisesRegex(ValueError,"unsafe bound source path"): + subject.bind(self.root,self.head,["../Proof.lean"]) + + def test_symlink_rejected(self): + (self.root/"Link.lean").symlink_to("Proof.lean") + with self.assertRaisesRegex(ValueError,"symlinked bound source"): + subject.bind(self.root,self.head,["Link.lean"]) + +class DependencyCustodyTests(SourceBindingTests): + def package(self): + temporary=tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + package=Path(temporary.name) + (package/".lake/packages").mkdir(parents=True) + (package/".lake/packages/Fixture").symlink_to(self.root,target_is_directory=True) + lock={"packages":[{"name":"Fixture","type":"git","rev":self.head}]} + return package,lock + + def test_dependency_hidden_dirty_bytes_rejected(self): + subprocess.run(["git","-C",str(self.root),"update-index","--assume-unchanged","Proof.lean"],check=True) + (self.root/"Proof.lean").write_text("theorem changedFixture : True := True.intro\n") + with self.assertRaisesRegex(ValueError,"source bytes differ"): + subject.bind_dependency(self.root,self.head) + + def test_dependency_changed_index_rejected_with_original_working_bytes(self): + original=(self.root/"Proof.lean").read_bytes() + (self.root/"Proof.lean").write_text("theorem changedFixture : True := True.intro\n") + subprocess.run(["git","-C",str(self.root),"add","Proof.lean"],check=True) + (self.root/"Proof.lean").write_bytes(original) + with self.assertRaisesRegex(ValueError,"index differs"): + subject.bind_dependency(self.root,self.head) + + def test_dependency_ignored_lean_shadow_rejected(self): + (self.root/".git/info/exclude").write_text("Shadow.lean\n") + (self.root/"Shadow.lean").write_text("theorem shadowFixture : True := True.intro\n") + with self.assertRaisesRegex(ValueError,"untracked Lean shadow"): + subject.bind_dependency(self.root,self.head) + + def test_dependency_change_during_actual_phase_rejected(self): + package,lock=self.package() + with self.assertRaisesRegex(ValueError,"source bytes differ"): + with subject.frozen_dependencies(package,lock): + subprocess.run(["git","-C",str(self.root),"update-index","--assume-unchanged","Metadata.txt"],check=True) + (self.root/"Metadata.txt").write_text("actual phase mutated a dependency\n") + + def test_git_replacement_cannot_relabel_a_new_tree_as_the_frozen_commit(self): + frozen=self.head + (self.root/"Proof.lean").write_text("theorem replacementFixture : True := True.intro\n") + subprocess.run(["git","-C",str(self.root),"add","Proof.lean"],check=True) + subprocess.run(["git","-C",str(self.root),"commit","-qm","replacement tree"],check=True) + replacement=subject.git(self.root,"rev-parse","HEAD").decode().strip() + subprocess.run(["git","-C",str(self.root),"replace",frozen,replacement],check=True) + subprocess.run(["git","-C",str(self.root),"update-ref","HEAD",frozen],check=True) + with self.assertRaisesRegex(ValueError,"index differs"): + subject.bind_dependency(self.root,frozen) + + def test_inherited_git_directory_cannot_redirect_dependency_identity(self): + with mock.patch.dict(os.environ,{"GIT_DIR":str(self.root/"missing-git"),"GIT_WORK_TREE":str(self.root/"missing-worktree")}): + bound=subject.bind_dependency(self.root,self.head) + self.assertEqual(bound["commit"],self.head) + +class CompiledObjectCustodyTests(unittest.TestCase): + def test_dependency_object_change_rejected_while_owned_object_is_stable(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary) + owned=package/".lake/build/lib/lean/Owned.olean" + dependency=package/".lake/packages/Fixture/.lake/build/lib/lean/Dependency.olean.private" + owned.parent.mkdir(parents=True) + dependency.parent.mkdir(parents=True) + owned.write_bytes(b"owned fixture object") + dependency.write_bytes(b"dependency fixture object") + with self.assertRaisesRegex(ValueError,"compiled objects changed"): + with subject.frozen_objects(package,["Fixture"]): + dependency.write_bytes(b"changed dependency fixture object") + self.assertEqual(owned.read_bytes(),b"owned fixture object") + + def test_unused_dependency_object_root_absence_is_explicit(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary) + owned=package/".lake/build/lib/lean/Owned.olean" + owned.parent.mkdir(parents=True) + owned.write_bytes(b"owned fixture object") + snapshot=subject.object_snapshot(package,["Unused"]) + self.assertFalse(snapshot["root_presence"][".lake/packages/Unused/.lake/build"]) + self.assertTrue(snapshot["root_presence"][".lake/build"]) + + def test_symlinked_build_root_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + outside=Path(temporary)/"outside" + package.joinpath(".lake").mkdir(parents=True) + outside.mkdir() + (outside/"hidden.olean").write_bytes(b"object") + package.joinpath(".lake","build").symlink_to(outside,target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + + def test_symlinked_nested_directory_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + outside=Path(temporary)/"outside" + build=package/".lake/build/lib/lean" + build.mkdir(parents=True) + outside.mkdir() + (build/"Owned.olean").write_bytes(b"owned") + (outside/"hidden.olean").write_bytes(b"hidden") + (build/"Shadow").symlink_to(outside,target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + + def test_symlinked_build_ancestor_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + outside=Path(temporary)/"outside" + package.mkdir() + outside.joinpath("build").mkdir(parents=True) + outside.joinpath("build","Owned.olean").write_bytes(b"object") + package.joinpath(".lake").symlink_to(outside,target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + + def test_dangling_nested_symlink_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + build=package/".lake/build/lib/lean" + build.mkdir(parents=True) + (build/"Owned.olean").write_bytes(b"owned") + (build/"Dangling").symlink_to(package/"missing",target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + + def test_dependency_object_root_appearance_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary) + owned=package/".lake/build/lib/lean/Owned.olean" + owned.parent.mkdir(parents=True) + owned.write_bytes(b"owned fixture object") + with self.assertRaisesRegex(ValueError,"compiled objects changed"): + with subject.frozen_objects(package,["Unused"]): + (package/".lake/packages/Unused/.lake/build").mkdir(parents=True) + +class LoadedCodeTests(unittest.TestCase): + def test_changed_loaded_bytes_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + path=Path(temporary)/"loaded.py" + path.write_text("value = 7\n") + with self.assertRaisesRegex(ValueError,"loaded code differs"): + subject.load("finite_loaded",path,subject.sha(b"value = 8\n")) + def test_immutable_loaded_bytes_are_the_recorded_identity(self): + with tempfile.TemporaryDirectory() as temporary: + path=Path(temporary)/"loaded.py" + data=b"value = 7\n" + path.write_bytes(data) + module=subject.load("finite_loaded",path,subject.sha(data)) + self.assertEqual(module.value,7) + self.assertEqual(module.__source_sha256__,subject.sha(data)) + +class ExecutionInputCustodyTests(SourceBindingTests): + def prepare(self): + tool=self.root/"tools/cbz_source514_hosted.py" + plan=self.root/"cbz/source514-hosted/domain.json" + tool.parent.mkdir() + plan.parent.mkdir(parents=True) + tool.write_bytes(b"value = 7\n") + plan.write_text('{"frozen": 7}\n') + subprocess.run(["git","-C",str(self.root),"add","tools","cbz"],check=True) + subprocess.run(["git","-C",str(self.root),"commit","-qm","execution input fixture"],check=True) + self.head=subject.git(self.root,"rev-parse","HEAD").decode().strip() + return tool,plan + + def test_loaded_launcher_then_restored_file_is_rejected(self): + tool,plan=self.prepare() + tool.write_bytes(b"value = 8\n") + loaded=subject.load("changed_launcher",tool,subject.sha(tool.read_bytes())) + tool.write_bytes(b"value = 7\n") + self.assertEqual(loaded.value,8) + with self.assertRaisesRegex(ValueError,"loaded launcher differs"): + subject.execution_inputs(self.root,self.head,loaded.__source_sha256__,plan) + + def test_plan_mutation_after_parse_is_rejected(self): + tool,plan=self.prepare() + loaded_sha=subject.sha(tool.read_bytes()) + parsed,binding=subject.execution_inputs(self.root,self.head,loaded_sha,plan) + self.assertEqual(parsed,{"frozen":7}) + plan.write_text('{"frozen": 8}\n') + with self.assertRaisesRegex(ValueError,"source bytes differ"): + subject.execution_inputs(self.root,self.head,loaded_sha,plan) + +class RegisteredDomainTests(unittest.TestCase): + def setUp(self): + self.temporary=tempfile.TemporaryDirectory() + self.addCleanup(self.temporary.cleanup) + self.root=Path(self.temporary.name) + self.production=["Production"+str(i) for i in range(67)] + self.support=["Support"+str(i) for i in range(25)] + self.elder=["SuperlevelBar","ElderClearance","ReusedCompactFrontier","ClosedSuperlevel","OrdinaryH0","ElderInterval","ElderBridge"] + self.plan={"production":self.production,"support":self.support,"elder":self.elder,"schema":"cbz-source514-exact-domain-v1","source_commit":subject.SOURCE_COMMIT} + (self.root/"inputs").mkdir() + for name in self.production: + (self.root/(name+".lean")).write_text("-- finite source fixture\n") + for name in self.support: + (self.root/"inputs"/(name+".lean")).write_text("-- finite input fixture\n") + (self.root/"inputs"/"elder").mkdir() + for name in self.elder: + (self.root/"inputs"/"elder"/(name+".lean")).write_text("-- consumed elder input fixture\n") + for name in ["lake-manifest.json","lean-toolchain"]: + (self.root/name).write_text("finite configuration fixture\n") + self.write_configuration() + + def write_configuration(self): + (self.root/"lakefile.toml").write_text("defaultTargets = "+json.dumps(self.production)+"\n[[lean_lib]]\nname = \"SourceDerivativeInputs\"\nroots = "+json.dumps(self.support)+"\n[[lean_lib]]\nname = \"SourceElderInputs\"\nsrcDir = \"inputs/elder\"\nroots = "+json.dumps(self.elder)+"\n") + + def test_complete_registered_domain(self): + modules,sources=subject.checked_domain(self.root,self.plan) + self.assertEqual(len(modules),99) + self.assertEqual(len(set(modules)),99) + self.assertEqual(len(sources),102) + for name in self.elder: + self.assertIn("inputs/elder/"+name+".lean",sources) + + def test_omitted_registered_elder_root_rejected(self): + plan = dict(self.plan, elder=self.elder[:-1]) + with self.assertRaisesRegex(ValueError, "domain differs"): + subject.checked_domain(self.root, plan) + + def test_missing_imported_elder_source_rejected(self): + (self.root/(self.production[0]+".lean")).write_text("import "+self.elder[-1]+"\n") + (self.root/"inputs"/"elder"/(self.elder[-1]+".lean")).unlink() + with self.assertRaisesRegex(ValueError,"registered source is absent"): + subject.checked_domain(self.root,self.plan) + + def test_plan_and_configuration_cannot_jointly_omit_elder_root(self): + self.elder.pop() + self.write_configuration() + with self.assertRaisesRegex(ValueError,"expected exactly"): + subject.checked_domain(self.root,self.plan) + + def test_plan_and_configuration_cannot_replace_elder_root(self): + self.elder[0]="SubstitutedElder" + (self.root/"inputs"/"elder"/"SubstitutedElder.lean").write_text("-- substituted\n") + self.write_configuration() + with self.assertRaisesRegex(ValueError,"elder roots"): + subject.checked_domain(self.root,self.plan) + + def test_elder_source_directory_is_exact(self): + path=self.root/"lakefile.toml" + path.write_text(path.read_text().replace('srcDir = "inputs/elder"','srcDir = "inputs/elsewhere"')) + with self.assertRaisesRegex(ValueError,"elder source directory"): + subject.checked_domain(self.root,self.plan) + + def test_reordered_domain_rejected(self): + plan=dict(self.plan,production=self.production[::-1]) + with self.assertRaisesRegex(ValueError,"domain differs"): + subject.checked_domain(self.root,plan) + + def test_duplicate_modules_rejected(self): + self.production[-1]=self.support[0] + self.write_configuration() + with self.assertRaisesRegex(ValueError,"unique support modules"): + subject.checked_domain(self.root,self.plan) + + def test_missing_source_rejected(self): + (self.root/(self.production[0]+".lean")).unlink() + with self.assertRaisesRegex(ValueError,"registered source is absent"): + subject.checked_domain(self.root,self.plan) + +class IndependentCensusTests(unittest.TestCase): + def row(self,module="Fixture",name="Fixture.witness"): + return dict(module=module,name=name,kind="theorem",type="True",user_written=True,user_name=name) + def stream(self,rows): + return "".join("SOURCE514_CENSUS "+json.dumps(r)+"\n" for r in rows) + def test_exact_census(self): + expected,rows=subject.parse_census(self.stream([self.row()]),["Fixture"]) + self.assertEqual(expected,{"module_counts":{"Fixture":1},"module_declarations":{"Fixture":["Fixture.witness"]}}) + self.assertEqual(len(rows),1) + def test_duplicate_names_rejected(self): + with self.assertRaisesRegex(ValueError,"duplicate census"): + subject.parse_census(self.stream([self.row(),self.row()]),["Fixture"]) + def test_omitted_registered_module_rejected(self): + with self.assertRaisesRegex(ValueError,"omitted a registered"): + subject.parse_census(self.stream([self.row()]),["Fixture","Other"]) + def test_unrecognized_output_rejected(self): + with self.assertRaisesRegex(ValueError,"unrecognized"): + subject.parse_census("PASS\n",["Fixture"]) + def test_empty_literal_type_rejected(self): + row=self.row();row["type"]="" + with self.assertRaisesRegex(ValueError,"literal type"): + subject.parse_census(self.stream([row]),["Fixture"]) + def test_non_boolean_origin_rejected(self): + row=self.row();row["user_written"]=1 + with self.assertRaisesRegex(ValueError,"literal type/origin"): + subject.parse_census(self.stream([row]),["Fixture"]) + def test_unknown_fields_rejected(self): + row=self.row();row["ignored"]={} + with self.assertRaisesRegex(ValueError,"record fields"): + subject.parse_census(self.stream([row]),["Fixture"]) + def test_duplicate_json_keys_rejected(self): + line=self.stream([self.row()]).replace('"name": "Fixture.witness"','"name": "other", "name": "Fixture.witness"') + with self.assertRaisesRegex(ValueError,"duplicate census JSON"): + subject.parse_census(line,["Fixture"]) + def test_unsupported_kind_rejected(self): + row=self.row();row["kind"]="ignored" + with self.assertRaisesRegex(ValueError,"unsupported census"): + subject.parse_census(self.stream([row]),["Fixture"]) + def test_empty_user_name_rejected(self): + row=self.row();row["user_name"]="" + with self.assertRaisesRegex(ValueError,"user name"): + subject.parse_census(self.stream([row]),["Fixture"]) + def test_non_kernel_codegen_names_are_explicitly_recorded(self): + metadata={"module":"Fixture","name":"Fixture.witness._boxed","classification":"NON_KERNEL_CODE_GENERATOR_OWNERSHIP"} + stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) + expected,rows=subject.parse_census(stream,["Fixture"]) + self.assertEqual(expected["non_kernel_codegen_ownership"],[metadata]) + self.assertEqual(expected["module_declarations"],{"Fixture":["Fixture.witness"]}) + self.assertEqual(len(rows),1) + def test_codegen_metadata_cannot_hide_a_kernel_declaration(self): + metadata={"module":"Fixture","name":"Fixture.witness","classification":"NON_KERNEL_CODE_GENERATOR_OWNERSHIP"} + stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) + with self.assertRaisesRegex(ValueError,"overlaps kernel census"): + subject.parse_census(stream,["Fixture"]) + def test_generated_census_uses_exact_table_and_all_modules(self): + program=subject.census_program(["Fixture","Other"]) + self.assertIn("let names := data.constNames.qsort Name.lt",program) + self.assertIn("for extraName in data.extraConstNames",program) + self.assertIn("code-generator metadata unexpectedly has a kernel declaration",program) + self.assertIn("#["+chr(96)+"Fixture, "+chr(96)+"Other]",program) + self.assertIn("missing independent census module",program) + self.assertNotIn("MODLITERAL",program) + +if __name__=="__main__": + unittest.main() diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index 2bddc8c2f..db58ee70d 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -11,6 +11,15 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) import cbz_source514_hosted as subject +class LeanEnvironmentTests(unittest.TestCase): + def test_inherited_module_search_paths_are_removed(self): + with mock.patch.dict(os.environ, {"LEAN_PATH":"/outside/lean","LEAN_SRC_PATH":"/outside/source","CBZ_FIXTURE":"retained"}): + result=subject.lean_environment() + self.assertNotIn("LEAN_PATH",result) + self.assertNotIn("LEAN_SRC_PATH",result) + self.assertEqual(result["CBZ_FIXTURE"],"retained") + self.assertEqual(result["LEAN_NUM_THREADS"],"2") + class SourceBindingTests(unittest.TestCase): def setUp(self): self.temporary = tempfile.TemporaryDirectory() @@ -154,6 +163,27 @@ def test_symlinked_nested_directory_is_rejected(self): with self.assertRaisesRegex(ValueError,"symlink"): subject.object_snapshot(package,[]) + def test_symlinked_build_ancestor_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + outside=Path(temporary)/"outside" + package.mkdir() + outside.joinpath("build").mkdir(parents=True) + outside.joinpath("build","Owned.olean").write_bytes(b"object") + package.joinpath(".lake").symlink_to(outside,target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + + def test_dangling_nested_symlink_is_rejected(self): + with tempfile.TemporaryDirectory() as temporary: + package=Path(temporary)/"package" + build=package/".lake/build/lib/lean" + build.mkdir(parents=True) + (build/"Owned.olean").write_bytes(b"owned") + (build/"Dangling").symlink_to(package/"missing",target_is_directory=True) + with self.assertRaisesRegex(ValueError,"symlink"): + subject.object_snapshot(package,[]) + def test_dependency_object_root_appearance_is_rejected(self): with tempfile.TemporaryDirectory() as temporary: package=Path(temporary) @@ -257,7 +287,20 @@ def test_missing_imported_elder_source_rejected(self): def test_plan_and_configuration_cannot_jointly_omit_elder_root(self): self.elder.pop() self.write_configuration() - with self.assertRaisesRegex(ValueError,"expected exactly"): + with self.assertRaisesRegex(ValueError,"elder roots"): + subject.checked_domain(self.root,self.plan) + + def test_plan_and_configuration_cannot_replace_elder_root(self): + self.elder[0]="SubstitutedElder" + (self.root/"inputs"/"elder"/"SubstitutedElder.lean").write_text("-- substituted\n") + self.write_configuration() + with self.assertRaisesRegex(ValueError,"elder roots"): + subject.checked_domain(self.root,self.plan) + + def test_elder_source_directory_is_exact(self): + path=self.root/"lakefile.toml" + path.write_text(path.read_text().replace('srcDir = "inputs/elder"','srcDir = "inputs/elsewhere"')) + with self.assertRaisesRegex(ValueError,"elder source directory"): subject.checked_domain(self.root,self.plan) def test_reordered_domain_rejected(self): diff --git a/tools/cbz_source514_hosted.py b/tools/cbz_source514_hosted.py index 1672fa21e..6b16fcf7d 100644 --- a/tools/cbz_source514_hosted.py +++ b/tools/cbz_source514_hosted.py @@ -25,6 +25,13 @@ def sha(data): return hashlib.sha256(data).hexdigest() +def lean_environment(): + environment = os.environ.copy() + for key in ("LEAN_PATH", "LEAN_SRC_PATH"): + environment.pop(key, None) + environment["LEAN_NUM_THREADS"] = "2" + return environment + def git_environment(): environment = {key: value for key, value in os.environ.items() if not key.startswith("GIT_")} environment.update(GIT_CONFIG_NOSYSTEM="1", GIT_CONFIG_GLOBAL=os.devnull, @@ -149,12 +156,18 @@ def object_snapshot(package, dependencies): records = {} root_presence = {} for index, root in enumerate(roots): - root_presence[str(root.relative_to(package))] = root.is_dir() + relative = root.relative_to(package) + for parent in [package.joinpath(*relative.parts[:i]) for i in range(1,len(relative.parts)+1)]: + if parent.is_symlink(): # MUTATION_ROOT_SYMLINK + raise ValueError("symlink in compiled-object root") + root_presence[str(relative)] = root.is_dir() if not root.is_dir(): if index == 0: raise ValueError("owned compiled object directory absent") continue for path in sorted(root.rglob("*")): + if path.is_symlink(): # MUTATION_NESTED_SYMLINK + raise ValueError("symlink within compiled-object root") if path.is_file() and (".olean" in path.name or ".ilean" in path.name or path.suffix in {".so", ".a"}): if path.is_symlink(): raise ValueError("aliased compiled object") @@ -189,15 +202,22 @@ def checked_domain(package, plan): configuration = tomllib.loads((package / "lakefile.toml").read_text()) production = configuration["defaultTargets"] support = next(x for x in configuration["lean_lib"] if x["name"] == "SourceDerivativeInputs")["roots"] - if production != plan["production"] or support != plan["support"]: # MUTATION_DOMAIN - raise ValueError("registered production/support domain differs from exact plan") - modules = support + production - if len(production) != 67 or len(support) != 25 or len(modules) != len(set(modules)): - raise ValueError("expected exactly 67 production and 25 unique support modules") + elder_library = next(x for x in configuration["lean_lib"] if x["name"] == "SourceElderInputs") + elder = elder_library["roots"] + if elder_library.get("srcDir") != "inputs/elder": + raise ValueError("registered elder source directory differs from exact plan") + if production != plan["production"] or support != plan["support"] or elder != plan["elder"]: # MUTATION_DOMAIN + raise ValueError("registered production/support/elder domain differs from exact plan") + if elder != ["SuperlevelBar", "ElderClearance", "ReusedCompactFrontier", "ClosedSuperlevel", "OrdinaryH0", "ElderInterval", "ElderBridge"]: # MUTATION_ELDER_IDENTITIES + raise ValueError("registered elder roots differ from frozen source") + modules = elder + support + production + if len(production) != 67 or len(support) != 25 or len(elder) != 7 or len(modules) != len(set(modules)): # MUTATION_ELDER_COUNT + raise ValueError("expected exactly 67 production and 32 unique support modules") for module in modules: if not isinstance(module, str) or not all(p.isidentifier() and p.isascii() for p in module.split(".")): raise ValueError("unsupported module name") - sources = ["inputs/" + m.replace(".", "/") + ".lean" for m in support] + sources = ["inputs/elder/" + m.replace(".", "/") + ".lean" for m in elder] + sources += ["inputs/" + m.replace(".", "/") + ".lean" for m in support] sources += [m.replace(".", "/") + ".lean" for m in production] sources += ["lakefile.toml", "lake-manifest.json", "lean-toolchain"] if any(not (package / p).is_file() for p in sources): @@ -321,10 +341,10 @@ def execute(source, replay, collector, plan_path, output, carrier, carrier_head, "started_utc": datetime.now(timezone.utc).isoformat(), "phase_results": [], "repository": os.environ.get("GITHUB_REPOSITORY"), "run_id": os.environ.get("GITHUB_RUN_ID"), "run_attempt": os.environ.get("GITHUB_RUN_ATTEMPT"), "owned_modules": modules, - "scope": "Exact frozen 92-module registered import closure; seven unconsumed elder copies and mathematical application/nonvacuity claims remain outside this replay.", + "scope": "Exact frozen 99-module registered import closure; mathematical application and premise-inhabitation claims remain outside this replay.", "recorder_sha256": recorder.__source_sha256__, "replay_tool_sha256": tool.__source_sha256__, "launcher_sha256": loaded_launcher_sha256, "execution_inputs_before": execution_before} - environment = dict(os.environ, LEAN_NUM_THREADS="2") + environment = lean_environment() def phase(name, command, cwd=package, timeout=1800): return recorder.run_phase(name, [str(x) for x in command], cwd, environment, output, report, timeout=timeout) try: diff --git a/tools/cbz_source514_mutations.py b/tools/cbz_source514_mutations.py index f2d4a57f1..a4cad7e45 100644 --- a/tools/cbz_source514_mutations.py +++ b/tools/cbz_source514_mutations.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Three reason-bound source mutations of the source514 recorder's custody/domain guards.""" +"""Six reason-bound source mutations of the source514 recorder's custody/domain guards.""" import json from pathlib import Path import shutil @@ -18,8 +18,11 @@ mutations=[ ("head",'if actual != expected_commit: # MUTATION_HEAD','if False: # MUTATION_HEAD',"SourceBindingTests.test_wrong_head_rejected"), ("bytes",'if actual_bytes != expected: # MUTATION_BYTES','if False: # MUTATION_BYTES',"SourceBindingTests.test_dirty_bytes_rejected_even_assume_unchanged"), - ("domain",'if production != plan["production"] or support != plan["support"]: # MUTATION_DOMAIN','if False: # MUTATION_DOMAIN',"RegisteredDomainTests.test_reordered_domain_rejected")] -report={"schema":"cbz-source514-recorder-mutations-v1","threshold":"all three source mutants in normal and optimized Python modes","source_sha256":hashlib.sha256(source.read_bytes()).hexdigest(),"executions":[],"status":"NOT_PASS"} + ("domain",'if production != plan["production"] or support != plan["support"] or elder != plan["elder"]: # MUTATION_DOMAIN','if False: # MUTATION_DOMAIN',"RegisteredDomainTests.test_reordered_domain_rejected"), + ("elder_identities",'if elder != ["SuperlevelBar", "ElderClearance", "ReusedCompactFrontier", "ClosedSuperlevel", "OrdinaryH0", "ElderInterval", "ElderBridge"]: # MUTATION_ELDER_IDENTITIES','if False: # MUTATION_ELDER_IDENTITIES',"RegisteredDomainTests.test_plan_and_configuration_cannot_replace_elder_root"), + ("object_root_symlink",'if parent.is_symlink(): # MUTATION_ROOT_SYMLINK','if False: # MUTATION_ROOT_SYMLINK',"CompiledObjectCustodyTests.test_symlinked_build_root_is_rejected"), + ("object_nested_symlink",'if path.is_symlink(): # MUTATION_NESTED_SYMLINK','if False: # MUTATION_NESTED_SYMLINK',"CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected")] +report={"schema":"cbz-source514-recorder-mutations-v1","threshold":"all six source mutants in normal and optimized Python modes","source_sha256":hashlib.sha256(source.read_bytes()).hexdigest(),"executions":[],"status":"NOT_PASS"} try: for mode in ["normal","optimized"]: optimize=["-O"] if mode=="optimized" else [] @@ -47,7 +50,7 @@ intended=(result.returncode==1 and "AssertionError: ValueError not raised" in stderr and "FAILED (failures=1)" in stderr and "Ran 1 test" in stderr and "ERROR:" not in stderr) report["executions"].append({"mode":mode,"label":label,"exit":result.returncode,"intended_guard_failure":intended}) if not intended: raise RuntimeError("mutant not killed for its named guard: "+prefix) - report["status"]="ALL_THREE_REASON_BOUND_MUTANTS_KILLED_IN_BOTH_MODES" + report["status"]="ALL_SIX_REASON_BOUND_MUTANTS_KILLED_IN_BOTH_MODES" finally: (args.output/"REPORT.json").write_text(json.dumps(report,indent=2)+"\n") print(report["status"]) From fcbf44e9420f92f8ea767913702f75dbdcd491d0 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:26:32 -0500 Subject: [PATCH 03/10] Test code-generator metadata overlapping real kernel declarations --- tests/test_cbz_source514_hosted.py | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index db58ee70d..8b8190934 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -373,6 +373,52 @@ def test_codegen_metadata_cannot_hide_a_kernel_declaration(self): stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) with self.assertRaisesRegex(ValueError,"overlaps kernel census"): subject.parse_census(stream,["Fixture"]) + def overlap(self, module="Fixture", name="Fixture.witness", actual="Fixture", candidates=None, resolved="Fixture"): + return {"module":module,"name":name,"classification":"KERNEL_CODE_GENERATOR_OVERLAP", + "declaring_modules":[actual] if candidates is None else candidates, + "resolved_module":resolved} + + def test_kernel_codegen_overlap_is_censused_exactly_once(self): + metadata=self.overlap() + stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) + expected,rows=subject.parse_census(stream,["Fixture"]) + self.assertEqual(expected["kernel_codegen_overlaps"],[metadata]) + self.assertEqual(expected["module_declarations"],{"Fixture":["Fixture.witness"]}) + self.assertEqual(len(rows),1) + + def test_cross_module_and_external_overlaps_keep_real_provenance(self): + metadata=[self.overlap(module="Fixture",name="Other.witness",actual="Other",resolved="Fixture"), + self.overlap(module="Fixture",name="External.witness",actual="External",resolved="Fixture")] + stream="".join("SOURCE514_CODEGEN_METADATA "+json.dumps(m)+"\n" for m in metadata) + stream+=self.stream([self.row(),self.row(module="Other",name="Other.witness")]) + expected,_=subject.parse_census(stream,["Fixture","Other"]) + self.assertEqual(expected["kernel_codegen_overlaps"],metadata) + self.assertEqual(expected["module_declarations"]["Other"],["Other.witness"]) + + def test_duplicate_extra_name_in_distinct_modules_is_not_a_duplicate_pair(self): + metadata=[self.overlap(module="Fixture",name="Other.witness",actual="Other"), + self.overlap(module="Other",name="Other.witness",actual="Other")] + stream="".join("SOURCE514_CODEGEN_METADATA "+json.dumps(m)+"\n" for m in metadata) + stream+=self.stream([self.row(),self.row(module="Other",name="Other.witness")]) + expected,_=subject.parse_census(stream,["Fixture","Other"]) + self.assertEqual(len(expected["kernel_codegen_overlaps"]),2) + + def test_overlap_requires_unique_true_owner_and_selected_kernel_row(self): + bad=[self.overlap(candidates=[]),self.overlap(candidates=["Fixture","Other"]), + self.overlap(actual="Other",candidates=["Fixture"]), + self.overlap(name="Fixture.missing")] + for metadata in bad: + with self.subTest(metadata=metadata): + stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) + with self.assertRaises(ValueError): + subject.parse_census(stream,["Fixture"]) + + def test_repeated_metadata_pair_rejected(self): + metadata=self.overlap() + stream=2*("SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n")+self.stream([self.row()]) + with self.assertRaisesRegex(ValueError,"duplicate"): + subject.parse_census(stream,["Fixture"]) + def test_generated_census_uses_exact_table_and_all_modules(self): program=subject.census_program(["Fixture","Other"]) self.assertIn("let names := data.constNames.qsort Name.lt",program) From 693be1cc025959eb21317828a4b53e4693c66bbd Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:29:26 -0500 Subject: [PATCH 04/10] Bind real declaration ownership across code-generator overlaps Preserve and hash-check the 99-module RED; recheck exact table provenance, include each selected kernel declaration once, and execute an adverse omitted-seed control on the actual SourceFourierSeries overlap. --- .github/workflows/cbz-source514-hosted.yml | 20 ++- cbz/source514-hosted/README.md | 14 +- tests/test_cbz_source514_hosted.py | 36 ++++- tools/cbz_source514_hosted.py | 165 +++++++++++++++++++-- tools/cbz_source514_mutations.py | 11 +- 5 files changed, 221 insertions(+), 25 deletions(-) diff --git a/.github/workflows/cbz-source514-hosted.yml b/.github/workflows/cbz-source514-hosted.yml index c3e0bc684..e100bcd42 100644 --- a/.github/workflows/cbz-source514-hosted.yml +++ b/.github/workflows/cbz-source514-hosted.yml @@ -48,7 +48,25 @@ jobs: print('RETAINED_ORIGINAL_RED_STREAM',item.filename) print(archive.read(item).decode('utf-8')) PY - - name: Verify recorder contracts and all six reason-bound source mutations + - name: Retain exact 99-module census overlap RED + env: + GH_TOKEN: ${{ github.token }} + run: | + gh api repos/d6g8k5htny-coder/Math-/actions/artifacts/12931294592/zip > "$RUNNER_TEMP/cbz-source514-overlap-original-red.zip" + python - "$RUNNER_TEMP/cbz-source514-overlap-original-red.zip" <<'PY' + import hashlib,sys,zipfile + raw=open(sys.argv[1],"rb").read() + if hashlib.sha256(raw).hexdigest() != "80da0006a541b084df5a939c6a032bb41a6e180058f3250f7489c6179fccaeee": + raise SystemExit("original overlap RED artifact hash mismatch") + with zipfile.ZipFile(sys.argv[1]) as archive: + matches=[n for n in archive.namelist() if n.endswith("independent-compiled-census.stdout")] + if len(matches)!=1: raise SystemExit("missing or ambiguous original census stdout") + original=archive.read(matches[0]).decode("utf-8") + marker="code-generator metadata unexpectedly has a kernel declaration: _private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter" + if marker not in original: raise SystemExit("original overlap failure not present") + print("ORIGINAL_OVERLAP_RED",marker) + PY + - name: Verify recorder contracts and all nine reason-bound source mutations run: | python -B -S tools/cbz_source514_mutations.py --output "$RUNNER_TEMP/cbz-source514-recorder-tests" - name: Obtain immutable mathematical source diff --git a/cbz/source514-hosted/README.md b/cbz/source514-hosted/README.md index 4a62947f8..a32b09b17 100644 --- a/cbz/source514-hosted/README.md +++ b/cbz/source514-hosted/README.md @@ -6,13 +6,13 @@ This narrow execution carrier serves CBZ criteria3,6,7,9 and11. It does not chan The independent census enumerates compiled module-table constants (with all code-generator ownership metadata explicitly recorded outside the kernel census), records every owned constant's literal type, kind and source-range origin, and is compared with the replay program's separate full environment ownership enumeration. The existing verified program checks every selected module, every owned declaration and its complete transitive type/value closure, rejects unsafe/partial constants and nonstandard axioms, and calls pinned Lean4.34.1's empty trust-level-zero Kernel.Environment.replay. Only Classical.choice, Quot.sound and propext are admitted. Mathematical model adequacy, satisfiability of all hypotheses and prose applications are outside this claim. -Run the recorder contracts and all six source mutations in both Python modes: +Run the recorder contracts and all nine source mutations in both Python modes: ```sh python3.11 -B -S tools/cbz_source514_mutations.py --output /new/recorder-selftest ``` -The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of six uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. +The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of nine uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. Prepare clean source/replay/collector checkouts at the above exact commits, install the package's pinned Lean/Mathlib dependencies, then run: @@ -28,8 +28,16 @@ Preserved test-first RED: b841fcc18ad7ebbe136ff7d237c8b61455e8e02f, native run40 Additional observed RED: native run40946268822/job123702332184 at source787ad73c42805155a50afca5a30b02e48e39726e ran43 cases and observed one real Git-replacement false acceptance plus one inherited-GIT_DIR redirect error. The repair reuses main701's no-replacement/sanitized-Git environment pattern for every command, including cat-file batch. Existing fixed-scope guard mutation thresholds are unchanged. -Original all92-module build: run40943603468/job123693053386 compiled every selected module with exit0. Its census then failed because it demanded a kernel declaration for `_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter._boxed`. Pinned Lean4.34.1's `ModuleData` explicitly defines extraConstNames as code-generator ownership metadata absent from the ConstantInfo mapping. The repaired census retains and prints every such extra name as NON_KERNEL_CODE_GENERATOR_OWNERSHIP and fails if it unexpectedly has a kernel declaration. Every actual kernel declaration remains checked by the independent full module-table census and the separate complete environment ownership enumeration; no mathematical theorem, bound, failed proof or test is dropped. The original failed diagnostic stream is retained, checksum-verified and printed by subsequent hosted attempts. This is a precise kernel/IR boundary, not a weakened proof obligation. +Original all92-module build: run40943603468/job123693053386 compiled every selected module with exit0. Its census then failed because it demanded a kernel declaration for `_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter._boxed`. Pinned Lean4.34.1's `ModuleData` explicitly defines extraConstNames as code-generator ownership metadata absent from the ConstantInfo mapping. That old census wrongly required every extra name to be non-kernel; the later 99-module run disproved this assumption. Every actual kernel declaration remains checked by the independent full module-table census and the separate complete environment ownership enumeration; no mathematical theorem, bound, failed proof or test is dropped. The original failed diagnostic stream is retained, checksum-verified and printed by subsequent hosted attempts. This is a precise kernel/IR boundary, not a weakened proof obligation. ## Corrected source and object boundary Independent review showed that seven SourceElderInputs roots are transitively imported by the production modules. The previous 92-module report omitted those source bindings and their owned-module census; prior runs remain historical and do not certify complete source custody. The revised carrier binds and replays all 99 roots and rejects symlinked compiled-object roots, ancestors, and nested entries. Inherited LEAN_PATH and LEAN_SRC_PATH are removed before execution. The in-memory Python 3.11 normal-mode adverse fixture run observed 10 failures among 16 tests on the prior source and no errors; the exact source and raw output are retained in this directory. A subsequent 16-case normal-mode run on the candidate before the separate environment-guard addition observed exit0; it is not a full suite or kernel qualification. Fresh native tests, all six mutations in both modes and actual 99-module replay remain required. Observation recorded 2026-10-29 20:36:47 UTC. + +## Real kernel declarations that overlap code-generator metadata + +The 99-module run 40950630609 built all 99 modules, then failed its census on `_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter`, a real declaration also listed as code-generator ownership metadata. Its original artifact 12931294592 is retained and checked against SHA-256 `80da0006a541b084df5a939c6a032bb41a6e180058f3250f7489c6179fccaeee`. No full replay passed in that run. + +The revised census scans all loaded module declaration tables for the actual owner of each selected extra name and distinguishes true non-kernel metadata from overlaps. It refuses missing or ambiguous provenance; repeated metadata names in different modules are recorded as distinct module/name pairs. An overlap owned by a selected module must occur exactly once in that module's kernel census. External overlaps are recorded without promotion. + +The replay program now enumerates environment declarations against unique declaration-table ownership rather than `getModuleIdxFor?`, whose map also consumes code-generator metadata. The original pinned collector and generated program's proof-closure/kernel logic remain unchanged, and both the original and corrected program hashes are recorded. The updated workflow includes an actual frozen SourceFourierSeries overlap fixture, a positive kernel replay, and an omitted-seed mutation requiring the specific count-mismatch rejection. New Python source mutations cover ambiguous/missing overlap handling and the replay replacement anchor. All tests, actual fixture execution, 99-module replay and downloaded artifact verification remain pending until observed on the corrected head. diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index 8b8190934..c70716a0d 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -405,7 +405,7 @@ def test_duplicate_extra_name_in_distinct_modules_is_not_a_duplicate_pair(self): def test_overlap_requires_unique_true_owner_and_selected_kernel_row(self): bad=[self.overlap(candidates=[]),self.overlap(candidates=["Fixture","Other"]), - self.overlap(actual="Other",candidates=["Fixture"]), + self.overlap(actual="Other"), self.overlap(name="Fixture.missing")] for metadata in bad: with self.subTest(metadata=metadata): @@ -413,17 +413,49 @@ def test_overlap_requires_unique_true_owner_and_selected_kernel_row(self): with self.assertRaises(ValueError): subject.parse_census(stream,["Fixture"]) + def test_ambiguous_extra_provenance_rejected(self): + metadata=self.overlap(candidates=["Fixture","Other"]) + stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) + with self.assertRaisesRegex(ValueError,"unique declaration provenance"): + subject.parse_census(stream,["Fixture"]) + + def test_selected_overlap_missing_from_owner_rejected(self): + metadata=self.overlap(name="Fixture.missing") + stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) + with self.assertRaisesRegex(ValueError,"selected kernel overlap missing"): + subject.parse_census(stream,["Fixture"]) + + def test_replay_generator_rejects_missing_original_ownership_anchor(self): + class FakeReplay: + def generate_program(self, helper, collector_hash, modules, imports): + return "changed generator", {"program_sha256":"original"} + with self.assertRaisesRegex(ValueError,"unexpected original replay"): + subject.corrected_replay_program(FakeReplay(),None,["Fixture"]) + def test_repeated_metadata_pair_rejected(self): metadata=self.overlap() stream=2*("SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n")+self.stream([self.row()]) with self.assertRaisesRegex(ValueError,"duplicate"): subject.parse_census(stream,["Fixture"]) + def test_corrected_replay_uses_declaration_tables_not_extra_ownership_map(self): + class FakeReplay: + def generate_program(self, helper, collector_hash, modules, imports): + return subject.REPLAY_OWNER_ORIGINAL, {"program_sha256":"old"} + program,metadata=subject.corrected_replay_program(FakeReplay(),None,["Fixture"]) + self.assertIn("REPLAY_DECLARATION_TABLE_PROVENANCE",program) + self.assertIn("tableOwners[name]?",program) + self.assertNotIn("env.getModuleIdxFor? name == some idx",program) + self.assertEqual(metadata["original_program_sha256"],"old") + self.assertEqual(metadata["program_sha256"],subject.sha(program.encode())) + def test_generated_census_uses_exact_table_and_all_modules(self): program=subject.census_program(["Fixture","Other"]) self.assertIn("let names := data.constNames.qsort Name.lt",program) self.assertIn("for extraName in data.extraConstNames",program) - self.assertIn("code-generator metadata unexpectedly has a kernel declaration",program) + self.assertIn("kernel overlap has non-unique declaration provenance",program) + self.assertIn("env.header.moduleData.size",program) + self.assertIn("declaring_modules",program) self.assertIn("#["+chr(96)+"Fixture, "+chr(96)+"Other]",program) self.assertIn("missing independent census module",program) self.assertNotIn("MODLITERAL",program) diff --git a/tools/cbz_source514_hosted.py b/tools/cbz_source514_hosted.py index 6b16fcf7d..8febccc6f 100644 --- a/tools/cbz_source514_hosted.py +++ b/tools/cbz_source514_hosted.py @@ -232,20 +232,43 @@ def census_program(modules): run_cmd do let env := (← getEnv).setExporting false let modules : Array Name := MODLITERAL + let mut extras : Array (Name × Name) := #[] + let mut extraNames : Std.HashSet Name := {} for modName in modules do let some idx := env.getModuleIdx? modName | throwError "missing independent census module: {modName}" - let data := env.header.moduleData[idx]! - -- Pinned Lean ModuleData declares extraConstNames to be code-generator - -- ownership metadata absent from its ConstantInfo mapping. Record every - -- such name explicitly; an unexpected kernel declaration fails closed. - for extraName in data.extraConstNames do - if (env.find? extraName).isSome then - throwError "code-generator metadata unexpectedly has a kernel declaration: {extraName}" + for extraName in env.header.moduleData[idx]!.extraConstNames do + extras := extras.push (modName, extraName) + extraNames := extraNames.insert extraName + let mut owners : Std.HashMap Name (Array Name) := {} + for idx in [:env.header.moduleData.size] do + let owner := env.header.moduleNames[idx]! + for name in env.header.moduleData[idx]!.constNames do + if extraNames.contains name then + owners := owners.insert name ((owners[name]?.getD #[]).push owner) + for (modName, extraName) in extras do + let candidates := owners[extraName]?.getD #[] + if (env.find? extraName).isSome then + if candidates.size != 1 then + throwError "kernel overlap has non-unique declaration provenance: {extraName} {candidates}" + let resolved := (env.getModuleIdxFor? extraName).map fun idx => toString (env.header.moduleNames[idx]!) + let metadata := Json.mkObj [ + ("module", Json.str (toString modName)), ("name", Json.str (toString extraName)), + ("classification", Json.str "KERNEL_CODE_GENERATOR_OVERLAP"), + ("declaring_modules", toJson (candidates.map toString)), + ("resolved_module", toJson resolved)] + liftIO <| IO.println s!"SOURCE514_CODEGEN_METADATA {metadata.compress}" + else + if !candidates.isEmpty then + throwError "non-kernel extra has declaration-table provenance: {extraName}" let metadata := Json.mkObj [ ("module", Json.str (toString modName)), ("name", Json.str (toString extraName)), ("classification", Json.str "NON_KERNEL_CODE_GENERATOR_OWNERSHIP")] liftIO <| IO.println s!"SOURCE514_CODEGEN_METADATA {metadata.compress}" + for modName in modules do + let some idx := env.getModuleIdx? modName + | throwError "missing independent census module: {modName}" + let data := env.header.moduleData[idx]! let names := data.constNames.qsort Name.lt if names.isEmpty then throwError "empty independent census module: {modName}" for name in names do @@ -277,17 +300,36 @@ def unique(pairs): value[key] = item return value result = {"module_counts": {}, "module_declarations": {}} - rows, extra_codegen = [], [] + rows, extra_codegen, kernel_overlaps = [], [], [] seen, extra_seen = set(), set() for line in text.splitlines(): if line.startswith("SOURCE514_CODEGEN_METADATA "): metadata = json.loads(line.removeprefix("SOURCE514_CODEGEN_METADATA "), object_pairs_hook=unique) - if set(metadata) != {"module", "name", "classification"} or metadata["module"] not in modules or metadata["classification"] != "NON_KERNEL_CODE_GENERATOR_OWNERSHIP": - raise ValueError("invalid non-kernel code-generator metadata") - if not isinstance(metadata["name"], str) or not metadata["name"] or metadata["name"] in extra_seen: - raise ValueError("invalid or duplicate code-generator metadata name") - extra_seen.add(metadata["name"]) - extra_codegen.append(metadata) + if not isinstance(metadata, dict): + raise ValueError("invalid code-generator metadata") + module, name = metadata.get("module"), metadata.get("name") + if module not in modules or not isinstance(name, str) or not name: + raise ValueError("invalid code-generator metadata identity") + pair = (module, name) + if pair in extra_seen: + raise ValueError("duplicate code-generator metadata pair") + extra_seen.add(pair) + classification = metadata.get("classification") + if classification == "NON_KERNEL_CODE_GENERATOR_OWNERSHIP": + if set(metadata) != {"module", "name", "classification"}: + raise ValueError("invalid non-kernel code-generator metadata") + extra_codegen.append(metadata) + elif classification == "KERNEL_CODE_GENERATOR_OVERLAP": + if set(metadata) != {"module", "name", "classification", "declaring_modules", "resolved_module"}: + raise ValueError("invalid kernel overlap metadata") + candidates, resolved = metadata["declaring_modules"], metadata["resolved_module"] + if not isinstance(candidates, list) or len(candidates) != 1 or not isinstance(candidates[0], str) or not candidates[0]: + raise ValueError("kernel overlap lacks unique declaration provenance") + if resolved is not None and (not isinstance(resolved, str) or not resolved): + raise ValueError("invalid ownership-map observation") + kernel_overlaps.append(metadata) + else: + raise ValueError("invalid code-generator metadata classification") continue if not line.startswith("SOURCE514_CENSUS "): raise ValueError("unrecognized independent census output") @@ -309,13 +351,59 @@ def unique(pairs): rows.append(row) if set(result["module_declarations"]) != set(modules): raise ValueError("independent census omitted a registered module") - if seen & extra_seen: + if seen & {item["name"] for item in extra_codegen}: raise ValueError("non-kernel code-generator metadata overlaps kernel census") + for item in kernel_overlaps: + owner, name = item["declaring_modules"][0], item["name"] + if owner in modules: + if name not in result["module_declarations"][owner]: + raise ValueError("selected kernel overlap missing from unique declaring module") + elif name in seen: + raise ValueError("external kernel overlap incorrectly included in selected census") result["module_counts"] = {m: len(ns) for m, ns in result["module_declarations"].items()} if extra_codegen: result["non_kernel_codegen_ownership"] = extra_codegen + if kernel_overlaps: + result["kernel_codegen_overlaps"] = kernel_overlaps return result, rows +# The legacy replay program uses getModuleIdxFor?, whose ownership metadata +# may overlap a declaration actually owned by another module. Preserve the +# original collector and proof-closure logic; replace only seed ownership with +# unique provenance from the complete imported constNames tables. +REPLAY_OWNER_ORIGINAL = ''' let mut seeds : Array Name := #[] + for modName in modules do + let some idx := env.getModuleIdx? modName + | throwError "missing candidate module: {modName}" + let names := (env.constants.toList.filterMap fun (name, _) => + if env.getModuleIdxFor? name == some idx then some name else none).toArray.qsort Name.lt''' + +REPLAY_OWNER_REPLACEMENT = ''' -- REPLAY_DECLARATION_TABLE_PROVENANCE + let mut tableOwners : Std.HashMap Name Name := {} + for idx in [:env.header.moduleData.size] do + let owner := env.header.moduleNames[idx]! + for name in env.header.moduleData[idx]!.constNames do + if (tableOwners[name]?).isSome then + throwError "kernel declaration has ambiguous table provenance: {name}" + tableOwners := tableOwners.insert name owner + let mut seeds : Array Name := #[] + for modName in modules do + let some _idx := env.getModuleIdx? modName + | throwError "missing candidate module: {modName}" + let names := (env.constants.toList.filterMap fun (name, _) => + if tableOwners[name]? == some modName then some name else none).toArray.qsort Name.lt''' + +def corrected_replay_program(tool, helper, modules): + program, metadata = tool.generate_program(helper, COLLECTOR_SHA256, modules, modules) + if program.count(REPLAY_OWNER_ORIGINAL) != 1: + raise ValueError("unexpected original replay ownership program") + corrected = program.replace(REPLAY_OWNER_ORIGINAL, REPLAY_OWNER_REPLACEMENT, 1) + metadata = dict(metadata) + metadata["original_program_sha256"] = metadata["program_sha256"] + metadata["program_sha256"] = sha(corrected.encode()) + metadata["seed_ownership"] = "unique declaration-table provenance; getModuleIdxFor is not used" + return corrected, metadata + def load(name, path, expected_sha256): data = Path(path).read_bytes() if sha(data) != expected_sha256: @@ -368,6 +456,53 @@ def phase(name, command, cwd=package, timeout=1800): for number, module in enumerate(modules): phase("build-" + str(number).zfill(2) + "-" + module.replace(".", "_"), ["lake", "build", "+" + module]) with frozen_objects(package, expected_revisions) as object_records: + # The source packet itself supplies a reproducible genuine + # extraConstNames/constNames overlap. Require the overlap, + # kernel replay its actual owner once, and execute an omitted + # seed mutant that the transcript validator must reject for + # the exact beginning/completion count discrepancy. + fixture_module = "SourceFourierSeries" + fixture_name = "_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter" + fixture_census_path = output / "OverlapFixtureCensus.lean" + fixture_census_path.write_text(census_program([fixture_module])) + phase("overlap-fixture-census", ["lake", "env", "lean", "-j2", "-M12000", fixture_census_path], timeout=2700) + if (output / "overlap-fixture-census.stderr").read_bytes(): + raise ValueError("overlap fixture census emitted stderr") + fixture_expected, _ = parse_census((output / "overlap-fixture-census.stdout").read_text(), [fixture_module]) + fixture_overlaps = [item for item in fixture_expected.get("kernel_codegen_overlaps", []) + if item["name"] == fixture_name] + if not fixture_overlaps or any(item["declaring_modules"] != [fixture_module] for item in fixture_overlaps): + raise ValueError("actual fixture did not establish the declared kernel overlap and owner") + if fixture_expected["module_declarations"][fixture_module].count(fixture_name) != 1: + raise ValueError("actual fixture overlap is not present exactly once in the kernel census") + fixture_program, fixture_metadata = corrected_replay_program(tool, helper, [fixture_module]) + fixture_program_path = output / "OverlapFixtureReplay.lean" + fixture_program_path.write_text(fixture_program) + _, _, fixture_code = phase("overlap-fixture-replay", ["lake", "env", "lean", "-j2", "-M12000", fixture_program_path], timeout=2700) + fixture_result = tool.validate_transcript( + (output / "overlap-fixture-replay.stdout").read_text(), fixture_expected, + fixture_metadata["program_sha256"], exit_code=fixture_code, + stderr=(output / "overlap-fixture-replay.stderr").read_text()) + original_seed = " seeds := seeds.push name" + mutated_seed = " if name != `" + fixture_name + " then seeds := seeds.push name" + if fixture_program.count(original_seed) != 1: + raise ValueError("overlap fixture seed mutation target is not unique") + mutated_program = fixture_program.replace(original_seed, mutated_seed, 1) + mutated_path = output / "OverlapFixtureOmittedSeed.lean" + mutated_path.write_text(mutated_program) + _, _, mutated_code = phase("overlap-fixture-omitted-seed", ["lake", "env", "lean", "-j2", "-M12000", mutated_path], timeout=2700) + try: + tool.validate_transcript( + (output / "overlap-fixture-omitted-seed.stdout").read_text(), fixture_expected, + sha(mutated_program.encode()), exit_code=mutated_code, + stderr=(output / "overlap-fixture-omitted-seed.stderr").read_text()) + except ValueError as error: + if str(error) != "replay beginning/completion/census counts disagree": + raise ValueError("overlap mutant failed for an unintended reason") from error + else: + raise ValueError("overlap omitted-seed mutant was not detected") + report["actual_overlap_fixture"] = {"name": fixture_name, "observations": fixture_overlaps, + "positive_replay": fixture_result, "omitted_seed_mutant": "EXPECTED_COUNT_MISMATCH"} census_path = output / "IndependentCensus.lean" census_path.write_text(census_program(modules)) phase("independent-compiled-census", ["lake", "env", "lean", "-j2", "-M12000", census_path], timeout=2700) diff --git a/tools/cbz_source514_mutations.py b/tools/cbz_source514_mutations.py index a4cad7e45..43a02dad8 100644 --- a/tools/cbz_source514_mutations.py +++ b/tools/cbz_source514_mutations.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Six reason-bound source mutations of the source514 recorder's custody/domain guards.""" +"""Nine reason-bound source mutations of the source514 recorder's custody/domain guards.""" import json from pathlib import Path import shutil @@ -21,8 +21,11 @@ ("domain",'if production != plan["production"] or support != plan["support"] or elder != plan["elder"]: # MUTATION_DOMAIN','if False: # MUTATION_DOMAIN',"RegisteredDomainTests.test_reordered_domain_rejected"), ("elder_identities",'if elder != ["SuperlevelBar", "ElderClearance", "ReusedCompactFrontier", "ClosedSuperlevel", "OrdinaryH0", "ElderInterval", "ElderBridge"]: # MUTATION_ELDER_IDENTITIES','if False: # MUTATION_ELDER_IDENTITIES',"RegisteredDomainTests.test_plan_and_configuration_cannot_replace_elder_root"), ("object_root_symlink",'if parent.is_symlink(): # MUTATION_ROOT_SYMLINK','if False: # MUTATION_ROOT_SYMLINK',"CompiledObjectCustodyTests.test_symlinked_build_root_is_rejected"), - ("object_nested_symlink",'if path.is_symlink(): # MUTATION_NESTED_SYMLINK','if False: # MUTATION_NESTED_SYMLINK',"CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected")] -report={"schema":"cbz-source514-recorder-mutations-v1","threshold":"all six source mutants in normal and optimized Python modes","source_sha256":hashlib.sha256(source.read_bytes()).hexdigest(),"executions":[],"status":"NOT_PASS"} + ("object_nested_symlink",'if path.is_symlink(): # MUTATION_NESTED_SYMLINK','if False: # MUTATION_NESTED_SYMLINK',"CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected"), + ("ambiguous_overlap",'len(candidates) != 1 or not isinstance(candidates[0], str)','False or not isinstance(candidates[0], str)',"IndependentCensusTests.test_ambiguous_extra_provenance_rejected"), + ("missing_overlap",'if name not in result["module_declarations"][owner]:','if False:',"IndependentCensusTests.test_selected_overlap_missing_from_owner_rejected"), + ("generator_anchor",'if program.count(REPLAY_OWNER_ORIGINAL) != 1:','if False:',"IndependentCensusTests.test_replay_generator_rejects_missing_original_ownership_anchor")] +report={"schema":"cbz-source514-recorder-mutations-v1","threshold":"all nine source mutants in normal and optimized Python modes","source_sha256":hashlib.sha256(source.read_bytes()).hexdigest(),"executions":[],"status":"NOT_PASS"} try: for mode in ["normal","optimized"]: optimize=["-O"] if mode=="optimized" else [] @@ -50,7 +53,7 @@ intended=(result.returncode==1 and "AssertionError: ValueError not raised" in stderr and "FAILED (failures=1)" in stderr and "Ran 1 test" in stderr and "ERROR:" not in stderr) report["executions"].append({"mode":mode,"label":label,"exit":result.returncode,"intended_guard_failure":intended}) if not intended: raise RuntimeError("mutant not killed for its named guard: "+prefix) - report["status"]="ALL_SIX_REASON_BOUND_MUTANTS_KILLED_IN_BOTH_MODES" + report["status"]="ALL_NINE_REASON_BOUND_MUTANTS_KILLED_IN_BOTH_MODES" finally: (args.output/"REPORT.json").write_text(json.dumps(report,indent=2)+"\n") print(report["status"]) From 5916b0884bf261bac976b038d70f1314b3048062 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:29:40 -0500 Subject: [PATCH 05/10] Align retained census source assertion with table scan --- tests/test_cbz_source514_hosted.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index c70716a0d..e9d8da68b 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -452,7 +452,7 @@ def generate_program(self, helper, collector_hash, modules, imports): def test_generated_census_uses_exact_table_and_all_modules(self): program=subject.census_program(["Fixture","Other"]) self.assertIn("let names := data.constNames.qsort Name.lt",program) - self.assertIn("for extraName in data.extraConstNames",program) + self.assertIn("for extraName in env.header.moduleData[idx]!.extraConstNames",program) self.assertIn("kernel overlap has non-unique declaration provenance",program) self.assertIn("env.header.moduleData.size",program) self.assertIn("declaring_modules",program) From 9c2c26d899b6a25cadd3459fb9ed12e3c033c3ec Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:31:18 -0500 Subject: [PATCH 06/10] Test contradictory repeated metadata observations --- tests/test_cbz_source514_hosted.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index e9d8da68b..a99882327 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -413,6 +413,22 @@ def test_overlap_requires_unique_true_owner_and_selected_kernel_row(self): with self.assertRaises(ValueError): subject.parse_census(stream,["Fixture"]) + def test_same_extra_name_cannot_have_inconsistent_classification(self): + first={"module":"Fixture","name":"External.witness","classification":"NON_KERNEL_CODE_GENERATOR_OWNERSHIP"} + second=self.overlap(module="Other",name="External.witness",actual="External",resolved="Fixture") + stream="".join("SOURCE514_CODEGEN_METADATA "+json.dumps(m)+"\n" for m in [first,second]) + stream+=self.stream([self.row(),self.row(module="Other",name="Other.witness")]) + with self.assertRaisesRegex(ValueError,"inconsistent metadata observations"): + subject.parse_census(stream,["Fixture","Other"]) + + def test_same_extra_name_cannot_have_inconsistent_provenance(self): + first=self.overlap(module="Fixture",name="External.witness",actual="External",resolved="Fixture") + second=self.overlap(module="Other",name="External.witness",actual="Different",resolved="Other") + stream="".join("SOURCE514_CODEGEN_METADATA "+json.dumps(m)+"\n" for m in [first,second]) + stream+=self.stream([self.row(),self.row(module="Other",name="Other.witness")]) + with self.assertRaisesRegex(ValueError,"inconsistent metadata observations"): + subject.parse_census(stream,["Fixture","Other"]) + def test_ambiguous_extra_provenance_rejected(self): metadata=self.overlap(candidates=["Fixture","Other"]) stream="SOURCE514_CODEGEN_METADATA "+json.dumps(metadata)+"\n"+self.stream([self.row()]) From 2ba10344225e92bc292c9c85968c5f07839d5df2 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:31:45 -0500 Subject: [PATCH 07/10] Reconcile selected declaration provenance and repeated metadata Run the full census before selecting the genuine overlap fixture. Apply the corrected replay program to the production domain, and reject inconsistent per-name metadata observations. --- .github/workflows/cbz-source514-hosted.yml | 2 +- cbz/source514-hosted/README.md | 8 +-- tools/cbz_source514_hosted.py | 58 +++++++++++++++------- tools/cbz_source514_mutations.py | 9 ++-- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/.github/workflows/cbz-source514-hosted.yml b/.github/workflows/cbz-source514-hosted.yml index e100bcd42..36ec4da67 100644 --- a/.github/workflows/cbz-source514-hosted.yml +++ b/.github/workflows/cbz-source514-hosted.yml @@ -66,7 +66,7 @@ jobs: if marker not in original: raise SystemExit("original overlap failure not present") print("ORIGINAL_OVERLAP_RED",marker) PY - - name: Verify recorder contracts and all nine reason-bound source mutations + - name: Verify recorder contracts and all ten reason-bound source mutations run: | python -B -S tools/cbz_source514_mutations.py --output "$RUNNER_TEMP/cbz-source514-recorder-tests" - name: Obtain immutable mathematical source diff --git a/cbz/source514-hosted/README.md b/cbz/source514-hosted/README.md index a32b09b17..17f720030 100644 --- a/cbz/source514-hosted/README.md +++ b/cbz/source514-hosted/README.md @@ -6,13 +6,13 @@ This narrow execution carrier serves CBZ criteria3,6,7,9 and11. It does not chan The independent census enumerates compiled module-table constants (with all code-generator ownership metadata explicitly recorded outside the kernel census), records every owned constant's literal type, kind and source-range origin, and is compared with the replay program's separate full environment ownership enumeration. The existing verified program checks every selected module, every owned declaration and its complete transitive type/value closure, rejects unsafe/partial constants and nonstandard axioms, and calls pinned Lean4.34.1's empty trust-level-zero Kernel.Environment.replay. Only Classical.choice, Quot.sound and propext are admitted. Mathematical model adequacy, satisfiability of all hypotheses and prose applications are outside this claim. -Run the recorder contracts and all nine source mutations in both Python modes: +Run the recorder contracts and all ten source mutations in both Python modes: ```sh python3.11 -B -S tools/cbz_source514_mutations.py --output /new/recorder-selftest ``` -The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of nine uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. +The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of ten uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. Prepare clean source/replay/collector checkouts at the above exact commits, install the package's pinned Lean/Mathlib dependencies, then run: @@ -40,4 +40,6 @@ The 99-module run 40950630609 built all 99 modules, then failed its census on `_ The revised census scans all loaded module declaration tables for the actual owner of each selected extra name and distinguishes true non-kernel metadata from overlaps. It refuses missing or ambiguous provenance; repeated metadata names in different modules are recorded as distinct module/name pairs. An overlap owned by a selected module must occur exactly once in that module's kernel census. External overlaps are recorded without promotion. -The replay program now enumerates environment declarations against unique declaration-table ownership rather than `getModuleIdxFor?`, whose map also consumes code-generator metadata. The original pinned collector and generated program's proof-closure/kernel logic remain unchanged, and both the original and corrected program hashes are recorded. The updated workflow includes an actual frozen SourceFourierSeries overlap fixture, a positive kernel replay, and an omitted-seed mutation requiring the specific count-mismatch rejection. New Python source mutations cover ambiguous/missing overlap handling and the replay replacement anchor. All tests, actual fixture execution, 99-module replay and downloaded artifact verification remain pending until observed on the corrected head. +The replay program now enumerates environment declarations against unique selected-declaration table ownership rather than `getModuleIdxFor?`, whose map also consumes code-generator metadata. The original pinned collector and generated program's proof-closure/kernel logic remain unchanged, and both the original and corrected program hashes are recorded. The updated workflow includes an actual frozen SourceFourierSeries overlap fixture, a positive kernel replay, and an omitted-seed mutation requiring the specific count-mismatch rejection. New Python source mutations cover ambiguous/missing overlap handling and the replay replacement anchor. All tests, actual fixture execution, 99-module replay and downloaded artifact verification remain pending until observed on the corrected head. + +Repeated metadata for the same name must agree on classification, unique declaring module and the observed map owner, while different module/name pairs remain separately recorded. Replay rejects ambiguity involving a selected declaration; unrelated external duplicate tables do not prevent admission of the selected domain. This correction is pending actual execution and artifact validation. diff --git a/tools/cbz_source514_hosted.py b/tools/cbz_source514_hosted.py index 8febccc6f..213f54d21 100644 --- a/tools/cbz_source514_hosted.py +++ b/tools/cbz_source514_hosted.py @@ -302,6 +302,7 @@ def unique(pairs): result = {"module_counts": {}, "module_declarations": {}} rows, extra_codegen, kernel_overlaps = [], [], [] seen, extra_seen = set(), set() + metadata_observations = {} for line in text.splitlines(): if line.startswith("SOURCE514_CODEGEN_METADATA "): metadata = json.loads(line.removeprefix("SOURCE514_CODEGEN_METADATA "), object_pairs_hook=unique) @@ -318,6 +319,7 @@ def unique(pairs): if classification == "NON_KERNEL_CODE_GENERATOR_OWNERSHIP": if set(metadata) != {"module", "name", "classification"}: raise ValueError("invalid non-kernel code-generator metadata") + observation = (classification, None, None) extra_codegen.append(metadata) elif classification == "KERNEL_CODE_GENERATOR_OVERLAP": if set(metadata) != {"module", "name", "classification", "declaring_modules", "resolved_module"}: @@ -327,9 +329,13 @@ def unique(pairs): raise ValueError("kernel overlap lacks unique declaration provenance") if resolved is not None and (not isinstance(resolved, str) or not resolved): raise ValueError("invalid ownership-map observation") + observation = (classification, tuple(candidates), resolved) kernel_overlaps.append(metadata) else: raise ValueError("invalid code-generator metadata classification") + if name in metadata_observations and metadata_observations[name] != observation: # MUTATION_OVERLAP_CONSISTENCY + raise ValueError("inconsistent metadata observations for same name") + metadata_observations[name] = observation continue if not line.startswith("SOURCE514_CENSUS "): raise ValueError("unrecognized independent census output") @@ -379,13 +385,20 @@ def unique(pairs): if env.getModuleIdxFor? name == some idx then some name else none).toArray.qsort Name.lt''' REPLAY_OWNER_REPLACEMENT = ''' -- REPLAY_DECLARATION_TABLE_PROVENANCE + let mut selectedNames : Std.HashSet Name := {} + for modName in modules do + let some idx := env.getModuleIdx? modName + | throwError "missing candidate module: {modName}" + for name in env.header.moduleData[idx]!.constNames do + selectedNames := selectedNames.insert name let mut tableOwners : Std.HashMap Name Name := {} for idx in [:env.header.moduleData.size] do let owner := env.header.moduleNames[idx]! for name in env.header.moduleData[idx]!.constNames do - if (tableOwners[name]?).isSome then - throwError "kernel declaration has ambiguous table provenance: {name}" - tableOwners := tableOwners.insert name owner + if selectedNames.contains name then + if (tableOwners[name]?).isSome then + throwError "selected kernel declaration has ambiguous table provenance: {name}" + tableOwners := tableOwners.insert name owner let mut seeds : Array Name := #[] for modName in modules do let some _idx := env.getModuleIdx? modName @@ -456,26 +469,42 @@ def phase(name, command, cwd=package, timeout=1800): for number, module in enumerate(modules): phase("build-" + str(number).zfill(2) + "-" + module.replace(".", "_"), ["lake", "build", "+" + module]) with frozen_objects(package, expected_revisions) as object_records: + census_path = output / "IndependentCensus.lean" + census_path.write_text(census_program(modules)) + phase("independent-compiled-census", ["lake", "env", "lean", "-j2", "-M12000", census_path], timeout=2700) + stderr = (output / "independent-compiled-census.stderr").read_bytes() + if stderr: + raise ValueError("independent census emitted stderr") + expected, literals = parse_census((output / "independent-compiled-census.stdout").read_text(), modules) + (output / "compiled-census.json").write_text(json.dumps(expected, indent=2) + "\n") + (output / "compiled-literal-types.json").write_text(json.dumps(literals, indent=2, ensure_ascii=False) + "\n") # The source packet itself supplies a reproducible genuine # extraConstNames/constNames overlap. Require the overlap, # kernel replay its actual owner once, and execute an omitted # seed mutant that the transcript validator must reject for # the exact beginning/completion count discrepancy. - fixture_module = "SourceFourierSeries" fixture_name = "_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter" + actual_overlaps = [item for item in expected.get("kernel_codegen_overlaps", []) + if item["name"] == fixture_name] + if not actual_overlaps: + raise ValueError("full census did not record the original real kernel overlap") + fixture_owner = actual_overlaps[0]["declaring_modules"][0] + if fixture_owner != "SourceFourierSeries": + raise ValueError("original overlap declaration has unexpected actual module") + fixture_modules = list(dict.fromkeys([item["module"] for item in actual_overlaps] + [fixture_owner])) fixture_census_path = output / "OverlapFixtureCensus.lean" - fixture_census_path.write_text(census_program([fixture_module])) + fixture_census_path.write_text(census_program(fixture_modules)) phase("overlap-fixture-census", ["lake", "env", "lean", "-j2", "-M12000", fixture_census_path], timeout=2700) if (output / "overlap-fixture-census.stderr").read_bytes(): raise ValueError("overlap fixture census emitted stderr") - fixture_expected, _ = parse_census((output / "overlap-fixture-census.stdout").read_text(), [fixture_module]) + fixture_expected, _ = parse_census((output / "overlap-fixture-census.stdout").read_text(), fixture_modules) fixture_overlaps = [item for item in fixture_expected.get("kernel_codegen_overlaps", []) if item["name"] == fixture_name] - if not fixture_overlaps or any(item["declaring_modules"] != [fixture_module] for item in fixture_overlaps): + if not fixture_overlaps or any(item["declaring_modules"] != [fixture_owner] for item in fixture_overlaps): raise ValueError("actual fixture did not establish the declared kernel overlap and owner") - if fixture_expected["module_declarations"][fixture_module].count(fixture_name) != 1: + if fixture_expected["module_declarations"][fixture_owner].count(fixture_name) != 1: raise ValueError("actual fixture overlap is not present exactly once in the kernel census") - fixture_program, fixture_metadata = corrected_replay_program(tool, helper, [fixture_module]) + fixture_program, fixture_metadata = corrected_replay_program(tool, helper, fixture_modules) fixture_program_path = output / "OverlapFixtureReplay.lean" fixture_program_path.write_text(fixture_program) _, _, fixture_code = phase("overlap-fixture-replay", ["lake", "env", "lean", "-j2", "-M12000", fixture_program_path], timeout=2700) @@ -503,16 +532,7 @@ def phase(name, command, cwd=package, timeout=1800): raise ValueError("overlap omitted-seed mutant was not detected") report["actual_overlap_fixture"] = {"name": fixture_name, "observations": fixture_overlaps, "positive_replay": fixture_result, "omitted_seed_mutant": "EXPECTED_COUNT_MISMATCH"} - census_path = output / "IndependentCensus.lean" - census_path.write_text(census_program(modules)) - phase("independent-compiled-census", ["lake", "env", "lean", "-j2", "-M12000", census_path], timeout=2700) - stderr = (output / "independent-compiled-census.stderr").read_bytes() - if stderr: - raise ValueError("independent census emitted stderr") - expected, literals = parse_census((output / "independent-compiled-census.stdout").read_text(), modules) - (output / "compiled-census.json").write_text(json.dumps(expected, indent=2) + "\n") - (output / "compiled-literal-types.json").write_text(json.dumps(literals, indent=2, ensure_ascii=False) + "\n") - program, metadata = tool.generate_program(helper, COLLECTOR_SHA256, modules, modules) + program, metadata = corrected_replay_program(tool, helper, modules) program_path = output / "BoundedKernelReplay.lean" program_path.write_text(program) (output / "replay-program.json").write_text(json.dumps(metadata, indent=2) + "\n") diff --git a/tools/cbz_source514_mutations.py b/tools/cbz_source514_mutations.py index 43a02dad8..7900c0b59 100644 --- a/tools/cbz_source514_mutations.py +++ b/tools/cbz_source514_mutations.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Nine reason-bound source mutations of the source514 recorder's custody/domain guards.""" +"""Ten reason-bound source mutations of the source514 recorder's custody/domain guards.""" import json from pathlib import Path import shutil @@ -24,8 +24,9 @@ ("object_nested_symlink",'if path.is_symlink(): # MUTATION_NESTED_SYMLINK','if False: # MUTATION_NESTED_SYMLINK',"CompiledObjectCustodyTests.test_symlinked_nested_directory_is_rejected"), ("ambiguous_overlap",'len(candidates) != 1 or not isinstance(candidates[0], str)','False or not isinstance(candidates[0], str)',"IndependentCensusTests.test_ambiguous_extra_provenance_rejected"), ("missing_overlap",'if name not in result["module_declarations"][owner]:','if False:',"IndependentCensusTests.test_selected_overlap_missing_from_owner_rejected"), - ("generator_anchor",'if program.count(REPLAY_OWNER_ORIGINAL) != 1:','if False:',"IndependentCensusTests.test_replay_generator_rejects_missing_original_ownership_anchor")] -report={"schema":"cbz-source514-recorder-mutations-v1","threshold":"all nine source mutants in normal and optimized Python modes","source_sha256":hashlib.sha256(source.read_bytes()).hexdigest(),"executions":[],"status":"NOT_PASS"} + ("generator_anchor",'if program.count(REPLAY_OWNER_ORIGINAL) != 1:','if False:',"IndependentCensusTests.test_replay_generator_rejects_missing_original_ownership_anchor"), + ("metadata_consistency",'if name in metadata_observations and metadata_observations[name] != observation: # MUTATION_OVERLAP_CONSISTENCY','if False: # MUTATION_OVERLAP_CONSISTENCY',"IndependentCensusTests.test_same_extra_name_cannot_have_inconsistent_classification")] +report={"schema":"cbz-source514-recorder-mutations-v1","threshold":"all ten source mutants in normal and optimized Python modes","source_sha256":hashlib.sha256(source.read_bytes()).hexdigest(),"executions":[],"status":"NOT_PASS"} try: for mode in ["normal","optimized"]: optimize=["-O"] if mode=="optimized" else [] @@ -53,7 +54,7 @@ intended=(result.returncode==1 and "AssertionError: ValueError not raised" in stderr and "FAILED (failures=1)" in stderr and "Ran 1 test" in stderr and "ERROR:" not in stderr) report["executions"].append({"mode":mode,"label":label,"exit":result.returncode,"intended_guard_failure":intended}) if not intended: raise RuntimeError("mutant not killed for its named guard: "+prefix) - report["status"]="ALL_NINE_REASON_BOUND_MUTANTS_KILLED_IN_BOTH_MODES" + report["status"]="ALL_TEN_REASON_BOUND_MUTANTS_KILLED_IN_BOTH_MODES" finally: (args.output/"REPORT.json").write_text(json.dumps(report,indent=2)+"\n") print(report["status"]) From 0d18f6081601928c22f96de72f99fe869a68521e Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:32:27 -0500 Subject: [PATCH 08/10] Use exact textual identity in the real omitted-seed control --- tools/cbz_source514_hosted.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cbz_source514_hosted.py b/tools/cbz_source514_hosted.py index 213f54d21..30f0b6a31 100644 --- a/tools/cbz_source514_hosted.py +++ b/tools/cbz_source514_hosted.py @@ -513,7 +513,7 @@ def phase(name, command, cwd=package, timeout=1800): fixture_metadata["program_sha256"], exit_code=fixture_code, stderr=(output / "overlap-fixture-replay.stderr").read_text()) original_seed = " seeds := seeds.push name" - mutated_seed = " if name != `" + fixture_name + " then seeds := seeds.push name" + mutated_seed = ' if toString name != "' + fixture_name + '" then seeds := seeds.push name' if fixture_program.count(original_seed) != 1: raise ValueError("overlap fixture seed mutation target is not unique") mutated_program = fixture_program.replace(original_seed, mutated_seed, 1) From 60eab243ee17d0adba915f91263383a1e8765e27 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:32:53 -0500 Subject: [PATCH 09/10] Clarify observed and pending overlap qualification evidence --- cbz/source514-hosted/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cbz/source514-hosted/README.md b/cbz/source514-hosted/README.md index 17f720030..755d3e1fb 100644 --- a/cbz/source514-hosted/README.md +++ b/cbz/source514-hosted/README.md @@ -12,7 +12,7 @@ Run the recorder contracts and all ten source mutations in both Python modes: python3.11 -B -S tools/cbz_source514_mutations.py --output /new/recorder-selftest ``` -The45 finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of ten uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. +The finite contract cases include dirty bytes under assume-unchanged, valid-but-different Git heads, loaded-code identity, missing/reordered/duplicate domain entries and malformed/incomplete compiled censuses. The mutation threshold is100% of ten uniquely anchored source guard removals in both Python modes, requiring the named assertion failure; launch/import/syntax failures do not count as kills. The workflow also runs the original replay reader's31 cases and three source mutants, followed by its actual Lean positive/adverse fixtures and six generated-auditor mutants in both modes before any package admission. Prepare clean source/replay/collector checkouts at the above exact commits, install the package's pinned Lean/Mathlib dependencies, then run: @@ -28,11 +28,11 @@ Preserved test-first RED: b841fcc18ad7ebbe136ff7d237c8b61455e8e02f, native run40 Additional observed RED: native run40946268822/job123702332184 at source787ad73c42805155a50afca5a30b02e48e39726e ran43 cases and observed one real Git-replacement false acceptance plus one inherited-GIT_DIR redirect error. The repair reuses main701's no-replacement/sanitized-Git environment pattern for every command, including cat-file batch. Existing fixed-scope guard mutation thresholds are unchanged. -Original all92-module build: run40943603468/job123693053386 compiled every selected module with exit0. Its census then failed because it demanded a kernel declaration for `_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter._boxed`. Pinned Lean4.34.1's `ModuleData` explicitly defines extraConstNames as code-generator ownership metadata absent from the ConstantInfo mapping. That old census wrongly required every extra name to be non-kernel; the later 99-module run disproved this assumption. Every actual kernel declaration remains checked by the independent full module-table census and the separate complete environment ownership enumeration; no mathematical theorem, bound, failed proof or test is dropped. The original failed diagnostic stream is retained, checksum-verified and printed by subsequent hosted attempts. This is a precise kernel/IR boundary, not a weakened proof obligation. +Original all92-module build: run40943603468/job123693053386 compiled every selected module with exit0. Its census then failed because it demanded a kernel declaration for `_private.SourceFourierSeries.0.I4Source.modeCoefficient.match_1.splitter._boxed`. Pinned Lean4.34.1 uses `extraConstNames` for additional code-generator ownership metadata; some such names have no kernel declaration while others overlap real declarations. That old census wrongly required every extra name to be non-kernel; the later 99-module run disproved this assumption. The revised carrier is designed to compare every selected actual kernel declaration with the separate environment ownership enumeration; no mathematical theorem, bound, failed proof or test is dropped. The original failed diagnostic stream is retained, checksum-verified and printed by subsequent hosted attempts. This is a precise kernel/IR boundary, not a weakened proof obligation. ## Corrected source and object boundary -Independent review showed that seven SourceElderInputs roots are transitively imported by the production modules. The previous 92-module report omitted those source bindings and their owned-module census; prior runs remain historical and do not certify complete source custody. The revised carrier binds and replays all 99 roots and rejects symlinked compiled-object roots, ancestors, and nested entries. Inherited LEAN_PATH and LEAN_SRC_PATH are removed before execution. The in-memory Python 3.11 normal-mode adverse fixture run observed 10 failures among 16 tests on the prior source and no errors; the exact source and raw output are retained in this directory. A subsequent 16-case normal-mode run on the candidate before the separate environment-guard addition observed exit0; it is not a full suite or kernel qualification. Fresh native tests, all six mutations in both modes and actual 99-module replay remain required. Observation recorded 2026-10-29 20:36:47 UTC. +Independent review showed that seven SourceElderInputs roots are transitively imported by the production modules. The previous 92-module report omitted those source bindings and their owned-module census; prior runs remain historical and do not certify complete source custody. The revised carrier binds and replays all 99 roots and rejects symlinked compiled-object roots, ancestors, and nested entries. Inherited LEAN_PATH and LEAN_SRC_PATH are removed before execution. The in-memory Python 3.11 normal-mode adverse fixture run observed 10 failures among 16 tests on the prior source and no errors; the exact source and raw output are retained in this directory. A subsequent 16-case normal-mode run on the candidate before the separate environment-guard addition observed exit0; it is not a full suite or kernel qualification. Fresh native tests, all ten mutations in both modes and actual 99-module replay remain required. Observation recorded 2026-10-29 20:36:47 UTC. ## Real kernel declarations that overlap code-generator metadata @@ -40,6 +40,6 @@ The 99-module run 40950630609 built all 99 modules, then failed its census on `_ The revised census scans all loaded module declaration tables for the actual owner of each selected extra name and distinguishes true non-kernel metadata from overlaps. It refuses missing or ambiguous provenance; repeated metadata names in different modules are recorded as distinct module/name pairs. An overlap owned by a selected module must occur exactly once in that module's kernel census. External overlaps are recorded without promotion. -The replay program now enumerates environment declarations against unique selected-declaration table ownership rather than `getModuleIdxFor?`, whose map also consumes code-generator metadata. The original pinned collector and generated program's proof-closure/kernel logic remain unchanged, and both the original and corrected program hashes are recorded. The updated workflow includes an actual frozen SourceFourierSeries overlap fixture, a positive kernel replay, and an omitted-seed mutation requiring the specific count-mismatch rejection. New Python source mutations cover ambiguous/missing overlap handling and the replay replacement anchor. All tests, actual fixture execution, 99-module replay and downloaded artifact verification remain pending until observed on the corrected head. +The replay program now enumerates environment declarations against unique selected-declaration table ownership rather than `getModuleIdxFor?`, whose map also consumes code-generator metadata. The original pinned collector and generated program's proof-closure/kernel logic remain unchanged, and both the original and corrected program hashes will be recorded when execution is observed. The updated workflow includes an actual frozen SourceFourierSeries overlap fixture, a positive kernel replay, and an omitted-seed mutation requiring the specific count-mismatch rejection. New Python source mutations cover ambiguous/missing overlap handling and the replay replacement anchor. All tests, actual fixture execution, 99-module replay and downloaded artifact verification remain pending until observed on the corrected head. Repeated metadata for the same name must agree on classification, unique declaring module and the observed map owner, while different module/name pairs remain separately recorded. Replay rejects ambiguity involving a selected declaration; unrelated external duplicate tables do not prevent admission of the selected domain. This correction is pending actual execution and artifact validation. From 785a71f0b8267d6d11b736dc5f621b1265bd7198 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:35:18 -0500 Subject: [PATCH 10/10] Require checked-kernel identity for metadata overlaps --- cbz/source514-hosted/README.md | 2 ++ tests/test_cbz_source514_hosted.py | 1 + tools/cbz_source514_hosted.py | 23 +++++++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cbz/source514-hosted/README.md b/cbz/source514-hosted/README.md index 755d3e1fb..c08fd95f0 100644 --- a/cbz/source514-hosted/README.md +++ b/cbz/source514-hosted/README.md @@ -43,3 +43,5 @@ The revised census scans all loaded module declaration tables for the actual own The replay program now enumerates environment declarations against unique selected-declaration table ownership rather than `getModuleIdxFor?`, whose map also consumes code-generator metadata. The original pinned collector and generated program's proof-closure/kernel logic remain unchanged, and both the original and corrected program hashes will be recorded when execution is observed. The updated workflow includes an actual frozen SourceFourierSeries overlap fixture, a positive kernel replay, and an omitted-seed mutation requiring the specific count-mismatch rejection. New Python source mutations cover ambiguous/missing overlap handling and the replay replacement anchor. All tests, actual fixture execution, 99-module replay and downloaded artifact verification remain pending until observed on the corrected head. Repeated metadata for the same name must agree on classification, unique declaring module and the observed map owner, while different module/name pairs remain separately recorded. Replay rejects ambiguity involving a selected declaration; unrelated external duplicate tables do not prevent admission of the selected domain. This correction is pending actual execution and artifact validation. + +Before labeling any overlap as a kernel declaration, the generated census also requires its name in Lean's checked kernel environment. An actual Lean inverse-guard mutation must refuse a real fixture overlap with the exact kernel-presence diagnostic; this control is pending execution along with the rest of the candidate. diff --git a/tests/test_cbz_source514_hosted.py b/tests/test_cbz_source514_hosted.py index a99882327..2730cdd4b 100644 --- a/tests/test_cbz_source514_hosted.py +++ b/tests/test_cbz_source514_hosted.py @@ -470,6 +470,7 @@ def test_generated_census_uses_exact_table_and_all_modules(self): self.assertIn("let names := data.constNames.qsort Name.lt",program) self.assertIn("for extraName in env.header.moduleData[idx]!.extraConstNames",program) self.assertIn("kernel overlap has non-unique declaration provenance",program) + self.assertIn("if (env.checked.get.find? extraName).isNone then",program) self.assertIn("env.header.moduleData.size",program) self.assertIn("declaring_modules",program) self.assertIn("#["+chr(96)+"Fixture, "+chr(96)+"Other]",program) diff --git a/tools/cbz_source514_hosted.py b/tools/cbz_source514_hosted.py index 30f0b6a31..eab17dabd 100644 --- a/tools/cbz_source514_hosted.py +++ b/tools/cbz_source514_hosted.py @@ -249,6 +249,8 @@ def census_program(modules): for (modName, extraName) in extras do let candidates := owners[extraName]?.getD #[] if (env.find? extraName).isSome then + if (env.checked.get.find? extraName).isNone then + throwError "code-generator overlap is not a kernel declaration: {extraName}" if candidates.size != 1 then throwError "kernel overlap has non-unique declaration provenance: {extraName} {candidates}" let resolved := (env.getModuleIdxFor? extraName).map fun idx => toString (env.header.moduleNames[idx]!) @@ -446,8 +448,9 @@ def execute(source, replay, collector, plan_path, output, carrier, carrier_head, "recorder_sha256": recorder.__source_sha256__, "replay_tool_sha256": tool.__source_sha256__, "launcher_sha256": loaded_launcher_sha256, "execution_inputs_before": execution_before} environment = lean_environment() - def phase(name, command, cwd=package, timeout=1800): - return recorder.run_phase(name, [str(x) for x in command], cwd, environment, output, report, timeout=timeout) + def phase(name, command, cwd=package, timeout=1800, expected_success=True): + return recorder.run_phase(name, [str(x) for x in command], cwd, environment, output, report, + timeout=timeout, expected_success=expected_success) try: report["source_before"] = bind(source, SOURCE_COMMIT, paths) report["replay_source"] = bind(replay, REPLAY_COMMIT, ["cbz/evidence/kernel/additional/replay-tool/replay_tool.py"]) @@ -498,6 +501,22 @@ def phase(name, command, cwd=package, timeout=1800): if (output / "overlap-fixture-census.stderr").read_bytes(): raise ValueError("overlap fixture census emitted stderr") fixture_expected, _ = parse_census((output / "overlap-fixture-census.stdout").read_text(), fixture_modules) + # Actual Lean control: invert the checked-kernel presence guard. + # A source overlap already verified in this same fixture must then + # be refused with the precise guard diagnostic, not a build error. + census_text = fixture_census_path.read_text() + positive_guard = "if (env.checked.get.find? extraName).isNone then" + inverse_guard = "if (env.checked.get.find? extraName).isSome then" + if census_text.count(positive_guard) != 1: + raise ValueError("actual kernel-presence mutation target is not unique") + inverse_path = output / "OverlapFixtureInverseKernelGuard.lean" + inverse_path.write_text(census_text.replace(positive_guard, inverse_guard, 1)) + _, inverse_output, inverse_code = phase( + "overlap-fixture-inverse-kernel-guard", + ["lake", "env", "lean", "-j2", "-M12000", inverse_path], + timeout=2700, expected_success=False) + if inverse_code != 1 or "code-generator overlap is not a kernel declaration:" not in inverse_output: + raise ValueError("inverse kernel-presence mutant failed for an unintended reason") fixture_overlaps = [item for item in fixture_expected.get("kernel_codegen_overlaps", []) if item["name"] == fixture_name] if not fixture_overlaps or any(item["declaring_modules"] != [fixture_owner] for item in fixture_overlaps):