From f63124c65ce7cd7c5837d948e161e8c9974b068f Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:58:47 -0700 Subject: [PATCH 01/25] test(architecture): define source-relative evidence regression adapter contract --- ...026-10-08-architecture-evidence-adapter.md | 108 +++ tests/test_architecture_evidence_adapter.py | 692 ++++++++++++++++++ 2 files changed, 800 insertions(+) create mode 100644 docs/plans/2026-10-08-architecture-evidence-adapter.md create mode 100644 tests/test_architecture_evidence_adapter.py diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md new file mode 100644 index 000000000..f8f432156 --- /dev/null +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -0,0 +1,108 @@ +# Architecture Evidence Adapter Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Validate inert evidence packets, preserve their original records, and report independent evidence dimensions and loss-only downstream revalidation without authenticating packet custody or promoting science. + +**Architecture:** A stdlib CLI consumes one closed-schema packet on stdin and emits one deterministic report on stdout. Separate adapters retain the main and Math formal formats and existing retrofit records; the independently pinned graph gate supplies graph validation and old/new union reverse-impact semantics. Actual Git capture, native artifact readback, and formal producer custody remain a separately claimed follow-up. + +**Tech Stack:** Python stdlib, JSON/base64/SHA-256/Git blob identities, unittest subprocess controls, existing pinned `hard_gate.py`, hosted ephemeral testing in both normal and optimized interpreter modes. + +**Spec:** [Research architecture design, sections 1/4 and 8](../superpowers/specs/2026-10-08-research-architecture-design.md); [original Task 2](../superpowers/plans/2026-10-08-research-architecture-plan.md). This bounded plan replaces that task's proposed module layout and internal four-argument interface with the agreed packet/CLI ABI below. + +## Global Constraints + +- Starting checkout: main `ad4509d58aea5b1b1ac32dbea7f2be3b591a1345`; worktree `project-evidence-adapter`; coordination pickup main307/6069575569. +- This increment owns new adapter, CLI, tests, and this plan only. Formal workflows, manifests, Lean sources, existing reviews, site assets, and other owners' branches are outside the edit scope. +- Drive/R17 governs research records; GitHub executes and reviews. Scientific effect is always `NONE`; scientific status authority is always exact boolean `false`. +- Source availability, kernel verification, computation, alignment, and review remain independent. Missing evidence is not a pass. Profiles are derived reports, not another scientific-status register. +- Preserve complete original node/edge/review/receipt records. Report holds separately; never rewrite classifications, controlling flags, review verdicts, or original receipts to match the report. +- Input hashes establish internal byte consistency only. No input `authenticated`, capture flag, signature-looking string, or self-consistent native metadata can authorize external custody. Global and every axis custody remain `unknown`. +- Execute no packet-supplied Python, gate, Lean, shell, or test code; fetch no packet-selected URL/path. Trusted gate bytes must match `a78f3e25f3b0cfe113e618a4c31a7a25d7f22af638c46dec1ecba221fa333ac8` before loading their verified buffer. +- No project Python execution on the owner laptop. Observe genuine hosted missing-CLI RED before implementation; retain exact source, normal/optimized logs, failures, and artifacts. Standing owner authorization requires no new permission checkpoint. + +## Review Focus + +- Self-consistent forged Git/run identities remain internally checkable but externally unverified; Task 1 pins this distinction. +- Deep, oversized, duplicate-key, nonfinite, type-coerced, or contradictory captures fail without success JSON; Task 1 pins parser limits and exact types. +- A proof-body edit cannot become a statement edit; absent or incomplete declared slices yield unresolved coverage; Task 3 pins both cases. +- Partial alignment, same-provider lineage, and negative-control runs cannot become whole-manifest alignment or positive kernel execution; Task 2 pins the distinctions. +- Removed dependencies, deleted nodes, context edges, and multiple original alignment identities remain visible in union impact; Task 3 pins exact traversal and affected-record identities. + +--- + +## Agreed v1 ABI + +Create `architecture/evidence_adapter.py`, `tools/architecture_evidence_adapter.py`, and `tests/test_architecture_evidence_adapter.py`. Synthetic fixtures live inside the test module; no separate fixture files are required. The CLI requires each of `--expected-repository`, `--expected-commit`, `--expected-run-id`, and `--expected-run-attempt` exactly once. They compare declared native metadata; they do not attest capture. The module exposes `adapt_packet(packet: dict, expected_context: dict[str, str]) -> dict`; the CLI exposes `main(argv: list[str] | None = None) -> int`. + +Stdin is one UTF-8 JSON document, at most 16 MiB, maximum nesting 64. Every decoded capture is at most 4 MiB. Reject duplicate keys, nonfinite numbers including exponent overflow, trailing documents, unsupported wrapper keys, invalid base64, and nonexact identity/slice types. The tests define the original native document fields supported by each format; no invented merged native schema is accepted. + +The exact packet is `{schema_version: 1, old: Snapshot, new: Snapshot, formal_records: [Formal], retrofit_records: [Retrofit]}`: + +| Type | Exact wrapper fields | +|---|---| +| `Snapshot` | `graph: GitCapture`, `bindings: [Binding]` | +| `Binding` | `node`, `source: GitCapture or null`, `statement_slice: Slice or null`, `proof_slice: Slice or null` | +| `Slice` | `start_byte`, `end_byte`, `sha256` | +| `GitCapture` | `ref: GitRef`, `raw_base64` | +| `GitRef` | `repository`, `commit`, `path`, `git_blob`, `sha256`, `bytes` | +| `RunCapture` | `ref: RunRef`, `raw_base64` | +| `RunRef` | `repository`, `checked_commit`, `run_id`, `run_attempt`, `artifact_id`, `member_path`, `sha256`, `bytes` | +| `Formal` | `id`, `format`, `manifest: GitCapture`, `scope: GitCapture`, `source_files: [GitCapture]`, `receipt: RunCapture or null`, `logs: [RunCapture]`, `alignment: GitCapture or null`, `native_run`, `node_targets: [{node, target}]` | +| `native_run` | `repository`, `checked_commit`, `run_head_sha`, `run_id`, `run_attempt`, `purpose`, `conclusion`, `expected_conclusion` | +| `Retrofit` | `id`, `record: GitCapture`, `node_records: [{node, record_id}]` | + +`format` is exactly `main-formal-gate/v1` or `math-formal-gate/v1`. SHA-256 is lowercase 64 hex; Git commit/blob is lowercase 40 hex; counts and offsets are exact integers; native run/attempt/artifact IDs are positive ASCII decimals without leading zeros. Paths are normalized safe relative paths. Verify raw byte count, SHA-256, and Git blob framing/hash against each capture before parsing embedded documents. Slices bind byte offsets and hashes in their explicit source capture and are **declared byte slices only**, not a semantic Lean parser or coverage certificate. + +The exact report has `schema_version`, `scientific_effect`, `scientific_status_authority`, `custody`, `original_packet`, `dimensions`, `formal_summary`, and `regression`. `original_packet` preserves the complete typed input, including original base64 bytes. Sort only derived lists/maps; do not reorder retained native arrays or alter retained native fields. + +- `dimensions` covers exactly surviving new graph nodes. Each has `source`, `review`, `kernel`, `computation`, and `alignment`, each exactly `{record_state, applicability, reasons, evidence_ids, custody}`. `record_state` uses `recorded`, `not_recorded`, `unknown`, `not_applicable`; applicability uses `current`, `stale`, `unknown`, `not_applicable`. Applicability describes packet-internal consistency only; custody always remains `unknown`. +- Every `formal_summary` row has exactly `{id, format, manifest_targets, node_targets, retained_manifest, retained_receipt, retained_alignment}`. Preserve the original decoded documents and original node-target bindings; `manifest_targets` is the complete sorted native inventory. Null receipts/alignment stay null. +- `regression` has exactly `{changed_nodes, impacted_nodes, statement_changed, proof_changed, unscoped_source_changed, traversal_edges, revalidation_required, affected_alignment_records}`. `revalidation_required` is sorted `[{node, reasons}]` for affected surviving new nodes. `affected_alignment_records` contains exact original alignment `GitRef` objects, deduplicated by full identity and sorted by canonical JSON. Select them only from explicit mapped impacted nodes or stale whole-manifest/scope contracts; unknown mappings never invent an affected record. +- Malformed or contradictory packets exit nonzero, write refusal detail to stderr, and emit no success report. Valid unknown/stale/negative evidence produces a report with exit zero. Output is deterministic and cannot mutate retained records. + +## Task 1: Bounded packet integrity and preservation + +**Files:** Create the adapter module, CLI, and external CLI test module listed above. Tests launch the CLI as a subprocess, propagate `-O`/`-OO`, and use `-B -S`; they do not import implementation code. + +**Interfaces:** Consume the complete v1 packet and expected context. Produce exact typed captures and a deterministic report envelope, preserving all originals with custody `unknown`. + +- [ ] Write subprocess controls for valid deterministic output, preservation, every required CLI argument, matching/changed declared native context, and refusal of any invented capture-auth override. Fixtures are labeled synthetic `TEST.A/B/C` with `TEST.Formal.alpha/beta`; they make no actual capture or execution claim. +- [ ] Add controls for duplicate/nonfinite/deep/oversized stdin, malformed base64, decoded capture limit, byte/SHA/blob mismatch, unsafe paths, offset/hash/type errors, unknown wrapper keys, and multiple documents. A bool must not pass an integer check. +- [ ] Publish the tests-only candidate and run `python -B -S -m unittest discover -s tests -p test_architecture_evidence_adapter.py -v` and the same command with `-O` in the hosted restricted lane. RED must explicitly identify the absent CLI; an import crash, zero discovery, or unrelated failure does not satisfy this step. Root records exact candidate/run/artifact identities and original logs. +- [ ] After observed RED, implement bounded strict parsing, inert capture verification, `adapt_packet`, and the stdout-only CLI. Load only independently pinned repository gate bytes; never a gate supplied in the packet. +- [ ] Repeat those hosted commands on the exact candidate. Require all controls executed, no skipped tests, and identical discovery in both modes. Freeze and commit this independently reviewable packet boundary through the integration owner. + +## Task 2: Native evidence adapters and independent dimensions + +**Files:** Extend `architecture/evidence_adapter.py` and `tests/test_architecture_evidence_adapter.py`; CLI ABI remains unchanged. + +**Interfaces:** Consume verified captures, native documents, explicit target bindings, and expected context from Task 1. Produce all five axes and retained native formal summaries without new authority fields. + +- [ ] Pin main's dict-target inventory, source rows, file hashes, original receipt/log bindings, and Math's distinct list-target inventory in external controls. Source files must cover manifest file hashes; original receipt/log axiom inventories must name only native targets and preserve permitted axioms. Incomplete positive inventories remain unresolved and cannot produce current kernel applicability. +- [ ] Add valid failed-build controls with null receipt and retain failed/skipped/cancelled/negative records. Positive kernel applicability requires `purpose == "check"` and actual `conclusion == "success"`; matching caller-declared `expected_conclusion == "failure"` cannot make a negative control positive. +- [ ] Pin explicit main target joins: node target, node statement slice, exact manifest source identity `(repository, commit, path, bytes, SHA-256)`, and exact informal-anchor bytes within the declared slice. Unknown mappings stay unresolved. Math's native format lacks this main source-row bridge; preserve its inventory/receipt without fabricating an equivalent join. +- [ ] Add whole-manifest alignment controls: exact manifest and scope hash bindings, unique full target coverage, accepted disposition, and distinct declared author/reviewer provider/family/agent. Partial/nonaccepted/stale records remain preserved with stale/unknown applicability; lineage strings establish no authenticated review or organizational independence. +- [ ] Add independent source/review/computation controls against original retrofit records. Changing one axis must not award another; graph classification, review text, matching hash, or green native metadata cannot manufacture kernel, computation, alignment, or scientific acceptance. +- [ ] Observe the corresponding hosted RED controls before implementing the two native adapters and retrofit projection. Rerun the complete adapter suite in both modes, retain originals and review this unit before committing through the integration owner. + +## Task 3: Loss-only union impact and exact alignment identities + +**Files:** Extend the same adapter and external CLI tests. Existing gate/source/review files remain unchanged. + +**Interfaces:** Consume both validated graphs, their explicit source/slice bindings, and Task 2 dimensions/native identities. Produce separate regression lists and exact original affected alignment refs; preserve original graphs unchanged. + +- [ ] Write changed-statement, proof-body-only, missing-slice, unscoped-source change, availability-loss, failed/skipped/missing receipt, stale alignment, removed-edge, deleted-node, added-node, context-edge, and unknown-mapping controls. Include full-record nested type changes that ordinary Python equality can hide. +- [ ] Write the original alignment-identity control: old/new union impacts a downstream node, and `affected_alignment_records` names its original repository/commit/path/blob/SHA/bytes exactly; canonical sorting/dedup cannot merge different original identities. Unmapped nodes yield no guessed review ref. +- [ ] Observe hosted RED, then implement canonical full-record comparisons and pinned union reverse impact. The gate uses **all** old/new `(from, to)` edges, including deleted/context edges; required-edge cycle validation remains a separate rule. Only surviving new nodes appear in revalidation proposals. +- [ ] Keep stable reason codes: `node_record_changed`, `dependency_edges_changed`, `graph_context_changed`, `statement_changed`, `proof_body_changed`, `source_changed_unscoped`, `dependency_changed`; axis reasons include `manifest_binding_changed`, `scope_binding_changed`, `target_coverage_changed`, `alignment_not_accepted`, `lineage_not_distinct`, `native_run_not_success`, `native_run_negative_control`, `native_context_changed`, `missing_statement_slice`, `missing_target_source_binding`. +- [ ] On a proof-only edit, invalidate affected kernel evidence and explicitly byte-bound reviews. Whole-manifest alignment can stale when manifest bytes change; report that binding change without adding `statement_changed` if its declared statement slice is unchanged. A fresh successful kernel record cannot automatically refresh alignment. +- [ ] Run the complete hosted suite in normal and optimized modes on frozen bytes, obtain fresh nonauthor source review, reconcile findings, and preserve the exact report/artifact. Root verifies required current-candidate checks and performs protected integration; this plan author runs no code or Git writes. + +## Completion boundary and follow-ups + +This increment is complete only when the exact CLI ABI and every substantive control pass in hosted execution with original records preserved and reviewed. That establishes packet validation and regression reporting, not authentic Git capture, native artifact custody, actual semantic alignment, or all-eight architecture completion. + +The current dated 49-node graph has no explicit node-to-Lean mapping. A shared informal-source hash does not make the full graph claim kernel checked; main's SIDE24 targets explicitly retain narrower scopes. Synthetic fixtures cannot fill that gap. + +Separately claimed work must acquire exact Git `commit:path` bytes and original native run artifacts, verify archive digests with a fail-closed readback, bind producer identities/current native context, and retain original manifests/receipts/logs. The existing formal upload lacks artifact ID/digest/name outputs and its name omits attempt; the original receipt lacks attempt. Do not edit those producers here or invent authenticated capture from this packet. Base/candidate real-input collection, every-PR required enforcement of this new adapter, SSG artifact consumption, and actual Math transition integration remain unimplemented until separately tested and reconciled with their current owners. diff --git a/tests/test_architecture_evidence_adapter.py b/tests/test_architecture_evidence_adapter.py new file mode 100644 index 000000000..cbbb095dc --- /dev/null +++ b/tests/test_architecture_evidence_adapter.py @@ -0,0 +1,692 @@ +"""External stdin contract controls for a conservative evidence adapter. + +Every graph, source, receipt, Lean-looking text and log below is a synthetic TEST +fixture. Nothing was elaborated by Lean or authenticated by Git/GitHub. Hash and +byte agreement is packet integrity only; custody is always unknown in v1. +Execute this module only in the hosted ephemeral runner, not on the laptop. +""" + +import base64 +import copy +import hashlib +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +CLI = ROOT / "tools/architecture_evidence_adapter.py" +REPO = "d6g8k5htny-coder/main" +HEAD = "a" * 40 +BASE = "b" * 40 +AXES = {"source", "review", "kernel", "computation", "alignment"} +STATES = {"recorded", "not_recorded", "unknown", "not_applicable"} +APPLICABILITY = {"current", "stale", "unknown", "not_applicable"} +ALPHA = "TEST alpha statement: λ\n".encode("utf-8") +PROOF = b"TEST proof old\n" +BETA = b"TEST beta statement\n" +SOURCE = ALPHA + PROOF + BETA +TARGETS = ["TEST.Formal.alpha", "TEST.Formal.beta"] + + +def sha(raw): + return hashlib.sha256(raw).hexdigest() + + +def encoded(document): + return (json.dumps(document, sort_keys=True, indent=2, allow_nan=False) + "\n").encode("utf-8") + + +def raw_bytes(capture): + return base64.b64decode(capture["raw_base64"], validate=True) + + +def document(capture): + return json.loads(raw_bytes(capture)) + + +def git_capture(raw, path, commit=HEAD, repository=REPO): + return {"ref": { + "repository": repository, "commit": commit, "path": path, + "git_blob": hashlib.sha1(b"blob " + str(len(raw)).encode("ascii") + b"\0" + raw).hexdigest(), + "sha256": sha(raw), "bytes": len(raw), + }, "raw_base64": base64.b64encode(raw).decode("ascii")} + + +def replace_git(capture, raw): + ref = capture["ref"] + return git_capture(raw, ref["path"], ref["commit"], ref["repository"]) + + +def run_capture(raw, member): + return {"ref": { + "repository": REPO, "checked_commit": HEAD, "run_id": "123", "run_attempt": "1", + "artifact_id": "456", "member_path": "formal-evidence/" + member, + "sha256": sha(raw), "bytes": len(raw), + }, "raw_base64": base64.b64encode(raw).decode("ascii")} + + +def replace_run(capture, raw): + updated = copy.deepcopy(capture) + updated["ref"].update({"sha256": sha(raw), "bytes": len(raw)}) + updated["raw_base64"] = base64.b64encode(raw).decode("ascii") + return updated + + +def slice_of(raw, start, end): + return {"start_byte": start, "end_byte": end, "sha256": sha(raw[start:end])} + + +class ArchitectureEvidenceAdapterContract(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.cwd = Path(temporary.name) + self.expected = {"repository": REPO, "commit": HEAD, "run-id": "123", "run-attempt": "1"} + graph = { + "schema_version": 1, "object": "TEST-ONLY-EVIDENCE-GRAPH", + "nodes": { + "TEST.A": {"classification": "PROVED_REVIEWED", "controlling": False, + "source": "TEST/source.md", "review_issue": 65, "review_disposition": "ACCEPTED"}, + "TEST.B": {"classification": "PROVED_REVIEWED", "controlling": False, + "notes": "TEST.Formal.alpha resembles this title; this is no target mapping", + "review_disposition": "ACCEPTED"}, + "TEST.C": {"classification": "AUTHOR_SIDE_CANDIDATE", "controlling": False}, + }, + "edges": [ + {"from": "TEST.B", "to": "TEST.A", "required": True, "relation": "TEST premise"}, + {"from": "TEST.C", "to": "TEST.B", "required": False, "relation": "TEST context"}, + ], + } + snapshots = {} + for label, commit in (("old", BASE), ("new", HEAD)): + source = git_capture(SOURCE, "TEST/source.md", commit) + snapshots[label] = { + "graph": git_capture(encoded(graph), "TEST/graph.json", commit), + "bindings": [{"node": "TEST.A", "source": source, + "statement_slice": slice_of(SOURCE, 0, len(ALPHA)), + "proof_slice": slice_of(SOURCE, len(ALPHA), len(ALPHA) + len(PROOF))}], + } + self.packet = {"schema_version": 1, **snapshots, "formal_records": [], "retrofit_records": []} + + def change_graph(self, packet, label, change): + capture = packet[label]["graph"] + graph = document(capture) + change(graph) + packet[label]["graph"] = replace_git(capture, encoded(graph)) + + def change_source(self, packet, label, raw, *, sliced=True): + binding = packet[label]["bindings"][0] + binding["source"] = replace_git(binding["source"], raw) + if sliced: + binding["statement_slice"] = slice_of(raw, 0, len(ALPHA)) + binding["proof_slice"] = slice_of(raw, len(ALPHA), len(ALPHA) + len(PROOF)) + else: + binding["statement_slice"] = binding["proof_slice"] = None + + def formal(self, packet=None): + packet = self.packet if packet is None else packet + source = copy.deepcopy(packet["new"]["bindings"][0]["source"]) + scope = git_capture(b"TEST scope: two declared True targets; no elaboration or scientific claim\n", "TEST/formal/SCOPE.md") + module = git_capture(b"namespace TEST.Formal\ntheorem alpha : True := by trivial\ntheorem beta : True := by trivial\n", "TEST/formal/Demo.lean") + files = [source, scope, module] + source_ref = source["ref"] + manifest = { + "schema_version": 1, "scientific_effect": "NONE", "scientific_status_authority": False, + "package": "TEST-synthetic-package", "package_root": "TEST/formal", "root_module": "TEST.Formal", + "formalization_status": "proved", "alignment_status": "PENDING_INDEPENDENT_REVIEW", + "lean_toolchain": "leanprover/lean4:v4.34.1", "dependency_revisions": {}, "allowed_axioms": [], + "source_modules": ["Demo.lean"], "files": {item["ref"]["path"]: item["ref"]["sha256"] for item in files}, + "sources": [{"id": "TEST-source", "repository": source_ref["repository"], "commit": source_ref["commit"], + "path": source_ref["path"], "bytes": source_ref["bytes"], "sha256": source_ref["sha256"], + "local_copy": source_ref["path"]}], + "targets": [{"name": target, "module": "Demo.lean", "title": "TEST declared target", + "source": "TEST-source", "informal_anchor": anchor.decode("utf-8"), + "does_not_claim": "actual Lean declaration existence or scientific acceptance"} + for target, anchor in zip(TARGETS, (ALPHA, BETA))], + } + manifest_capture = git_capture(encoded(manifest), "TEST/formal/manifest.json") + logs = [run_capture(raw, name) for name, raw in ( + ("build.log", b"TEST synthetic build text; not an executed build\n"), + ("leanchecker.log", b"TEST synthetic checker text; not an executed checker\n"), + ("axioms.log", b"'TEST.Formal.alpha' does not depend on any axioms\n'TEST.Formal.beta' does not depend on any axioms\n"), + ("elaborated-types.log", b"TEST.Formal.alpha : True\nTEST.Formal.beta : True\n"), + )] + receipt = { + "schema_version": 1, "scientific_effect": "NONE", "scientific_status_authority": False, + "package": "TEST-synthetic-package", "formalization_status": "kernel-checked", + "alignment_status": "PENDING_INDEPENDENT_REVIEW", "manifest_sha256": sha(raw_bytes(manifest_capture)), + "checked_commit": HEAD, "repository": REPO, "workflow_run_id": "123", + "lean_version": "Lean (version 4.34.1, TEST fixture only)", "dependency_revisions": {}, + "axioms": {target: [] for target in TARGETS}, + "negative_controls": {"TEST_false_claim": "REJECTED_BY_LEAN", "sorry": "REJECTED_BY_AXIOM_GATE", + "custom_imported": "REJECTED_BY_AXIOM_GATE", "native": "REJECTED_BY_AXIOM_GATE"}, + "logs": {item["ref"]["member_path"].rsplit("/", 1)[1]: item["ref"]["sha256"] for item in logs}, + } + alignment = { + "disposition": "ACCEPTED", "manifest_sha256": sha(raw_bytes(manifest_capture)), + "scope_sha256": scope["ref"]["sha256"], "targets": TARGETS, + "author": {"provider": "TEST-author", "family": "TEST-author-family", "agent": "TEST-author-agent"}, + "reviewer": {"provider": "TEST-reviewer", "family": "TEST-reviewer-family", "agent": "TEST-reviewer-agent"}, + "evidence": {"repository": REPO, "commit": HEAD, "path": "TEST/review-substance.md", "sha256": "e" * 64}, + } + return { + "id": "TEST-formal-1", "format": "main-formal-gate/v1", "manifest": manifest_capture, + "scope": scope, "source_files": files, "receipt": run_capture(encoded(receipt), "receipt.json"), + "logs": logs, "alignment": git_capture(encoded(alignment), "TEST/alignment.json"), + "native_run": {"repository": REPO, "checked_commit": HEAD, "run_head_sha": "d" * 40, + "run_id": "123", "run_attempt": "1", "purpose": "check", + "conclusion": "success", "expected_conclusion": "success"}, + "node_targets": [{"node": "TEST.A", "target": "TEST.Formal.alpha"}], + } + + def with_formal(self): + packet = copy.deepcopy(self.packet) + packet["formal_records"] = [self.formal(packet)] + return packet + + def update_receipt(self, formal, change): + receipt = document(formal["receipt"]) + change(receipt) + formal["receipt"] = replace_run(formal["receipt"], encoded(receipt)) + + def update_alignment(self, formal, change): + alignment = document(formal["alignment"]) + change(alignment) + formal["alignment"] = replace_git(formal["alignment"], encoded(alignment)) + + def replace_log(self, formal, name, raw): + for index, capture in enumerate(formal["logs"]): + if capture["ref"]["member_path"].endswith("/" + name): + formal["logs"][index] = replace_run(capture, raw) + self.update_receipt(formal, lambda receipt: receipt["logs"].update({name: sha(raw)})) + return + self.fail("TEST fixture log not found: " + name) + + def run_adapter(self, packet=None, *, raw=None, expected=None, arguments=None): + self.assertTrue(CLI.is_file(), "required evidence adapter CLI tools/architecture_evidence_adapter.py is absent") + if raw is None: + raw = encoded(self.packet if packet is None else packet).decode("utf-8") + identity = self.expected if expected is None else expected + if arguments is None: + arguments = [] + for name in ("repository", "commit", "run-id", "run-attempt"): + arguments.extend(["--expected-" + name, identity[name]]) + flags = ["-B", "-S"] + if sys.flags.optimize: + flags.append("-" + "O" * sys.flags.optimize) + env = os.environ.copy() + env.pop("PYTHONOPTIMIZE", None) + try: + return subprocess.run([sys.executable, *flags, str(CLI), *arguments], input=raw, + cwd=self.cwd, env=env, capture_output=True, text=True, encoding="utf-8", + timeout=20, check=False) + except subprocess.TimeoutExpired: + self.fail("evidence adapter did not finish within 20 seconds") + + def accepted(self, packet=None, **kwargs): + packet = self.packet if packet is None else packet + result = self.run_adapter(packet, **kwargs) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(result.stderr, "") + report = json.loads(result.stdout) + self.assertEqual(set(report), {"schema_version", "scientific_effect", "scientific_status_authority", + "custody", "original_packet", "dimensions", "formal_summary", "regression"}) + self.assertIs(type(report["schema_version"]), int) + self.assertEqual(report["schema_version"], 1) + self.assertEqual(report["scientific_effect"], "NONE") + self.assertIs(report["scientific_status_authority"], False) + self.assertEqual(report["custody"], "unknown") + self.assertEqual(json.dumps(report["original_packet"], sort_keys=True, allow_nan=False), + json.dumps(packet, sort_keys=True, allow_nan=False), "original typed records changed") + self.assertEqual(set(report["dimensions"]), set(document(packet["new"]["graph"])["nodes"])) + for node, dimensions in report["dimensions"].items(): + self.assertEqual(set(dimensions), AXES, node) + for axis in dimensions.values(): + self.assertEqual(set(axis), {"record_state", "applicability", "reasons", "evidence_ids", "custody"}) + self.assertIn(axis["record_state"], STATES) + self.assertIn(axis["applicability"], APPLICABILITY) + self.assertEqual(axis["custody"], "unknown") + self.assertIsInstance(axis["reasons"], list) + self.assertIsInstance(axis["evidence_ids"], list) + self.assertEqual(set(report["regression"]), {"changed_nodes", "impacted_nodes", "statement_changed", + "proof_changed", "unscoped_source_changed", "traversal_edges", "revalidation_required", + "affected_alignment_records"}) + for proposal in report["regression"]["revalidation_required"]: + self.assertEqual(set(proposal), {"node", "reasons"}) + for summary, formal in zip(report["formal_summary"], packet["formal_records"]): + self.assertEqual(set(summary), {"id", "format", "manifest_targets", "node_targets", + "retained_manifest", "retained_receipt", "retained_alignment"}) + self.assertEqual(summary["id"], formal["id"]) + self.assertEqual(summary["format"], formal["format"]) + retained = {"retained_manifest": document(formal["manifest"]), + "retained_receipt": None if formal["receipt"] is None else document(formal["receipt"]), + "retained_alignment": None if formal["alignment"] is None else document(formal["alignment"]), + "node_targets": formal["node_targets"]} + for key, original in retained.items(): + self.assertEqual(json.dumps(summary[key], sort_keys=True, allow_nan=False), + json.dumps(original, sort_keys=True, allow_nan=False), key) + self.assertEqual(len(report["formal_summary"]), len(packet["formal_records"])) + return report, result + + def refused(self, packet=None, **kwargs): + result = self.run_adapter(packet, **kwargs) + self.assertNotEqual(result.returncode, 0, "invalid packet was accepted") + self.assertNotIn('"original_packet"', result.stdout, "refusal emitted a valid report") + + def test_minimal_unchanged_packet_is_deterministic_unknown_and_inert(self): + before = tuple(self.cwd.iterdir()) + first, first_result = self.accepted() + _, second_result = self.accepted() + self.assertEqual(first_result.stdout, second_result.stdout) + self.assertEqual(tuple(self.cwd.iterdir()), before) + self.assertEqual(first["regression"]["changed_nodes"], []) + self.assertEqual(first["regression"]["impacted_nodes"], []) + self.assertEqual(first["regression"]["affected_alignment_records"], []) + self.assertIn("declared_byte_slice_only", first["dimensions"]["TEST.A"]["source"]["reasons"]) + for axis in ("kernel", "computation", "alignment"): + self.assertEqual(first["dimensions"]["TEST.A"][axis]["applicability"], "unknown") + + def test_complete_formal_scope_is_retained_without_authenticated_or_fuzzy_joins(self): + packet = self.with_formal() + report, _ = self.accepted(packet) + self.assertEqual(report["formal_summary"][0]["manifest_targets"], TARGETS) + self.assertEqual(set(report["formal_summary"][0]["retained_receipt"]["axioms"]), set(TARGETS)) + for axis in ("kernel", "alignment"): + self.assertEqual(report["dimensions"]["TEST.A"][axis]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.A"][axis]["custody"], "unknown") + self.assertEqual(report["dimensions"]["TEST.B"]["kernel"]["applicability"], "unknown") + self.assertNotIn("lemma_exists", report) + self.assertNotIn("kernel_verified", report) + + def test_math_native_receipt_does_not_acquire_main_only_native_fields(self): + packet = self.with_formal() + formal = packet["formal_records"][0] + formal["format"] = "math-formal-gate/v1" + manifest = document(formal["manifest"]) + manifest["targets"] = TARGETS + for field in ("package", "package_root", "root_module", "scientific_status_authority", + "sources", "allowed_axioms", "lean_toolchain"): + del manifest[field] + declared_archive = b"TEST archive metadata only; no retained archive or custody claim" + manifest["source_archive"] = {"name": "TEST-declared-only.zip", "sha256": sha(declared_archive), + "size_bytes": len(declared_archive)} + formal["manifest"] = replace_git(formal["manifest"], encoded(manifest)) + self.update_receipt(formal, lambda receipt: (receipt.pop("package"), receipt.pop("scientific_status_authority"), + receipt.update({"manifest_sha256": formal["manifest"]["ref"]["sha256"]}))) + self.update_alignment(formal, lambda review: review.update({"manifest_sha256": formal["manifest"]["ref"]["sha256"]})) + formal["node_targets"] = [] + report, _ = self.accepted(packet) + retained = report["formal_summary"][0]["retained_receipt"] + self.assertNotIn("package", retained) + self.assertNotIn("scientific_status_authority", retained) + self.assertEqual(report["formal_summary"][0]["manifest_targets"], TARGETS) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + + def test_failed_or_skipped_incomplete_run_and_expected_failure_never_become_positive_kernel(self): + for conclusion, purpose in (("failure", "check"), ("skipped", "check"), ("cancelled", "check"), + ("failure", "negative_control")): + with self.subTest(conclusion=conclusion, purpose=purpose): + packet = self.with_formal() + formal = packet["formal_records"][0] + formal["receipt"] = None + formal["logs"] = formal["logs"][:1] + formal["native_run"].update({"conclusion": conclusion, "purpose": purpose, "expected_conclusion": "failure"}) + report, _ = self.accepted(packet) + self.assertNotEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + self.assertEqual(report["formal_summary"][0]["retained_receipt"], None) + # Complete positive-looking original logs cannot override the native purpose/conclusion. + for conclusion, purpose, expected in (("failure", "check", "failure"), + ("success", "negative_control", "success")): + with self.subTest(complete_receipt=True, conclusion=conclusion, purpose=purpose): + packet = self.with_formal() + packet["formal_records"][0]["native_run"].update( + {"conclusion": conclusion, "purpose": purpose, "expected_conclusion": expected}) + report, _ = self.accepted(packet) + self.assertNotEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + + def test_expected_native_context_mismatch_is_valid_stale_not_authentication(self): + packet = self.with_formal() + for field, stale in (("repository", "other-owner/research"), ("commit", "c" * 40), ("run-id", "124"), ("run-attempt", "2")): + with self.subTest(field=field): + report, _ = self.accepted(packet, expected={**self.expected, field: stale}) + kernel = report["dimensions"]["TEST.A"]["kernel"] + self.assertNotEqual(kernel["applicability"], "current") + self.assertIn("native_context_changed", kernel["reasons"]) + + def test_partial_successful_target_inventory_is_retained_but_not_current_kernel(self): + packet = self.with_formal() + formal = packet["formal_records"][0] + self.replace_log(formal, "axioms.log", b"'TEST.Formal.alpha' does not depend on any axioms\n") + self.update_receipt(formal, lambda receipt: receipt.update({"axioms": {TARGETS[0]: []}})) + report, _ = self.accepted(packet) + self.assertEqual(report["formal_summary"][0]["manifest_targets"], TARGETS) + self.assertEqual(report["formal_summary"][0]["retained_receipt"]["axioms"], {TARGETS[0]: []}) + kernel = report["dimensions"]["TEST.A"]["kernel"] + self.assertEqual(kernel["applicability"], "unknown") + self.assertIn("target_inventory_incomplete", kernel["reasons"]) + + def test_original_axioms_dump_cannot_contradict_receipt_target_scope_or_values(self): + for raw in (b"'TEST.Formal.alpha' does not depend on any axioms\n'TEST.Formal.foreign' does not depend on any axioms\n", + b"'TEST.Formal.alpha' depends on axioms: [Classical.choice]\n'TEST.Formal.beta' does not depend on any axioms\n", + b"'TEST.Formal.alpha' does not depend on any axioms\n'TEST.Formal.alpha' does not depend on any axioms\n"): + with self.subTest(raw=raw): + packet = self.with_formal() + self.replace_log(packet["formal_records"][0], "axioms.log", raw) + self.refused(packet) + + def test_main_target_requires_exact_source_identity_and_explicit_statement_slice(self): + for mutation in ("missing_statement", "partial_statement", "foreign_source_path", "foreign_source_commit"): + with self.subTest(mutation=mutation): + packet = self.with_formal() + binding = packet["new"]["bindings"][0] + if mutation == "missing_statement": + binding["statement_slice"] = None + elif mutation == "partial_statement": + binding["statement_slice"] = slice_of(SOURCE, 0, len(ALPHA) - 1) + elif mutation == "foreign_source_path": + binding["source"]["ref"]["path"] = "TEST/different-source.md" + else: + binding["source"]["ref"]["commit"] = "c" * 40 + report, _ = self.accepted(packet) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + + def test_unknown_or_duplicate_explicit_node_target_binding_is_a_contradiction(self): + for binding in ([{"node": "TEST.A", "target": "TEST.Formal.absent"}], + [{"node": "TEST.absent", "target": TARGETS[0]}], + [{"node": "TEST.A", "target": TARGETS[0]}] * 2): + with self.subTest(binding=binding): + packet = self.with_formal() + packet["formal_records"][0]["node_targets"] = binding + self.refused(packet) + + def test_statement_change_uses_removed_and_context_edges_and_names_exact_review(self): + packet = self.with_formal() + raw = SOURCE.replace(b"alpha", b"ALPHA", 1) + self.change_source(packet, "new", raw) + self.change_graph(packet, "new", lambda graph: graph.update({"edges": graph["edges"][1:]})) + report, _ = self.accepted(packet) + regression = report["regression"] + self.assertEqual(regression["statement_changed"], ["TEST.A"]) + self.assertEqual(regression["impacted_nodes"], ["TEST.A", "TEST.B", "TEST.C"]) + self.assertEqual(regression["traversal_edges"], [["TEST.B", "TEST.A"], ["TEST.C", "TEST.B"]]) + self.assertEqual([item["node"] for item in regression["revalidation_required"]], ["TEST.A", "TEST.B", "TEST.C"]) + self.assertEqual(regression["affected_alignment_records"], [packet["formal_records"][0]["alignment"]["ref"]]) + self.assertEqual(document(report["original_packet"]["new"]["graph"])["nodes"]["TEST.B"]["review_disposition"], "ACCEPTED") + + def test_proof_only_change_stales_whole_manifest_alignment_without_statement_change(self): + packet = self.with_formal() + original_alignment = copy.deepcopy(packet["formal_records"][0]["alignment"]) + self.change_source(packet, "new", SOURCE.replace(b"proof old", b"proof new")) + packet["formal_records"] = [self.formal(packet)] + packet["formal_records"][0]["alignment"] = original_alignment + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["statement_changed"], []) + self.assertEqual(report["regression"]["proof_changed"], ["TEST.A"]) + alignment = report["dimensions"]["TEST.A"]["alignment"] + self.assertEqual(alignment["applicability"], "stale") + self.assertIn("manifest_binding_changed", alignment["reasons"]) + self.assertNotIn("statement_changed", alignment["reasons"]) + self.assertEqual(report["regression"]["affected_alignment_records"], [original_alignment["ref"]]) + + def test_alignment_partial_coverage_stale_scope_or_lineage_remains_original_stale_record(self): + for change in (lambda review: review.update({"targets": [TARGETS[0]]}), + lambda review: review.update({"scope_sha256": "f" * 64}), + lambda review: review.update({"disposition": "PENDING"}), + lambda review: review.update({"reviewer": copy.deepcopy(review["author"])})): + packet = self.with_formal() + self.update_alignment(packet["formal_records"][0], change) + report, _ = self.accepted(packet) + self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "stale") + self.assertEqual(report["regression"]["affected_alignment_records"], [packet["formal_records"][0]["alignment"]["ref"]]) + + def test_affected_alignment_references_deduplicate_full_original_identity(self): + packet = self.with_formal() + second = copy.deepcopy(packet["formal_records"][0]) + second["id"] = "TEST-formal-2" + packet["formal_records"].append(second) + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.A"].update({"notes": "TEST changed record"})) + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["affected_alignment_records"], [second["alignment"]["ref"]]) + + def test_distinct_original_alignment_identities_are_retained_and_canonically_sorted(self): + packet = self.with_formal() + second = copy.deepcopy(packet["formal_records"][0]) + second["id"] = "TEST-formal-2" + second["alignment"]["ref"]["path"] = "TEST/another-original-alignment.json" + second["alignment"]["ref"]["commit"] = BASE + packet["formal_records"].append(second) + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.A"].update({"notes": "TEST changed record"})) + report, _ = self.accepted(packet) + original_refs = [formal["alignment"]["ref"] for formal in packet["formal_records"]] + expected = sorted(original_refs, key=lambda ref: json.dumps(ref, sort_keys=True, separators=(",", ":"))) + self.assertEqual(report["regression"]["affected_alignment_records"], expected) + self.assertEqual(len(report["regression"]["affected_alignment_records"]), 2) + + def test_unmapped_similar_node_does_not_invent_an_affected_alignment_record(self): + packet = self.with_formal() + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.B"].update({"notes": "TEST.Formal.alpha changed title"})) + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["impacted_nodes"], ["TEST.B", "TEST.C"]) + self.assertEqual(report["regression"]["affected_alignment_records"], []) + + def test_unscoped_source_change_is_unknown_not_a_guessed_statement_or_proof_split(self): + packet = copy.deepcopy(self.packet) + self.change_source(packet, "old", SOURCE, sliced=False) + self.change_source(packet, "new", SOURCE + b"TEST changed bytes\n", sliced=False) + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["unscoped_source_changed"], ["TEST.A"]) + self.assertEqual(report["regression"]["statement_changed"], []) + self.assertEqual(report["regression"]["proof_changed"], []) + + def test_canonical_record_numeric_types_are_changes_even_when_python_equality_agrees(self): + packet = copy.deepcopy(self.packet) + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.A"].update({"review_issue": 65.0})) + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["changed_nodes"], ["TEST.A"]) + self.assertEqual(report["regression"]["impacted_nodes"], ["TEST.A", "TEST.B", "TEST.C"]) + self.assertIs(type(document(report["original_packet"]["new"]["graph"])["nodes"]["TEST.A"]["review_issue"]), float) + + def test_graph_context_changes_revalidate_all_nodes_and_preserve_context(self): + packet = copy.deepcopy(self.packet) + self.change_graph(packet, "new", lambda graph: graph.update({"object": "TEST-CHANGED-CONTEXT"})) + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["changed_nodes"], ["TEST.A", "TEST.B", "TEST.C"]) + + def test_deleted_and_added_nodes_use_union_edges_but_only_survivors_get_proposals(self): + packet = copy.deepcopy(self.packet) + def delete(graph): + del graph["nodes"]["TEST.B"] + graph["edges"] = [] + self.change_graph(packet, "new", delete) + report, _ = self.accepted(packet) + regression = report["regression"] + self.assertEqual(regression["changed_nodes"], ["TEST.B", "TEST.C"]) + self.assertEqual(regression["impacted_nodes"], ["TEST.C"]) + self.assertEqual(regression["traversal_edges"], [["TEST.B", "TEST.A"], ["TEST.C", "TEST.B"]]) + self.assertEqual([item["node"] for item in regression["revalidation_required"]], ["TEST.C"]) + self.assertIn("TEST.B", document(report["original_packet"]["old"]["graph"])["nodes"]) + packet = copy.deepcopy(self.packet) + def add(graph): + graph["nodes"]["TEST.D"] = {"classification": "AUTHOR_SIDE_CANDIDATE", "controlling": False} + graph["edges"].append({"from": "TEST.D", "to": "TEST.A", "required": False, "relation": "TEST added context"}) + self.change_graph(packet, "new", add) + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["changed_nodes"], ["TEST.D"]) + self.assertEqual(report["regression"]["impacted_nodes"], ["TEST.D"]) + self.assertIn(["TEST.D", "TEST.A"], report["regression"]["traversal_edges"]) + + def test_source_availability_loss_is_unresolved_and_propagates_without_guessed_slices(self): + packet = copy.deepcopy(self.packet) + binding = packet["new"]["bindings"][0] + binding["source"] = binding["statement_slice"] = binding["proof_slice"] = None + report, _ = self.accepted(packet) + self.assertEqual(report["regression"]["impacted_nodes"], ["TEST.A", "TEST.B", "TEST.C"]) + self.assertEqual(report["regression"]["statement_changed"], []) + self.assertEqual(report["regression"]["proof_changed"], []) + self.assertNotEqual(report["dimensions"]["TEST.A"]["source"]["applicability"], "current") + + def test_required_cycle_and_boolean_coercion_are_refused_but_context_cycle_is_valid(self): + for mutation in ("required_cycle", "numeric_controlling", "numeric_required"): + with self.subTest(mutation=mutation): + packet = copy.deepcopy(self.packet) + def change(graph): + if mutation == "required_cycle": + graph["edges"].append({"from": "TEST.A", "to": "TEST.B", "required": True, "relation": "TEST cycle"}) + elif mutation == "numeric_controlling": + graph["nodes"]["TEST.A"]["controlling"] = 0 + else: + graph["edges"][0]["required"] = 1 + self.change_graph(packet, "new", change) + self.refused(packet) + packet = copy.deepcopy(self.packet) + self.change_graph(packet, "new", lambda graph: graph["edges"].append( + {"from": "TEST.A", "to": "TEST.C", "required": False, "relation": "TEST context cycle"})) + self.accepted(packet) + + def test_closed_packet_capture_binding_and_formal_wrappers_refuse_extra_or_missing_keys(self): + for mutation in ("top_extra", "top_missing", "schema_bool", "ref_extra", "binding_extra", "formal_extra"): + with self.subTest(mutation=mutation): + packet = self.with_formal() + if mutation == "top_extra": packet["authenticated_capture"] = True + elif mutation == "top_missing": del packet["old"] + elif mutation == "schema_bool": packet["schema_version"] = True + elif mutation == "ref_extra": packet["new"]["graph"]["ref"]["authenticated"] = True + elif mutation == "binding_extra": packet["new"]["bindings"][0]["target_guess"] = TARGETS[0] + else: packet["formal_records"][0]["capture_verified"] = True + self.refused(packet) + + def test_git_capture_checks_exact_raw_byte_count_sha_blob_and_canonical_base64(self): + for field, value in (("bytes", True), ("bytes", len(SOURCE) + 1), ("sha256", "f" * 64), + ("git_blob", "e" * 40), ("commit", "A" * 40), ("path", "../TEST/source.md")): + with self.subTest(field=field): + packet = copy.deepcopy(self.packet) + packet["new"]["bindings"][0]["source"]["ref"][field] = value + self.refused(packet) + packet = copy.deepcopy(self.packet) + packet["new"]["bindings"][0]["source"]["raw_base64"] = "not base64!!" + self.refused(packet) + + def test_run_artifact_is_not_a_git_file_and_raw_hashes_and_native_bindings_must_match(self): + for mutation in ("raw_hash", "git_field", "attempt_contradiction"): + with self.subTest(mutation=mutation): + packet = self.with_formal() + ref = packet["formal_records"][0]["receipt"]["ref"] + if mutation == "raw_hash": ref["sha256"] = "f" * 64 + elif mutation == "git_field": ref["git_blob"] = "e" * 40 + else: ref["run_attempt"] = "2" + self.refused(packet) + + def test_native_manifest_file_coverage_and_receipt_log_hashes_cannot_contradict_captures(self): + for mutation in ("missing_source", "changed_source", "changed_receipt_log"): + with self.subTest(mutation=mutation): + packet = self.with_formal() + formal = packet["formal_records"][0] + if mutation == "missing_source": + del formal["source_files"][0] + elif mutation == "changed_source": + formal["source_files"][0] = replace_git(formal["source_files"][0], SOURCE + b"TEST changed capture\n") + else: + self.update_receipt(formal, lambda receipt: receipt["logs"].update({"axioms.log": "f" * 64})) + self.refused(packet) + + def test_statement_and_proof_slice_bounds_types_and_hashes_are_exact_bytes(self): + for field, value in (("start_byte", True), ("start_byte", -1), ("end_byte", len(SOURCE) + 1), + ("end_byte", 0), ("sha256", "f" * 64)): + with self.subTest(field=field, value=value): + packet = copy.deepcopy(self.packet) + packet["new"]["bindings"][0]["statement_slice"][field] = value + self.refused(packet) + packet = copy.deepcopy(self.packet) + packet["new"]["bindings"][0]["source"] = None + self.refused(packet) + + def test_duplicate_and_nonfinite_json_and_oversized_packets_are_refused(self): + valid = encoded(self.packet).decode("utf-8") + for raw in ('{"schema_version":1,' + valid[1:], + valid.replace('"schema_version": 1', '"schema_version": NaN'), + valid.replace('"schema_version": 1', '"schema_version": Infinity'), + valid.replace('"schema_version": 1', '"schema_version": 1e999'), + valid + "{}", valid[:-1] + " TEST", + valid + " " * (16 * 1024 * 1024 + 1 - len(valid.encode("utf-8")))): + with self.subTest(raw=raw[:40]): + self.refused(raw=raw) + + def test_decoded_capture_limit_and_embedded_json_depth_and_duplicate_keys_are_bounded(self): + packet = copy.deepcopy(self.packet) + self.change_source(packet, "new", b"T" * (4 * 1024 * 1024 + 1), sliced=False) + self.refused(packet) + packet = copy.deepcopy(self.packet) + nested = "TEST deepest metadata" + for _ in range(65): + nested = {"TEST": nested} + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.A"].update({"metadata": nested})) + self.refused(packet) + for raw in (raw_bytes(self.packet["new"]["graph"]).replace(b'"review_issue": 65', b'"review_issue": 65, "review_issue": 65'), + raw_bytes(self.packet["new"]["graph"]).replace(b'"review_issue": 65', b'"review_issue": NaN'), + raw_bytes(self.packet["new"]["graph"]).replace(b'"review_issue": 65', b'"review_issue": 1e999')): + packet = copy.deepcopy(self.packet) + packet["new"]["graph"] = replace_git(packet["new"]["graph"], raw) + self.refused(packet) + + def test_all_expected_context_flags_are_required_unique_and_syntax_checked(self): + for omitted in self.expected: + with self.subTest(omitted=omitted): + arguments = [part for name, value in self.expected.items() if name != omitted for part in ("--expected-" + name, value)] + self.refused(arguments=arguments) + arguments = [part for name, value in self.expected.items() for part in ("--expected-" + name, value)] + for name, value in self.expected.items(): + with self.subTest(duplicate=name): + self.refused(arguments=arguments + ["--expected-" + name, value]) + for field, value in (("repository", "owner/repo/extra"), ("commit", "A" * 40), ("run-id", "0123"), ("run-attempt", "0")): + with self.subTest(field=field): + self.refused(expected={**self.expected, field: value}) + + def test_unknown_native_format_or_packet_authentication_claim_is_refused(self): + packet = self.with_formal() + packet["formal_records"][0]["format"] = "unified-formal-schema/guessed" + self.refused(packet) + self.refused(arguments=["--capture-authenticated", "true"]) + + def test_retrofit_failed_evidence_remains_recorded_without_positive_kernel_or_computation(self): + packet = copy.deepcopy(self.packet) + ref = packet["new"]["bindings"][0]["source"]["ref"] + run = {"kind": "workflow_run", "repository": "main", "ref": "123", "attempt": 1, "job": "789", + "run_head_sha": "d" * 40, "checked_commit": HEAD, "purpose": "negative_control", + "conclusion": "failure", "expected_conclusion": "failure"} + person = {"provider": "TEST", "model_or_agent": "TEST synthetic", "session": "TEST not an actual review"} + records = [] + for record_id, axis in (("TEST-formal", "formal_evidence"), ("TEST-numeric", "numerical_reproduction")): + records.append({"id": record_id, "subject": {"repository": "main", "commit": HEAD, + "path": ref["path"], "blob": ref["git_blob"]}, "delta": True, + "axis": axis, "state": "recorded", "evidence": [run], "performer": person, + "exposure": "TEST synthetic failed control", "independence_credit": 0, + "alias_of": None, "notes": "TEST no success selection"}) + data = {"schema": "retrofit-records/v0.1", "shard": "TEST", "baseline": { + "Math-": "08f86862f859ac4804b4fd6c6477a7ed0421e37f", "main": "cddbb7f6cf3f57f3b495277f7da148287e027b19"}, + "author": person, "scientific_effect": "NONE", "status_authority": False, "records": records} + packet["retrofit_records"] = [{"id": "TEST-retrofit", "record": git_capture(encoded(data), "TEST/RECORDS.json"), + "node_records": [{"node": "TEST.A", "record_id": record["id"]} for record in records]}] + report, _ = self.accepted(packet) + for axis in ("kernel", "computation"): + self.assertEqual(report["dimensions"]["TEST.A"][axis]["record_state"], "recorded") + self.assertEqual(report["dimensions"]["TEST.A"][axis]["applicability"], "unknown") + self.assertEqual(document(report["original_packet"]["retrofit_records"][0]["record"]), data) + + def test_captured_code_and_paths_remain_inert_packet_data(self): + packet = copy.deepcopy(self.packet) + canary = self.cwd / "TEST-untrusted-code-executed" + raw = ("from pathlib import Path\nPath(" + repr(str(canary)) + ").write_text('executed')\n").encode("utf-8") + binding = packet["new"]["bindings"][0] + binding["source"] = git_capture(raw, "TEST/untrusted.py") + binding["statement_slice"] = binding["proof_slice"] = None + self.accepted(packet) + self.assertFalse(canary.exists()) + + +if __name__ == "__main__": + unittest.main() From cb39e820828be33628258e18663645be002eec02 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 15:06:19 -0700 Subject: [PATCH 02/25] test(architecture): preserve immutable captures and native formal package conventions --- tests/test_architecture_evidence_adapter.py | 128 +++++++++++++++++--- 1 file changed, 108 insertions(+), 20 deletions(-) diff --git a/tests/test_architecture_evidence_adapter.py b/tests/test_architecture_evidence_adapter.py index cbbb095dc..e09e73929 100644 --- a/tests/test_architecture_evidence_adapter.py +++ b/tests/test_architecture_evidence_adapter.py @@ -128,22 +128,28 @@ def change_source(self, packet, label, raw, *, sliced=True): else: binding["statement_slice"] = binding["proof_slice"] = None - def formal(self, packet=None): + def formal(self, packet=None, *, source_snapshot="new"): packet = self.packet if packet is None else packet - source = copy.deepcopy(packet["new"]["bindings"][0]["source"]) + source = copy.deepcopy(packet[source_snapshot]["bindings"][0]["source"]) + local_copy = git_capture(raw_bytes(source), "TEST/formal/sources/source.md") scope = git_capture(b"TEST scope: two declared True targets; no elaboration or scientific claim\n", "TEST/formal/SCOPE.md") module = git_capture(b"namespace TEST.Formal\ntheorem alpha : True := by trivial\ntheorem beta : True := by trivial\n", "TEST/formal/Demo.lean") - files = [source, scope, module] + files = [local_copy, scope, module] source_ref = source["ref"] manifest = { "schema_version": 1, "scientific_effect": "NONE", "scientific_status_authority": False, "package": "TEST-synthetic-package", "package_root": "TEST/formal", "root_module": "TEST.Formal", "formalization_status": "proved", "alignment_status": "PENDING_INDEPENDENT_REVIEW", + "meaning": "TEST synthetic source metadata; no executed or authenticated evidence", + "coordination": {"guide": "TEST/guide.md", "work_item": "TEST fixture only"}, + "author": {"provider": "TEST-author", "family": "TEST-author-family", "agent": "TEST-author-agent"}, "lean_toolchain": "leanprover/lean4:v4.34.1", "dependency_revisions": {}, "allowed_axioms": [], + "unbound_files": ["TEST/formal/manifest.json", "TEST/formal/ALIGNMENT.md"], + "negative_controls": {"TEST_false_claim": {"module": "Demo.lean", "replace": "True", "with": "False"}}, "source_modules": ["Demo.lean"], "files": {item["ref"]["path"]: item["ref"]["sha256"] for item in files}, "sources": [{"id": "TEST-source", "repository": source_ref["repository"], "commit": source_ref["commit"], "path": source_ref["path"], "bytes": source_ref["bytes"], "sha256": source_ref["sha256"], - "local_copy": source_ref["path"]}], + "local_copy": local_copy["ref"]["path"]}], "targets": [{"name": target, "module": "Demo.lean", "title": "TEST declared target", "source": "TEST-source", "informal_anchor": anchor.decode("utf-8"), "does_not_claim": "actual Lean declaration existence or scientific acceptance"} @@ -189,6 +195,27 @@ def with_formal(self): packet["formal_records"] = [self.formal(packet)] return packet + def math_formal(self, packet): + formal = self.formal(packet) + formal["format"] = "math-formal-gate/v1" + manifest = document(formal["manifest"]) + manifest["targets"] = TARGETS + # Math native file keys are formal-root-relative; Git refs remain repo-relative. + prefix = formal["manifest"]["ref"]["path"].rsplit("/", 1)[0] + "/" + manifest["files"] = {path[len(prefix):]: digest for path, digest in manifest["files"].items()} + for field in ("package", "package_root", "root_module", "scientific_status_authority", + "sources", "allowed_axioms", "lean_toolchain", "meaning", "coordination", + "author", "unbound_files", "negative_controls"): + del manifest[field] + declared_archive = b"TEST archive metadata only; no retained archive or custody claim" + manifest["source_archive"] = {"name": "TEST-declared-only.zip", "sha256": sha(declared_archive), + "size_bytes": len(declared_archive)} + formal["manifest"] = replace_git(formal["manifest"], encoded(manifest)) + self.update_receipt(formal, lambda receipt: (receipt.pop("package"), receipt.pop("scientific_status_authority"), + receipt.update({"manifest_sha256": formal["manifest"]["ref"]["sha256"]}))) + self.update_alignment(formal, lambda review: review.update({"manifest_sha256": formal["manifest"]["ref"]["sha256"]})) + return formal + def update_receipt(self, formal, change): receipt = document(formal["receipt"]) change(receipt) @@ -304,29 +331,48 @@ def test_complete_formal_scope_is_retained_without_authenticated_or_fuzzy_joins( self.assertNotIn("kernel_verified", report) def test_math_native_receipt_does_not_acquire_main_only_native_fields(self): - packet = self.with_formal() - formal = packet["formal_records"][0] - formal["format"] = "math-formal-gate/v1" - manifest = document(formal["manifest"]) - manifest["targets"] = TARGETS - for field in ("package", "package_root", "root_module", "scientific_status_authority", - "sources", "allowed_axioms", "lean_toolchain"): - del manifest[field] - declared_archive = b"TEST archive metadata only; no retained archive or custody claim" - manifest["source_archive"] = {"name": "TEST-declared-only.zip", "sha256": sha(declared_archive), - "size_bytes": len(declared_archive)} - formal["manifest"] = replace_git(formal["manifest"], encoded(manifest)) - self.update_receipt(formal, lambda receipt: (receipt.pop("package"), receipt.pop("scientific_status_authority"), - receipt.update({"manifest_sha256": formal["manifest"]["ref"]["sha256"]}))) - self.update_alignment(formal, lambda review: review.update({"manifest_sha256": formal["manifest"]["ref"]["sha256"]})) + packet = copy.deepcopy(self.packet) + formal = self.math_formal(packet) formal["node_targets"] = [] + packet["formal_records"] = [formal] report, _ = self.accepted(packet) retained = report["formal_summary"][0]["retained_receipt"] self.assertNotIn("package", retained) self.assertNotIn("scientific_status_authority", retained) + self.assertIn("SCOPE.md", report["formal_summary"][0]["retained_manifest"]["files"]) + self.assertIn("TEST/formal/SCOPE.md", {capture["ref"]["path"] for capture in formal["source_files"]}) self.assertEqual(report["formal_summary"][0]["manifest_targets"], TARGETS) self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + def test_math_alignment_checks_every_proposer_normalized_lineage_and_target_scope(self): + packet = copy.deepcopy(self.packet) + formal = self.math_formal(packet) + packet["formal_records"] = [formal] + proposers = [ + {"provider": "TEST-proposer-one", "family": "TEST-family-one", "agent": "TEST-agent-one", "targets": [TARGETS[0]]}, + {"provider": "TEST-proposer-two", "family": "TEST-family-two", "agent": "TEST-agent-two", "targets": [TARGETS[1]]}, + ] + self.update_alignment(formal, lambda review: review.update({"proposal_authors": proposers})) + report, _ = self.accepted(packet) + self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + for mutation in ("nonfirst_provider", "normalized_family", "placeholder_agent", "foreign_scope"): + with self.subTest(mutation=mutation): + changed = copy.deepcopy(packet) + def alter(review): + if mutation == "nonfirst_provider": + review["proposal_authors"][1]["provider"] = review["reviewer"]["provider"] + elif mutation == "normalized_family": + review["reviewer"]["family"] = "TEST Reviewer Family" + review["proposal_authors"][1]["family"] = " test reviewer\tFAMILY " + elif mutation == "placeholder_agent": + review["proposal_authors"][1]["agent"] = " NOT\tKNOWN " + else: + review["proposal_authors"][1]["targets"] = ["TEST.Formal.absent"] + self.update_alignment(changed["formal_records"][0], alter) + report, _ = self.accepted(changed) + self.assertNotEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "current") + def test_failed_or_skipped_incomplete_run_and_expected_failure_never_become_positive_kernel(self): for conclusion, purpose in (("failure", "check"), ("skipped", "check"), ("cancelled", "check"), ("failure", "negative_control")): @@ -395,6 +441,27 @@ def test_main_target_requires_exact_source_identity_and_explicit_statement_slice report, _ = self.accepted(packet) self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + def test_main_origin_source_is_distinct_from_its_bound_local_copy(self): + packet = copy.deepcopy(self.packet) + for label in ("old", "new"): + packet[label]["bindings"][0]["source"] = git_capture( + SOURCE, "TEST/origin-source.md", "c" * 40, "d6g8k5htny-coder/Math-") + formal = self.formal(packet) + packet["formal_records"] = [formal] + report, _ = self.accepted(packet) + origin = report["formal_summary"][0]["retained_manifest"]["sources"][0] + self.assertEqual((origin["repository"], origin["commit"], origin["path"]), + ("d6g8k5htny-coder/Math-", "c" * 40, "TEST/origin-source.md")) + self.assertEqual(origin["local_copy"], "TEST/formal/sources/source.md") + local = formal["source_files"][0] + self.assertEqual((local["ref"]["repository"], local["ref"]["commit"], local["ref"]["path"]), + (REPO, HEAD, origin["local_copy"])) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + mismatch = copy.deepcopy(packet) + mismatch["new"]["bindings"][0]["source"]["ref"]["commit"] = "e" * 40 + report, _ = self.accepted(mismatch) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + def test_unknown_or_duplicate_explicit_node_target_binding_is_a_contradiction(self): for binding in ([{"node": "TEST.A", "target": "TEST.Formal.absent"}], [{"node": "TEST.absent", "target": TARGETS[0]}], @@ -405,7 +472,9 @@ def test_unknown_or_duplicate_explicit_node_target_binding_is_a_contradiction(se self.refused(packet) def test_statement_change_uses_removed_and_context_edges_and_names_exact_review(self): - packet = self.with_formal() + packet = copy.deepcopy(self.packet) + # Retain the historical source at BASE; changed bytes belong to HEAD. + packet["formal_records"] = [self.formal(packet, source_snapshot="old")] raw = SOURCE.replace(b"alpha", b"ALPHA", 1) self.change_source(packet, "new", raw) self.change_graph(packet, "new", lambda graph: graph.update({"edges": graph["edges"][1:]})) @@ -571,6 +640,25 @@ def test_git_capture_checks_exact_raw_byte_count_sha_blob_and_canonical_base64(s packet["new"]["bindings"][0]["source"]["raw_base64"] = "not base64!!" self.refused(packet) + def test_conflicting_bytes_for_one_immutable_git_identity_anywhere_are_refused(self): + for location in ("snapshots", "bindings", "graph_and_source", "formal_and_binding"): + with self.subTest(location=location): + packet = self.with_formal() if location == "formal_and_binding" else copy.deepcopy(self.packet) + if location == "snapshots": + packet["old"]["bindings"][0]["source"]["ref"]["commit"] = HEAD + self.change_source(packet, "new", SOURCE.replace(b"proof old", b"proof new")) + else: + if location == "bindings": + ref = packet["new"]["bindings"][0]["source"]["ref"] + elif location == "graph_and_source": + ref = packet["new"]["graph"]["ref"] + else: + ref = packet["formal_records"][0]["scope"]["ref"] + conflicting = git_capture(b"TEST conflicting bytes", ref["path"], ref["commit"], ref["repository"]) + packet["new"]["bindings"].append({"node": "TEST.B", "source": conflicting, + "statement_slice": None, "proof_slice": None}) + self.refused(packet) + def test_run_artifact_is_not_a_git_file_and_raw_hashes_and_native_bindings_must_match(self): for mutation in ("raw_hash", "git_field", "attempt_contradiction"): with self.subTest(mutation=mutation): From 8212d488182f8dba0723c075a30bf356bc4004d7 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 15:22:36 -0700 Subject: [PATCH 03/25] Adapt inert native evidence and report loss-only graph regression Implement the corrected 35-method contract after genuine hosted absent-CLI RED. Retain original packets/manifests/receipts/reviews, separate main origin/local-copy and Math native formats, verify strict captures and union impact. Custody unknown, scientific effect NONE; exact-candidate hosted validation and nonauthor review remain pending. --- architecture/evidence_adapter.py | 973 ++++++++++++++++++ ...026-10-08-architecture-evidence-adapter.md | 14 + tools/architecture_evidence_adapter.py | 40 + 3 files changed, 1027 insertions(+) create mode 100644 architecture/evidence_adapter.py create mode 100644 tools/architecture_evidence_adapter.py diff --git a/architecture/evidence_adapter.py b/architecture/evidence_adapter.py new file mode 100644 index 000000000..5cfe49340 --- /dev/null +++ b/architecture/evidence_adapter.py @@ -0,0 +1,973 @@ +"""Validate inert evidence packets without authenticating custody or science. + +All current/stale decisions concern declared records inside the packet. Only the +independently pinned repository graph gate is executable; captures are data. +""" +from __future__ import annotations + +import base64 +import binascii +from dataclasses import dataclass +import hashlib +import json +import math +import os +from pathlib import Path, PurePosixPath +import re +import stat +from types import ModuleType +from typing import Any + + +MAX_PACKET_BYTES = 16 * 1024 * 1024 +MAX_CAPTURE_BYTES = 4 * 1024 * 1024 +MAX_DEPTH = 64 +TRUSTED_GATE_SHA256 = "a78f3e25f3b0cfe113e618a4c31a7a25d7f22af638c46dec1ecba221fa333ac8" +ROOT = Path(__file__).resolve().parents[1] +HEX40 = re.compile(r"[0-9a-f]{40}") +HEX64 = re.compile(r"[0-9a-f]{64}") +DECIMAL = re.compile(r"[1-9][0-9]*") +REPOSITORY = re.compile(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+") +NAME = re.compile(r"[A-Za-z_][A-Za-z0-9_.']*") +AXIOM_LINE = re.compile( + r"'([A-Za-z_][A-Za-z0-9_.']*)' " + r"(?:depends on axioms: \[([^\]]*)\]|does not depend on any axioms)" +) +ALLOWED_AXIOMS = frozenset({"propext", "Classical.choice", "Quot.sound"}) +STATES = frozenset({"recorded", "not_recorded", "unknown", "not_applicable"}) +AXES = ("source", "review", "kernel", "computation", "alignment") +PLACEHOLDERS = frozenset({ + "unknown", "unverified", "not known", "not available", "not provided", "unavailable", "unspecified", + "pending", "tbd", "todo", "none", "null", "n/a", "na", "?", "-", +}) + + +def require(condition: bool, message: str) -> None: + if not condition: + raise ValueError(message) + + +def canonical(value: Any) -> str: + return json.dumps(value, sort_keys=True, separators=(",", ":"), + ensure_ascii=True, allow_nan=False) + + +def keys(value: Any, expected: set[str], label: str) -> dict[str, Any]: + require(type(value) is dict and set(value) == expected, label + ": invalid fields") + return value + + +def text(value: Any, label: str) -> str: + require(type(value) is str and bool(value.strip()), label + ": expected nonempty string") + return value + + +def digest(value: Any, pattern: re.Pattern[str], label: str) -> str: + require(type(value) is str and pattern.fullmatch(value) is not None, + label + ": invalid identity") + return value + + +def repository(value: Any, label: str) -> str: + digest(value, REPOSITORY, label) + require(all(part not in (".", "..") for part in value.split("/")), + label + ": invalid repository") + return value + + +def relative_path(value: Any, label: str) -> str: + text(value, label) + require(not value.startswith("/") and "\\" not in value + and not any(ord(char) < 32 or ord(char) == 127 for char in value), + label + ": unsafe path") + require(all(part not in ("", ".", "..") for part in value.split("/")) + and PurePosixPath(value).as_posix() == value, + label + ": nonnormalized path") + return value + + +def positive_decimal(value: Any, label: str) -> str: + return digest(value, DECIMAL, label) + + +def _depth_and_types(value: Any, depth: int = 0) -> None: + require(depth <= MAX_DEPTH, "JSON nesting exceeds limit") + if type(value) is dict: + require(all(type(key) is str for key in value), "nonstring JSON key") + for child in value.values(): + _depth_and_types(child, depth + 1) + elif type(value) is list: + for child in value: + _depth_and_types(child, depth + 1) + elif type(value) is float: + require(math.isfinite(value), "nonfinite JSON number") + else: + require(value is None or type(value) in (str, int, bool), "non-JSON value") + + +def strict_json(raw: bytes, label: str, *, limit: int = MAX_CAPTURE_BYTES) -> Any: + require(type(raw) is bytes and len(raw) <= limit, label + ": JSON byte limit") + decoded = raw.decode("utf-8") + # Bound nesting before the decoder recurses, accounting for escaped strings. + depth = 0 + quoted = False + escaped = False + for char in decoded: + if quoted: + if escaped: + escaped = False + elif char == "\\": + escaped = True + elif char == '"': + quoted = False + elif char == '"': + quoted = True + elif char in "[{": + depth += 1 + require(depth <= MAX_DEPTH, label + ": JSON nesting exceeds limit") + elif char in "]}": + depth -= 1 + + def unique(pairs: list[tuple[str, Any]]) -> dict[str, Any]: + result: dict[str, Any] = {} + for key, value in pairs: + require(key not in result, label + ": duplicate JSON key") + result[key] = value + return result + + def constant(value: str) -> Any: + raise ValueError(label + ": nonfinite JSON constant") + + def floating(value: str) -> float: + result = float(value) + require(math.isfinite(result), label + ": nonfinite JSON number") + return result + + result = json.loads(decoded, object_pairs_hook=unique, + parse_constant=constant, parse_float=floating) + _depth_and_types(result) + return result + + +def parse_packet(raw: bytes) -> dict[str, Any]: + result = strict_json(raw, "packet", limit=MAX_PACKET_BYTES) + require(type(result) is dict, "packet must be object") + return result + + +def validate_expected_context(value: dict[str, str]) -> dict[str, str]: + keys(value, {"repository", "commit", "run-id", "run-attempt"}, "expected context") + repository(value["repository"], "expected repository") + digest(value["commit"], HEX40, "expected commit") + positive_decimal(value["run-id"], "expected run id") + positive_decimal(value["run-attempt"], "expected run attempt") + return value + + +@dataclass(frozen=True) +class Capture: + ref: dict[str, Any] + raw: bytes + + def document(self, label: str) -> dict[str, Any]: + result = strict_json(self.raw, label) + require(type(result) is dict, label + ": expected JSON object") + return result + + +class Captures: + """Verified identities shared across every capture role in one packet.""" + + def __init__(self) -> None: + self.git_identities: dict[tuple[str, str, str], Capture] = {} + self.run_identities: dict[tuple[str, ...], Capture] = {} + + @staticmethod + def raw(value: dict[str, Any], label: str) -> bytes: + encoded = value["raw_base64"] + require(type(encoded) is str and len(encoded) <= 4 * ((MAX_CAPTURE_BYTES + 2) // 3), + label + ": encoded capture exceeds limit") + try: + raw = base64.b64decode(encoded.encode("ascii"), validate=True) + except (UnicodeError, binascii.Error, ValueError) as exc: + raise ValueError(label + ": invalid base64") from exc + require(len(raw) <= MAX_CAPTURE_BYTES + and base64.b64encode(raw).decode("ascii") == encoded, + label + ": noncanonical or oversized base64") + return raw + + @staticmethod + def identity_bytes(ref: dict[str, Any], raw: bytes, label: str) -> None: + require(type(ref["bytes"]) is int and 0 <= ref["bytes"] <= MAX_CAPTURE_BYTES, + label + ": invalid byte count") + digest(ref["sha256"], HEX64, label + " SHA256") + require(ref["bytes"] == len(raw) + and ref["sha256"] == hashlib.sha256(raw).hexdigest(), + label + ": raw byte identity mismatch") + + def git(self, value: Any, label: str) -> Capture: + keys(value, {"ref", "raw_base64"}, label) + ref = keys(value["ref"], {"repository", "commit", "path", "git_blob", "sha256", "bytes"}, + label + " GitRef") + repository(ref["repository"], label + " repository") + digest(ref["commit"], HEX40, label + " commit") + relative_path(ref["path"], label + " path") + digest(ref["git_blob"], HEX40, label + " blob") + raw = self.raw(value, label) + self.identity_bytes(ref, raw, label) + blob = hashlib.sha1(b"blob " + str(len(raw)).encode("ascii") + b"\0" + raw, + usedforsecurity=False).hexdigest() + require(ref["git_blob"] == blob, label + ": Git blob identity mismatch") + capture = Capture(ref, raw) + identity = (ref["repository"], ref["commit"], ref["path"]) + previous = self.git_identities.get(identity) + require(previous is None or (previous.raw == raw and canonical(previous.ref) == canonical(ref)), + label + ": conflicting immutable Git capture") + self.git_identities[identity] = capture + return capture + + def run(self, value: Any, native: dict[str, Any], label: str) -> Capture: + keys(value, {"ref", "raw_base64"}, label) + ref = keys(value["ref"], {"repository", "checked_commit", "run_id", "run_attempt", + "artifact_id", "member_path", "sha256", "bytes"}, label + " RunRef") + repository(ref["repository"], label + " repository") + digest(ref["checked_commit"], HEX40, label + " checked commit") + for key in ("run_id", "run_attempt", "artifact_id"): + positive_decimal(ref[key], label + " " + key) + relative_path(ref["member_path"], label + " member path") + require(all(ref[key] == native[key] for key in + ("repository", "checked_commit", "run_id", "run_attempt")), + label + ": native run binding contradiction") + raw = self.raw(value, label) + self.identity_bytes(ref, raw, label) + capture = Capture(ref, raw) + identity = tuple(ref[key] for key in ("repository", "checked_commit", "run_id", "run_attempt", + "artifact_id", "member_path")) + previous = self.run_identities.get(identity) + require(previous is None or (previous.raw == raw and canonical(previous.ref) == canonical(ref)), + label + ": conflicting native artifact member") + self.run_identities[identity] = capture + return capture + + +def _gate() -> ModuleType: + """Read one fixed regular file through anchored no-follow descriptors.""" + descriptor = os.open(ROOT, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + try: + for name in ("docs", "site", "dependency-source"): + child = os.open(name, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, + dir_fd=descriptor) + os.close(descriptor) + descriptor = child + file_descriptor = os.open("hard_gate.py", os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, + dir_fd=descriptor) + try: + info = os.fstat(file_descriptor) + require(stat.S_ISREG(info.st_mode) and info.st_size <= MAX_CAPTURE_BYTES, + "trusted gate is not a bounded regular file") + parts = [] + remaining = MAX_CAPTURE_BYTES + 1 + while remaining: + part = os.read(file_descriptor, min(remaining, 65536)) + if not part: + break + parts.append(part) + remaining -= len(part) + raw = b"".join(parts) + require(len(raw) <= MAX_CAPTURE_BYTES and hashlib.sha256(raw).hexdigest() == TRUSTED_GATE_SHA256, + "trusted gate SHA256 pin mismatch") + finally: + os.close(file_descriptor) + finally: + os.close(descriptor) + path = ROOT / "docs/site/dependency-source/hard_gate.py" + module = ModuleType("_verified_architecture_evidence_graph_gate") + module.__file__ = str(path) + exec(compile(raw, str(path), "exec"), module.__dict__) + return module + + +def _slice(value: Any, source: Capture | None, label: str) -> dict[str, Any] | None: + if value is None: + return None + keys(value, {"start_byte", "end_byte", "sha256"}, label) + require(source is not None, label + ": slice without source") + start, end = value["start_byte"], value["end_byte"] + require(type(start) is int and type(end) is int and 0 <= start < end <= len(source.raw), + label + ": invalid byte bounds") + digest(value["sha256"], HEX64, label + " SHA256") + require(hashlib.sha256(source.raw[start:end]).hexdigest() == value["sha256"], + label + ": byte slice hash mismatch") + return value + + +def _snapshot(value: Any, captures: Captures, gate: ModuleType, label: str) -> dict[str, Any]: + keys(value, {"graph", "bindings"}, label) + graph_capture = captures.git(value["graph"], label + " graph") + graph = graph_capture.document(label + " graph") + gate.validate_graph_fail_closed(graph) + require(type(value["bindings"]) is list, label + ": bindings must be array") + bindings = {} + for binding in value["bindings"]: + keys(binding, {"node", "source", "statement_slice", "proof_slice"}, label + " binding") + node = text(binding["node"], label + " node") + require(node in graph["nodes"] and node not in bindings, label + ": unknown or duplicate node binding") + source = None if binding["source"] is None else captures.git(binding["source"], label + " source") + statement = _slice(binding["statement_slice"], source, label + " statement slice") + proof = _slice(binding["proof_slice"], source, label + " proof slice") + bindings[node] = {"source": source, "statement_slice": statement, "proof_slice": proof} + return {"graph": graph, "graph_capture": graph_capture, "bindings": bindings} + + +def _native(value: Any) -> dict[str, Any]: + keys(value, {"repository", "checked_commit", "run_head_sha", "run_id", "run_attempt", + "purpose", "conclusion", "expected_conclusion"}, "native run") + repository(value["repository"], "native repository") + digest(value["checked_commit"], HEX40, "native checked commit") + digest(value["run_head_sha"], HEX40, "native run head") + positive_decimal(value["run_id"], "native run id") + positive_decimal(value["run_attempt"], "native run attempt") + require(value["purpose"] in ("check", "negative_control"), "unknown native run purpose") + conclusions = {"success", "failure", "skipped", "cancelled", "timed_out", "action_required", "neutral", "stale"} + require(type(value["conclusion"]) is str and value["conclusion"] in conclusions, + "unknown native conclusion") + require(type(value["expected_conclusion"]) is str and value["expected_conclusion"] in conclusions, + "unknown expected native conclusion") + return value + + +def _same_context(native: dict[str, Any], expected: dict[str, str]) -> bool: + return (native["repository"] == expected["repository"] + and native["checked_commit"] == expected["commit"] + and native["run_id"] == expected["run-id"] + and native["run_attempt"] == expected["run-attempt"]) + + +def _science(document: dict[str, Any], label: str, *, main: bool) -> None: + require(type(document.get("schema_version")) is int and document["schema_version"] == 1 + and document.get("scientific_effect") == "NONE", label + ": invalid native schema/effect") + if main or "scientific_status_authority" in document: + require(document.get("scientific_status_authority") is False, + label + ": scientific authority must be false") + + +def _axioms(value: Any, targets: set[str], label: str) -> dict[str, list[str]]: + require(type(value) is dict, label + ": expected axiom object") + result = {} + for target, axioms in value.items(): + require(target in targets and type(axioms) is list and all(type(item) is str for item in axioms), + label + ": foreign target or malformed axiom list") + require(len(axioms) == len(set(axioms)) and set(axioms) <= ALLOWED_AXIOMS, + label + ": duplicate or forbidden axiom") + result[target] = sorted(axioms) + return result + + +def _axiom_dump(raw: bytes, targets: set[str]) -> dict[str, list[str]]: + decoded = raw.decode("utf-8") + result = {} + for match in AXIOM_LINE.finditer(decoded): + target, listed = match.groups() + require(target in targets and target not in result, "foreign or duplicate original axiom target") + axioms = [] if listed is None or not listed.strip() else [item.strip() for item in listed.split(",")] + result.update(_axioms({target: axioms}, targets, "original axioms log")) + require(not AXIOM_LINE.sub("", decoded).strip(), "unrecognized original axiom output") + return result + + +def _target_inventory(manifest: dict[str, Any], main: bool) -> tuple[list[str], dict[str, Any], dict[str, Any]]: + targets = manifest.get("targets") + require(type(targets) is list and bool(targets), "empty native target inventory") + rows = {} + sources = {} + if main: + for row in targets: + keys(row, {"name", "module", "title", "source", "informal_anchor", "does_not_claim"}, + "main target") + name = digest(row["name"], NAME, "main target name") + require(name not in rows, "duplicate main target") + for field in ("title", "source", "informal_anchor", "does_not_claim"): + text(row[field], "main target " + field) + relative_path(row["module"], "main target module") + rows[name] = row + source_rows = manifest.get("sources") + require(type(source_rows) is list and bool(source_rows), "missing main source rows") + for row in source_rows: + keys(row, {"id", "repository", "commit", "path", "bytes", "sha256", "local_copy"}, + "main source row") + identity = text(row["id"], "main source id") + require(identity not in sources, "duplicate main source id") + repository(row["repository"], "main origin repository") + digest(row["commit"], HEX40, "main origin commit") + relative_path(row["path"], "main origin path") + relative_path(row["local_copy"], "main local copy") + digest(row["sha256"], HEX64, "main origin SHA256") + require(type(row["bytes"]) is int and 0 < row["bytes"] <= MAX_CAPTURE_BYTES, + "main origin byte count") + sources[identity] = row + require(all(row["source"] in sources for row in rows.values()), "unknown main target source") + else: + for name in targets: + digest(name, NAME, "Math target name") + require(name not in rows, "duplicate Math target") + rows[name] = None + return sorted(rows), rows, sources + + +def _lineage(party: Any, *, normalized: bool) -> dict[str, str] | None: + if type(party) is not dict: + return None + result = {} + for field in ("provider", "family", "agent"): + value = party.get(field) + if type(value) is not str or not value.strip(): + return None + compared = " ".join(value.split()).casefold() if normalized else value.strip().casefold() + if normalized and compared in PLACEHOLDERS: + return None + result[field] = compared + return result + + +def _alignment_reasons(document: dict[str, Any] | None, manifest: Capture, scope: Capture, + targets: list[str], *, main: bool) -> list[str]: + if document is None: + return ["alignment_not_recorded"] + reasons = [] + for field in ("manifest_sha256", "scope_sha256"): + if field in document: + digest(document[field], HEX64, "alignment " + field) + if document.get("manifest_sha256") != manifest.ref["sha256"]: + reasons.append("manifest_binding_changed") + if document.get("scope_sha256") != scope.ref["sha256"]: + reasons.append("scope_binding_changed") + covered = document.get("targets") + if not (type(covered) is list and all(type(item) is str for item in covered) + and len(covered) == len(set(covered)) and set(covered) == set(targets)): + reasons.append("target_coverage_changed") + if document.get("disposition") != "ACCEPTED": + reasons.append("alignment_not_accepted") + reviewer = _lineage(document.get("reviewer"), normalized=not main) + authors = [_lineage(document.get("author"), normalized=not main)] + if not main: + proposers = document.get("proposal_authors", []) + if type(proposers) is not list: + reasons.append("lineage_not_distinct") + else: + for proposer in proposers: + authors.append(_lineage(proposer, normalized=True)) + if type(proposer) is dict and "targets" in proposer: + subset = proposer["targets"] + if not (type(subset) is list and bool(subset) + and all(type(item) is str and item in targets for item in subset) + and len(subset) == len(set(subset))): + reasons.append("target_coverage_changed") + if reviewer is None or any(author is None or any(author[field] == reviewer[field] + for field in reviewer) for author in authors): + reasons.append("lineage_not_distinct") + evidence = document.get("evidence") + if type(evidence) is not dict: + reasons.append("alignment_evidence_unresolved") + else: + # These declarations are structurally checked, never fetched or credited as custody. + try: + repository(evidence.get("repository"), "alignment evidence repository") + digest(evidence.get("commit"), HEX40, "alignment evidence commit") + digest(evidence.get("sha256"), HEX64, "alignment evidence SHA256") + relative_path(evidence.get("path"), "alignment evidence path") + except ValueError: + reasons.append("alignment_evidence_unresolved") + return sorted(set(reasons)) + + +def _formal(value: Any, captures: Captures, nodes: set[str], expected: dict[str, str]) -> dict[str, Any]: + keys(value, {"id", "format", "manifest", "scope", "source_files", "receipt", "logs", + "alignment", "native_run", "node_targets"}, "formal record") + identity = text(value["id"], "formal id") + require(value["format"] in ("main-formal-gate/v1", "math-formal-gate/v1"), "unknown native format") + main = value["format"] == "main-formal-gate/v1" + native = _native(value["native_run"]) + manifest_capture = captures.git(value["manifest"], "formal manifest") + scope = captures.git(value["scope"], "formal scope") + manifest = manifest_capture.document("formal manifest") + _science(manifest, "formal manifest", main=main) + require(manifest.get("formalization_status") == "proved" + and manifest.get("alignment_status") == "PENDING_INDEPENDENT_REVIEW", + "native source metadata cannot award execution or review") + targets, target_rows, source_rows = _target_inventory(manifest, main) + target_set = set(targets) + require(type(value["source_files"]) is list, "formal source_files must be array") + sources = {} + for original in value["source_files"]: + capture = captures.git(original, "formal source file") + require(capture.ref["path"] not in sources, "duplicate formal source file") + sources[capture.ref["path"]] = capture + for capture in [manifest_capture, scope, *sources.values()]: + require(capture.ref["repository"] == native["repository"] + and capture.ref["commit"] == native["checked_commit"], + "native checked source binding contradiction") + files = manifest.get("files") + require(type(files) is dict and bool(files), "missing native file hashes") + parent = str(PurePosixPath(manifest_capture.ref["path"]).parent) + paths = {} + for name, expected_hash in files.items(): + relative_path(name, "native file key") + digest(expected_hash, HEX64, "native file SHA256") + path = name if main or parent == "." else parent + "/" + name + relative_path(path, "native source lookup") + require(path not in paths, "duplicate native source lookup") + paths[path] = expected_hash + require(path in sources and sources[path].ref["sha256"] == expected_hash, + "native source file missing or contradictory") + require(scope.ref["path"] in paths and paths[scope.ref["path"]] == scope.ref["sha256"], + "native scope is not bound by manifest files") + if main: + for row in source_rows.values(): + local = sources.get(row["local_copy"]) + require(local is not None and row["local_copy"] in paths + and local.ref["bytes"] == row["bytes"] and local.ref["sha256"] == row["sha256"], + "main checked local copy differs from pinned origin bytes") + modules = manifest.get("source_modules") + require(type(modules) is list and bool(modules) and all(type(item) is str for item in modules) + and len(modules) == len(set(modules)), "invalid main source module inventory") + package_root = relative_path(manifest.get("package_root"), "main package root") + for module in modules: + relative_path(module, "main source module") + require(package_root + "/" + module in paths, "unbound main source module") + require(all(row["module"] in modules for row in target_rows.values()), "target module not registered") + for row in target_rows.values(): + local = sources[source_rows[row["source"]]["local_copy"]] + require(row["informal_anchor"].encode("utf-8") in local.raw, + "main target anchor absent from checked source") + require(type(value["node_targets"]) is list, "node_targets must be array") + mappings = [] + seen = set() + for binding in value["node_targets"]: + keys(binding, {"node", "target"}, "node target binding") + require(type(binding["node"]) is str and binding["node"] in nodes + and type(binding["target"]) is str and binding["target"] in target_set, + "unknown explicit node or native target") + pair = (binding["node"], binding["target"]) + require(pair not in seen, "duplicate explicit node target binding") + seen.add(pair) + mappings.append(binding) + require(type(value["logs"]) is list, "formal logs must be array") + logs = {} + members = [] + for original in value["logs"]: + capture = captures.run(original, native, "formal log") + name = PurePosixPath(capture.ref["member_path"]).name + require(name not in logs, "duplicate native log filename") + logs[name] = capture + members.append(capture) + receipt_capture = None if value["receipt"] is None else captures.run(value["receipt"], native, "formal receipt") + receipt = None if receipt_capture is None else receipt_capture.document("formal receipt") + if receipt_capture is not None: + members.append(receipt_capture) + require(len({capture.ref["artifact_id"] for capture in members}) <= 1, + "native receipt/log artifact identity contradiction") + complete = False + if receipt is not None: + _science(receipt, "formal receipt", main=main) + require(receipt.get("manifest_sha256") == manifest_capture.ref["sha256"] + and receipt.get("repository") == native["repository"] + and receipt.get("checked_commit") == native["checked_commit"] + and receipt.get("workflow_run_id") == native["run_id"], "native receipt identity contradiction") + require(receipt.get("formalization_status") == "kernel-checked" + and receipt.get("alignment_status") == "PENDING_INDEPENDENT_REVIEW", + "unsupported native receipt status") + if main: + require(type(manifest.get("package")) is str and receipt.get("package") == manifest["package"], + "main receipt package contradiction") + require(type(manifest.get("dependency_revisions")) is dict + and canonical(receipt.get("dependency_revisions")) == canonical(manifest["dependency_revisions"]), + "native dependency receipt contradiction") + for revision in manifest["dependency_revisions"].values(): + digest(revision, HEX40, "native dependency revision") + text(receipt.get("lean_version"), "native Lean version record") + recorded_logs = receipt.get("logs") + require(type(recorded_logs) is dict, "missing native receipt log inventory") + for name, expected_hash in recorded_logs.items(): + relative_path(name, "receipt log name") + require("/" not in name, "receipt log key must be native basename") + digest(expected_hash, HEX64, "receipt log SHA256") + require(name in logs and logs[name].ref["sha256"] == expected_hash, + "original receipt log hash contradiction") + require(set(logs) == set(recorded_logs), "unbound original native log") + receipt_axioms = _axioms(receipt.get("axioms"), target_set, "native receipt axioms") + dumped = None if "axioms.log" not in logs else _axiom_dump(logs["axioms.log"].raw, target_set) + if dumped is not None: + require(canonical(dumped) == canonical(receipt_axioms), "original axiom log contradicts receipt") + complete = (dumped is not None and set(dumped) == target_set + and {"build.log", "leanchecker.log", "elaborated-types.log"} <= set(logs)) + controls = receipt.get("negative_controls") + require(type(controls) is dict and all(type(name) is str and outcome in + ("REJECTED_BY_LEAN", "REJECTED_BY_AXIOM_GATE") for name, outcome in controls.items()), + "invalid native negative-control outcomes") + if main: + registered = manifest.get("negative_controls") + require(type(registered) is dict, "missing main negative-control declarations") + complete = complete and (set(registered) | {"sorry", "custom_imported", "native"}) <= set(controls) + alignment_capture = None if value["alignment"] is None else captures.git(value["alignment"], "formal alignment") + alignment = None if alignment_capture is None else alignment_capture.document("formal alignment") + alignment_reasons = _alignment_reasons(alignment, manifest_capture, scope, targets, main=main) + return { + "id": identity, "main": main, "native": native, "context_current": _same_context(native, expected), + "manifest_capture": manifest_capture, "scope": scope, "manifest": manifest, + "targets": targets, "target_rows": target_rows, "source_rows": source_rows, + "receipt": receipt, "complete": complete, "mappings": mappings, + "alignment": alignment, "alignment_capture": alignment_capture, "alignment_reasons": alignment_reasons, + "summary": {"id": identity, "format": value["format"], "manifest_targets": targets, + "node_targets": value["node_targets"], "retained_manifest": manifest, + "retained_receipt": receipt, "retained_alignment": alignment}, + } + + +RETROFIT_BASELINE = {"Math-": "08f86862f859ac4804b4fd6c6477a7ed0421e37f", + "main": "cddbb7f6cf3f57f3b495277f7da148287e027b19"} +RETROFIT_AXES = frozenset({"source_review", "provider_distinct_review", "blind_reconstruction", + "adversarial_attack", "formal_evidence", "numerical_reproduction", + "novelty", "human_reading", "custody", "observable_statement"}) +RETROFIT_REPOSITORIES = frozenset({"Math-", "main", "Universal-Law-Workspace", "d6g8k5htny-coder", + "google-drive", "governance-", "meta-framework", "query-", "sandbox", "trial"}) +RETROFIT_EVIDENCE_KEYS = { + "file": {"kind", "repository", "commit", "path", "blob"}, + "github_comment": {"kind", "repository", "ref"}, + "github_review": {"kind", "repository", "ref", "commit"}, + "workflow_run": {"kind", "repository", "ref", "attempt", "job", "run_head_sha", + "checked_commit", "purpose", "conclusion", "expected_conclusion"}, +} +RETROFIT_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,63}") +RETROFIT_DECIMAL = re.compile(r"[1-9][0-9]{0,19}") + + +def _retrofit_person(value: Any) -> None: + keys(value, {"provider", "model_or_agent", "session"}, "retrofit performer") + for field in value: + text(value[field], "retrofit performer " + field) + + +def _retrofit_evidence(item: Any) -> None: + require(type(item) is dict and type(item.get("kind")) is str + and item["kind"] in RETROFIT_EVIDENCE_KEYS, "unknown retrofit evidence kind") + kind = item["kind"] + keys(item, RETROFIT_EVIDENCE_KEYS[kind], "retrofit evidence") + require(type(item["repository"]) is str and item["repository"] in RETROFIT_REPOSITORIES, + "unknown retrofit evidence repository") + if kind == "file": + relative_path(item["path"], "retrofit evidence file") + digest(item["commit"], HEX40, "retrofit file commit") + digest(item["blob"], HEX40, "retrofit file blob") + else: + digest(item["ref"], RETROFIT_DECIMAL, "retrofit native id") + if kind == "github_review": + digest(item["commit"], HEX40, "retrofit native review commit") + if kind == "workflow_run": + require(type(item["attempt"]) is int and item["attempt"] > 0, + "retrofit run attempt must be positive integer") + if item["job"] is not None: + digest(item["job"], RETROFIT_DECIMAL, "retrofit native job") + digest(item["run_head_sha"], HEX40, "retrofit run head") + if item["checked_commit"] is not None: + digest(item["checked_commit"], HEX40, "retrofit checked commit") + require(item["purpose"] in ("check", "negative_control"), "unknown retrofit purpose") + require(item["conclusion"] in ("success", "failure", "cancelled", "skipped", "timed_out", + "neutral", "action_required", "stale", "startup_failure"), + "unknown retrofit native conclusion") + require(item["expected_conclusion"] in ("success", "failure"), "unknown retrofit expected conclusion") + + +def _retrofit(value: Any, captures: Captures, nodes: set[str]) -> dict[str, Any]: + keys(value, {"id", "record", "node_records"}, "retrofit wrapper") + identity = text(value["id"], "retrofit id") + capture = captures.git(value["record"], "retrofit original record") + document = capture.document("retrofit original record") + keys(document, {"schema", "shard", "baseline", "author", "scientific_effect", "status_authority", "records"}, + "retrofit native document") + require(document["schema"] == "retrofit-records/v0.1" and document["scientific_effect"] == "NONE" + and document["status_authority"] is False, "invalid retrofit schema or authority") + digest(document["shard"], re.compile(r"[A-Z][A-Za-z0-9_]{0,39}"), "retrofit shard") + require(canonical(document["baseline"]) == canonical(RETROFIT_BASELINE), "retrofit baseline contradiction") + _retrofit_person(document["author"]) + require(type(document["records"]) is list and bool(document["records"]), "empty retrofit native records") + records = {} + for record in document["records"]: + keys(record, {"id", "subject", "delta", "axis", "state", "evidence", "performer", "exposure", + "independence_credit", "alias_of", "notes"}, "retrofit native record") + record_id = digest(record["id"], RETROFIT_ID, "retrofit record id") + require(record_id not in records, "duplicate retrofit record id") + subject = keys(record["subject"], {"repository", "commit", "path", "blob"}, "retrofit subject") + require(type(subject["repository"]) is str and subject["repository"] in RETROFIT_REPOSITORIES, + "unknown retrofit subject repository") + digest(subject["commit"], HEX40, "retrofit subject commit") + digest(subject["blob"], HEX40, "retrofit subject blob") + relative_path(subject["path"], "retrofit subject path") + require(type(record["delta"]) is bool, "retrofit delta must be exact boolean") + require(record["delta"] or RETROFIT_BASELINE.get(subject["repository"]) == subject["commit"], + "nonbaseline retrofit subject requires delta") + require(type(record["axis"]) is str and record["axis"] in RETROFIT_AXES, "unknown retrofit axis") + require(type(record["state"]) is str and record["state"] in STATES, "unknown retrofit availability") + require(type(record["evidence"]) is list, "retrofit evidence must be array") + require(record["state"] != "recorded" or bool(record["evidence"]), "recorded retrofit lacks evidence") + require(record["state"] not in ("not_recorded", "not_applicable") or not record["evidence"], + "absent retrofit availability cannot carry evidence") + for item in record["evidence"]: + _retrofit_evidence(item) + _retrofit_person(record["performer"]) + text(record["exposure"], "retrofit exposure") + require(type(record["independence_credit"]) is int and record["independence_credit"] == 0, + "retrofit independence credit must be integer zero") + require(record["alias_of"] is None or type(record["alias_of"]) is str, "invalid retrofit alias id") + require(type(record["notes"]) is str, "retrofit notes must be text") + records[record_id] = record + for record in records.values(): + if record["alias_of"] is not None: + original = records.get(record["alias_of"]) + require(original is not None and original is not record and original["alias_of"] is None, + "dangling or chained retrofit alias") + require(original["axis"] == record["axis"] and original["state"] == record["state"] + and sorted(canonical(item) for item in original["evidence"]) + == sorted(canonical(item) for item in record["evidence"]), "retrofit alias differs from original") + require(type(value["node_records"]) is list, "retrofit node_records must be array") + bindings = [] + seen = set() + for binding in value["node_records"]: + keys(binding, {"node", "record_id"}, "retrofit node record") + require(type(binding["node"]) is str and binding["node"] in nodes + and type(binding["record_id"]) is str and binding["record_id"] in records, + "unknown retrofit node or record") + pair = (binding["node"], binding["record_id"]) + require(pair not in seen, "duplicate retrofit node record binding") + seen.add(pair) + bindings.append((binding["node"], records[binding["record_id"]])) + return {"id": identity, "capture": capture, "document": document, "bindings": bindings} + + +def _fingerprint(binding: dict[str, Any] | None) -> Any: + if binding is None: + return None + source = binding["source"] + return {"source": None if source is None else {key: source.ref[key] for key in + ("repository", "commit", "path", "bytes", "sha256")}, + "statement_slice": binding["statement_slice"], "proof_slice": binding["proof_slice"]} + + +def _regression(old: dict[str, Any], new: dict[str, Any], gate: ModuleType) -> dict[str, Any]: + old_graph, new_graph = old["graph"], new["graph"] + old_sources = {node: _fingerprint(old["bindings"].get(node)) for node in old_graph["nodes"]} + new_sources = {node: _fingerprint(new["bindings"].get(node)) for node in new_graph["nodes"]} + # Snapshot-relative source commits normally advance with the graph commit. + # Ignore that paired revision change while preserving fixed-origin changes. + for node in set(old_sources) & set(new_sources): + before, after = old_sources[node], new_sources[node] + if before is None or after is None or before["source"] is None or after["source"] is None: + continue + if all(fingerprint["source"]["repository"] == snapshot["graph_capture"].ref["repository"] + and fingerprint["source"]["commit"] == snapshot["graph_capture"].ref["commit"] + for fingerprint, snapshot in ((before, old), (after, new))): + before["source"]["commit"] = after["source"]["commit"] = None + impact = gate.reverse_impact_between(old_graph, new_graph, old_sources=old_sources, new_sources=new_sources) + reasons: dict[str, set[str]] = {node: set() for node in impact["changed_nodes"]} + statement_changed = [] + proof_changed = [] + unscoped = [] + for node in impact["changed_nodes"]: + if node not in old_graph["nodes"] or node not in new_graph["nodes"]: + reasons[node].add("node_record_changed") + elif canonical(old_graph["nodes"][node]) != canonical(new_graph["nodes"][node]): + reasons[node].add("node_record_changed") + old_edges = sorted(canonical(edge) for edge in old_graph["edges"] if edge["from"] == node) + new_edges = sorted(canonical(edge) for edge in new_graph["edges"] if edge["from"] == node) + if old_edges != new_edges: + reasons[node].add("dependency_edges_changed") + if impact["context_changed"]: + reasons[node].add("graph_context_changed") + if node in old_sources and node in new_sources and canonical(old_sources[node]) != canonical(new_sources[node]): + before, after = old["bindings"].get(node), new["bindings"].get(node) + scoped = False + if before is not None and after is not None and before["source"] is not None and after["source"] is not None: + for field, code, changed in (("statement_slice", "statement_changed", statement_changed), + ("proof_slice", "proof_body_changed", proof_changed)): + first, last = before[field], after[field] + if first is not None and last is not None and first["sha256"] != last["sha256"]: + changed.append(node) + reasons[node].add(code) + scoped = True + if not scoped: + unscoped.append(node) + reasons[node].add("source_changed_unscoped") + proposals = [] + for node in impact["impacted"]: + codes = reasons.get(node, {"dependency_changed"}) + proposals.append({"node": node, "reasons": sorted(codes or {"dependency_changed"})}) + return {"changed_nodes": impact["changed_nodes"], "impacted_nodes": impact["impacted"], + "statement_changed": sorted(statement_changed), "proof_changed": sorted(proof_changed), + "unscoped_source_changed": sorted(unscoped), "traversal_edges": impact["traversal_edges"], + "revalidation_required": proposals, "affected_alignment_records": []} + + +def _axis(state: str = "unknown", applicability: str = "unknown", *, reasons: list[str] | None = None, + evidence: list[str] | None = None) -> dict[str, Any]: + return {"record_state": state, "applicability": applicability, "reasons": sorted(set(reasons or [])), + "evidence_ids": sorted(set(evidence or [])), "custody": "unknown"} + + +def _merge_axis(records: list[dict[str, Any]]) -> dict[str, Any]: + if not records: + return _axis() + states = {record["record_state"] for record in records} + state = "recorded" if "recorded" in states else next(iter(states)) if len(states) == 1 else "unknown" + applications = {record["applicability"] for record in records} + applicability = "stale" if "stale" in applications else next(iter(applications)) if len(applications) == 1 else "unknown" + return _axis(state, applicability, + reasons=[code for record in records for code in record["reasons"]], + evidence=[identity for record in records for identity in record["evidence_ids"]]) + + +def _main_join(formal: dict[str, Any], node: str, target: str, bindings: dict[str, Any]) -> tuple[bool, list[str]]: + binding = bindings.get(node) + if not formal["main"] or binding is None or binding["source"] is None: + return False, ["missing_target_source_binding"] + row = formal["target_rows"][target] + origin = formal["source_rows"][row["source"]] + capture = binding["source"] + if any(capture.ref[key] != origin[key] for key in ("repository", "commit", "path", "bytes", "sha256")): + return False, ["missing_target_source_binding"] + statement = binding["statement_slice"] + if statement is None: + return False, ["missing_statement_slice"] + portion = capture.raw[statement["start_byte"]:statement["end_byte"]] + if row["informal_anchor"].encode("utf-8") not in portion: + return False, ["missing_statement_slice"] + return True, ["declared_byte_slice_only"] + + +def _kernel(formal: dict[str, Any], joined: bool, join_reasons: list[str]) -> dict[str, Any]: + reasons = list(join_reasons) + native = formal["native"] + if not formal["context_current"]: + reasons.append("native_context_changed") + if native["purpose"] != "check": + reasons.append("native_run_negative_control") + if native["conclusion"] != "success": + reasons.append("native_run_not_success") + if not formal["complete"]: + reasons.append("target_inventory_incomplete") + current = (joined and formal["context_current"] and formal["complete"] + and native["purpose"] == "check" and native["conclusion"] == "success") + applicability = "current" if current else "stale" if not formal["context_current"] else "unknown" + return _axis("recorded" if formal["receipt"] is not None else "unknown", applicability, + reasons=reasons, evidence=[formal["id"]]) + + +def _retrofit_projection(record: dict[str, Any], binding: dict[str, Any] | None) -> dict[str, Any]: + reasons = ["retrofit_availability_only", "native_custody_unknown"] + source = None if binding is None else binding["source"] + subject = record["subject"] + # This is the native contract's explicit repository alias, not a fuzzy join. + qualified = "d6g8k5htny-coder/" + subject["repository"] + matching = (source is not None and source.ref["repository"] == qualified + and source.ref["commit"] == subject["commit"] and source.ref["path"] == subject["path"] + and source.ref["git_blob"] == subject["blob"]) + if not matching: + reasons.append("source_binding_changed") + for evidence in record["evidence"]: + if evidence["kind"] == "workflow_run": + if evidence["purpose"] != "check": + reasons.append("native_run_negative_control") + if evidence["conclusion"] != "success": + reasons.append("native_run_not_success") + applicability = "not_applicable" if record["state"] == "not_applicable" else "unknown" if matching else "stale" + return _axis(record["state"], applicability, reasons=reasons, evidence=[record["id"]]) + + +def _dimensions(new: dict[str, Any], formals: list[dict[str, Any]], retrofits: list[dict[str, Any]], + regression: dict[str, Any]) -> dict[str, Any]: + projected = {node: {axis: [] for axis in AXES} for node in new["graph"]["nodes"]} + for node, original in new["graph"]["nodes"].items(): + binding = new["bindings"].get(node) + source = None if binding is None else binding["source"] + if source is not None: + ref = source.ref + source_id = ref["repository"] + "@" + ref["commit"] + ":" + ref["path"] + "#" + ref["git_blob"] + reasons = ["declared_byte_slice_only"] + if binding["statement_slice"] is None: + reasons.append("missing_statement_slice") + projected[node]["source"].append(_axis("recorded", "current", reasons=reasons, evidence=[source_id])) + else: + projected[node]["source"].append(_axis(reasons=["source_not_captured"])) + review_fields = {key: value for key, value in original.items() if key.startswith("review_")} + if review_fields: + review_reasons = ["graph_review_record_only"] + application = "unknown" + if source is not None and node in regression["statement_changed"] + regression["proof_changed"]: + review_reasons.extend(code for code, changed in + (("statement_changed", regression["statement_changed"]), + ("proof_body_changed", regression["proof_changed"])) if node in changed) + application = "stale" + # No independent native review ID is supplied by graph review text. + projected[node]["review"].append(_axis("recorded", application, reasons=review_reasons)) + for formal in formals: + for mapping in formal["mappings"]: + node, target = mapping["node"], mapping["target"] + joined, join_reasons = _main_join(formal, node, target, new["bindings"]) + projected[node]["kernel"].append(_kernel(formal, joined, join_reasons)) + reasons = list(formal["alignment_reasons"]) + if not formal["context_current"]: + reasons.append("native_context_changed") + unresolved_join = formal["main"] and not joined + if unresolved_join: + reasons.extend(join_reasons) + if formal["alignment"] is None: + alignment = _axis(reasons=reasons, evidence=[formal["id"]]) + else: + contract_stale = bool(formal["alignment_reasons"]) or not formal["context_current"] + application = "stale" if contract_stale else "unknown" if unresolved_join else "current" + alignment = _axis("recorded", application, + reasons=reasons, evidence=[formal["id"]]) + projected[node]["alignment"].append(alignment) + retrofit_mapping = {"source_review": "review", "provider_distinct_review": "review", + "formal_evidence": "kernel", "numerical_reproduction": "computation"} + for retrofit in retrofits: + for node, record in retrofit["bindings"]: + axis = retrofit_mapping.get(record["axis"]) + if axis is not None: + projected[node][axis].append(_retrofit_projection(record, new["bindings"].get(node))) + return {node: {axis: _merge_axis(projected[node][axis]) for axis in AXES} for node in sorted(projected)} + + +def adapt_packet(packet: dict, expected_context: dict[str, str]) -> dict: + """Produce a loss-only derived report; never modify packet or source records.""" + _depth_and_types(packet) + require(len(canonical(packet).encode("utf-8")) <= MAX_PACKET_BYTES, "packet byte limit") + expected = validate_expected_context(expected_context) + keys(packet, {"schema_version", "old", "new", "formal_records", "retrofit_records"}, "packet") + require(type(packet["schema_version"]) is int and packet["schema_version"] == 1, + "unsupported packet schema") + captures = Captures() + gate = _gate() + old = _snapshot(packet["old"], captures, gate, "old") + new = _snapshot(packet["new"], captures, gate, "new") + nodes = set(new["graph"]["nodes"]) + require(type(packet["formal_records"]) is list and type(packet["retrofit_records"]) is list, + "native record collections must be arrays") + formals = [_formal(value, captures, nodes, expected) for value in packet["formal_records"]] + retrofits = [_retrofit(value, captures, nodes) for value in packet["retrofit_records"]] + identities = [record["id"] for record in formals + retrofits] + require(len(identities) == len(set(identities)), "duplicate packet record id") + regression = _regression(old, new, gate) + affected = {} + impacted = set(regression["impacted_nodes"]) + for formal in formals: + capture = formal["alignment_capture"] + if capture is None: + continue + mapped_impact = any(binding["node"] in impacted for binding in formal["mappings"]) + stale_contract = bool(formal["alignment_reasons"]) or not formal["context_current"] + if mapped_impact or stale_contract: + affected[canonical(capture.ref)] = capture.ref + regression["affected_alignment_records"] = [affected[identity] for identity in sorted(affected)] + return {"schema_version": 1, "scientific_effect": "NONE", "scientific_status_authority": False, + "custody": "unknown", "original_packet": packet, + "dimensions": _dimensions(new, formals, retrofits, regression), + "formal_summary": [formal["summary"] for formal in formals], "regression": regression} diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index f8f432156..21e2808fd 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -20,6 +20,7 @@ - Input hashes establish internal byte consistency only. No input `authenticated`, capture flag, signature-looking string, or self-consistent native metadata can authorize external custody. Global and every axis custody remain `unknown`. - Execute no packet-supplied Python, gate, Lean, shell, or test code; fetch no packet-selected URL/path. Trusted gate bytes must match `a78f3e25f3b0cfe113e618a4c31a7a25d7f22af638c46dec1ecba221fa333ac8` before loading their verified buffer. - No project Python execution on the owner laptop. Observe genuine hosted missing-CLI RED before implementation; retain exact source, normal/optimized logs, failures, and artifacts. Standing owner authorization requires no new permission checkpoint. +- The corrected external suite is frozen at 35 methods in `tests/test_architecture_evidence_adapter.py`, SHA-256 `397581308cc517545b5e0e8a1716ce696a14aa7e9f885f61cd07dd46dcb7de63`. Its native-contract corrections below are the current test authority; the earlier 32-method draft is superseded. The implementation owner creates only the two new adapter/CLI files after the integration owner records genuine hosted absent-CLI RED for these corrected bytes. ## Review Focus @@ -54,6 +55,16 @@ The exact packet is `{schema_version: 1, old: Snapshot, new: Snapshot, formal_re `format` is exactly `main-formal-gate/v1` or `math-formal-gate/v1`. SHA-256 is lowercase 64 hex; Git commit/blob is lowercase 40 hex; counts and offsets are exact integers; native run/attempt/artifact IDs are positive ASCII decimals without leading zeros. Paths are normalized safe relative paths. Verify raw byte count, SHA-256, and Git blob framing/hash against each capture before parsing embedded documents. Slices bind byte offsets and hashes in their explicit source capture and are **declared byte slices only**, not a semantic Lean parser or coverage certificate. +### Resolved native contracts + +All Git captures share one packet-wide immutable-identity registry keyed by `(repository, commit, path)`. Repeated captures of that identity must have identical verified raw bytes, byte count, SHA-256, and Git blob identity. Conflicts are a refusal even when the captures occur in different graphs, bindings, scopes, source lists, alignment records, or retrofit records. Consistency within each wrapper alone is insufficient. + +Main's manifest `sources` rows identify the original informal source separately from the checked main repository's `local_copy`. The origin can be an older Math commit and path while the local copy lives at a current main path such as `formal/sources/...`. Compare the node's explicit source binding to the complete origin identity, then independently verify the local copy against the native `files` hash and checked main repository/commit. Keep both roles and their original fields; never demand that the origin use main's checked commit, or join the node by the local-copy path. A mismatch in the origin join leaves kernel applicability unknown; contradictory capture or file identities are a refusal. + +Math's native `files` keys are relative to the captured manifest's parent directory. Derive a safe root-relative Git lookup path by joining that parent with each native key, and match the resulting path to `source_files`. For example, a manifest at `TEST/formal/manifest.json` with key `SCOPE.md` binds the capture at `TEST/formal/SCOPE.md`. The retained manifest still contains its original `SCOPE.md` key. This lookup rule does not add main-only source rows, receipt fields, or a node-to-target bridge to Math. + +Math alignment keeps its source-native `author`, `reviewer`, `proposal_authors`, and target declarations. Normalize lineage comparison values with split-whitespace joining and case folding; compare the reviewer with the primary author and every declared proposal author for provider, family, and agent. Empty or placeholder lineage, a matching normalized lineage component, and invalid proposer target scope cannot become current alignment. Each proposer target declaration must be a valid unique subset of the complete native target inventory. Valid partial coverage and unresolved lineage stay preserved as stale/unknown evidence, with no new accepted-review marker or organizational-independence credit. Preserve all original native annotations, including main's meaning, coordination, author, unbound-file, and negative-control fields, rather than rewriting either format into a merged schema. + The exact report has `schema_version`, `scientific_effect`, `scientific_status_authority`, `custody`, `original_packet`, `dimensions`, `formal_summary`, and `regression`. `original_packet` preserves the complete typed input, including original base64 bytes. Sort only derived lists/maps; do not reorder retained native arrays or alter retained native fields. - `dimensions` covers exactly surviving new graph nodes. Each has `source`, `review`, `kernel`, `computation`, and `alignment`, each exactly `{record_state, applicability, reasons, evidence_ids, custody}`. `record_state` uses `recorded`, `not_recorded`, `unknown`, `not_applicable`; applicability uses `current`, `stale`, `unknown`, `not_applicable`. Applicability describes packet-internal consistency only; custody always remains `unknown`. @@ -69,6 +80,7 @@ The exact report has `schema_version`, `scientific_effect`, `scientific_status_a - [ ] Write subprocess controls for valid deterministic output, preservation, every required CLI argument, matching/changed declared native context, and refusal of any invented capture-auth override. Fixtures are labeled synthetic `TEST.A/B/C` with `TEST.Formal.alpha/beta`; they make no actual capture or execution claim. - [ ] Add controls for duplicate/nonfinite/deep/oversized stdin, malformed base64, decoded capture limit, byte/SHA/blob mismatch, unsafe paths, offset/hash/type errors, unknown wrapper keys, and multiple documents. A bool must not pass an integer check. +- [ ] Pin packet-wide immutable Git identity consistency, including conflicts crossing graph/source/formal capture roles; do not limit collision checks to a single record or list. - [ ] Publish the tests-only candidate and run `python -B -S -m unittest discover -s tests -p test_architecture_evidence_adapter.py -v` and the same command with `-O` in the hosted restricted lane. RED must explicitly identify the absent CLI; an import crash, zero discovery, or unrelated failure does not satisfy this step. Root records exact candidate/run/artifact identities and original logs. - [ ] After observed RED, implement bounded strict parsing, inert capture verification, `adapt_packet`, and the stdout-only CLI. Load only independently pinned repository gate bytes; never a gate supplied in the packet. - [ ] Repeat those hosted commands on the exact candidate. Require all controls executed, no skipped tests, and identical discovery in both modes. Freeze and commit this independently reviewable packet boundary through the integration owner. @@ -80,9 +92,11 @@ The exact report has `schema_version`, `scientific_effect`, `scientific_status_a **Interfaces:** Consume verified captures, native documents, explicit target bindings, and expected context from Task 1. Produce all five axes and retained native formal summaries without new authority fields. - [ ] Pin main's dict-target inventory, source rows, file hashes, original receipt/log bindings, and Math's distinct list-target inventory in external controls. Source files must cover manifest file hashes; original receipt/log axiom inventories must name only native targets and preserve permitted axioms. Incomplete positive inventories remain unresolved and cannot produce current kernel applicability. +- [ ] Verify main origin and checked local-copy identities separately, including a Math origin at a historical commit with a current main local copy. Rebase Math native relative file keys only for safe source-file lookup and retain all native key spellings and annotations unchanged. - [ ] Add valid failed-build controls with null receipt and retain failed/skipped/cancelled/negative records. Positive kernel applicability requires `purpose == "check"` and actual `conclusion == "success"`; matching caller-declared `expected_conclusion == "failure"` cannot make a negative control positive. - [ ] Pin explicit main target joins: node target, node statement slice, exact manifest source identity `(repository, commit, path, bytes, SHA-256)`, and exact informal-anchor bytes within the declared slice. Unknown mappings stay unresolved. Math's native format lacks this main source-row bridge; preserve its inventory/receipt without fabricating an equivalent join. - [ ] Add whole-manifest alignment controls: exact manifest and scope hash bindings, unique full target coverage, accepted disposition, and distinct declared author/reviewer provider/family/agent. Partial/nonaccepted/stale records remain preserved with stale/unknown applicability; lineage strings establish no authenticated review or organizational independence. +- [ ] For Math, validate every proposal author's normalized lineage and unique native-target subset, including a conflict in a nonfirst proposer, whitespace/case collisions, placeholder agent values, and foreign target scope. This extends native contract checking without authenticating any declared lineage. - [ ] Add independent source/review/computation controls against original retrofit records. Changing one axis must not award another; graph classification, review text, matching hash, or green native metadata cannot manufacture kernel, computation, alignment, or scientific acceptance. - [ ] Observe the corresponding hosted RED controls before implementing the two native adapters and retrofit projection. Rerun the complete adapter suite in both modes, retain originals and review this unit before committing through the integration owner. diff --git a/tools/architecture_evidence_adapter.py b/tools/architecture_evidence_adapter.py new file mode 100644 index 000000000..2490579fb --- /dev/null +++ b/tools/architecture_evidence_adapter.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Read one inert evidence packet on stdin and emit a conservative JSON report.""" +from __future__ import annotations + +import argparse +import json +from pathlib import Path +import sys + + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from architecture.evidence_adapter import MAX_PACKET_BYTES, adapt_packet, parse_packet + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__, allow_abbrev=False) + fields = ("repository", "commit", "run-id", "run-attempt") + for field in fields: + parser.add_argument("--expected-" + field, required=True, action="append") + arguments = parser.parse_args(argv) + expected = {} + for field in fields: + values = getattr(arguments, "expected_" + field.replace("-", "_")) + if len(values) != 1: + parser.error("--expected-" + field + " must occur exactly once") + expected[field] = values[0] + try: + raw = sys.stdin.buffer.read(MAX_PACKET_BYTES + 1) + packet = parse_packet(raw) + report = adapt_packet(packet, expected) + output = json.dumps(report, sort_keys=True, indent=2, ensure_ascii=True, allow_nan=False) + "\n" + except (ValueError, OSError, UnicodeError, RecursionError, TypeError, OverflowError) as exc: + print("architecture evidence adapter refused: " + str(exc), file=sys.stderr) + return 1 + sys.stdout.write(output) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From 04b17cb807a3f55c017c1dd5b50bdfe3914cb91c Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 15:29:07 -0700 Subject: [PATCH 04/25] Pin native scope, rejection mechanism and Lean-version substitutions Three external methods preserve all 35 existing controls while challenging internally coherent wrong native scope files, swapped rejection phases and incompatible current producer toolchains. Implementation remains frozen pending genuine hosted RED; fixtures do not claim Lean execution or custody. --- tests/test_architecture_evidence_adapter.py | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_architecture_evidence_adapter.py b/tests/test_architecture_evidence_adapter.py index e09e73929..a9856527d 100644 --- a/tests/test_architecture_evidence_adapter.py +++ b/tests/test_architecture_evidence_adapter.py @@ -513,6 +513,53 @@ def test_alignment_partial_coverage_stale_scope_or_lineage_remains_original_stal self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "stale") self.assertEqual(report["regression"]["affected_alignment_records"], [packet["formal_records"][0]["alignment"]["ref"]]) + def test_native_SCOPE_file_cannot_be_substituted_by_another_manifest_bound_file(self): + for native_format in ("main-formal-gate/v1", "math-formal-gate/v1"): + with self.subTest(native_format=native_format): + packet = copy.deepcopy(self.packet) + formal = self.formal(packet) if native_format == "main-formal-gate/v1" else self.math_formal(packet) + packet["formal_records"] = [formal] + module = next(capture for capture in formal["source_files"] + if capture["ref"]["path"] == "TEST/formal/Demo.lean") + formal["scope"] = copy.deepcopy(module) + self.update_alignment(formal, lambda review: review.update({"scope_sha256": module["ref"]["sha256"]})) + # The real SCOPE.md, complete file inventory, receipt and logs remain intact. + result = self.run_adapter(packet) + self.assertNotEqual(result.returncode, 0, "a module replaced the source-native SCOPE.md identity") + self.assertEqual(result.stdout, "", "scope substitution emitted a JSON report") + + def test_native_negative_control_outcomes_cannot_swap_Lean_and_axiom_gate_rejections(self): + for name, wrong_outcome in (("TEST_false_claim", "REJECTED_BY_AXIOM_GATE"), + ("sorry", "REJECTED_BY_LEAN"), + ("custom_imported", "REJECTED_BY_LEAN"), + ("native", "REJECTED_BY_LEAN")): + with self.subTest(name=name): + packet = self.with_formal() + self.update_receipt(packet["formal_records"][0], + lambda receipt: receipt["negative_controls"].update({name: wrong_outcome})) + # Only this original receipt outcome and its capture byte hashes change. + result = self.run_adapter(packet) + self.assertNotEqual(result.returncode, 0, "native rejection mechanism was substituted for " + name) + self.assertEqual(result.stdout, "", "contradictory native rejection emitted a JSON report") + + def test_main_native_producer_requires_its_fixed_toolchain_and_Lean_version(self): + for mutation in ("receipt_version_only", "manifest_and_receipt_version"): + with self.subTest(mutation=mutation): + packet = self.with_formal() + formal = packet["formal_records"][0] + if mutation == "manifest_and_receipt_version": + manifest = document(formal["manifest"]) + manifest["lean_toolchain"] = "leanprover/lean4:v5.0.0" + formal["manifest"] = replace_git(formal["manifest"], encoded(manifest)) + self.update_alignment(formal, lambda review: review.update( + {"manifest_sha256": formal["manifest"]["ref"]["sha256"]})) + self.update_receipt(formal, lambda receipt: receipt.update( + {"lean_version": "Lean (version 5.0.0, TEST fixture only)", + "manifest_sha256": formal["manifest"]["ref"]["sha256"]})) + result = self.run_adapter(packet) + self.assertNotEqual(result.returncode, 0, "unsupported native producer toolchain/version was accepted") + self.assertEqual(result.stdout, "", "unsupported native producer version emitted a JSON report") + def test_affected_alignment_references_deduplicate_full_original_identity(self): packet = self.with_formal() second = copy.deepcopy(packet["formal_records"][0]) From ebc12a64609beb8ef368c911af220fe27c693a4e Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:24:03 -0700 Subject: [PATCH 05/25] Test retained Main author lineage while preserving native Math proposer format --- ...026-10-08-architecture-evidence-adapter.md | 12 +++ tests/test_architecture_evidence_adapter.py | 98 +++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index 15986c652..ef75819e1 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -144,3 +144,15 @@ PR325 was marked ready on8October22:47UTC; native readiness review completed at2 PR324 subsequently landed through a guarded normal merge at actual main `f08dfdf9ec4dbf62553766a7d6b6a758f1f99f9a`, tree `f0a4db84c978edef586eb93b7ff03d0ff7b8270e`, parents00bcd986/f6e90d2d. Native main/tree/parents readback matches its tested tree. Root now reconciles exactly these four adapter paths onto that source, preserving all source-isolation/site/brand/math content. Module `dd36165b…`, CLI `ad759f3f…` and38 tests `3180ae17…` remain byte-identical to review5463745559. Fresh hosted127 required controls and ten separate casefold controls, native original archive readback and current-head readiness review remain pending for this new revision. Separately claimed work must acquire exact Git `commit:path` bytes and original native run artifacts, verify archive digests with a fail-closed readback, bind producer identities/current native context, and retain original manifests/receipts/logs. The existing formal upload lacks artifact ID/digest/name outputs and its name omits attempt; the original receipt lacks attempt. Do not edit those producers here or invent authenticated capture from this packet. Base/candidate real-input collection, every-PR required enforcement of this new adapter, SSG artifact consumption, and actual Math transition integration remain unimplemented until separately tested and reconciled with their current owners. + +## Current-base evidence and author-lineage review + +Reconciled head `60aa00e9cc85b548c5c2f93181dda294f2599737` produced fresh required run37857698366/attempt1, checked merge `5d73e7900d2524d1131ab0698c1eb51213c389cb`, tree `a9411c6649b6a584db39c3a27ccab8aae5295217`, parentsf08dfdf9/60aa00e9. Both restricted modes passed127 unique identical methods, normal90.137s and optimized87.243s. Original artifact11585146326 is22815 bytes, raw/native SHA256 `946d63d15605ea65f6f1ffeeac45d5fbed62c11293b5c90b83c1ed0ea996c41f`; all12 manifest hashes and eight receipt inputs match. Receipt `c576661ca269678871cb4ceee164f18c326069ac65e26f0e70353fc959383cae` binds original four native context fields; caller113586792384 accepts all eight exact bindings. Graph30cdceda is unchanged. + +An actual workflow_dispatch casefold probe37858013139/attempt1 at the same checked5d73e790/treea941 passed2x10, with native ext4 F precondition and durations1.379s/1.392s. Original artifact11585096776 is4767 bytes, raw/native SHA256 `bbb01359f530e24e116a45bda09a5ad2605b121274a85357217dcaf5930a4fee`; all ten member hashes match. This was a dispatch at the checked revision, not a rerun or rebinding of historical evidence. Root verified both original ZIPs with data-only reads. These passing controls do not close later source findings. + +Automatic review on60aa00e9 raised two P1 suggestions. Independent receiving-review assessment by actual `/root/required_binding_tests` and root rejects mandatory Math proposer target lists (thread4225066097): native Math formal/gate.py88-99 preserves historical optional targets, while100-103 still compares every declared proposer lineage against the reviewer. An absent subset is an unscoped whole-manifest proposer under that v1 format. A focused positive omitted-target control and negative unscoped/nonfirst lineage conflict controls will preserve it; no native Math format is changed. + +The Main author consistency finding4225066106 is accepted. The retained manifest declares source author provider/family/agent, but the adapter currently compares only parties claimed inside alignment. Relabeling that author can make a reviewer equal to the real source author look independent. Main manifest18-22, SCOPE54-55 and REVIEW_LANE74-75 preserve that source lineage. Freeze focused external controls against the unchanged module `dd36165b...`: each field mismatch, relabeled author plus actual-author reviewer, and coherently rehashed missing/invalid manifest author. Include strip/casefold-equivalent valid lineage as a positive. Such packets retain their original records and independently applicable kernel axis, while alignment is noncurrent and its exact original reference requires revalidation. Math has no manifest author requirement and keeps its original format. + +At this checkpoint no merge has been attempted. New author-binding controls, genuine hosted RED, Main-only correction, exact corrected-source nonauthor review, fresh full GREEN and original archive readback remain pending. Owner authorization already exists; this hold is for substantive technical validation. Packet custody remains unknown, scientific effect NONE and authority false. diff --git a/tests/test_architecture_evidence_adapter.py b/tests/test_architecture_evidence_adapter.py index a9856527d..ffcb757a3 100644 --- a/tests/test_architecture_evidence_adapter.py +++ b/tests/test_architecture_evidence_adapter.py @@ -822,6 +822,104 @@ def test_captured_code_and_paths_remain_inert_packet_data(self): self.accepted(packet) self.assertFalse(canary.exists()) + def test_main_alignment_author_binds_retained_manifest_lineage_without_relabeling(self): + packet = self.with_formal() + formal = packet["formal_records"][0] + author = document(formal["manifest"])["author"] + self.update_alignment(formal, lambda review: review.update({ + "author": {field: " \t" + value.swapcase() + "\t " for field, value in author.items()}})) + report, _ = self.accepted(packet) + self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + self.assertEqual(report["regression"]["affected_alignment_records"], []) + + mutations = ("mismatched_provider", "mismatched_family", "mismatched_agent", + "relabeled_author_real_reviewer", "missing_manifest_author", "invalid_manifest_author", + "missing_manifest_provider", "missing_manifest_family", "missing_manifest_agent", + "invalid_manifest_provider", "invalid_manifest_family", "invalid_manifest_agent") + for mutation in mutations: + with self.subTest(mutation=mutation): + packet = self.with_formal() + formal = packet["formal_records"][0] + manifest = document(formal["manifest"]) + original_author = copy.deepcopy(manifest["author"]) + if mutation.startswith("mismatched_"): + field = mutation.removeprefix("mismatched_") + self.update_alignment(formal, lambda review: review["author"].update( + {field: "TEST-relabeled-" + field})) + elif mutation == "relabeled_author_real_reviewer": + self.update_alignment(formal, lambda review: review.update({ + "author": {field: "TEST-relabeled-" + field for field in original_author}, + "reviewer": original_author})) + else: + if mutation == "missing_manifest_author": + del manifest["author"] + elif mutation == "invalid_manifest_author": + manifest["author"] = True + elif mutation.startswith("missing_manifest_"): + del manifest["author"][mutation.removeprefix("missing_manifest_")] + else: + manifest["author"][mutation.removeprefix("invalid_manifest_")] = 0 + formal["manifest"] = replace_git(formal["manifest"], encoded(manifest)) + manifest_hash = formal["manifest"]["ref"]["sha256"] + self.update_receipt(formal, lambda receipt: receipt.update({"manifest_sha256": manifest_hash})) + self.update_alignment(formal, lambda review: review.update({"manifest_sha256": manifest_hash})) + # Every native/source/log binding stays consistent; only declared authorship is unresolved. + report, _ = self.accepted(packet) + alignment = report["dimensions"]["TEST.A"]["alignment"] + self.assertEqual(alignment["record_state"], "recorded") + self.assertIn(alignment["applicability"], {"stale", "unknown"}) + self.assertTrue(alignment["reasons"], "authorship inconsistency had no derived reason") + self.assertEqual(alignment["custody"], "unknown") + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + self.assertEqual(report["regression"]["affected_alignment_records"], [formal["alignment"]["ref"]]) + + def test_math_optional_proposer_scopes_preserve_historical_schema_and_every_lineage(self): + proposers = [ + {"provider": "TEST-unscoped-one", "family": "TEST-unscoped-family-one", "agent": "TEST-unscoped-agent-one"}, + {"provider": "TEST-unscoped-two", "family": "TEST-unscoped-family-two", "agent": "TEST-unscoped-agent-two"}, + ] + for schema in ("historical_single_author", "unscoped_proposers"): + with self.subTest(schema=schema): + packet = copy.deepcopy(self.packet) + formal = self.math_formal(packet) + packet["formal_records"] = [formal] + if schema == "unscoped_proposers": + self.update_alignment(formal, lambda review: review.update({"proposal_authors": proposers})) + report, _ = self.accepted(packet) + retained = report["formal_summary"][0] + self.assertNotIn("author", retained["retained_manifest"]) + if schema == "historical_single_author": + self.assertNotIn("proposal_authors", retained["retained_alignment"]) + else: + self.assertEqual(retained["retained_alignment"]["proposal_authors"], proposers) + for proposer in retained["retained_alignment"]["proposal_authors"]: + self.assertNotIn("targets", proposer) + self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + self.assertEqual(report["regression"]["affected_alignment_records"], []) + + for mutation in ("unscoped_proposer_reviewer_conflict", "nonfirst_normalized_conflict"): + with self.subTest(mutation=mutation): + packet = copy.deepcopy(self.packet) + formal = self.math_formal(packet) + packet["formal_records"] = [formal] + def alter(review): + review["proposal_authors"] = copy.deepcopy(proposers) + if mutation == "unscoped_proposer_reviewer_conflict": + review["proposal_authors"][0]["agent"] = review["reviewer"]["agent"] + else: + review["reviewer"]["family"] = "TEST Reviewer Family" + review["proposal_authors"][1]["family"] = " test reviewer\tFAMILY " + self.update_alignment(formal, alter) + report, _ = self.accepted(packet) + alignment = report["dimensions"]["TEST.A"]["alignment"] + self.assertEqual(alignment["record_state"], "recorded") + self.assertIn(alignment["applicability"], {"stale", "unknown"}) + self.assertIn("lineage_not_distinct", alignment["reasons"]) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + self.assertEqual(report["regression"]["affected_alignment_records"], [formal["alignment"]["ref"]]) + if __name__ == "__main__": unittest.main() From 98608a1ee4e54467d0df95106baa461768250233 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:30:38 -0700 Subject: [PATCH 06/25] Bind Main alignment author to retained source lineage without changing kernel evidence --- architecture/evidence_adapter.py | 16 +++++++++++++--- .../2026-10-08-architecture-evidence-adapter.md | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/architecture/evidence_adapter.py b/architecture/evidence_adapter.py index d7224ba91..525bed47b 100644 --- a/architecture/evidence_adapter.py +++ b/architecture/evidence_adapter.py @@ -432,7 +432,7 @@ def _lineage(party: Any, *, normalized: bool) -> dict[str, str] | None: def _alignment_reasons(document: dict[str, Any] | None, manifest: Capture, scope: Capture, - targets: list[str], *, main: bool) -> list[str]: + targets: list[str], *, main: bool, source_author: Any = None) -> list[str]: if document is None: return ["alignment_not_recorded"] reasons = [] @@ -451,7 +451,16 @@ def _alignment_reasons(document: dict[str, Any] | None, manifest: Capture, scope reasons.append("alignment_not_accepted") reviewer = _lineage(document.get("reviewer"), normalized=not main) authors = [_lineage(document.get("author"), normalized=not main)] - if not main: + if main: + retained_author = _lineage(source_author, normalized=False) + if retained_author is None: + reasons.append("manifest_author_unresolved") + else: + if authors[0] != retained_author: + reasons.append("author_binding_changed") + # A review cannot gain distinct lineage by relabeling its author. + authors.append(retained_author) + else: proposers = document.get("proposal_authors", []) if type(proposers) is not list: reasons.append("lineage_not_distinct") @@ -625,7 +634,8 @@ def _formal(value: Any, captures: Captures, nodes: set[str], expected: dict[str, complete = complete and set(phases) <= set(controls) alignment_capture = None if value["alignment"] is None else captures.git(value["alignment"], "formal alignment") alignment = None if alignment_capture is None else alignment_capture.document("formal alignment") - alignment_reasons = _alignment_reasons(alignment, manifest_capture, scope, targets, main=main) + alignment_reasons = _alignment_reasons(alignment, manifest_capture, scope, targets, + main=main, source_author=manifest.get("author")) return { "id": identity, "main": main, "native": native, "context_current": _same_context(native, expected), "manifest_capture": manifest_capture, "scope": scope, "manifest": manifest, diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index ef75819e1..e39bcf343 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -156,3 +156,9 @@ Automatic review on60aa00e9 raised two P1 suggestions. Independent receiving-rev The Main author consistency finding4225066106 is accepted. The retained manifest declares source author provider/family/agent, but the adapter currently compares only parties claimed inside alignment. Relabeling that author can make a reviewer equal to the real source author look independent. Main manifest18-22, SCOPE54-55 and REVIEW_LANE74-75 preserve that source lineage. Freeze focused external controls against the unchanged module `dd36165b...`: each field mismatch, relabeled author plus actual-author reviewer, and coherently rehashed missing/invalid manifest author. Include strip/casefold-equivalent valid lineage as a positive. Such packets retain their original records and independently applicable kernel axis, while alignment is noncurrent and its exact original reference requires revalidation. Math has no manifest author requirement and keeps its original format. At this checkpoint no merge has been attempted. New author-binding controls, genuine hosted RED, Main-only correction, exact corrected-source nonauthor review, fresh full GREEN and original archive readback remain pending. Owner authorization already exists; this hold is for substantive technical validation. Packet custody remains unknown, scientific effect NONE and authority false. + +The pending RED checkpoint above is now superseded operationally by actual run37859224871/attempt1, architecture job113590723075. Tests-only head `ebc12a64609beb8ef368c911af220fe27c693a4e`, tree `0818b162de0f9bdfd40822aa4e114e02d29fde67`, checked merge `c333ab76dccfaa982e07a9ef3b63d1328d2a6c9c` with the same tree/parentsf08dfdf9+ebc12a64 preserves implementation dd36165b and CLIad759f3f. Both modes ran129 methods: prior127 and the Math optional-scope method pass; the Main author-binding method fails12 coherent cases because alignment remains current. Normal89.026s and optimized88.843s. Native formal succeeded, architecture failed, landing skipped and verify failed; disposal, failure archive and strict release succeeded. Accepted identity emission skipped. + +Original artifact11586085043 is19357 bytes, raw/native SHA256 `e207a2cb103e0ea8a613b1c5ce86e76fdd9172210f360763e3a3f26a155569c2`; all eight retained member hashes match. Root read both full original failure inventories. Frozen40-test SHA256 `7de370ea659d289edf0560a93daba6e0eb1d2edaa67a0ae6d4c1ae45983ab710` adds only lines825-922; deleting those98 inserted lines recovers original38-test SHA3180ae17 exactly. The author is now correcting only the Main lineage consistency check. Source review, fresh129 GREEN and integration remain pending; the real failure is retained without rewriting earlier successful scope. + +The Main-only correction is SOURCE_PREPARED at module SHA256 `49fc152b6f8b2df099677469db510a56942c7df81f03890a95bad940b23cf310`. Root's source comparison against retained dd36165b confirms exactly three edits: optional source_author input to alignment analysis, Main-only retained-lineage comparison/reviewer distinctness, and the callsite supplying manifest.get(author). Existing Main strip/casefold semantics derive `manifest_author_unresolved` for missing/malformed source lineage and `author_binding_changed` for a different claimed author. Existing stale-contract handling names the exact original alignment reference. Kernel calculation, original packet/records and the Math branch are byte-identical. CLIad759f3f and40tests7de370ea remain unchanged. This is a source acceptance by a distinct implementation nonauthor, source-exposed organization-independence0; fresh129-mode execution, exact original archive custody, current automatic review and integration remain pending. From fd8fe0f5b0b9cb64f8b1591287ca3f0c8b72f0c2 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:47:23 -0700 Subject: [PATCH 07/25] test: retain unresolved lineage and shared alignment regression controls --- ...026-10-08-architecture-evidence-adapter.md | 9 ++ tests/test_architecture_evidence_adapter.py | 111 ++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index e39bcf343..9e109c494 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -162,3 +162,12 @@ The pending RED checkpoint above is now superseded operationally by actual run37 Original artifact11586085043 is19357 bytes, raw/native SHA256 `e207a2cb103e0ea8a613b1c5ce86e76fdd9172210f360763e3a3f26a155569c2`; all eight retained member hashes match. Root read both full original failure inventories. Frozen40-test SHA256 `7de370ea659d289edf0560a93daba6e0eb1d2edaa67a0ae6d4c1ae45983ab710` adds only lines825-922; deleting those98 inserted lines recovers original38-test SHA3180ae17 exactly. The author is now correcting only the Main lineage consistency check. Source review, fresh129 GREEN and integration remain pending; the real failure is retained without rewriting earlier successful scope. The Main-only correction is SOURCE_PREPARED at module SHA256 `49fc152b6f8b2df099677469db510a56942c7df81f03890a95bad940b23cf310`. Root's source comparison against retained dd36165b confirms exactly three edits: optional source_author input to alignment analysis, Main-only retained-lineage comparison/reviewer distinctness, and the callsite supplying manifest.get(author). Existing Main strip/casefold semantics derive `manifest_author_unresolved` for missing/malformed source lineage and `author_binding_changed` for a different claimed author. Existing stale-contract handling names the exact original alignment reference. Kernel calculation, original packet/records and the Math branch are byte-identical. CLIad759f3f and40tests7de370ea remain unchanged. This is a source acceptance by a distinct implementation nonauthor, source-exposed organization-independence0; fresh129-mode execution, exact original archive custody, current automatic review and integration remain pending. + +## Placeholder lineage and shared alignment regression follow-up + +The prior pending129-mode checkpoint is superseded by genuine GREEN run37859841587/attempt1 at exact head98608a1ee4e54467d0df95106baa461768250233, checked merge4d5c40335adf4e1487269491a97412fde69ac962, tree762dac9575d24a4167603c91b9f44d79290bdb81, parentsf08dfdf9/98608a1. Both restricted modes report129 unique identical methods/OK, normal112.380s and optimized113.214s. Original artifact11586071017 is23036 bytes, native/raw SHA2564f97d252e8dc9e80ff935bd131d233ed8427a0c8d52907d424461332d31ed79e; all12 manifest members and eight receipt inputs match. Original receiptb284d9037046894ead0f59bcdc785017750c17d7a9f8cba4213b94e3b854fd3f matches the native context and caller113593860702's eight bound outputs. All eight head checks succeeded. Fresh actual root nonauthor source review5464070754 accepts the Main-only author-binding source49fc152b; organization-independence0 and scientific effect NONE remain. + +Automatic review6070628711 completed on98608a1 at23:38:27UTC and raised two NEW findings4225219972 and4225219976. Root and actual original implementation author /root/architecture_design_review independently confirm both source paths. Main's strip/casefold comparison must remain native-compatible, but recognized unresolved words must be rejected independently of comparison mode. This is a conservative adapter guard: the native Main gate itself checks nonempty lineage, rather than already providing this placeholder guarantee. Graph/dependency/context regression must also make impacted explicitly mapped alignment noncurrent. A whole-manifest original alignment record held for revalidation must not be simultaneously projected current through another explicit mapping of that same record. Its other mappings need an explicit shared-record reason, without inventing graph impact or erasing independently current kernel evidence. A separate unimpacted original alignment identity can remain current; no fuzzy target join is permitted. + +Root-authored external controls add only111 lines924-1033 to the original40-method file:42 methods, SHA256a761861bce9b35e2d5ad0be7655b8e9bf1ed0fc675735b26ee9b8ad61bb90792. The first method covers16 literal reserved words with decorated case/whitespace for a reviewer and a coherently rebound manifest/alignment author, plus each single unresolved lineage component (38 cases). The second retains a source-bound unchanged positive, shared B/D whole-manifest alignment and a separate E review identity, then challenges upstream statement, proof, source loss, node record, removed dependency, relation and whole-graph context changes. Original records and kernel applicability remain independent, and unmapped C retains unknown alignment. Source review and actual hosted RED are pending; implementation49fc152b and CLIad759f3f remain unchanged. There is no local Python/Node/test execution or merge attempt. Earlier GREEN scopes and genuine failures remain retained, without claiming these new cases already passed. +Fresh actual /root/graph_tests_review nonauthor source assessment ACCEPT_SCOPED_SOURCE covers the exact new a761861b tests and their native capture/mutation helpers. Data-only deletion of111 added lines924-1034 reproduces original40 SHA7de370ea exactly. The independent review confirms38 coherent placeholder cases, admitted positive source joins, seven union-regression cases and shared-record versus separate-ref controls, without a kernel or organizational-independence claim. Source runtime remains NOT_RUN; publish tests-only against unchanged49fc152b before any implementation correction. diff --git a/tests/test_architecture_evidence_adapter.py b/tests/test_architecture_evidence_adapter.py index ffcb757a3..d2931b623 100644 --- a/tests/test_architecture_evidence_adapter.py +++ b/tests/test_architecture_evidence_adapter.py @@ -921,5 +921,116 @@ def alter(review): self.assertEqual(report["regression"]["affected_alignment_records"], [formal["alignment"]["ref"]]) + def test_main_placeholder_lineage_cannot_be_current_even_with_coherent_author_bindings(self): + placeholders = ("unknown", "unverified", "not known", "not available", "not provided", + "unavailable", "unspecified", "pending", "tbd", "todo", "none", "null", + "n/a", "na", "?", "-") + for party in ("reviewer", "bound_author"): + for token in placeholders: + for field in ("all", "provider", "family", "agent") if token == "unknown" else ("all",): + with self.subTest(party=party, token=token, field=field): + packet = self.with_formal() + formal = packet["formal_records"][0] + value = " \t" + " \t ".join(token.upper().split()) + "\t " + fields = ("provider", "family", "agent") if field == "all" else (field,) + replacement = {name: value for name in fields} + if party == "reviewer": + self.update_alignment(formal, lambda review: review["reviewer"].update(replacement)) + else: + manifest = document(formal["manifest"]) + manifest["author"].update(replacement) + formal["manifest"] = replace_git(formal["manifest"], encoded(manifest)) + manifest_hash = formal["manifest"]["ref"]["sha256"] + self.update_receipt(formal, lambda receipt: receipt.update({"manifest_sha256": manifest_hash})) + def alter(review): + review["author"].update(replacement) + review["manifest_sha256"] = manifest_hash + self.update_alignment(formal, alter) + report, _ = self.accepted(packet) + alignment = report["dimensions"]["TEST.A"]["alignment"] + self.assertEqual(alignment["record_state"], "recorded") + self.assertIn(alignment["applicability"], {"stale", "unknown"}) + self.assertIn("lineage_not_distinct", alignment["reasons"]) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + self.assertEqual(report["regression"]["affected_alignment_records"], [formal["alignment"]["ref"]]) + + def test_dependency_regression_stales_shared_whole_alignment_without_erasing_kernel(self): + statement = b"TEST upstream statement old\n" + proof = b"TEST upstream proof old\n" + upstream = statement + proof + base = copy.deepcopy(self.packet) + for label, commit in (("old", BASE), ("new", HEAD)): + binding = base[label]["bindings"][0] + binding["node"] = "TEST.B" + binding["statement_slice"] = slice_of(SOURCE, len(ALPHA) + len(PROOF), len(SOURCE)) + binding["proof_slice"] = None + for node in ("TEST.D", "TEST.E"): + self.change_graph(base, label, lambda graph, node=node: graph["nodes"].update({ + node: {"classification": "PROVED_REVIEWED", "controlling": False}})) + extra = copy.deepcopy(binding) + extra["node"] = node + extra["statement_slice"] = slice_of(SOURCE, 0, len(ALPHA)) + base[label]["bindings"].append(extra) + base[label]["bindings"].append({ + "node": "TEST.A", "source": git_capture(upstream, "TEST/upstream.md", commit), + "statement_slice": slice_of(upstream, 0, len(statement)), + "proof_slice": slice_of(upstream, len(statement), len(upstream))}) + formal = self.formal(base) + formal["node_targets"] = [{"node": "TEST.B", "target": TARGETS[1]}, {"node": "TEST.D", "target": TARGETS[0]}] + separate = copy.deepcopy(formal) + separate["id"] = "TEST-unaffected-formal" + separate["node_targets"] = [{"node": "TEST.E", "target": TARGETS[0]}] + separate["alignment"] = git_capture(raw_bytes(separate["alignment"]), "TEST/separate-alignment.json") + base["formal_records"] = [formal, separate] + unchanged, _ = self.accepted(base) + for node in ("TEST.B", "TEST.D", "TEST.E"): + self.assertEqual(unchanged["dimensions"][node]["alignment"]["applicability"], "current") + self.assertEqual(unchanged["dimensions"][node]["kernel"]["applicability"], "current") + self.assertEqual(unchanged["regression"]["affected_alignment_records"], []) + for mutation in ("statement", "proof", "source_loss", "upstream_record", + "removed_dependency", "dependency_relation", "graph_context"): + with self.subTest(mutation=mutation): + packet = copy.deepcopy(base) + if mutation in ("statement", "proof"): + raw = upstream.replace((mutation + " old").encode("ascii"), (mutation + " new").encode("ascii")) + binding = packet["new"]["bindings"][-1] + binding["source"] = replace_git(binding["source"], raw) + binding["statement_slice"] = slice_of(raw, 0, len(statement)) + binding["proof_slice"] = slice_of(raw, len(statement), len(raw)) + elif mutation == "source_loss": + binding = packet["new"]["bindings"][-1] + binding["source"] = binding["statement_slice"] = binding["proof_slice"] = None + elif mutation == "upstream_record": + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.A"].update({"notes": "TEST changed"})) + elif mutation == "removed_dependency": + self.change_graph(packet, "new", lambda graph: graph.update({"edges": graph["edges"][1:]})) + elif mutation == "dependency_relation": + self.change_graph(packet, "new", lambda graph: graph["edges"][0].update({"relation": "TEST changed"})) + else: + self.change_graph(packet, "new", lambda graph: graph.update({"object": "TEST changed context"})) + report, _ = self.accepted(packet) + regression = report["regression"] + self.assertIn("TEST.B", regression["impacted_nodes"]) + self.assertIn("TEST.C", regression["impacted_nodes"]) + self.assertIn(formal["alignment"]["ref"], regression["affected_alignment_records"]) + for node in ("TEST.B", "TEST.D"): + alignment = report["dimensions"][node]["alignment"] + self.assertEqual(alignment["record_state"], "recorded") + self.assertEqual(alignment["applicability"], "stale") + self.assertTrue(alignment["reasons"]) + self.assertEqual(report["dimensions"][node]["kernel"]["applicability"], "current") + if mutation != "graph_context": + self.assertNotIn("TEST.D", regression["impacted_nodes"]) + self.assertNotIn("TEST.E", regression["impacted_nodes"]) + self.assertEqual(regression["affected_alignment_records"], [formal["alignment"]["ref"]]) + self.assertEqual(report["dimensions"]["TEST.E"]["alignment"]["applicability"], "current") + else: + self.assertIn("TEST.E", regression["impacted_nodes"]) + self.assertEqual(report["dimensions"]["TEST.E"]["alignment"]["applicability"], "stale") + self.assertIn(separate["alignment"]["ref"], regression["affected_alignment_records"]) + self.assertEqual(report["dimensions"]["TEST.C"]["alignment"]["record_state"], "unknown") + self.assertEqual(report["dimensions"]["TEST.C"]["alignment"]["applicability"], "unknown") + + if __name__ == "__main__": unittest.main() From f756883c22ee54ef0f3b6b2889fc3ef428ebcc50 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:59:20 -0700 Subject: [PATCH 08/25] fix: hold unresolved lineage and shared regression alignment records --- architecture/evidence_adapter.py | 25 ++++++++++++++++--- ...026-10-08-architecture-evidence-adapter.md | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/architecture/evidence_adapter.py b/architecture/evidence_adapter.py index 525bed47b..ba08c4c92 100644 --- a/architecture/evidence_adapter.py +++ b/architecture/evidence_adapter.py @@ -424,9 +424,10 @@ def _lineage(party: Any, *, normalized: bool) -> dict[str, str] | None: value = party.get(field) if type(value) is not str or not value.strip(): return None - compared = " ".join(value.split()).casefold() if normalized else value.strip().casefold() - if normalized and compared in PLACEHOLDERS: + normalized_value = " ".join(value.split()).casefold() + if normalized_value in PLACEHOLDERS: return None + compared = normalized_value if normalized else value.strip().casefold() result[field] = compared return result @@ -908,6 +909,17 @@ def _retrofit_projection(record: dict[str, Any], binding: dict[str, Any] | None) def _dimensions(new: dict[str, Any], formals: list[dict[str, Any]], retrofits: list[dict[str, Any]], regression: dict[str, Any]) -> dict[str, Any]: + regression_reasons = {proposal["node"]: proposal["reasons"] + for proposal in regression["revalidation_required"]} + alignment_holds: dict[str, set[str]] = {} + for formal in formals: + capture = formal["alignment_capture"] + if capture is None: + continue + held_reasons = {code for mapping in formal["mappings"] + for code in regression_reasons.get(mapping["node"], [])} + if held_reasons: + alignment_holds.setdefault(canonical(capture.ref), set()).update(held_reasons) projected = {node: {axis: [] for axis in AXES} for node in new["graph"]["nodes"]} for node, original in new["graph"]["nodes"].items(): binding = new["bindings"].get(node) @@ -933,11 +945,17 @@ def _dimensions(new: dict[str, Any], formals: list[dict[str, Any]], retrofits: l # No independent native review ID is supplied by graph review text. projected[node]["review"].append(_axis("recorded", application, reasons=review_reasons)) for formal in formals: + capture = formal["alignment_capture"] + held_reasons = set() if capture is None else alignment_holds.get(canonical(capture.ref), set()) for mapping in formal["mappings"]: node, target = mapping["node"], mapping["target"] joined, join_reasons = _main_join(formal, node, target, new["bindings"]) projected[node]["kernel"].append(_kernel(formal, joined, join_reasons)) reasons = list(formal["alignment_reasons"]) + if held_reasons: + # The hold covers every explicit mapping of this original whole record. + reasons.extend(sorted(held_reasons)) + reasons.append("alignment_record_revalidation_required") if not formal["context_current"]: reasons.append("native_context_changed") unresolved_join = formal["main"] and not joined @@ -946,7 +964,8 @@ def _dimensions(new: dict[str, Any], formals: list[dict[str, Any]], retrofits: l if formal["alignment"] is None: alignment = _axis(reasons=reasons, evidence=[formal["id"]]) else: - contract_stale = bool(formal["alignment_reasons"]) or not formal["context_current"] + contract_stale = (bool(formal["alignment_reasons"]) or not formal["context_current"] + or bool(held_reasons)) application = "stale" if contract_stale else "unknown" if unresolved_join else "current" alignment = _axis("recorded", application, reasons=reasons, evidence=[formal["id"]]) diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index 9e109c494..9b119c5c6 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -171,3 +171,5 @@ Automatic review6070628711 completed on98608a1 at23:38:27UTC and raised two NEW Root-authored external controls add only111 lines924-1033 to the original40-method file:42 methods, SHA256a761861bce9b35e2d5ad0be7655b8e9bf1ed0fc675735b26ee9b8ad61bb90792. The first method covers16 literal reserved words with decorated case/whitespace for a reviewer and a coherently rebound manifest/alignment author, plus each single unresolved lineage component (38 cases). The second retains a source-bound unchanged positive, shared B/D whole-manifest alignment and a separate E review identity, then challenges upstream statement, proof, source loss, node record, removed dependency, relation and whole-graph context changes. Original records and kernel applicability remain independent, and unmapped C retains unknown alignment. Source review and actual hosted RED are pending; implementation49fc152b and CLIad759f3f remain unchanged. There is no local Python/Node/test execution or merge attempt. Earlier GREEN scopes and genuine failures remain retained, without claiming these new cases already passed. Fresh actual /root/graph_tests_review nonauthor source assessment ACCEPT_SCOPED_SOURCE covers the exact new a761861b tests and their native capture/mutation helpers. Data-only deletion of111 added lines924-1034 reproduces original40 SHA7de370ea exactly. The independent review confirms38 coherent placeholder cases, admitted positive source joins, seven union-regression cases and shared-record versus separate-ref controls, without a kernel or organizational-independence claim. Source runtime remains NOT_RUN; publish tests-only against unchanged49fc152b before any implementation correction. +Actual new two-method RED is now retained: run37861392790/attempt1, architecture job113597709898, tests-onlyfd8fe0f5, checked1ab7c8d7635772c81b6cbad0208baf2ed867dd0d/tree4cc75004ea8bd4099a5c70c15791b0b7019d6207/parentsf08dfdf9+fd8fe0f5. Both original full logs ran131 methods with45 assertion failures:38 placeholder cases and seven upstream/dependency/context cases, while129 prior unique methods pass identically. Normal73.181s and optimized73.349s. The shared-record D assertions occur after the first failing B assertion and remain to be exercised after correction. Native formal succeeded, architecture/verify failed and landing skipped; failure archive/disposal/strict release succeeded, accepted identity emission skipped. Original artifact11585544866 is22614 bytes, native/raw SHA256be9d35e25261c74cf1ef8680084c0c36cbe8c0e941e8e093b19c3fc6af02d9a4, and all eight original ARTIFACT_SHA256SUMS payload hashes match. Root read both complete failure inventories. An initial data lookup requested nonexistent SHA256SUMS.txt; original member listing established ARTIFACT_SHA256SUMS and its readback succeeded, with no archive transfer retry or product execution. Distinct implementation author /root/graph_tests_review is now assigned a bounded module-only correction after this actual RED; frozen42 tests and CLI are unchanged. Fresh source review, full131 GREEN, original custody and current automatic review remain pending. +Fresh actual root implementation-nonauthor source assessment accepts exact module08adf2661a3ee490f1f9f12bf58f0a97bd5237b6f078bad1127988428757746e after reading both changed functions and comparing the complete source against retained49fc152b. Exactly five bounded replacements add1059 characters: placeholder recognition independent of lineage comparison mode; a canonical-full-GitRef hold map derived only from existing explicitly mapped revalidation proposals; and whole-record stale projection with actual regression codes plus alignment_record_revalidation_required. The entire regression/main-source-join/kernel/adapt_packet functions, original records and affected-ref selection are byte-identical. Root authored the two new external tests and is distinct from this correction author /root/graph_tests_review; exposure is source/test-exposed and organization-independence0.42tests a761861b and CLIad759f3f are unchanged. Fresh hosted131-mode GREEN, original archive/native readback, current automatic findings and later-current-main integration are still pending; no local execution or merge attempt. From 2601c2cc97d51c2f324653d01107b084ace6ff46 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Fri, 9 Oct 2026 11:26:45 -0700 Subject: [PATCH 09/25] Freeze three reviewed adapter regressions before implementation correction --- ...026-10-08-architecture-evidence-adapter.md | 12 ++ tests/test_architecture_evidence_adapter.py | 154 ++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index 87104960d..1ade034f2 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -197,3 +197,15 @@ The pending RED is now actual retained failure: head0fdfe616e9ef49848a49e02179dc Following owner token-restoration6085820307 and root scope-resume6085859861, actual /root/graph_tests_review authored only the module correction SHA2565fb28b0b64054163b6fd529951802c78bdfbb0de19d74ed285161803a68e9fad (1106L59210B;109insertions20deletions). It validates optional reviewed_graph closed6-field refs, groups full original alignment identities consistently for dimensions and affected records, clears a regression hold only with every formal use's full current bindings and exact verified new graph context, isolates expected native context to kernel, admits old/new formal-node union while projecting only survivors, and checks exact substantive multiline elaborated target coverage without rejecting silent checker success. CLIad759f3f and46tests897701ff remain byte-identical. Root fresh source review read the complete1106-line module and frozen tests, inspected all changed helpers and source preservation, and accepts this scoped candidate for hosted validation. Root is a nonauthor of this implementation, author of the four new methods and previously source-exposed; organizational independence0. This is source acceptance, not corrected runtime GREEN, authentic custody, scientific alignment acceptance or integration. Actual main on resumed reconciliation is032267c259162728229e3ddd14d08fe1c3f9a392/treea32a3a7c6dc4fe6715e8c912f31181637fb8b7fe after337. Publication composes only these four adapter paths over that main and preserves every intervening peer change. Exact135-method hosted GREEN, original archive readback, current automatic review, exact checked-revision casefold controls and review-thread closure remain required before ordinary protected merge. The full eight-item objective remains active. + +## Retained135-method GREEN and three-regression resource amendment + +The last pending135-method checkpoint now has actual hosted GREEN: head5b0d2a3248ee6f67518c7f89fe4060870caf43af, run37967019742/attempt1, checked7fc8e2c8fbb67980ffa203b0d34c084811d5bda4/tree6352cd67f69112fd1294c0fa49470f52e84148b4, ordered parents032267c259162728229e3ddd14d08fe1c3f9a392+5b0d2a3248ee6f67518c7f89fe4060870caf43af. Both restricted modes ran135 identical unique methods/OK, normal133.599s/optimized131.179s. Original artifact11634551473 is23577B/raw-and-nativeSHA2568ec0a27b7132d086f54de6c273ba63ac08832d6a87714581fcc652f7647fd2eb; root verified all12payload hashes and eight receipt input bytes/hashes, original receipt54bf2991327556180fe3d81cc0ed0e96078a416abea0056b9136f6d4a5e57f1f, and native accepted caller113945671475's eight output bindings. This remains its bounded historical scope, not final acceptance or a merge. + +Actual automatic review5473413944 on5b0d2a32 raised three new findings4232898480/8492/8497. Root and distinct test author operations_contract_review assessed the unchanged implementation5fb28b0b against these source paths. A comment-only text following a declared target's colon cannot establish a substantive elaborated type, while quoted comment markers, trailing/nested comments attached to substantive types and legitimate multiline native headers remain compatible. An exact new reviewed_graph identity cannot clear a whole original alignment record if any Main use lacks the complete node-to-origin-source/statement/target-anchor join; independently current kernel evidence and a separate original review remain independent. The pinned gate repeatedly scans outgoing edges, so the adapter needs a bounded graph cardinality admission before invoking that independently pinned gate; this source assessment is not a measured runtime estimate or evidence that the full every-PR graph product is complete. + +This additive v1 resource ABI admits at most256 nodes and2048 edges in each old and new captured graph, including aliased immutable captures. Verify capture byte/blob/hash integrity and parse the original graph, then refuse excessive cardinality before any pinned graph-gate classification/traversal. A refused packet exits1 with empty stdout and a deterministic stderr prefixed `architecture evidence adapter refused: ` containing `graph node limit` or `graph edge limit` respectively. Cardinality admission precedes gate classification even if an oversized original graph also contains an unsupported classification. Exact256/2048 boundaries remain admitted when otherwise lawful. The dated49-node/55-edge graph is within this scope. Existing16MiB packet/4MiB capture/depth64 and inert-code/custody/scientific boundaries remain unchanged. This is a deliberately bounded adapter contract, not a25,000-node performance benchmark, optimized gate replacement or full architecture completion. + +Exactly three additive external methods are SOURCE_PREPARED at49methods/1285L/85510B/SHA256ed65e2ae0a4d2f52436ccfd6a5c4774bf5b2f3fbf0cfdd33f3caa9ec231707be. The154-line block1130–1283 has zero deletions; passive deletion recovers original46SHA897701ff6d981b59c1ec5679f578c083e69143e8ad45c3898d323ac00a5bf056. The comment-only method covers four compatible substantive positive logs and nine missing-target comment-only negatives with a silent checker. The shared-alignment method retains unchanged/exact-successor complete-join positives and three coherent Main join-loss cases, holding the shared original record once while the joined survivor's kernel and disjoint review remain current. The cardinality method has four lawful exact-boundary positives and twelve old/new/alias oversized or classification-order negatives, each with two deterministic CLI calls; all graphs remain at most257nodes/2049 unique shallow context edges, raw graph below512KiB and packet below2MiB, without timing probes or gate mutation. + +Actual source author operations_contract_review; fresh distinct graph_reader_design_review ACCEPT_SCOPED_SOURCE reads the entire154-line delta and all constructors/helpers1–307, confirms exact46 recovery and unchanged module5fb28b0b/CLIad759f3f/trustedgatea78f3e25. Source/test-exposed, organizational independence0 and scienceNONE. Root owns this contract amendment and publication; neither test author nor reviewer edited implementation or ran local project code. Publish these tests and this additive history against unchanged implementation before any correction. Genuine138-method hosted RED, original logs/native/archive readback, distinct implementation correction, fresh full138GREEN, current auto review, exact-final checked-revision casefold and all thread closure remain pending. Source-only static mismatches are not the required hosted failure. Main integration remains queued328 then325 under root's current coordination window; source publication does not merge or seize a peer scope. diff --git a/tests/test_architecture_evidence_adapter.py b/tests/test_architecture_evidence_adapter.py index 81eb62ec4..94724dd56 100644 --- a/tests/test_architecture_evidence_adapter.py +++ b/tests/test_architecture_evidence_adapter.py @@ -1127,5 +1127,159 @@ def test_elaborated_target_coverage_is_required_and_silent_checker_is_valid(self self.assertEqual(multiline["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + def test_elaborated_comment_only_types_are_incomplete_but_real_types_remain_current(self): + positive_logs = ( + b"TEST.Formal.alpha : True -- TEST trailing comment\nTEST.Formal.beta : True -- TEST trailing comment\n", + b"TEST.Formal.alpha : True /- TEST outer /- TEST nested -/ TEST tail -/\nTEST.Formal.beta : True /- TEST comment -/\n", + b'TEST.Formal.alpha : ("TEST -- /- literal -/" = "TEST -- /- literal -/")\nTEST.Formal.beta : True\n', + b"TEST.Formal.alpha (TEST_parameter : Nat)\n : True /- TEST outer\n /- TEST nested -/ TEST tail -/\nTEST.Formal.beta :\n True -- TEST multiline type\n", + ) + for raw in positive_logs: + with self.subTest(kind="substantive_type", raw=raw): + packet = self.with_formal() + formal = packet["formal_records"][0] + self.replace_log(formal, "leanchecker.log", b"") + self.replace_log(formal, "elaborated-types.log", raw) + report, _ = self.accepted(packet) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "current") + self.assertEqual(report["regression"]["affected_alignment_records"], []) + comment_bodies = ( + "-- TEST a comment is not a type", + "/- TEST outer /- TEST nested -/ TEST tail -/", + "\n /- TEST outer\n /- TEST nested -/\n TEST tail -/", + ) + for comment in comment_bodies: + for incomplete in (set(TARGETS), {TARGETS[0]}, {TARGETS[1]}): + with self.subTest(kind="comment_only_type", comment=comment, incomplete=sorted(incomplete)): + raw = "".join(target + " : " + (comment if target in incomplete else "True") + "\n" + for target in TARGETS).encode("utf-8") + packet = self.with_formal() + formal = packet["formal_records"][0] + self.replace_log(formal, "leanchecker.log", b"") + self.replace_log(formal, "elaborated-types.log", raw) + report, _ = self.accepted(packet) + kernel = report["dimensions"]["TEST.A"]["kernel"] + self.assertEqual(kernel["applicability"], "unknown") + self.assertIn("target_inventory_incomplete", kernel["reasons"]) + self.assertEqual(report["dimensions"]["TEST.A"]["alignment"]["applicability"], "current") + self.assertEqual(report["regression"]["affected_alignment_records"], []) + + def test_exact_successor_review_cannot_clear_shared_alignment_with_one_unresolved_main_join(self): + base = copy.deepcopy(self.packet) + for label, commit in (("old", BASE), ("new", HEAD)): + for node, start, end in (("TEST.D", len(ALPHA) + len(PROOF), len(SOURCE)), + ("TEST.E", 0, len(ALPHA))): + self.change_graph(base, label, lambda graph, node=node: graph["nodes"].update({ + node: {"classification": "PROVED_REVIEWED", "controlling": False}})) + base[label]["bindings"].append({"node": node, "source": git_capture(SOURCE, "TEST/source.md", commit), + "statement_slice": slice_of(SOURCE, start, end), "proof_slice": None}) + for graph_changed in (False, True): + packet = copy.deepcopy(base) + if graph_changed: + self.change_graph(packet, "new", lambda graph: graph["nodes"]["TEST.A"].update({ + "notes": "TEST successor node record requires explicit graph review"})) + formal = self.formal(packet) + self.update_alignment(formal, lambda review: review.update({ + "reviewed_graph": copy.deepcopy(packet["new"]["graph"]["ref"])})) + shared = copy.deepcopy(formal) + shared["id"] = "TEST-shared-survivor-formal" + shared["node_targets"] = [{"node": "TEST.D", "target": TARGETS[1]}] + separate = copy.deepcopy(formal) + separate["id"] = "TEST-disjoint-formal" + separate["node_targets"] = [{"node": "TEST.E", "target": TARGETS[0]}] + separate["alignment"] = git_capture(raw_bytes(separate["alignment"]), "TEST/disjoint-alignment.json") + packet["formal_records"] = [formal, shared, separate] + with self.subTest(kind="all_joins_present", graph_changed=graph_changed): + current, _ = self.accepted(packet) + for node in ("TEST.A", "TEST.D", "TEST.E"): + self.assertEqual(current["dimensions"][node]["kernel"]["applicability"], "current") + self.assertEqual(current["dimensions"][node]["alignment"]["applicability"], "current") + self.assertEqual(current["regression"]["affected_alignment_records"], []) + self.assertEqual(bool(current["regression"]["impacted_nodes"]), graph_changed) + if not graph_changed: + continue + for mutation in ("missing_source", "missing_statement", "different_origin"): + changed = copy.deepcopy(packet) + binding = changed["new"]["bindings"][0] + if mutation == "missing_source": + binding["source"] = binding["statement_slice"] = binding["proof_slice"] = None + elif mutation == "missing_statement": + binding["statement_slice"] = None + else: + binding["source"] = git_capture(SOURCE, "TEST/unjoined-origin.md", "c" * 40, "TEST-other/origin") + report, _ = self.accepted(changed) + regression = report["regression"] + with self.subTest(mutation=mutation, check="independent_kernel_and_disjoint_review"): + self.assertIn("TEST.A", regression["impacted_nodes"]) + self.assertNotIn("TEST.D", regression["impacted_nodes"]) + self.assertNotIn("TEST.E", regression["impacted_nodes"]) + self.assertEqual(report["dimensions"]["TEST.A"]["kernel"]["applicability"], "unknown") + self.assertEqual(report["dimensions"]["TEST.D"]["kernel"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.E"]["kernel"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.E"]["alignment"]["applicability"], "current") + self.assertEqual(report["dimensions"]["TEST.C"]["alignment"]["applicability"], "unknown") + for node in ("TEST.A", "TEST.D"): + with self.subTest(mutation=mutation, check="shared_whole_record_hold", node=node): + alignment = report["dimensions"][node]["alignment"] + self.assertEqual(alignment["record_state"], "recorded") + self.assertEqual(alignment["applicability"], "stale") + self.assertIn("alignment_record_revalidation_required", alignment["reasons"]) + with self.subTest(mutation=mutation, check="original_identity_affected_once"): + self.assertEqual(regression["affected_alignment_records"], [formal["alignment"]["ref"]]) + self.assertEqual(changed["formal_records"][0]["alignment"], changed["formal_records"][1]["alignment"]) + self.assertNotEqual(formal["alignment"]["ref"], separate["alignment"]["ref"]) + + def test_graph_node_and_edge_admission_limits_cover_both_snapshots_and_alias_captures(self): + def fixture(node_count, edge_count, *, label=None, aliases=False, invalid_classification=False): + packet = copy.deepcopy(self.packet) + graph = document(packet["new"]["graph"]) + for index in range(3, node_count): + graph["nodes"]["TEST.LIMIT.%04d" % index] = { + "classification": "AUTHOR_SIDE_CANDIDATE", "controlling": False} + graph["edges"] = [{"from": "TEST.A", "to": "TEST.B", "required": False, + "relation": "TEST limit context %04d" % index} for index in range(edge_count)] + if invalid_classification: + # Only graph data changes: resource refusal must precede gate classification. + graph["nodes"]["TEST.A"]["classification"] = "TEST_UNSUPPORTED_CLASSIFICATION" + raw = (json.dumps(graph, sort_keys=True, separators=(",", ":"), allow_nan=False) + "\n").encode("utf-8") + self.assertEqual(len(graph["nodes"]), node_count) + self.assertEqual(len(graph["edges"]), edge_count) + self.assertEqual(len({(edge["from"], edge["to"], edge["relation"]) for edge in graph["edges"]}), edge_count) + self.assertLess(len(raw), 512 * 1024, "TEST limit fixture became a large timing probe") + for snapshot, commit in (("old", BASE), ("new", HEAD)): + if label is None or snapshot == label: + packet[snapshot]["graph"] = git_capture(raw, "TEST/graph.json", commit) + if aliases: + packet["old"]["graph"] = copy.deepcopy(packet["new"]["graph"]) + packet["old"]["bindings"][0]["source"] = copy.deepcopy(packet["new"]["bindings"][0]["source"]) + self.assertLess(len(encoded(packet)), 2 * 1024 * 1024, "TEST packet exceeded its small resource-control scope") + return packet + + for nodes, edges, aliases in ((256, 0, False), (3, 2048, False), (256, 2048, False), (256, 2048, True)): + with self.subTest(kind="exact_admitted_boundary", nodes=nodes, edges=edges, aliases=aliases): + packet = fixture(nodes, edges, aliases=aliases) + report, _ = self.accepted(packet) + self.assertEqual(len(report["dimensions"]), nodes) + self.assertEqual(report["regression"]["changed_nodes"], []) + self.assertEqual(report["regression"]["impacted_nodes"], []) + for nodes, edges, resource in ((257, 0, "node"), (3, 2049, "edge")): + for label, aliases in (("old", False), ("new", False), (None, True)): + for invalid_classification in (False, True): + with self.subTest(kind="resource_refusal", nodes=nodes, edges=edges, label=label, + aliases=aliases, invalid_classification=invalid_classification): + packet = fixture(nodes, edges, label=label, aliases=aliases, + invalid_classification=invalid_classification) + first = self.run_adapter(packet) + second = self.run_adapter(packet) + self.assertEqual((first.returncode, first.stdout, first.stderr), + (second.returncode, second.stdout, second.stderr), "resource refusal was nondeterministic") + self.assertEqual(first.returncode, 1, "graph beyond the declared resource ABI was admitted") + self.assertEqual(first.stdout, "", "resource refusal emitted a valid report") + self.assertTrue(first.stderr.startswith("architecture evidence adapter refused: ")) + self.assertRegex(first.stderr, r"graph.*" + resource + r".*limit", + "resource admission did not precede the pinned graph gate") + + if __name__ == "__main__": unittest.main() From e5325ac1c8679979e84bc3f1749866c11ae78946 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:17:27 -0700 Subject: [PATCH 10/25] Freeze original negative-control log regressions before adapter correction --- ...026-10-08-architecture-evidence-adapter.md | 12 ++ tests/test_architecture_evidence_adapter.py | 135 ++++++++++++++++++ 2 files changed, 147 insertions(+) diff --git a/docs/plans/2026-10-08-architecture-evidence-adapter.md b/docs/plans/2026-10-08-architecture-evidence-adapter.md index 9d73a94c3..c1d1fdd1c 100644 --- a/docs/plans/2026-10-08-architecture-evidence-adapter.md +++ b/docs/plans/2026-10-08-architecture-evidence-adapter.md @@ -222,3 +222,15 @@ PR328 actually integrated by one expected-head normal merge at2026-10-09T18:57:3 Publish the corrected four adapter paths over actualmain36eed0e9, with old2601head andactualmain asorderedparents, preservingallpeer/main/runtime sources. Freshfull138normal/optimizedGREEN/originalnativearchivecustody/currentautomaticreview/exactfinalchecked-revisioncasefold/allthreadclosure remainrequired beforeordinaryexpected-headmerge325. All eightgoals remainACTIVE. +## Negative-control original-log coverage amendment + +Automatic finding4233374415 at head8aedd7a6ef0ba0c2d71f13d9978400327f780035 is accepted as a source defect: a self-consistent Main packet can remove every required negative-control log from both original-log and receipt inventories while retaining all outcome labels, and the current module still regards its formal record as complete. The preceding required138-method run37977491475 is an earlier-control checkpoint; these new cases were absent. Its original archive/native binding review remains root-owned. Preserve that execution and all earlier RED/GREEN history without claiming it covers this amendment. + +Fresh native Main producer `tools/formal_gate_check.py` at36eed0e9e2c7d4d1ad26bc2c2ae8499d31e78563 is literal byte-equal to the local23282B/SHA25621c355e02ac6e01337d10465a3105b34b93f832586ee60aa2430f662a90cd8b7 source. It writes each `