diff --git a/bin/task_bench/figures/test_gather.py b/bin/task_bench/figures/test_gather.py index 045435dd..a9d73b3f 100644 --- a/bin/task_bench/figures/test_gather.py +++ b/bin/task_bench/figures/test_gather.py @@ -2,6 +2,7 @@ import contextlib import io import json +import os import pathlib import shutil import subprocess @@ -9,7 +10,8 @@ import sys import tempfile import unittest -sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2])) +BIN = pathlib.Path(__file__).resolve().parents[2] +sys.path.insert(0, str(BIN)) from failure import Failure from task_bench.figures.gather import gather, PROMPT @@ -140,5 +142,17 @@ class GatherTest(unittest.TestCase): self.assertEqual(errors.getvalue(), f"{self.bench} holds no digest: run task-bench in this checkout first.\n") +class RunClaude(unittest.TestCase): + def test_runs_claude_in_the_folder_with_the_prompt_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) + # A process of its own, so the test changes no PATH but that process's. + call = f"import sys; sys.path.insert(0, {str(BIN)!r}); from task_bench.figures.gather import run_claude; print(run_claude(['-p'], {folder!r}, 'asked').stdout, end='')" + done = subprocess.run([sys.executable, "-c", call], capture_output=True, env={"PATH": f"{folder}:/usr/bin:/bin"}, text=True) + self.assertEqual(done.stdout, f"{os.path.realpath(folder)} -p asked {BIN}:{folder}:/usr/bin:/bin\n", done.stderr) + + if __name__ == "__main__": unittest.main()