diff --git a/pm-stack/opencode-claimant/test/test_claimant.py b/pm-stack/opencode-claimant/test/test_claimant.py index 20d7e56322..8ed5b1aa2e 100644 --- a/pm-stack/opencode-claimant/test/test_claimant.py +++ b/pm-stack/opencode-claimant/test/test_claimant.py @@ -50,6 +50,23 @@ def __init__(self, returncode=0, stdout="", stderr=""): self.stderr = stderr +def _fake_git_run(argv, **kwargs): + """Fake git at the subprocess boundary for fire-log tests. + + log_fire() records read_code_source()'s provenance read in every + entry; that read spawns git, which the hermetic suite forbids. + Fire-log tests whose subject is another entry field fake the read + here (the TestCodeSourceFireLog shape, #13254) so the entry still + carries a real-shaped code_source and no spawn is attempted. + """ + stdout = ( + "main\n" + if "--abbrev-ref" in argv + else "0123456789abcdef0123456789abcdef01234567\n" + ) + return Result(0, stdout) + + def make_fake_run(events, *, create_rc=0, messages="[]"): """subprocess.run stub dispatching on argv shape, recording an ordered event log: ("create",) / ("bind", argv) / ("prompt", argv) @@ -327,6 +344,7 @@ def test_fire_log_entries_carry_the_mode_source(self): with ( patch.object(claimant, "STATE_DIR", tmp), patch.object(claimant, "FIRES_FILE", fires), + patch.object(claimant.subprocess, "run", _fake_git_run), ): claimant.log_fire("shadow", [], [], None, [{"reason": "no_candidates"}]) entry = json.loads(fires.read_text().splitlines()[-1]) diff --git a/pm-stack/opencode-claimant/test_babysitter.py b/pm-stack/opencode-claimant/test_babysitter.py index 18dbe7698b..55bca988d2 100644 --- a/pm-stack/opencode-claimant/test_babysitter.py +++ b/pm-stack/opencode-claimant/test_babysitter.py @@ -35,6 +35,7 @@ import importlib.util import json +import subprocess import tempfile import unittest from pathlib import Path @@ -53,6 +54,24 @@ def _load(name, filename): babysitter = _load("babysitter", "babysitter.py") claimant = _load("claimant_for_babysitter", "claimant.py") + +def _fake_git_run(argv, **kwargs): + """Fake git at the subprocess boundary for fire-log tests. + + log_fire() records read_code_source()'s provenance read in every + entry; that read spawns git, which the hermetic suite forbids. + Fire-log tests whose subject is another entry field fake the read + here (the TestCodeSourceFireLog shape, #13254) so the entry still + carries a real-shaped code_source and no spawn is attempted. + """ + stdout = ( + "main\n" + if "--abbrev-ref" in argv + else "0123456789abcdef0123456789abcdef01234567\n" + ) + return subprocess.CompletedProcess(argv, 0, stdout=stdout) + + NOW = 1_700_000_000_000 # fixed round clock (ms) MIN = 60 * 1000 @@ -402,6 +421,7 @@ def babysitter_step(mode): ), patch.object(claimant, "STATE_DIR", state_dir), patch.object(claimant, "FIRES_FILE", fires), + patch.object(claimant.subprocess, "run", _fake_git_run), ): rc = claimant.main() self.assertEqual(rc, 0) diff --git a/pm-stack/opencode-claimant/test_claimant.py b/pm-stack/opencode-claimant/test_claimant.py index cb2f54a281..8d68ec7bf7 100644 --- a/pm-stack/opencode-claimant/test_claimant.py +++ b/pm-stack/opencode-claimant/test_claimant.py @@ -59,6 +59,23 @@ _spec.loader.exec_module(claimant) +def _fake_git_run(argv, **kwargs): + """Fake git at the subprocess boundary for fire-log tests. + + log_fire() records read_code_source()'s provenance read in every + entry; that read spawns git, which the hermetic suite forbids. + Fire-log tests whose subject is another entry field fake the read + here (the TestCodeSourceFireLog shape, #13254) so the entry still + carries a real-shaped code_source and no spawn is attempted. + """ + stdout = ( + "main\n" + if "--abbrev-ref" in argv + else "0123456789abcdef0123456789abcdef01234567\n" + ) + return subprocess.CompletedProcess(argv, 0, stdout=stdout) + + class Result: """Minimal subprocess.run stand-in.""" @@ -915,6 +932,7 @@ def test_cap_unknown_logs_cap_room_null_not_sentinel(self): ), patch.object(claimant, "STATE_DIR", state_dir), patch.object(claimant, "FIRES_FILE", fires), + patch.object(claimant.subprocess, "run", _fake_git_run), patch.object(claimant, "fire_opencode_working_hook") as hook, ): self.assertEqual(claimant.main(), 1) @@ -975,6 +993,7 @@ def test_gate_exit_logs_cap_room_null_not_zero(self): ), patch.object(claimant, "STATE_DIR", state_dir), patch.object(claimant, "FIRES_FILE", fires), + patch.object(claimant.subprocess, "run", _fake_git_run), ): self.assertEqual(claimant.main(), 0) entries = [ diff --git a/pm-stack/opencode-claimant/test_nudges.py b/pm-stack/opencode-claimant/test_nudges.py index 0de40b6ec2..3cb36b1a1a 100644 --- a/pm-stack/opencode-claimant/test_nudges.py +++ b/pm-stack/opencode-claimant/test_nudges.py @@ -38,6 +38,7 @@ import importlib.util import json +import subprocess import tempfile import unittest from pathlib import Path @@ -57,6 +58,23 @@ def _load(name, filename): claimant = _load("claimant_for_nudges", "claimant.py") +def _fake_git_run(argv, **kwargs): + """Fake git at the subprocess boundary for fire-log tests. + + log_fire() records read_code_source()'s provenance read in every + entry; that read spawns git, which the hermetic suite forbids. + Fire-log tests whose subject is another entry field fake the read + here (the TestCodeSourceFireLog shape, #13254) so the entry still + carries a real-shaped code_source and no spawn is attempted. + """ + stdout = ( + "main\n" + if "--abbrev-ref" in argv + else "0123456789abcdef0123456789abcdef01234567\n" + ) + return subprocess.CompletedProcess(argv, 0, stdout=stdout) + + def record(round_no=3, verdicts=None): return {"round": round_no, "verdicts": verdicts or {}, "changes": []} @@ -416,6 +434,7 @@ def nudge_step(mode, record, **kw): patch.object(claimant, "_load_nudges_module", return_value=FakeNudges), patch.object(claimant, "STATE_DIR", state_dir), patch.object(claimant, "FIRES_FILE", fires), + patch.object(claimant.subprocess, "run", _fake_git_run), ): rc = claimant.main() self.assertEqual(rc, 0)