personal memory agent
0

Configure Feed

Select the types of activity you want to include in your feed.

solstone / tests / test_release_install_smoke.py
38 kB 1097 lines
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4from __future__ import annotations 5 6import os 7import zipfile 8from collections.abc import Callable 9from dataclasses import replace 10from datetime import UTC, datetime 11from pathlib import Path 12from typing import Any 13 14import pytest 15 16import scripts.check_rust_release_manifest as checker 17import scripts.release_install_smoke as smoke 18from scripts.release_digest import candidate_digest, file_sha256_size 19from scripts.release_public_evidence import validate_public_evidence_tree 20from tests.helpers.release_wheel_fixtures import ROOT_LAUNCHER_BYTES, record_hash 21 22SOURCE_COMMIT = "a" * 40 23CORE_LOCK = "b" * 64 24LEDGER_SHA = "c" * 64 25 26 27def _core_member_payload(prefix: str, *, sha256: str = "d" * 64) -> dict[str, dict]: 28 return { 29 name: { 30 "path": f"{prefix}/{name}", 31 "sha256": sha256, 32 "bytes": 5, 33 } 34 for name in checker.CORE_SCRIPT_NAMES 35 } 36 37 38def _wheel_metadata(name: str) -> tuple[str, str]: 39 parts = name.removesuffix(".whl").split("-") 40 distribution = parts[0] 41 version = parts[1] 42 return ( 43 f"{distribution}-{version}.dist-info/METADATA", 44 f"Name: {distribution.replace('_', '-')}\nVersion: {version}\n", 45 ) 46 47 48def _write_metadata_wheel(path: Path) -> None: 49 metadata_name, metadata = _wheel_metadata(path.name) 50 with zipfile.ZipFile(path, "w") as wheel: 51 members = {metadata_name: metadata.encode("utf-8")} 52 if path.name.startswith("solstone-"): 53 version = path.name.removesuffix(".whl").split("-")[1] 54 members[f"solstone-{version}.dist-info/WHEEL"] = b"Wheel-Version: 1.0\n" 55 for name, content in ROOT_LAUNCHER_BYTES.items(): 56 members[f"solstone-{version}.data/scripts/{name}"] = content 57 record_name = f"solstone-{version}.dist-info/RECORD" 58 record = "\n".join( 59 f"{name},{record_hash(content)},{len(content)}" 60 for name, content in members.items() 61 ) 62 members[record_name] = f"{record}\n{record_name},,".encode("utf-8") 63 for name, content in members.items(): 64 info = zipfile.ZipInfo(name) 65 info.external_attr = ( 66 0o755 << 16 67 if Path(name).name in checker.ROOT_LAUNCHER_NAMES 68 else 0o644 << 16 69 ) 70 wheel.writestr(info, content) 71 72 73def _candidate(tmp_path: Path) -> tuple[Path, list[Path]]: 74 candidate = tmp_path / "candidate" 75 candidate.mkdir() 76 wanted = [] 77 for name in checker.expected_package_names(include_models=False): 78 if name.endswith(".whl") and ( 79 name.startswith("solstone-") 80 or name.startswith("solstone_core-") 81 or name.startswith("solstone_journal-") 82 or name.startswith("solstone_journal_cuda-") 83 ): 84 wanted.append(name) 85 paths = [candidate / name for name in wanted] 86 for path in paths: 87 _write_metadata_wheel(path) 88 return candidate, paths 89 90 91def _ledger_payload(digest: str, candidate: Path) -> dict: 92 return { 93 "source_commit": SOURCE_COMMIT, 94 "core_lock_sha256": CORE_LOCK, 95 "candidate": { 96 "candidate_digest": digest, 97 "files": [ 98 { 99 "name": path.name, 100 "bytes": path.stat().st_size, 101 "sha256": file_sha256_size(path)[0], 102 } 103 for path in sorted(candidate.iterdir(), key=lambda item: item.name) 104 if path.is_file() 105 ], 106 }, 107 "native_summary": { 108 "macos_core_script": { 109 "member": {"path": "solstone-core", "sha256": "d" * 64, "bytes": 5} 110 }, 111 "macos_root_helper": { 112 "member": {"path": "parakeet-helper", "sha256": "e" * 64, "bytes": 6} 113 }, 114 }, 115 "native_members": { 116 "linux-x86_64-musl": _core_member_payload("linux-x86"), 117 "linux-aarch64-musl": _core_member_payload("linux-aarch64"), 118 "macos-arm64": { 119 **_core_member_payload("macos"), 120 "parakeet-helper": { 121 "path": "macos/parakeet-helper", 122 "sha256": "e" * 64, 123 "bytes": 6, 124 }, 125 }, 126 }, 127 } 128 129 130def _observation( 131 *, 132 env_root: Path, 133 candidate_dir: Path, 134 install_paths: tuple[Path, ...], 135 macos: bool = True, 136 member_hash: str = "d" * 64, 137) -> smoke.InstallObservation: 138 (env_root / "bin").mkdir(parents=True, exist_ok=True) 139 for name, content in ROOT_LAUNCHER_BYTES.items(): 140 (env_root / "bin" / name).write_bytes(content) 141 for name in checker.CORE_SCRIPT_NAMES: 142 (env_root / "bin" / name).write_bytes(b"core") 143 (env_root / "bin" / "python").write_bytes(b"python") 144 if macos: 145 (env_root / "bin" / "parakeet-helper").write_bytes(b"helper") 146 members = [ 147 { 148 "name": name, 149 "path": env_root / "bin" / name, 150 "sha256": file_sha256_size(env_root / "bin" / name)[0], 151 "symlink": False, 152 } 153 for name in checker.ROOT_LAUNCHER_NAMES 154 ] 155 members += [ 156 { 157 "name": name, 158 "path": env_root / "bin" / name, 159 "sha256": member_hash, 160 "symlink": False, 161 } 162 for name in checker.CORE_SCRIPT_NAMES 163 ] 164 if macos: 165 members.append( 166 { 167 "name": "parakeet-helper", 168 "path": env_root / "bin" / "parakeet-helper", 169 "sha256": "e" * 64, 170 "symlink": False, 171 } 172 ) 173 return smoke.InstallObservation( 174 env_root=env_root, 175 preexisting_distributions=(), 176 install=smoke.CommandResult( 177 argv=( 178 str(env_root / "bin" / "python"), 179 "-m", 180 "pip", 181 "install", 182 "--no-index", 183 "--no-deps", 184 *(str(path) for path in install_paths), 185 ), 186 exit_code=0, 187 stdout="installed", 188 env=smoke.SCRUBBED_COMMAND_ENV, 189 ), 190 installed_distributions=smoke.expected_distribution_entries(install_paths), 191 installed_members=tuple(members), 192 smoke={ 193 name: smoke.CommandResult( 194 argv=(str(env_root / "bin" / name), "--version"), 195 exit_code=0, 196 stdout=f"{smoke.CORE_SMOKE_STDOUT[name]} 1.0.0", 197 env=smoke.SCRUBBED_COMMAND_ENV, 198 ) 199 for name in smoke.INSTALL_SCRIPT_NAMES 200 }, 201 ) 202 203 204def test_proof_targets_explicitly_match_release_lanes() -> None: 205 assert smoke.PROOF_TARGETS == ( 206 "linux-x86_64-musl", 207 "linux-aarch64-musl", 208 "macos-arm64", 209 ) 210 assert set(smoke.PROOF_TARGETS) | {"source"} == set(checker.LANES) 211 assert smoke.proof_targets_match_lanes() 212 213 214def test_expected_distribution_entries_requires_wheel_metadata(tmp_path: Path) -> None: 215 wheel = tmp_path / "solstone-1.0.0-py3-none-any.whl" 216 wheel.write_bytes(b"not a wheel") 217 218 with pytest.raises(smoke.InstallProofError) as exc: 219 smoke.expected_distribution_entries((wheel,)) 220 221 assert ( 222 exc.value.failures[0].error 223 == "install proof candidate wheel metadata is invalid" 224 ) 225 226 227def test_install_proof_records_inventory_normalized_argv_and_paths( 228 tmp_path: Path, 229) -> None: 230 candidate, paths = _candidate(tmp_path) 231 digest = candidate_digest(candidate) 232 ledger = _ledger_payload(digest, candidate) 233 install_paths = smoke.target_install_paths_from_ledger( 234 ledger, 235 target="macos-arm64", 236 candidate_dir=candidate, 237 ) 238 239 proof = smoke.build_install_proof( 240 target="macos-arm64", 241 version="1.0.0", 242 source_commit=SOURCE_COMMIT, 243 core_lock_sha256=CORE_LOCK, 244 candidate_digest=digest, 245 ledger_sha256=LEDGER_SHA, 246 candidate_dir=candidate, 247 candidate_paths=paths, 248 ledger_payload=ledger, 249 observation=_observation( 250 env_root=tmp_path / "env", 251 candidate_dir=candidate, 252 install_paths=install_paths, 253 ), 254 recorded_at=datetime(2026, 7, 20, 12, 34, 56, tzinfo=UTC), 255 ) 256 257 assert proof["candidate_files"] == smoke.candidate_file_entries(install_paths) 258 argv = proof["install"]["command"]["argv"] 259 assert "--plat-name=macosx_14_0_arm64" not in argv 260 assert "--plat-name" not in argv 261 assert "macosx_14_0_arm64" not in argv 262 assert "ENVROOT/bin/python" in argv 263 assert all(f"CANDIDATE/{path.name}" in argv for path in install_paths) 264 installed = {member["name"]: member for member in proof["installed_members"]} 265 assert installed["solstone-core"]["wheel_member_path"] == "macos/solstone-core" 266 assert installed["solstone-core"]["installed_path"] == "ENVROOT/bin/solstone-core" 267 assert proof["recorded_at"] == "2026-07-20T12:34:56Z" 268 269 270def test_install_proof_normalizes_pip24_stdout_candidate_paths( 271 tmp_path: Path, 272) -> None: 273 candidate, paths = _candidate(tmp_path) 274 digest = candidate_digest(candidate) 275 ledger = _ledger_payload(digest, candidate) 276 install_paths = smoke.target_install_paths_from_ledger( 277 ledger, 278 target="linux-x86_64-musl", 279 candidate_dir=candidate, 280 ) 281 core_wheel = next( 282 path for path in install_paths if path.name.startswith("solstone_core-") 283 ) 284 journal_wheel = next( 285 path for path in install_paths if path.name.startswith("solstone_journal-") 286 ) 287 stdout = "\n".join( 288 ( 289 f"Processing {candidate}/{core_wheel.name}", 290 f"Processing {candidate}/{journal_wheel.name}", 291 "Installing collected packages: solstone-journal, solstone-core", 292 "Successfully installed solstone-core-1.0.0 solstone-journal-1.0.0", 293 ) 294 ) 295 observation = _observation( 296 env_root=tmp_path / "env", 297 candidate_dir=candidate, 298 install_paths=install_paths, 299 macos=False, 300 ) 301 observation = replace( 302 observation, 303 install=replace(observation.install, stdout=stdout), 304 ) 305 306 proof = smoke.build_install_proof( 307 target="linux-x86_64-musl", 308 version="1.0.0", 309 source_commit=SOURCE_COMMIT, 310 core_lock_sha256=CORE_LOCK, 311 candidate_digest=digest, 312 ledger_sha256=LEDGER_SHA, 313 candidate_dir=candidate, 314 candidate_paths=paths, 315 ledger_payload=ledger, 316 observation=observation, 317 recorded_at=datetime(2026, 7, 20, 12, 34, 56, tzinfo=UTC), 318 ) 319 320 assert validate_public_evidence_tree("install_proof", proof) == [] 321 normalized_stdout = proof["install"]["command"]["stdout"] 322 assert f"CANDIDATE/{core_wheel.name}" in normalized_stdout 323 assert f"CANDIDATE/{journal_wheel.name}" in normalized_stdout 324 assert str(candidate) not in normalized_stdout 325 326 327def test_install_proof_rejects_unrelated_absolute_stdout_path( 328 tmp_path: Path, 329) -> None: 330 candidate, paths = _candidate(tmp_path) 331 digest = candidate_digest(candidate) 332 ledger = _ledger_payload(digest, candidate) 333 install_paths = smoke.target_install_paths_from_ledger( 334 ledger, 335 target="linux-x86_64-musl", 336 candidate_dir=candidate, 337 ) 338 observation = _observation( 339 env_root=tmp_path / "env", 340 candidate_dir=candidate, 341 install_paths=install_paths, 342 macos=False, 343 ) 344 observation = replace( 345 observation, 346 install=replace(observation.install, stdout="note /etc/shadow here"), 347 ) 348 349 with pytest.raises(smoke.InstallProofError) as exc: 350 smoke.build_install_proof( 351 target="linux-x86_64-musl", 352 version="1.0.0", 353 source_commit=SOURCE_COMMIT, 354 core_lock_sha256=CORE_LOCK, 355 candidate_digest=digest, 356 ledger_sha256=LEDGER_SHA, 357 candidate_dir=candidate, 358 candidate_paths=paths, 359 ledger_payload=ledger, 360 observation=observation, 361 recorded_at=datetime(2026, 7, 20, 12, 34, 56, tzinfo=UTC), 362 ) 363 364 assert any( 365 failure.error 366 == "install_proof.install.command.stdout contains disallowed content" 367 for failure in exc.value.failures 368 ) 369 370 371def test_install_proof_rejects_prefix_sibling_stdout_paths( 372 tmp_path: Path, 373) -> None: 374 candidate, paths = _candidate(tmp_path) 375 digest = candidate_digest(candidate) 376 ledger = _ledger_payload(digest, candidate) 377 install_paths = smoke.target_install_paths_from_ledger( 378 ledger, 379 target="linux-x86_64-musl", 380 candidate_dir=candidate, 381 ) 382 env_root = tmp_path / "env" 383 stdout = "\n".join( 384 ( 385 f"note {candidate}-evil/data.txt here", 386 f"note {env_root}x/data.txt here", 387 ) 388 ) 389 observation = _observation( 390 env_root=env_root, 391 candidate_dir=candidate, 392 install_paths=install_paths, 393 macos=False, 394 ) 395 observation = replace( 396 observation, 397 install=replace(observation.install, stdout=stdout), 398 ) 399 400 with pytest.raises(smoke.InstallProofError) as exc: 401 smoke.build_install_proof( 402 target="linux-x86_64-musl", 403 version="1.0.0", 404 source_commit=SOURCE_COMMIT, 405 core_lock_sha256=CORE_LOCK, 406 candidate_digest=digest, 407 ledger_sha256=LEDGER_SHA, 408 candidate_dir=candidate, 409 candidate_paths=paths, 410 ledger_payload=ledger, 411 observation=observation, 412 recorded_at=datetime(2026, 7, 20, 12, 34, 56, tzinfo=UTC), 413 ) 414 415 assert any( 416 failure.error 417 == "install_proof.install.command.stdout contains disallowed content" 418 for failure in exc.value.failures 419 ) 420 421 422def test_install_proof_normalizes_stderr_and_preserves_empty_streams( 423 tmp_path: Path, 424) -> None: 425 candidate, paths = _candidate(tmp_path) 426 digest = candidate_digest(candidate) 427 ledger = _ledger_payload(digest, candidate) 428 install_paths = smoke.target_install_paths_from_ledger( 429 ledger, 430 target="linux-x86_64-musl", 431 candidate_dir=candidate, 432 ) 433 wheel = next( 434 path for path in install_paths if path.name.startswith("solstone_core-") 435 ) 436 env_root = tmp_path / "env" 437 stderr = "\n".join( 438 ( 439 f"warning using {candidate}/{wheel.name}", 440 f"created environment {env_root}/bin/python", 441 ) 442 ) 443 observation = _observation( 444 env_root=env_root, 445 candidate_dir=candidate, 446 install_paths=install_paths, 447 macos=False, 448 ) 449 observation = replace( 450 observation, 451 install=replace(observation.install, stderr=stderr), 452 ) 453 454 proof = smoke.build_install_proof( 455 target="linux-x86_64-musl", 456 version="1.0.0", 457 source_commit=SOURCE_COMMIT, 458 core_lock_sha256=CORE_LOCK, 459 candidate_digest=digest, 460 ledger_sha256=LEDGER_SHA, 461 candidate_dir=candidate, 462 candidate_paths=paths, 463 ledger_payload=ledger, 464 observation=observation, 465 recorded_at=datetime(2026, 7, 20, 12, 34, 56, tzinfo=UTC), 466 ) 467 468 normalized_stderr = proof["install"]["command"]["stderr"] 469 assert f"CANDIDATE/{wheel.name}" in normalized_stderr 470 assert "ENVROOT/bin/python" in normalized_stderr 471 assert str(candidate) not in normalized_stderr 472 assert str(env_root) not in normalized_stderr 473 assert proof["smoke"]["solstone-core"]["stderr"] == "" 474 475 476def test_install_proof_normalizes_realpath_aliases_in_command_output( 477 tmp_path: Path, 478) -> None: 479 real_parent = tmp_path / "real-parent" 480 real_parent.mkdir() 481 link_parent = tmp_path / "link-parent" 482 link_parent.symlink_to(real_parent, target_is_directory=True) 483 candidate, paths = _candidate(link_parent) 484 env_root = link_parent / "env" 485 assert str(candidate) != os.path.realpath(candidate) 486 assert str(env_root) != os.path.realpath(env_root) 487 digest = candidate_digest(candidate) 488 ledger = _ledger_payload(digest, candidate) 489 install_paths = smoke.target_install_paths_from_ledger( 490 ledger, 491 target="linux-x86_64-musl", 492 candidate_dir=candidate, 493 ) 494 wheel = next( 495 path for path in install_paths if path.name.startswith("solstone_core-") 496 ) 497 stdout = "\n".join( 498 ( 499 f"Processing {os.path.realpath(candidate)}/{wheel.name}", 500 f"Using interpreter {os.path.realpath(env_root)}/bin/python", 501 ) 502 ) 503 observation = _observation( 504 env_root=env_root, 505 candidate_dir=candidate, 506 install_paths=install_paths, 507 macos=False, 508 ) 509 observation = replace( 510 observation, 511 install=replace(observation.install, stdout=stdout), 512 ) 513 514 proof = smoke.build_install_proof( 515 target="linux-x86_64-musl", 516 version="1.0.0", 517 source_commit=SOURCE_COMMIT, 518 core_lock_sha256=CORE_LOCK, 519 candidate_digest=digest, 520 ledger_sha256=LEDGER_SHA, 521 candidate_dir=candidate, 522 candidate_paths=paths, 523 ledger_payload=ledger, 524 observation=observation, 525 recorded_at=datetime(2026, 7, 20, 12, 34, 56, tzinfo=UTC), 526 ) 527 528 normalized_stdout = proof["install"]["command"]["stdout"] 529 assert f"CANDIDATE/{wheel.name}" in normalized_stdout 530 assert "ENVROOT/bin/python" in normalized_stdout 531 assert os.path.realpath(candidate) not in normalized_stdout 532 assert os.path.realpath(env_root) not in normalized_stdout 533 534 535def test_install_proof_rejects_symlink_duplicate_and_member_hash_mismatch( 536 tmp_path: Path, 537) -> None: 538 candidate, paths = _candidate(tmp_path) 539 digest = candidate_digest(candidate) 540 ledger = _ledger_payload(digest, candidate) 541 install_paths = smoke.target_install_paths_from_ledger( 542 ledger, 543 target="macos-arm64", 544 candidate_dir=candidate, 545 ) 546 selected = install_paths[0] 547 selected.unlink() 548 selected.symlink_to(install_paths[1]) 549 with pytest.raises(smoke.InstallProofError) as exc: 550 smoke.build_install_proof( 551 target="macos-arm64", 552 version="1.0.0", 553 source_commit=SOURCE_COMMIT, 554 core_lock_sha256=CORE_LOCK, 555 candidate_digest=digest, 556 ledger_sha256=LEDGER_SHA, 557 candidate_dir=candidate, 558 candidate_paths=paths, 559 ledger_payload=ledger, 560 observation=_observation( 561 env_root=tmp_path / "env", 562 candidate_dir=candidate, 563 install_paths=install_paths, 564 ), 565 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 566 ) 567 568 errors = {failure.error for failure in exc.value.failures} 569 assert "proof candidate file is a symlink" in errors 570 571 selected.unlink() 572 _write_metadata_wheel(selected) 573 ledger = _ledger_payload(candidate_digest(candidate), candidate) 574 selected_entry = next( 575 entry 576 for entry in ledger["candidate"]["files"] 577 if entry["name"] == selected.name 578 ) 579 ledger["candidate"]["files"].append(dict(selected_entry)) 580 581 with pytest.raises(smoke.InstallProofError) as exc: 582 smoke.build_install_proof( 583 target="macos-arm64", 584 version="1.0.0", 585 source_commit=SOURCE_COMMIT, 586 core_lock_sha256=CORE_LOCK, 587 candidate_digest=candidate_digest(candidate), 588 ledger_sha256=LEDGER_SHA, 589 candidate_dir=candidate, 590 candidate_paths=paths, 591 ledger_payload=ledger, 592 observation=_observation( 593 env_root=tmp_path / "env-duplicate", 594 candidate_dir=candidate, 595 install_paths=smoke.target_install_paths_from_ledger( 596 ledger, 597 target="macos-arm64", 598 candidate_dir=candidate, 599 ), 600 ), 601 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 602 ) 603 604 assert any( 605 failure.error == "proof candidate file basename is duplicated" 606 for failure in exc.value.failures 607 ) 608 609 with pytest.raises(smoke.InstallProofError) as exc: 610 smoke.build_install_proof( 611 target="macos-arm64", 612 version="1.0.0", 613 source_commit=SOURCE_COMMIT, 614 core_lock_sha256=CORE_LOCK, 615 candidate_digest=candidate_digest(candidate), 616 ledger_sha256=LEDGER_SHA, 617 candidate_dir=candidate, 618 candidate_paths=paths, 619 ledger_payload=_ledger_payload(candidate_digest(candidate), candidate), 620 observation=_observation( 621 env_root=tmp_path / "env", 622 candidate_dir=candidate, 623 install_paths=smoke.target_install_paths_from_ledger( 624 _ledger_payload(candidate_digest(candidate), candidate), 625 target="macos-arm64", 626 candidate_dir=candidate, 627 ), 628 member_hash="0" * 64, 629 ), 630 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 631 ) 632 assert any( 633 failure.error == "installed member hash does not match expected payload" 634 for failure in exc.value.failures 635 ) 636 637 638def test_observed_expected_hash_has_no_authority(tmp_path: Path) -> None: 639 candidate, paths = _candidate(tmp_path) 640 observation = _observation( 641 env_root=tmp_path / "env", 642 candidate_dir=candidate, 643 install_paths=smoke.target_install_paths_from_ledger( 644 _ledger_payload(candidate_digest(candidate), candidate), 645 target="macos-arm64", 646 candidate_dir=candidate, 647 ), 648 member_hash="0" * 64, 649 ) 650 members = [dict(member) for member in observation.installed_members] 651 members[0]["expected_sha256"] = "0" * 64 652 observation = smoke.InstallObservation( 653 env_root=observation.env_root, 654 preexisting_distributions=observation.preexisting_distributions, 655 install=observation.install, 656 installed_distributions=observation.installed_distributions, 657 installed_members=tuple(members), 658 smoke=observation.smoke, 659 ) 660 661 with pytest.raises(smoke.InstallProofError) as exc: 662 smoke.build_install_proof( 663 target="macos-arm64", 664 version="1.0.0", 665 source_commit=SOURCE_COMMIT, 666 core_lock_sha256=CORE_LOCK, 667 candidate_digest=candidate_digest(candidate), 668 ledger_sha256=LEDGER_SHA, 669 candidate_dir=candidate, 670 candidate_paths=paths, 671 ledger_payload=_ledger_payload(candidate_digest(candidate), candidate), 672 observation=observation, 673 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 674 ) 675 676 errors = {failure.error for failure in exc.value.failures} 677 assert "install proof observation supplies forbidden expected hash" in errors 678 assert "installed member hash does not match expected payload" in errors 679 680 681def test_observed_wheel_member_path_has_no_authority(tmp_path: Path) -> None: 682 candidate, paths, ledger, install_paths = _linux_context(tmp_path) 683 observation = _observation( 684 env_root=tmp_path / "env-observed-wheel-member", 685 candidate_dir=candidate, 686 install_paths=install_paths, 687 macos=False, 688 ) 689 members = [dict(member) for member in observation.installed_members] 690 members[0]["wheel_member_path"] = "forged/member/path" 691 observation = replace(observation, installed_members=tuple(members)) 692 693 with pytest.raises(smoke.InstallProofError) as exc: 694 smoke.build_install_proof( 695 target="linux-x86_64-musl", 696 version="1.0.0", 697 source_commit=SOURCE_COMMIT, 698 core_lock_sha256=CORE_LOCK, 699 candidate_digest=ledger["candidate"]["candidate_digest"], 700 ledger_sha256=LEDGER_SHA, 701 candidate_dir=candidate, 702 candidate_paths=paths, 703 ledger_payload=ledger, 704 observation=observation, 705 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 706 ) 707 708 assert any( 709 failure.error 710 == "install proof observation supplies forbidden wheel member path" 711 for failure in exc.value.failures 712 ) 713 714 715def test_install_proof_rejects_empty_or_extra_member_sets(tmp_path: Path) -> None: 716 candidate, paths = _candidate(tmp_path) 717 digest = candidate_digest(candidate) 718 ledger_payload = _ledger_payload(digest, candidate) 719 ledger_payload["native_members"]["linux-x86_64-musl"] = {} 720 empty = smoke.InstallObservation( 721 env_root=tmp_path / "env-empty", 722 preexisting_distributions=(), 723 install=smoke.CommandResult(argv=("python",), exit_code=0, stdout="ok"), 724 installed_distributions=(), 725 installed_members=(), 726 smoke={}, 727 ) 728 729 with pytest.raises(smoke.InstallProofError) as exc: 730 smoke.build_install_proof( 731 target="linux-x86_64-musl", 732 version="1.0.0", 733 source_commit=SOURCE_COMMIT, 734 core_lock_sha256=CORE_LOCK, 735 candidate_digest=digest, 736 ledger_sha256=LEDGER_SHA, 737 candidate_dir=candidate, 738 candidate_paths=paths, 739 ledger_payload=ledger_payload, 740 observation=empty, 741 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 742 ) 743 744 assert any( 745 failure.error 746 == "install proof member set does not match expected executable payload" 747 for failure in exc.value.failures 748 ) 749 750 observation = _observation( 751 env_root=tmp_path / "env-extra", 752 candidate_dir=candidate, 753 install_paths=smoke.target_install_paths_from_ledger( 754 _ledger_payload(digest, candidate), 755 target="linux-x86_64-musl", 756 candidate_dir=candidate, 757 ), 758 macos=False, 759 ) 760 extra_members = [ 761 *observation.installed_members, 762 { 763 "name": "extra-helper", 764 "path": tmp_path / "env-extra" / "bin" / "extra-helper", 765 "sha256": "f" * 64, 766 "symlink": False, 767 }, 768 ] 769 (tmp_path / "env-extra" / "bin" / "extra-helper").write_bytes(b"extra") 770 observation = smoke.InstallObservation( 771 env_root=observation.env_root, 772 preexisting_distributions=observation.preexisting_distributions, 773 install=observation.install, 774 installed_distributions=observation.installed_distributions, 775 installed_members=tuple(extra_members), 776 smoke=observation.smoke, 777 ) 778 779 with pytest.raises(smoke.InstallProofError) as exc: 780 smoke.build_install_proof( 781 target="linux-x86_64-musl", 782 version="1.0.0", 783 source_commit=SOURCE_COMMIT, 784 core_lock_sha256=CORE_LOCK, 785 candidate_digest=digest, 786 ledger_sha256=LEDGER_SHA, 787 candidate_dir=candidate, 788 candidate_paths=paths, 789 ledger_payload=_ledger_payload(digest, candidate), 790 observation=observation, 791 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 792 ) 793 794 assert any( 795 failure.error 796 == "install proof member set does not match expected executable payload" 797 for failure in exc.value.failures 798 ) 799 800 801def test_written_install_proof_rejects_public_evidence_hazards(tmp_path: Path) -> None: 802 candidate, paths = _candidate(tmp_path) 803 digest = candidate_digest(candidate) 804 ledger = _ledger_payload(digest, candidate) 805 install_paths = smoke.target_install_paths_from_ledger( 806 ledger, 807 target="linux-x86_64-musl", 808 candidate_dir=candidate, 809 ) 810 proof = smoke.build_install_proof( 811 target="linux-x86_64-musl", 812 version="1.0.0", 813 source_commit=SOURCE_COMMIT, 814 core_lock_sha256=CORE_LOCK, 815 candidate_digest=digest, 816 ledger_sha256=LEDGER_SHA, 817 candidate_dir=candidate, 818 candidate_paths=paths, 819 ledger_payload=ledger, 820 observation=_observation( 821 env_root=tmp_path / "env", 822 candidate_dir=candidate, 823 install_paths=install_paths, 824 macos=False, 825 ), 826 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 827 ) 828 proof["install"]["command"]["argv"].append("--flag=value") 829 830 with pytest.raises(TypeError): 831 smoke.validate_install_proof(proof) 832 833 failures = smoke.validate_install_proof( 834 proof, 835 target="linux-x86_64-musl", 836 version="1.0.0", 837 source_commit=SOURCE_COMMIT, 838 core_lock_sha256=CORE_LOCK, 839 candidate_digest=digest, 840 ledger_sha256=LEDGER_SHA, 841 candidate_dir=candidate, 842 ledger_payload=ledger, 843 ) 844 845 assert failures 846 847 848def test_install_proof_validators_require_binding_arguments(tmp_path: Path) -> None: 849 candidate, paths = _candidate(tmp_path) 850 digest = candidate_digest(candidate) 851 ledger = _ledger_payload(digest, candidate) 852 install_paths = smoke.target_install_paths_from_ledger( 853 ledger, 854 target="linux-x86_64-musl", 855 candidate_dir=candidate, 856 ) 857 proof = smoke.build_install_proof( 858 target="linux-x86_64-musl", 859 version="1.0.0", 860 source_commit=SOURCE_COMMIT, 861 core_lock_sha256=CORE_LOCK, 862 candidate_digest=digest, 863 ledger_sha256=LEDGER_SHA, 864 candidate_dir=candidate, 865 candidate_paths=paths, 866 ledger_payload=ledger, 867 observation=_observation( 868 env_root=tmp_path / "env", 869 candidate_dir=candidate, 870 install_paths=install_paths, 871 macos=False, 872 ), 873 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 874 ) 875 876 with pytest.raises(TypeError): 877 smoke.validate_install_proof(proof) 878 with pytest.raises(TypeError): 879 smoke.validate_install_proof_bytes(smoke.canonical_json_bytes(proof)) 880 881 882def test_install_proof_candidate_file_bad_bytes_returns_failure( 883 tmp_path: Path, 884) -> None: 885 candidate, paths, ledger, install_paths = _linux_context(tmp_path) 886 proof = smoke.build_install_proof( 887 target="linux-x86_64-musl", 888 version="1.0.0", 889 source_commit=SOURCE_COMMIT, 890 core_lock_sha256=CORE_LOCK, 891 candidate_digest=ledger["candidate"]["candidate_digest"], 892 ledger_sha256=LEDGER_SHA, 893 candidate_dir=candidate, 894 candidate_paths=paths, 895 ledger_payload=ledger, 896 observation=_observation( 897 env_root=tmp_path / "env", 898 candidate_dir=candidate, 899 install_paths=install_paths, 900 macos=False, 901 ), 902 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 903 ) 904 proof["candidate_files"][0]["bytes"] = "bad" 905 906 failures = smoke.validate_install_proof( 907 proof, 908 target="linux-x86_64-musl", 909 version="1.0.0", 910 source_commit=SOURCE_COMMIT, 911 core_lock_sha256=CORE_LOCK, 912 candidate_digest=ledger["candidate"]["candidate_digest"], 913 ledger_sha256=LEDGER_SHA, 914 candidate_dir=candidate, 915 ledger_payload=ledger, 916 ) 917 918 assert any( 919 failure.error == "install proof candidate file byte count is invalid" 920 and "restore the retained install proof" in failure.repair 921 for failure in failures 922 ) 923 924 925def _linux_context( 926 tmp_path: Path, 927) -> tuple[Path, list[Path], dict[str, Any], tuple[Path, ...]]: 928 candidate, paths = _candidate(tmp_path) 929 digest = candidate_digest(candidate) 930 ledger = _ledger_payload(digest, candidate) 931 install_paths = smoke.target_install_paths_from_ledger( 932 ledger, 933 target="linux-x86_64-musl", 934 candidate_dir=candidate, 935 ) 936 return candidate, paths, ledger, install_paths 937 938 939@pytest.mark.parametrize( 940 "mutate,error", 941 [ 942 ( 943 lambda observation, _tmp_path: replace( 944 observation, 945 install=smoke.CommandResult( 946 argv=observation.install.argv[:-1], 947 exit_code=0, 948 stdout="installed", 949 env=smoke.SCRUBBED_COMMAND_ENV, 950 ), 951 ), 952 "install proof command argv is not exact", 953 ), 954 ( 955 lambda observation, _tmp_path: replace( 956 observation, 957 install=smoke.CommandResult( 958 argv=(*observation.install.argv, "--index-url"), 959 exit_code=0, 960 stdout="installed", 961 env=smoke.SCRUBBED_COMMAND_ENV, 962 ), 963 ), 964 "install proof command contains forbidden resolver option", 965 ), 966 ( 967 lambda observation, _tmp_path: replace( 968 observation, 969 install=smoke.CommandResult( 970 argv=observation.install.argv, 971 exit_code=0, 972 stdout="installed", 973 env={**smoke.SCRUBBED_COMMAND_ENV, "HTTPS_PROXY": "proxy.invalid"}, 974 ), 975 ), 976 "install proof install command environment is not scrubbed", 977 ), 978 ( 979 lambda observation, _tmp_path: replace( 980 observation, 981 installed_distributions=( 982 *observation.installed_distributions, 983 {"name": "solstone-extra", "version": "1.0.0"}, 984 ), 985 ), 986 "install proof installed distribution set is invalid", 987 ), 988 ( 989 lambda observation, _tmp_path: replace( 990 observation, 991 installed_distributions=( 992 *observation.installed_distributions, 993 observation.installed_distributions[0], 994 ), 995 ), 996 "install proof installed distribution set is invalid", 997 ), 998 ( 999 lambda observation, _tmp_path: replace( 1000 observation, 1001 smoke={ 1002 **observation.smoke, 1003 "solstone-core": replace( 1004 observation.smoke["solstone-core"], 1005 argv=("ENVROOT/bin/solstone-core",), 1006 ), 1007 }, 1008 ), 1009 "install proof smoke command argv is not exact", 1010 ), 1011 ( 1012 lambda observation, _tmp_path: replace( 1013 observation, 1014 smoke={ 1015 **observation.smoke, 1016 "solstone-core": replace( 1017 observation.smoke["solstone-core"], 1018 stdout="solstone-core wrong", 1019 ), 1020 }, 1021 ), 1022 "install proof smoke stdout is not exact", 1023 ), 1024 ( 1025 lambda observation, _tmp_path: replace( 1026 observation, 1027 preexisting_distributions=("solstone",), 1028 ), 1029 "install proof environment already has solstone distributions", 1030 ), 1031 ( 1032 lambda observation, tmp_path: _outside_member_observation( 1033 observation, 1034 tmp_path, 1035 ), 1036 "install proof member path escapes ENVROOT", 1037 ), 1038 ( 1039 lambda observation, _tmp_path: _symlink_member_observation(observation), 1040 "install proof member is a symlink", 1041 ), 1042 ], 1043) 1044def test_install_proof_rejects_semantic_observation_mutations( 1045 tmp_path: Path, 1046 mutate: Callable[[smoke.InstallObservation, Path], smoke.InstallObservation], 1047 error: str, 1048) -> None: 1049 candidate, paths, ledger, install_paths = _linux_context(tmp_path) 1050 observation = _observation( 1051 env_root=tmp_path / "env-semantic", 1052 candidate_dir=candidate, 1053 install_paths=install_paths, 1054 macos=False, 1055 ) 1056 1057 with pytest.raises(smoke.InstallProofError) as exc: 1058 smoke.build_install_proof( 1059 target="linux-x86_64-musl", 1060 version="1.0.0", 1061 source_commit=SOURCE_COMMIT, 1062 core_lock_sha256=CORE_LOCK, 1063 candidate_digest=ledger["candidate"]["candidate_digest"], 1064 ledger_sha256=LEDGER_SHA, 1065 candidate_dir=candidate, 1066 candidate_paths=paths, 1067 ledger_payload=ledger, 1068 observation=mutate(observation, tmp_path), 1069 recorded_at=datetime(2026, 7, 20, 12, tzinfo=UTC), 1070 ) 1071 1072 assert any(failure.error == error for failure in exc.value.failures) 1073 1074 1075def _outside_member_observation( 1076 observation: smoke.InstallObservation, 1077 tmp_path: Path, 1078) -> smoke.InstallObservation: 1079 outside = tmp_path / "outside" / "solstone-core" 1080 outside.parent.mkdir() 1081 outside.write_bytes(b"outside") 1082 members = [dict(member) for member in observation.installed_members] 1083 members[0]["path"] = outside 1084 return replace(observation, installed_members=tuple(members)) 1085 1086 1087def _symlink_member_observation( 1088 observation: smoke.InstallObservation, 1089) -> smoke.InstallObservation: 1090 member_path = Path(observation.installed_members[0]["path"]) 1091 target = member_path.with_name("solstone-core-target") 1092 target.write_bytes(b"target") 1093 member_path.unlink() 1094 member_path.symlink_to(target) 1095 members = [dict(member) for member in observation.installed_members] 1096 members[0]["symlink"] = False 1097 return replace(observation, installed_members=tuple(members))