Skip to content

Commit 2f12692

Browse files
committed
refactor(benchmarks): inline the web-flag negation per review
Drop _closed_book_for(): the negation has one call site, and a helper introduced purely as a test seam is not worth the indirection. The regression is now pinned where the bug lived. The test calls run_eval() with resolve_closed_book() monkeypatched as a spy that records the override it receives and raises a sentinel to stop before task execution, asserting False/True/None for --web, --no-web and no flag. That covers the faulty handoff itself rather than a helper wrapping it.
1 parent 69ea517 commit 2f12692

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

‎benchmarks/public/runner/run_subprocess.py‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,6 @@ async def run_task_subprocess(
203203

204204
# ── One-run evaluator ────────────────────────────────────────────────
205205

206-
def _closed_book_for(args: argparse.Namespace) -> bool:
207-
"""Book policy for this run, honouring ``--web`` / ``--no-web``.
208-
209-
The two are *open-book* flags: ``--web`` sets ``args.web`` True, ``--no-web``
210-
sets it False, and absence leaves None. ``resolve_closed_book`` takes the
211-
opposite polarity — its ``override`` is the *closed-book* decision, returned
212-
verbatim. Feeding ``args.web`` in unnegated makes both flags do the reverse of
213-
their help text, and exports an inverted ``REACT_NO_WEB``/``SWARM_NO_WEB`` to
214-
every worker, so the run scores under the book policy nobody asked for.
215-
216-
None stays None so an unflagged run still falls through to the benchmark's
217-
own declaration.
218-
"""
219-
from benchmarks.public.sandbox_profiles import resolve_closed_book
220-
221-
web = getattr(args, "web", None)
222-
return resolve_closed_book(args.benchmark, None if web is None else not web)
223-
224-
225206
async def run_eval(
226207
args: argparse.Namespace,
227208
*,
@@ -241,10 +222,20 @@ async def run_eval(
241222
# Both names are set because the toggle is read per workflow — stateful
242223
# reads REACT_NO_WEB, agent-team reads SWARM_NO_WEB — and a benchmark should
243224
# get the same policy whichever workflow runs it.
244-
closed = _closed_book_for(args)
225+
# --web/--no-web are open-book flags; resolve_closed_book's override is the
226+
# closed-book decision, returned verbatim. Negate, or both flags do the
227+
# reverse of their help text. None falls through to the benchmark's own
228+
# declaration.
229+
from benchmarks.public.sandbox_profiles import resolve_closed_book
230+
231+
web = getattr(args, "web", None)
232+
closed = resolve_closed_book(
233+
args.benchmark,
234+
None if web is None else not web,
235+
)
245236
os.environ["REACT_NO_WEB"] = "1" if closed else "0"
246237
os.environ["SWARM_NO_WEB"] = "1" if closed else "0"
247-
source = "--web/--no-web" if getattr(args, "web", None) is not None else "benchmark default"
238+
source = "--web/--no-web" if web is not None else "benchmark default"
248239
logger.info(
249240
"Book policy: %s (%s) — web tools %s",
250241
"closed-book" if closed else "open-book", source,

‎tests/test_benchmark_sandbox_profiles.py‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,39 @@ def test_book_policy_override_wins_both_ways():
9292
assert resolve_closed_book("browsecomp", True) is True # --no-web
9393

9494

95-
def test_runner_does_not_invert_the_web_flags() -> None:
96-
"""``--no-web`` must reach the workers as closed-book, and vice versa.
95+
async def test_runner_does_not_invert_the_web_flags(
96+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
97+
) -> None:
98+
"""``--no-web`` must reach ``resolve_closed_book`` as closed-book, and vice versa.
9799
98100
``resolve_closed_book`` is polarity-correct on its own, so its unit tests
99101
above stay green even when the runner hands it an un-negated *open-book*
100-
flag. That is exactly how the flags shipped inverted, so the regression
101-
has to be pinned at the runner's translation step.
102+
flag. That is exactly how the flags shipped inverted, so the regression has
103+
to be pinned on the handoff inside ``run_eval``.
102104
"""
103105
import argparse
104106

105-
from benchmarks.public.runner.run_subprocess import _closed_book_for
107+
from benchmarks.public import sandbox_profiles
108+
from benchmarks.public.runner import run_subprocess
106109

107-
# Explicit flags win over the benchmark's own declaration, both ways.
108-
assert _closed_book_for(argparse.Namespace(benchmark="browsecomp", web=False)) is True
109-
assert _closed_book_for(argparse.Namespace(benchmark="officeqa", web=True)) is False
110+
class _Stop(Exception):
111+
"""Sentinel: end the run once the override has been observed."""
110112

111-
# No flag: the benchmark default decides and must be left alone.
112-
assert _closed_book_for(argparse.Namespace(benchmark="browsecomp", web=None)) is False
113-
assert _closed_book_for(argparse.Namespace(benchmark="officeqa", web=None)) is True
113+
seen: list[bool | None] = []
114114

115-
# An args namespace without the attribute at all still resolves.
116-
assert _closed_book_for(argparse.Namespace(benchmark="officeqa")) is True
115+
def _spy(benchmark: str, override: bool | None = None) -> bool:
116+
seen.append(override)
117+
raise _Stop
118+
119+
monkeypatch.setattr(sandbox_profiles, "resolve_closed_book", _spy)
120+
121+
for web in (True, False, None):
122+
args = argparse.Namespace(benchmark="browsecomp", pipeline=None, web=web)
123+
with pytest.raises(_Stop):
124+
await run_subprocess.run_eval(args, out_dir=tmp_path, seed=0)
125+
126+
# --web is open-book, --no-web is closed-book, no flag defers to the benchmark.
127+
assert seen == [False, True, None]
117128

118129

119130
class _FakeResourceManager:

0 commit comments

Comments
 (0)