test: consolidate scripted MockClient doubles into a shared conftest fixture#76
Open
SuperMarioYL wants to merge 2 commits into
Open
Conversation
…fixture The runner, slot-worker, and eval-budget unit tests each carried their own hand-rolled mock LLM client. The three had quietly diverged: differing exhaustion behavior (IndexError vs. a fallback TextResponse), differing stream semantics (text deltas, FINAL-only, or unsupported), and uneven call-spy and api_format coverage. Replace them with one configurable MockClient in tests/conftest.py that is a behavioral superset, with knobs (on_exhausted, stream_mode, api_format, context_length) defaulting to the most common case. Each test file imports the shared class and passes only the kwargs needed to reproduce its original behavior; no test assertions or bodies changed.
Removing the three local mock classes left their type-only imports (AsyncIterator, LLMResponse, ChunkType, StreamChunk, ToolSpec) unused; drop the ones no longer referenced.
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.
Summary
The runner, slot-worker, and eval-budget unit tests each ship their own
hand-rolled mock
LLMClient. The three started as copies and have sincequietly diverged — they now disagree on observable behavior, so picking
"a"
MockClientno longer gives a predictable contract.test_runner.pytest_slot_worker.pytest_eval_budget.pyresponsesIndexErrorIndexErrorTextResponse("stuck")send_streamTEXT_DELTA+FINALNotImplementedErrorFINALonlyapi_formatattr"ollama"The exhaustion split is the riskiest: a test moved between files (or a new test
copying the "wrong" double) silently changes from a hard error to a soft
fallback, which can mask a real defect.
Change
Replaces the three local classes with one configurable
MockClientintests/conftest.py(previously empty). It is a behavioral superset, withthe variations promoted to explicit constructor knobs:
on_exhausted—"raise"(default) or a fallback response objectstream_mode—"deltas"(default) /"final"/"unsupported"api_format,context_length— defaulted to the common casesend_calls/send_stream_calls) are always populatedEach test file imports the shared class and passes only the kwargs needed to
reproduce its original behavior. No test assertion or test body was changed —
only the mock's source moved. The single-use inline
NoFinalClientintest_runner.pyis intentionally left in place; it is a one-off for onenegative-path test, not a duplicate.
Why not just keep three mocks
A single shared double is only safe if it does not erase the per-test behavior
the three variants encoded — so the behavior is made configurable, not
collapsed. Each call site keeps its exact prior semantics, and the contract is
now visible at the construction site instead of hidden in three drifting class
bodies.
Test plan
pytest tests/unit/test_runner.py tests/unit/test_slot_worker.py tests/unit/test_eval_budget.py— 105 passed, unchanged from before.pytest tests/unit/— full suite green.