From 3e7f491d2842ef9d5138d3859f8d19ed0842607f Mon Sep 17 00:00:00 2001 From: Brett Heap Date: Fri, 13 Nov 2026 18:13:34 +0000 Subject: [PATCH 1/2] test: execute canonical assembly download fallbacks --- tests/test_download_transport.py | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/test_download_transport.py b/tests/test_download_transport.py index 05c841b2..9598d41d 100644 --- a/tests/test_download_transport.py +++ b/tests/test_download_transport.py @@ -130,3 +130,63 @@ def request(url): initial = request(f"http://localhost:{plain_port}/unsafe") assert initial.returncode != 0, "download accepted an initial HTTP URL" assert len(plain_requests) == before, "initial HTTP reached the server" + + +def test_standalone_assembly_launcher_refuses_failed_payload_fetch(tmp_path): + """Run the complete, byte-identical launcher through all curl fallbacks. + + The transport tests above enforce protocol behavior. This public CLI case + also gives the collector real canonical-source execution, and proves that + a failed implementation fetch cannot run a partial payload. + """ + assembly = ROOTS.root_of("assembly") + if assembly is None: + ROOTS.need("assembly", "openRepoTools canonical download fallbacks") + source = assembly / "openRepoTools" + standalone = tmp_path / "standalone" + standalone.mkdir() + launcher = standalone / "openRepoTools" + launcher.write_bytes(source.read_bytes()) + launcher.chmod(0o755) + pin = assembly / "contracts" / "code-pin.yaml" + commit = re.search(r"^commit: *['\"]?([0-9a-f]{40})", pin.read_text(), + re.MULTILINE).group(1) + fake = tmp_path / "bin" + fake.mkdir() + (fake / "gh").write_text("#!/bin/sh\nexit 1\n") + (fake / "gh").chmod(0o755) + (fake / "curl").write_text("""#!/usr/bin/env python3 +import json, os, sys +from pathlib import Path +url = next(arg for arg in sys.argv[1:] if arg.startswith("https://")) +with open(os.environ["DOWNLOAD_REQUESTS"], "a") as out: + out.write(url + "\\n") +if "/commits/" in url: + print("a" * 40) +elif url.endswith("/contracts/code-pin.yaml"): + sys.stdout.buffer.write(Path(os.environ["DOWNLOAD_PIN"]).read_bytes()) +elif "/git/trees/" in url: + print(json.dumps({"tree": [{"type": "commit", "path": "code", + "sha": os.environ["DOWNLOAD_COMMIT"]}]})) +else: + print("fixture refuses implementation download", file=sys.stderr) + sys.exit(22) +""") + (fake / "curl").chmod(0o755) + requests = tmp_path / "requests" + env = {**os.environ, "PATH": f"{fake}:{os.environ['PATH']}", + "TMPDIR": str(tmp_path), "OPENREPOTOOLS_REPO": "example/assembly", + "OPENREPOTOOLS_REF": "main", "DOWNLOAD_REQUESTS": str(requests), + "DOWNLOAD_PIN": str(pin), "DOWNLOAD_COMMIT": commit} + result = subprocess.run(["bash", str(launcher), "--install"], env=env, + cwd=standalone, capture_output=True, text=True, timeout=20) + assert result.returncode == 2, result.stderr + assert "could not fetch openRepoTools" in result.stderr, result.stderr + assert "fixture refuses implementation download" in result.stderr + urls = requests.read_text().splitlines() + assert len(urls) == 4, urls + assert urls[0].endswith("/commits/main") + assert urls[1].endswith("/contracts/code-pin.yaml") + assert "/git/trees/" in urls[2] + assert urls[3].endswith("/openRepoTools") + assert launcher.read_bytes() == source.read_bytes() From e2ebf0f5c466d477ab25b55b04b6a43e39a1945a Mon Sep 17 00:00:00 2001 From: Brett Heap Date: Fri, 13 Nov 2026 18:18:50 +0000 Subject: [PATCH 2/2] test: prove failed downloads never execute partial payloads --- tests/test_download_transport.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_download_transport.py b/tests/test_download_transport.py index 9598d41d..c367ca33 100644 --- a/tests/test_download_transport.py +++ b/tests/test_download_transport.py @@ -169,20 +169,25 @@ def test_standalone_assembly_launcher_refuses_failed_payload_fetch(tmp_path): print(json.dumps({"tree": [{"type": "commit", "path": "code", "sha": os.environ["DOWNLOAD_COMMIT"]}]})) else: + print("#!/usr/bin/env bash") + print('printf ran > "$DOWNLOAD_EXECUTED"') print("fixture refuses implementation download", file=sys.stderr) sys.exit(22) """) (fake / "curl").chmod(0o755) requests = tmp_path / "requests" + executed = tmp_path / "payload-ran" env = {**os.environ, "PATH": f"{fake}:{os.environ['PATH']}", "TMPDIR": str(tmp_path), "OPENREPOTOOLS_REPO": "example/assembly", "OPENREPOTOOLS_REF": "main", "DOWNLOAD_REQUESTS": str(requests), - "DOWNLOAD_PIN": str(pin), "DOWNLOAD_COMMIT": commit} + "DOWNLOAD_PIN": str(pin), "DOWNLOAD_COMMIT": commit, + "DOWNLOAD_EXECUTED": str(executed)} result = subprocess.run(["bash", str(launcher), "--install"], env=env, cwd=standalone, capture_output=True, text=True, timeout=20) assert result.returncode == 2, result.stderr assert "could not fetch openRepoTools" in result.stderr, result.stderr assert "fixture refuses implementation download" in result.stderr + assert not executed.exists(), "a partial payload ran after curl failed" urls = requests.read_text().splitlines() assert len(urls) == 4, urls assert urls[0].endswith("/commits/main")