test: pin the n=1 accept path for the MMLU/GSM8K slice loaders (no network)#13
Merged
Merged
Conversation
Nitjsefnie
force-pushed
the
feat/accept-path-test
branch
from
July 17, 2026 12:45
e847427 to
1484fdb
Compare
Pre-seed a temporary cache_dir so n=1 hits cache and never touches the network or the user's real cache. Verifies the loader returns exactly one well-shaped example. Co-Authored-By: Kimi K2.7 Code <noreply@kimi.com>
Nitjsefnie
force-pushed
the
feat/accept-path-test
branch
from
July 17, 2026 12:46
1484fdb to
17e0eaf
Compare
Owner
|
Independently reproduced your mutation check here — dropping the cache-hit rows makes both new tests fail with Good catch on the cache-hit-not-sliced-to- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #12, taking you up on the suggestion in its merge note:
What this adds
Two tests in
tests/test_metrics.py, placed directly after the existing reject-case tests and following their conventions:test_load_mmlu_slice_accepts_n_equal_1test_load_gsm8k_slice_accepts_n_equal_1Each seeds a pytest
tmp_pathcache dir with the exact JSON cache file the loader looks for (mmlu_1_0.json/gsm8k_1_0.json), calls the real loader withn=1, and asserts it returns exactly one item of the right dataclass with the promised field shapes (MMLU:strquestion,list[str]choices,intanswer; GSM8K:strquestion/answer).No network, verified rather than assumed
Both tests monkeypatch
socket.socketto raise, so a network attempt fails loudly instead of silently passing on a machine that happens to be online. They were additionally run under asitecustomize.pythat blockssocket.socketprocess-wide — 2 passed. Because the cache hits, the gateddatasetsimport is never reached, so the tests also work without thedataextra installed.The tests bite
Mutating the loaders so their cache-hit path yields no rows makes both new tests fail (
assert 0 == 1); restoring makes them pass. So they pin the accept path rather than just decorating it.Gates
ruff check src tests→ 0 ·mypy src→ 0 ·pytest→ 0 (56 passed, 2 skipped). No production code changed; the diff is one test file (+57).One thing I noticed while writing these (not fixed here)
On a cache hit both loaders return every row in the cache file, without checking the row count against
n(src/steerbench/metrics.py:578and:619).nis part of the cache key, so this is invisible in normal use — but a hand-edited or stale cache file would makeload_*_slice(n=1)return however many rows the file holds, silently violating the contract these very tests assert. I kept it out of scope since the merge note asked only for the accept path; happy to send a follow-up that slices ton(or validates and re-fetches) if you want it — just say which behavior you would prefer.Implemented with AI assistance (Kimi K2.7 Code), reviewed, and independently mutation-verified by me before submitting.