Repository navigation
Commit b5ed5a4
test(bash_arena): stop pure-logic tests paying for Docker prebuild (#848)
## Summary
Cuts the CI unit-test job from **4m35s to 59s**. Independent of my other
open PRs — off `main`, mergeable on its own.
`control_arena/settings/bash_arena/tests/conftest.py` pre-builds Docker
images and downloads a HuggingFace dataset from a **`scope="session",
autouse=True`** fixture, so *every* test in that directory pays for it.
But `test_scorer.py` is five pure-arithmetic assertions over
`build_main_task_value` that never start a container — and it carries no
markers, so it runs in the standard unit job. `--durations` attributed
**241s of a 275s run** to the setup of a single one of those assertions:
**88% of the wall clock**, spent building Docker images for tests that
execute in 0.03s.
### Why not just mark them `long_running`
That was the first instinct, but it moves the cost rather than removing
it — the same 241s would still be paid, just in the other job — and it
mislabels five millisecond-long tests as long-running.
The actual fault is `autouse=True` imposing a container build on tests
that never use a container. So the fixture is no longer autouse;
`test_side_tasks.py`, which *does* run real sandboxes and is already
`long_running`, requests it explicitly:
```python
pytestmark = pytest.mark.usefixtures("prebuild_bash_arena_images")
```
The xdist file-lock coordination in the fixture is untouched.
### Also: documents the conventions that let this happen
`CONTRIBUTING.md`'s "Running Tests" section listed two pytest commands
without saying what the markers mean or when to reach for them — which
is how an unmarked test came to cost four minutes of every CI run. It
now covers:
- What `long_running` and `skip_ci` each mean, and that they map to
separate CI jobs. In particular that **`skip_ci` excludes a test from
*both***, so a `skip_ci` test never runs automatically and a mock model
is usually the better option.
- The fixture-cost trap behind this PR: an autouse fixture is charged to
every test in its directory, and `--durations` reports that time under
`setup` rather than `call`, so it looks like a slow test rather than a
slow fixture. Plus `--setup-plan` for checking fixture wiring without
running the slow part.
- `-n 8`, matching CI. Its absence makes the suite several times slower
than it needs to be.
## Test Plan
```bash
uv run pytest -n 8 -m "not skip_ci and not long_running"
```
- **Before:** 275s (4m35s), with `241.11s setup
.../test_scorer.py::test_build_main_task_value_full_pass_default_threshold`
topping the durations.
- **After:** 59s, 881 passed, 288 skipped, and **no bash_arena entry in
the slowest durations at all**.
The scorer tests alone go from ~241s to `5 passed in 0.03s`.
Verified the fixture wiring with `--setup-plan`, which shows the closure
without executing anything:
```bash
# still present for every test that needs a sandbox
$ uv run pytest .../test_side_tasks.py -m long_running --setup-plan -q | grep prebuild
SETUP S prebuild_bash_arena_images (fixtures used: tmp_path_factory, worker_id)
...::test_disable_firewall (fixtures used: ..., prebuild_bash_arena_images, ...)
# and absent from the pure-logic tests
$ uv run pytest .../test_scorer.py --setup-plan -q | grep -c prebuild
0
```
I also ran one of the `long_running` side-task tests end to end against
real Docker (`test_disable_firewall`, 1 passed in 5m30s), so the
prebuild still does its job where it is needed.
Independent corroboration from CI: this PR's Unit Tests job runs in
**2m29s** against 4m24s on a branch differing only by this change.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent e5ffa80 commit b5ed5a4
3 files changed
Lines changed: 59 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
47 | 84 | | |
48 | 85 | | |
49 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
2 | 8 | | |
3 | 9 | | |
4 | 10 | | |
| |||
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
45 | | - | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
51 | | - | |
52 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
| |||
0 commit comments