From 212324e4f052bc9da6824569e026e23b30869209 Mon Sep 17 00:00:00 2001 From: Grok Bot agent 3 Date: Thu, 22 Oct 2026 11:59:34 -0500 Subject: [PATCH 1/7] Add read-only evidence-to-artifact path tool (LANES-20261022 Lane 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tools/evidence_path.py emits node -> pinned source -> artifact binding -> execution receipt -> review link with an explicit missing list; unknown nodes are refused. math.d5-component.punctured-pin-proof reports 'public projection not admitted (#327 exporter held by Claude017)'. No network, no writes. Refs main#475. credit 0 · sci NONE · eng≠discharge · no flags · OBL OPEN --- tests/test_evidence_path.py | 98 ++++++++++++++++++ tools/evidence_path.py | 193 ++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+) create mode 100644 tests/test_evidence_path.py create mode 100644 tools/evidence_path.py diff --git a/tests/test_evidence_path.py b/tests/test_evidence_path.py new file mode 100644 index 000000000..efbf7da80 --- /dev/null +++ b/tests/test_evidence_path.py @@ -0,0 +1,98 @@ +"""Tests for tools/evidence_path.py (LANES-20261022 Lane 1, main#475). + +Scientific effect NONE. The complete path uses a synthetic fixture node; the +real punctured-pin node must stay explicitly missing. +""" +import copy +import importlib.util +import io +import json +from pathlib import Path +import contextlib +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +SPEC = importlib.util.spec_from_file_location("evidence_path", ROOT / "tools" / "evidence_path.py") +evidence_path_module = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(evidence_path_module) +evidence_path = evidence_path_module.evidence_path +Refused = evidence_path_module.EvidencePathRefused + +PIN = "math.d5-component.punctured-pin-proof" +PIN_MISSING = "public projection not admitted (#327 exporter held by Claude017)" +FIXTURE_NODE = "fixture.lane1.bound-node" +COMMIT = "a" * 40 +GRAPH = { + "data": {"edges": [ + {"from": FIXTURE_NODE, "relation": "requires_evidence", "required": True, "to": PIN}, + ]}, + "identity": {"repository": "example/fixture", "commit": COMMIT, "path": "GRAPH.json"}, +} +BINDINGS = [{"node_id": FIXTURE_NODE, "artifact_id": "FIXTURE-ARTIFACT-v1", "roles": ["source"]}] +RECEIPTS = {"FIXTURE-ARTIFACT-v1": {"url": "https://example.invalid/receipt", "sha": "b" * 64}} +REVIEWS = {"FIXTURE-ARTIFACT-v1": {"url": "https://example.invalid/review"}} + + +class EvidencePathTests(unittest.TestCase): + def test_complete_path_for_synthetic_bound_node(self): + result = evidence_path(FIXTURE_NODE, GRAPH, BINDINGS, RECEIPTS, REVIEWS) + self.assertEqual(result["missing"], []) + self.assertTrue(result["complete"]) + self.assertEqual(result["source"], { + "url": "https://github.com/example/fixture/blob/" + COMMIT + "/GRAPH.json", "sha": COMMIT}) + self.assertEqual(result["artifacts"], [{"artifact_id": "FIXTURE-ARTIFACT-v1", "roles": ["source"]}]) + self.assertEqual(result["receipts"][0]["sha"], "b" * 64) + self.assertEqual(result["reviews"][0]["url"], "https://example.invalid/review") + self.assertEqual(result["scientific_effect"], "NONE") + + def test_punctured_pin_projection_is_explicitly_missing(self): + result = evidence_path(PIN, GRAPH, BINDINGS, RECEIPTS, REVIEWS) + self.assertFalse(result["complete"]) + self.assertEqual(result["artifacts"], []) + self.assertIn(PIN_MISSING, result["missing"]) + self.assertNotIn("artifact index binding not recorded", result["missing"]) + self.assertEqual(result["receipts"], []) + self.assertEqual(result["reviews"], []) + + def test_missing_receipt_and_review_are_named_not_padded(self): + result = evidence_path(FIXTURE_NODE, GRAPH, BINDINGS) + self.assertEqual(result["missing"], [ + "execution receipt not recorded for FIXTURE-ARTIFACT-v1", + "review link not recorded for FIXTURE-ARTIFACT-v1"]) + + def test_unknown_node_is_refused(self): + with self.assertRaises(Refused) as caught: + evidence_path("fixture.lane1.not-in-graph", GRAPH, BINDINGS) + self.assertEqual(caught.exception.code, "unknown-node") + + def test_malformed_node_id_is_refused(self): + for bad in ("", "../x", 7, None): + with self.assertRaises(Refused): + evidence_path(bad, GRAPH, BINDINGS) + + def test_inputs_are_not_mutated(self): + before = copy.deepcopy((GRAPH, BINDINGS, RECEIPTS, REVIEWS)) + evidence_path(FIXTURE_NODE, GRAPH, BINDINGS, RECEIPTS, REVIEWS) + self.assertEqual(before, (GRAPH, BINDINGS, RECEIPTS, REVIEWS)) + + def test_repository_punctured_pin_is_missing_via_cli(self): + # Reads the checked-in graph and bindings only; no network, no writes. + out = io.StringIO() + with contextlib.redirect_stdout(out): + code = evidence_path_module.main([PIN]) + self.assertEqual(code, 0) + result = json.loads(out.getvalue()) + self.assertIn(PIN_MISSING, result["missing"]) + self.assertFalse(result["complete"]) + + def test_cli_refuses_unknown_node(self): + err = io.StringIO() + with contextlib.redirect_stderr(err): + code = evidence_path_module.main(["fixture.lane1.not-in-graph"]) + self.assertEqual(code, 2) + self.assertIn("unknown-node", err.getvalue()) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/evidence_path.py b/tools/evidence_path.py new file mode 100644 index 000000000..51df132fd --- /dev/null +++ b/tools/evidence_path.py @@ -0,0 +1,193 @@ +#!/usr/bin/env python3 +"""Emit the read-only evidence-to-artifact path for one graph node. + +LANES-20261022 Lane 1 (main#475). Given a graph node id, report +node -> pinned source (url + sha) -> artifact (Artifact Index binding) +-> execution receipt -> review link, plus an explicit ``missing`` list. + +The module treats every input as inert JSON. It performs no network access, +writes no files, executes nothing it reads, and asserts no scientific status: +every result carries ``scientific_effect: "NONE"``. A missing link is reported +as missing; it is never padded, inferred or invented. Unknown nodes are refused. +""" +from __future__ import annotations + +import argparse +import json +from pathlib import Path +import re +import sys + + +ROOT = Path(__file__).resolve().parents[1] +DEFAULT_GRAPH = ROOT / "docs" / "site" / "current.json" +DEFAULT_BINDINGS = ROOT / "architecture" / "public-artifact-index-bindings.json" +FILE_LIMIT = 16 * 1024 * 1024 +IDENTIFIER = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.:-]{0,191}") +SHA = re.compile(r"[0-9a-f]{40}|[0-9a-f]{64}") +REPOSITORY = re.compile(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+") + +# Known, documented gaps. These are reported verbatim and never filled in. +KNOWN_MISSING = { + "math.d5-component.punctured-pin-proof": ( + "public projection not admitted (#327 exporter held by Claude017)", + ), +} + + +class EvidencePathRefused(ValueError): + """An opaque refusal whose message names the reason code only.""" + + def __init__(self, code): + super().__init__("EVIDENCE_PATH_REFUSED: " + code) + self.code = code + + +def _require(condition, code): + if not condition: + raise EvidencePathRefused(code) + + +def _identifier(value, code): + _require(type(value) is str and IDENTIFIER.fullmatch(value) is not None, code) + return value + + +def graph_nodes(graph_data): + """Return the node id set named by a graph ``data`` object (nodes and edges).""" + _require(type(graph_data) is dict, "graph-shape") + nodes = set() + for node in graph_data.get("nodes", ()) or (): + if type(node) is dict and "id" in node: + nodes.add(_identifier(node["id"], "graph-node-id")) + elif type(node) is str: + nodes.add(_identifier(node, "graph-node-id")) + for edge in graph_data.get("edges", ()) or (): + _require(type(edge) is dict, "graph-edge-shape") + for key in ("from", "to"): + if key in edge: + nodes.add(_identifier(edge[key], "graph-edge-id")) + return nodes + + +def _pinned_source(identity): + if type(identity) is not dict: + return None + repository, commit = identity.get("repository"), identity.get("commit") + if type(repository) is not str or REPOSITORY.fullmatch(repository) is None: + return None + if type(commit) is not str or SHA.fullmatch(commit) is None: + return None + path = identity.get("path") + url = "https://github.com/" + repository + "/blob/" + commit + if type(path) is str and path and ".." not in path.split("/"): + url += "/" + path + return {"url": url, "sha": commit} + + +def _https_url(value): + return type(value) is str and value.startswith("https://") and len(value) <= 2048 + + +def evidence_path(node_id, graph, bindings, receipts=None, reviews=None): + """Return the evidence path for ``node_id`` or raise ``EvidencePathRefused``. + + ``graph`` is a ``{"data": ..., "identity": ...}`` object (docs/site/current.json + ``graph``); ``bindings`` is the public Artifact Index bindings list; + ``receipts`` and ``reviews`` map artifact ids to ``{"url", "sha"?}`` records. + Inputs are not mutated. + """ + _identifier(node_id, "node-id") + _require(type(graph) is dict, "graph-shape") + nodes = graph_nodes(graph.get("data")) + _require(node_id in nodes, "unknown-node") + _require(type(bindings) is list, "bindings-shape") + receipts = receipts or {} + reviews = reviews or {} + _require(type(receipts) is dict and type(reviews) is dict, "evidence-shape") + + missing = [] + source = _pinned_source(graph.get("identity")) + if source is None: + missing.append("pinned source (url+sha) not recorded") + + artifacts = [] + for binding in bindings: + _require(type(binding) is dict, "binding-shape") + if binding.get("node_id") != node_id: + continue + artifact_id = _identifier(binding.get("artifact_id"), "binding-artifact-id") + roles = binding.get("roles") + _require(type(roles) is list and all(type(r) is str for r in roles), "binding-roles") + artifacts.append({"artifact_id": artifact_id, "roles": sorted(roles)}) + artifacts.sort(key=lambda item: item["artifact_id"]) + + known = KNOWN_MISSING.get(node_id, ()) + missing.extend(known) + if not artifacts and not known: + missing.append("artifact index binding not recorded") + + receipt_links, review_links = [], [] + for artifact in artifacts: + artifact_id = artifact["artifact_id"] + for table, links, label in ((receipts, receipt_links, "execution receipt"), + (reviews, review_links, "review link")): + record = table.get(artifact_id) + if type(record) is dict and _https_url(record.get("url")): + entry = {"artifact_id": artifact_id, "url": record["url"]} + if type(record.get("sha")) is str and SHA.fullmatch(record["sha"]): + entry["sha"] = record["sha"] + links.append(entry) + else: + missing.append(label + " not recorded for " + artifact_id) + if not artifacts: + missing.append("execution receipt not recorded") + missing.append("review link not recorded") + + return { + "schema_version": 0, + "node_id": node_id, + "source": source, + "artifacts": artifacts, + "receipts": receipt_links, + "reviews": review_links, + "missing": missing, + "complete": not missing, + "scientific_effect": "NONE", + } + + +def _read_json(path): + with open(path, "rb") as handle: + raw = handle.read(FILE_LIMIT + 1) + _require(len(raw) <= FILE_LIMIT, "file-limit") + return json.loads(raw.decode("utf-8")) + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("node_id") + parser.add_argument("--graph", default=str(DEFAULT_GRAPH), + help="JSON file whose 'graph' object holds data + identity") + parser.add_argument("--bindings", default=str(DEFAULT_BINDINGS)) + parser.add_argument("--evidence", help="optional JSON {receipts:{}, reviews:{}}") + args = parser.parse_args(argv) + try: + document = _read_json(args.graph) + graph = document.get("graph", document) if type(document) is dict else document + evidence = _read_json(args.evidence) if args.evidence else {} + _require(type(evidence) is dict, "evidence-shape") + result = evidence_path(args.node_id, graph, _read_json(args.bindings), + evidence.get("receipts"), evidence.get("reviews")) + except EvidencePathRefused as error: + print(str(error), file=sys.stderr) + return 2 + except (OSError, ValueError): + print("EVIDENCE_PATH_REFUSED: unreadable-input", file=sys.stderr) + return 2 + sys.stdout.write(json.dumps(result, indent=2, sort_keys=True) + "\n") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From e9bbda2acc323e6517a808ee9bf8aeba90dca2ae Mon Sep 17 00:00:00 2001 From: Grok Bot agent 3 Date: Thu, 22 Oct 2026 12:06:06 -0500 Subject: [PATCH 2/7] Kill surviving evidence_path mutants (Lane 1, #493 review N3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds tests for a generic unbound node (binding line must be reported missing) and for non-SHA identity commits (no pinned source). Tests only; tools/evidence_path.py unchanged. Refs main#475, #493/6346527429. credit 0 · sci NONE · eng≠discharge · no flags · OBL OPEN --- tests/test_evidence_path.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_evidence_path.py b/tests/test_evidence_path.py index efbf7da80..ecb885564 100644 --- a/tests/test_evidence_path.py +++ b/tests/test_evidence_path.py @@ -61,6 +61,27 @@ def test_missing_receipt_and_review_are_named_not_padded(self): "execution receipt not recorded for FIXTURE-ARTIFACT-v1", "review link not recorded for FIXTURE-ARTIFACT-v1"]) + def test_generic_unbound_node_reports_missing_binding(self): + graph = copy.deepcopy(GRAPH) + graph["data"]["edges"].append( + {"from": FIXTURE_NODE, "relation": "requires_evidence", "to": "fixture.lane1.unbound-node"}) + result = evidence_path("fixture.lane1.unbound-node", graph, BINDINGS, RECEIPTS, REVIEWS) + self.assertFalse(result["complete"]) + self.assertEqual(result["artifacts"], []) + self.assertEqual(result["missing"], [ + "artifact index binding not recorded", + "execution receipt not recorded", + "review link not recorded"]) + + def test_non_sha_commit_in_identity_is_not_a_pinned_source(self): + for bad in ("main", "HEAD", "a" * 39, "A" * 40, "g" * 40, "a" * 41, 7, None): + graph = copy.deepcopy(GRAPH) + graph["identity"]["commit"] = bad + result = evidence_path(FIXTURE_NODE, graph, BINDINGS, RECEIPTS, REVIEWS) + self.assertIsNone(result["source"], bad) + self.assertIn("pinned source (url+sha) not recorded", result["missing"]) + self.assertFalse(result["complete"]) + def test_unknown_node_is_refused(self): with self.assertRaises(Refused) as caught: evidence_path("fixture.lane1.not-in-graph", GRAPH, BINDINGS) From 073c7629d72d75b92bd22a48d6624270c3e285fb Mon Sep 17 00:00:00 2001 From: Grok Bot agent 3 Date: Thu, 22 Oct 2026 16:17:41 -0500 Subject: [PATCH 3/7] Add architecture adapter for evidence_path tests (Lane 1 #493 N1) Runs the unchanged EvidencePathTests methods under test_architecture_* identities so the architecture receipt's TEST_ID rule admits them. Adopted in #493 comment 6351492498. No workflow/validator/test edits. --- tests/test_architecture_evidence_path.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/test_architecture_evidence_path.py diff --git a/tests/test_architecture_evidence_path.py b/tests/test_architecture_evidence_path.py new file mode 100644 index 000000000..cdb5c5728 --- /dev/null +++ b/tests/test_architecture_evidence_path.py @@ -0,0 +1,20 @@ +from importlib import util as _util +from pathlib import Path as _Path +_spec = _util.spec_from_file_location( + "_evidence_path_source_tests", _Path(__file__).with_name("test_evidence_path.py")) +_source = _util.module_from_spec(_spec) +_spec.loader.exec_module(_source) + +class EvidencePathArchitectureTests(_source.EvidencePathTests): + """Run the original case methods under an explicit architecture adapter.""" + + +def load_tests(loader, standard_tests, pattern): + original = loader.getTestCaseNames(_source.EvidencePathTests) + adapted = loader.getTestCaseNames(EvidencePathArchitectureTests) + if not original or adapted != original: + raise RuntimeError("evidence-path adapter must preserve a nonempty method set") + suite = loader.loadTestsFromTestCase(EvidencePathArchitectureTests) + if suite.countTestCases() != len(original): + raise RuntimeError("evidence-path adapter case count mismatch") + return suite From 840b8a8a7f568fb6fe714885d420bac70444c098 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 22 Oct 2026 21:38:11 +0000 Subject: [PATCH 4/7] ci: retrigger after checkout timeout (run 39857067338) Co-authored-by: Dylan Roy From 917bcbd49bd378df6d2c572f97d0f577664cebee Mon Sep 17 00:00:00 2001 From: Grok Bot agent 3 Date: Thu, 22 Oct 2026 19:33:48 -0500 Subject: [PATCH 5/7] Report missing/empty/traversal identity path as missing source (#493 Codex P2 4354504411) A pinned source must name a file. When identity.path is missing, empty, non-string, absolute or contains ./.. segments, _pinned_source now returns None, so 'pinned source (url+sha) not recorded' is listed and complete is false. Adds a test covering missing, empty, traversal, inner-traversal, absolute and non-string paths. Scientific effect NONE. --- tests/test_evidence_path.py | 15 +++++++++++++++ tools/evidence_path.py | 10 +++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/test_evidence_path.py b/tests/test_evidence_path.py index ecb885564..c9a825ca8 100644 --- a/tests/test_evidence_path.py +++ b/tests/test_evidence_path.py @@ -82,6 +82,21 @@ def test_non_sha_commit_in_identity_is_not_a_pinned_source(self): self.assertIn("pinned source (url+sha) not recorded", result["missing"]) self.assertFalse(result["complete"]) + def test_missing_empty_or_traversal_path_is_not_a_pinned_source(self): + cases = {"missing": None, "empty": "", "traversal": "../GRAPH.json", + "inner-traversal": "docs/../../GRAPH.json", "absolute": "/GRAPH.json", + "non-string": 7} + for label, bad in cases.items(): + graph = copy.deepcopy(GRAPH) + if bad is None: + del graph["identity"]["path"] + else: + graph["identity"]["path"] = bad + result = evidence_path(FIXTURE_NODE, graph, BINDINGS, RECEIPTS, REVIEWS) + self.assertIsNone(result["source"], label) + self.assertIn("pinned source (url+sha) not recorded", result["missing"], label) + self.assertFalse(result["complete"], label) + def test_unknown_node_is_refused(self): with self.assertRaises(Refused) as caught: evidence_path("fixture.lane1.not-in-graph", GRAPH, BINDINGS) diff --git a/tools/evidence_path.py b/tools/evidence_path.py index 51df132fd..c90c2371d 100644 --- a/tools/evidence_path.py +++ b/tools/evidence_path.py @@ -79,9 +79,13 @@ def _pinned_source(identity): if type(commit) is not str or SHA.fullmatch(commit) is None: return None path = identity.get("path") - url = "https://github.com/" + repository + "/blob/" + commit - if type(path) is str and path and ".." not in path.split("/"): - url += "/" + path + # A pinned source names a file: a missing, empty, absolute or traversing + # path is not a source, so the caller reports it as missing evidence. + if type(path) is not str or not path or "\\" in path: + return None + if any(part in ("", ".", "..") for part in path.split("/")): + return None + url = "https://github.com/" + repository + "/blob/" + commit + "/" + path return {"url": url, "sha": commit} From c52f9fed2af6a4e34325ea4cd98fd0e197a1f0f4 Mon Sep 17 00:00:00 2001 From: "Astra Pro adapter-verification (OpenAI GPT-6)" Date: Thu, 22 Oct 2026 21:34:39 -0500 Subject: [PATCH 6/7] evidence_path: serialize the pinned source path as URL path data Adopts the exact 2913-byte proposal main#493/6355840583 (sha256 ead1104a88e688a9363b9dec2279f5e581b1d9d515a0a2f4e8c935d3a98cadc7) for finding 4355176519 / AMEND_SCOPED 5622870013. Nonauthor review PASS_SCOPED 6355983718. Applied by Grok Bot agent 3 (source owner). --- tests/test_evidence_path.py | 28 ++++++++++++++++++++++++++++ tools/evidence_path.py | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test_evidence_path.py b/tests/test_evidence_path.py index c9a825ca8..df14062fc 100644 --- a/tests/test_evidence_path.py +++ b/tests/test_evidence_path.py @@ -97,6 +97,34 @@ def test_missing_empty_or_traversal_path_is_not_a_pinned_source(self): self.assertIn("pinned source (url+sha) not recorded", result["missing"], label) self.assertFalse(result["complete"], label) + def test_source_path_is_serialized_as_url_path_data(self): + cases = ( + ("GRAPH.json", "GRAPH.json"), + ("docs/GRAPH.json", "docs/GRAPH.json"), + ("%2e%2e/GRAPH.json", "%252e%252e/GRAPH.json"), + ("%2E%2E/GRAPH.json", "%252E%252E/GRAPH.json"), + (".%2e/GRAPH.json", ".%252e/GRAPH.json"), + ("%2e./GRAPH.json", "%252e./GRAPH.json"), + ("docs/%2e%2e/%2e%2e/GRAPH.json", "docs/%252e%252e/%252e%252e/GRAPH.json"), + ("docs/a#b?.json", "docs/a%23b%3F.json"), + ("docs/a b%.json", "docs/a%20b%25.json"), + ("docs/a%2Fb.json", "docs/a%252Fb.json"), + ("docs/caf\u00e9.json", "docs/caf%C3%A9.json"), + ("docs/a\tb\n.json", "docs/a%09b%0A.json"), + ) + for path, encoded in cases: + with self.subTest(path=path): + graph = copy.deepcopy(GRAPH) + graph["identity"]["path"] = path + result = evidence_path(FIXTURE_NODE, graph, BINDINGS, RECEIPTS, REVIEWS) + self.assertEqual(result["source"], { + "url": "https://github.com/example/fixture/blob/" + COMMIT + "/" + encoded, + "sha": COMMIT, + }) + self.assertEqual(result["missing"], []) + self.assertTrue(result["complete"]) + self.assertEqual(graph["identity"]["path"], path) + def test_unknown_node_is_refused(self): with self.assertRaises(Refused) as caught: evidence_path("fixture.lane1.not-in-graph", GRAPH, BINDINGS) diff --git a/tools/evidence_path.py b/tools/evidence_path.py index c90c2371d..0061d010c 100644 --- a/tools/evidence_path.py +++ b/tools/evidence_path.py @@ -17,6 +17,7 @@ from pathlib import Path import re import sys +from urllib.parse import quote ROOT = Path(__file__).resolve().parents[1] @@ -85,7 +86,9 @@ def _pinned_source(identity): return None if any(part in ("", ".", "..") for part in path.split("/")): return None - url = "https://github.com/" + repository + "/blob/" + commit + "/" + path + # Quote filename data before URL parsing can interpret escapes or delimiters. + url = ("https://github.com/" + repository + "/blob/" + commit + "/" + + quote(path, safe="/")) return {"url": url, "sha": commit} From fdf16feb2bbee7527cea6cf1417e6ab6c59cc865 Mon Sep 17 00:00:00 2001 From: "Astra Pro Architecture Task Sweep (OpenAI GPT-6)" Date: Thu, 22 Oct 2026 21:34:47 -0500 Subject: [PATCH 7/7] evidence_path: refuse receipt/review URLs without a usable HTTPS authority Adopts the exact 6173-byte AST493-F1 repair proposal main#493/6355896565 (sha256 2c5ee80a8d43e974aafa6f330593e16b73b3abfb22b9b32412039969da85ba3e), diagnostic 6355430256. Nonauthor review routed to GROK-H03 (fallback agent 16), pending. Applied by Grok Bot agent 3 (source owner). Conflict resolution by Grok Bot agent 3 when stacking on the path-encoding commit: import line merged to 'quote, urlsplit'; both test insertions kept in order (path-encoding test, then the AST493-F1 tests). No other change. --- tests/test_evidence_path.py | 65 +++++++++++++++++++++++++++++++++++++ tools/evidence_path.py | 27 +++++++++++++-- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/tests/test_evidence_path.py b/tests/test_evidence_path.py index df14062fc..9206b5635 100644 --- a/tests/test_evidence_path.py +++ b/tests/test_evidence_path.py @@ -125,6 +125,71 @@ def test_source_path_is_serialized_as_url_path_data(self): self.assertTrue(result["complete"]) self.assertEqual(graph["identity"]["path"], path) + def test_malformed_https_evidence_authorities_are_missing(self): + bad_urls = ( + "https://", "https://?r=1", "https://#review", "https://:443/r", + "https://[::1/r", "https://example.invalid:notaport/r", + "https://example.invalid:65536/r", "https://bad host.invalid/r", + "https://[::1]suffix/r", "https://prefix[::1]/r", + "https://[v1.a]/r", "https://bad|host.invalid/r", + "https://%20/r", "https://example.invalid:\uff14\uff14\uff13/r", + ) + for channel, label in (("receipts", "execution receipt"), ("reviews", "review link")): + for value in bad_urls: + with self.subTest(channel=channel, value=value): + tables = {"receipts": copy.deepcopy(RECEIPTS), "reviews": copy.deepcopy(REVIEWS)} + tables[channel]["FIXTURE-ARTIFACT-v1"]["url"] = value + before = copy.deepcopy(tables) + result = evidence_path(FIXTURE_NODE, GRAPH, BINDINGS, **tables) + self.assertFalse(result["complete"]) + self.assertEqual(result[channel], []) + self.assertEqual(result["missing"], [label + " not recorded for FIXTURE-ARTIFACT-v1"]) + self.assertEqual(result["scientific_effect"], "NONE") + self.assertEqual(tables, before) + + def test_raw_url_whitespace_controls_and_backslashes_are_missing(self): + bad_urls = ( + "https://example.invalid/r\n", "https://exa\tmple.invalid/r", + "https://example.invalid/r\r", "https://example.invalid/\x00r", + "https://example.invalid/\x1fr", "https://example.invalid/\x7fr", + "https://example.invalid/a b", "https://example.invalid/\u00a0r", + "https://example.invalid\\other/r", "https://example.invalid/r\\x", + ) + for channel, label in (("receipts", "execution receipt"), ("reviews", "review link")): + for value in bad_urls: + with self.subTest(channel=channel, value=value): + tables = {"receipts": copy.deepcopy(RECEIPTS), "reviews": copy.deepcopy(REVIEWS)} + tables[channel]["FIXTURE-ARTIFACT-v1"]["url"] = value + result = evidence_path(FIXTURE_NODE, GRAPH, BINDINGS, **tables) + self.assertFalse(result["complete"]) + self.assertEqual(result[channel], []) + self.assertEqual(result["missing"], [label + " not recorded for FIXTURE-ARTIFACT-v1"]) + + def test_https_evidence_values_and_existing_limits_are_preserved(self): + base = "https://example.invalid/" + good_urls = ( + base, base + "receipt?attempt=1#L2", "https://EXAMPLE.invalid:443/r", + "https://[::1]:443/r", "https://[2001:db8::1]/r", + base + "a%20b?q=%23#review", "https://b\u00fccher.example/r", + base + "x" * (2048 - len(base)), + ) + for channel, label in (("receipts", "execution receipt"), ("reviews", "review link")): + for value in good_urls + ("", None, True, 7, "http://example.invalid/r", base + "x" * 2048): + valid = value in good_urls + with self.subTest(channel=channel, value=value): + tables = {"receipts": copy.deepcopy(RECEIPTS), "reviews": copy.deepcopy(REVIEWS)} + tables[channel]["FIXTURE-ARTIFACT-v1"]["url"] = value + before = copy.deepcopy(tables) + result = evidence_path(FIXTURE_NODE, GRAPH, BINDINGS, **tables) + self.assertEqual(result["complete"], valid) + self.assertEqual(result["missing"], [] if valid else [label + " not recorded for FIXTURE-ARTIFACT-v1"]) + if valid: + self.assertEqual(result[channel][0]["url"], value) + else: + self.assertEqual(result[channel], []) + self.assertEqual(tables, before) + self.assertEqual(result["scientific_effect"], "NONE") + def test_unknown_node_is_refused(self): with self.assertRaises(Refused) as caught: evidence_path("fixture.lane1.not-in-graph", GRAPH, BINDINGS) diff --git a/tools/evidence_path.py b/tools/evidence_path.py index 0061d010c..622f42dc2 100644 --- a/tools/evidence_path.py +++ b/tools/evidence_path.py @@ -14,10 +14,11 @@ import argparse import json +from ipaddress import IPv6Address from pathlib import Path import re import sys -from urllib.parse import quote +from urllib.parse import quote, urlsplit ROOT = Path(__file__).resolve().parents[1] @@ -93,7 +94,29 @@ def _pinned_source(identity): def _https_url(value): - return type(value) is str and value.startswith("https://") and len(value) <= 2048 + # A locator needs a usable authority; parsing alone is not validation. + if type(value) is not str or not value.startswith("https://") or len(value) > 2048: + return False + # Refuse raw characters that parsers can strip or reinterpret. Encoded + # path/query data remains inert and the original URL is never rewritten. + if "\\" in value or any(c.isspace() or ord(c) < 32 or ord(c) == 127 for c in value): + return False + try: + parts = urlsplit(value) + host = parts.hostname + parts.port # Access validates the port's numeric syntax and range. + if parts.scheme != "https" or not host: + return False + authority = parts.netloc.rsplit("@", 1)[-1] + if authority.startswith("["): + if re.fullmatch(r"\[[0-9A-Fa-f:.]+\](?::[0-9]*)?", authority) is None: + return False + IPv6Address(host) + elif re.fullmatch(r"[A-Za-z0-9_.-]+", host.encode("idna").decode("ascii")) is None: + return False + return True + except (ValueError, UnicodeError): + return False def evidence_path(node_id, graph, bindings, receipts=None, reviews=None):