Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pm-stack/opencode-claimant/test/test_claimant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down
20 changes: 20 additions & 0 deletions pm-stack/opencode-claimant/test_babysitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import importlib.util
import json
import subprocess
import tempfile
import unittest
from pathlib import Path
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions pm-stack/opencode-claimant/test_claimant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = [
Expand Down
19 changes: 19 additions & 0 deletions pm-stack/opencode-claimant/test_nudges.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import importlib.util
import json
import subprocess
import tempfile
import unittest
from pathlib import Path
Expand All @@ -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": []}

Expand Down Expand Up @@ -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)
Expand Down