diff --git a/README.md b/README.md index 1e242470..897ab18c 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ CI runs `ci.sh` on every pull request, and `main` doesn't merge anything until i To mutation-test the lines a branch changes, run `~/.claude/bin/run-heavy ~/.claude/bin/mutate-changes --prefix 'uvx --python "$(command -v python3)" --with pytest==9.2.0 --from "mutmut>=3,<4"'` in its checkout. -To bench how hard the code is to fix a bug in, run `docker build --quiet --memory 2g --memory-swap 2g -t claude-config-task-bench task-bench-image && ~/.claude/bin/task-bench --image claude-config-task-bench --test 'python -m pytest -q -p no:cacheprovider -n 4 bin --ignore=bin/adf_codec --ignore=bin/run_tests --ignore=bin/repo_checks/test_types.py --deselect bin/plan/test_touches.py::PredictedTest --deselect bin/loop_effects/test_effects.py::ChildShells'` in its checkout, under `~/.claude/bin/run-heavy`. A scoring run starts this command with `--record-figures`. The bench runs the tests in `task-bench-image/Dockerfile`'s image with no network, so the image holds Python, pytest, pytest-xdist, git and tmux. The test command leaves out what needs docker or `uvx` and the process tests that need an init; run `bin/run-tests` on the host for those. +To bench how hard the code is to fix a bug in, build the image first, with `~/.claude/bin/run-heavy docker build --quiet --memory 2g --memory-swap 2g -t claude-config-task-bench task-bench-image`. Then run `~/.claude/bin/task-bench --image claude-config-task-bench --prefix 'uvx --python "$(command -v python3)" --with pytest==9.2.0 --from "mutmut>=3,<4"' --test 'python -m pytest -q -p no:cacheprovider -n 4 bin --ignore=bin/adf_codec --ignore=bin/run_tests --ignore=bin/repo_checks/test_types.py --deselect bin/plan/test_touches.py::PredictedTest --deselect bin/loop_effects/test_effects.py::ChildShells'` in this checkout, under `~/.claude/bin/run-heavy`. A scoring run starts it with `--record-figures` added. The bench runs the tests with no network, so the image holds everything they need. The `--test` leaves out the tests that need docker or `uvx`, and `ChildShells`, which needs `docker run --init` to reap its processes: `bin/run-tests` on the host runs those. ## Tracking a new file diff --git a/bin/repo_checks/test_task_bench_image.py b/bin/repo_checks/test_task_bench_image.py new file mode 100644 index 00000000..b8e93df4 --- /dev/null +++ b/bin/repo_checks/test_task_bench_image.py @@ -0,0 +1,24 @@ +import pathlib +import re +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from repo_checks import ROOT +from run_tests.main import PYTEST + +DOCKERFILE = (ROOT / "task-bench-image" / "Dockerfile").read_text(encoding="utf-8") + + +class TaskBenchImage(unittest.TestCase): + def test_the_image_has_the_python_tag_that_ci_sh_runs(self): + images = re.findall(r"^FROM (python:\S+)$", DOCKERFILE, re.MULTILINE) + self.assertEqual(len(images), 1, "task-bench-image/Dockerfile starts from one python image") + # ci.sh prints its Dockerfile with printf, so the line ends in a backslash and an n. + self.assertIn(f"FROM {images[0]}\\n", (ROOT / "ci.sh").read_text(encoding="utf-8")) + + def test_the_image_installs_the_pytest_pins_that_run_tests_uses(self): + installed = set(re.findall(r"\b(pytest(?:-xdist)?==[\d.]+)", DOCKERFILE)) + pins = {word for word in PYTEST if re.fullmatch(r"pytest(?:-xdist)?==[\d.]+", word)} + self.assertEqual(installed, pins) diff --git a/bin/run_tests/main.py b/bin/run_tests/main.py index c339649a..c19420ff 100644 --- a/bin/run_tests/main.py +++ b/bin/run_tests/main.py @@ -22,7 +22,7 @@ import typing from machine_load.slots import CPUS_PER_SLOT BIN = pathlib.Path(__file__).resolve().parents[1] -# ci.sh runs this command, so its pins live here; README.md → Test's mutation command repeats the pytest pin, so change both. The workers fill one heavy slot, since run-heavy grants one. +# ci.sh runs this command, so its pins live here; README.md → Test's mutation command and task-bench-image/Dockerfile repeat the pytest pins, so change all three. The workers fill one heavy slot, since run-heavy grants one. PYTEST = ["uvx", "--python", shutil.which("python3") or sys.executable, "--with", "pytest-xdist==3.8.0", "pytest==9.2.0", "-n", str(CPUS_PER_SLOT)] SECTION = re.compile(r"^=+ (.+) =+$") TEST_HEADER = re.compile(r"^_+ .+ _+$") diff --git a/task-bench-image/Dockerfile b/task-bench-image/Dockerfile index 8490e749..6e78bb2d 100644 --- a/task-bench-image/Dockerfile +++ b/task-bench-image/Dockerfile @@ -1,5 +1,4 @@ -# The image `task-bench` runs this repo's tests in, with no network: README.md → Install documents its command. -# The python tag is ci.sh's; the pytest pins are bin/run_tests/main.py's. git and tmux are what the tests run; Debian's apt holds one version of each per release, so the base's tag pins them. +# The python tag is ci.sh's, and the pytest pins are bin/run_tests/main.py's; bin/repo_checks/test_task_bench_image.py holds them equal. git and tmux come from Debian's current apt: the tests need no exact version. FROM python:3.14.8 RUN apt-get update \ && apt-get install --yes --no-install-recommends git tmux \