Put the release's tools on PATH of every claude the loop starts, and name them bare in the prose
CI / tests (pull_request) Successful in 4m36s

This commit is contained in:
2026-12-03 12:49:56 +01:00
parent fb1dd763e2
commit 0653c2744e
64 changed files with 306 additions and 169 deletions
+5 -4
View File
@@ -23,6 +23,7 @@ from project_config.settings import Notifier
from text_files.file_writes import replace_file
from forge.commands import Run, runner
from machine_load.slots import slot_folder
from loop_state.paths import with_release_tools
# Seconds before a Python script loop-claude runs is stopped, so a hung one, such as chunk-preflight, cannot hold the loop.
PYTHON_TIMEOUT = 600
@@ -83,7 +84,7 @@ class Effects:
class StreamingClaude:
def __init__(self, args: list[str], cwd: str, env: dict[str, str]) -> None:
self.proc = subprocess.Popen(["claude", *args], cwd=cwd, env={**os.environ, **env}, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, bufsize=0)
self.proc = subprocess.Popen(["claude", *args], cwd=cwd, env=with_release_tools({**os.environ, **env}), stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, bufsize=0)
def lines(self, idle: float) -> typing.Iterable[str | None]:
# Reads the pipe's file descriptor itself. select cannot see what a buffered reader holds.
@@ -115,12 +116,12 @@ class StreamingClaude:
def system_effects(home: pathlib.Path, env: typing.Mapping[str, str], backends: typing.Mapping[Notifier, Backend[typing.Any]] = BACKENDS, forge_timeout: float = FORGE_TIMEOUT) -> Effects:
"""The effects on this machine: the configs of its DM are under home, and tmux runs in env.
"""The effects on this machine: the configs of its DM are under home, and tmux and the headless claude run in env. Every claude starts with the release's tools first on its `PATH`.
A test hands in `backends` that don't send anything, in place of the notifiers loop-claude's DM goes through. It hands in a short `forge_timeout`, so a command that outlasts it ends quickly.
"""
return Effects(
claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, input=stdin, text=True),
claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, env=with_release_tools(env), input=stdin, text=True),
claude_on_terminal=claude_on_terminal,
discard_typed=lambda: termios.tcflush(sys.stdin, termios.TCIFLUSH),
dm=lambda text, directory: notify(text, directory, home, backends),
@@ -147,7 +148,7 @@ def claude_on_terminal(args: list[str], cwd: str, env: dict[str, str]) -> int:
# A Python handler, unlike SIG_IGN, is reset to the default as claude starts, so Ctrl-C still reaches claude.
previous = signal.signal(signal.SIGINT, lambda number, frame: None)
try:
return subprocess.run(["claude", *args], cwd=cwd, env={**os.environ, **env}).returncode
return subprocess.run(["claude", *args], cwd=cwd, env=with_release_tools({**os.environ, **env})).returncode
finally:
signal.signal(signal.SIGINT, previous)
+24
View File
@@ -15,6 +15,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from loop_effects import child_shells
from failure import Failure
from loop_state.paths import RELEASE_ROOT
from loop_effects.effects import run_python, say, start_timer, StreamingClaude, system_effects
NOW = 1790000000
@@ -100,6 +101,25 @@ class ClaudeOnTerminal(unittest.TestCase):
def test_starts_claude_with_the_releases_tools_first_on_its_path(self):
with tempfile.TemporaryDirectory() as folder:
claude = pathlib.Path(folder, "claude")
claude.write_text('#!/bin/sh\necho "$PATH" > path\n')
claude.chmod(0o755)
system_effects(pathlib.Path.home(), os.environ).claude_on_terminal([], folder, {"PATH": f"{folder}:/usr/bin:/bin"})
self.assertEqual(pathlib.Path(folder, "path").read_text(), f"{RELEASE_ROOT}/bin:{folder}:/usr/bin:/bin\n")
class HeadlessClaude(unittest.TestCase):
def test_runs_claude_in_the_folder_with_its_input_and_the_releases_tools_first_on_its_path(self):
with tempfile.TemporaryDirectory() as folder:
claude = pathlib.Path(folder, "claude")
claude.write_text('#!/bin/sh\necho "$PWD $* $(cat) $PATH"\n')
claude.chmod(0o755)
done = system_effects(pathlib.Path.home(), os.environ | {"PATH": f"{folder}:/usr/bin:/bin"}).claude(["-p"], folder, "asked")
self.assertEqual(done.stdout, f"{os.path.realpath(folder)} -p asked {RELEASE_ROOT}/bin:{folder}:/usr/bin:/bin\n")
class ForgeEffect(unittest.TestCase):
def test_runs_the_forges_cli_in_the_checkout_it_is_given(self):
with tempfile.TemporaryDirectory() as folder:
@@ -325,6 +345,10 @@ class StreamingClaudeLines(unittest.TestCase):
os.close(each)
self.assertEqual(list(streaming.lines(5)), [f"{os.path.realpath(folder)} marked -p hi\n", "eof\n"])
def test_starts_claude_with_the_releases_tools_first_on_its_path(self):
streaming, folder = self.claude('echo "$PATH"')
self.assertEqual(list(streaming.lines(5)), [f"{RELEASE_ROOT}/bin:{folder}:{os.environ['PATH']}\n"])
def test_yields_none_whenever_the_idle_time_passes_without_a_line(self):
streaming, _ = self.claude("sleep 1; echo late")
seen = list(streaming.lines(0.1))