"""Software-only process evidence tests for the Python RX runner.""" from __future__ import annotations import hashlib import json from pathlib import Path import sys from tools.rf001_capture_runner import run_capture def test_python_runner_persists_child_exit_and_hash(tmp_path: Path) -> None: child = tmp_path / "child.py" capture = tmp_path / "capture.cs8" capture_bytes = b"software-only-capture-evidence\x00\x01" child.write_text( "from pathlib import Path\n" f"Path({str(capture)!r}).write_bytes({capture_bytes!r})\n", encoding="utf-8", ) arguments = tmp_path / "arguments.json" arguments.write_text(json.dumps(["-B", str(child)]), encoding="utf-8") stdout = tmp_path / "stdout.txt" stderr = tmp_path / "stderr.txt" started = tmp_path / "started.json" result = tmp_path / "result.json" exit_code = run_capture( Path(sys.executable), arguments, capture, stdout, stderr, started, result, ) start_record = json.loads(started.read_text(encoding="utf-8")) final_record = json.loads(result.read_text(encoding="utf-8")) assert exit_code == 0 assert start_record["state"] == "RUNNING" assert start_record["rf_tx"] == 0 assert final_record["exit_code"] == 0 assert final_record["capture_size"] == len(capture_bytes) assert final_record["sha256"] == hashlib.sha256(capture_bytes).hexdigest() assert final_record["runner_error"] is None assert final_record["rf_tx"] == 0