test: add unit coverage for llm/client.py error mapping#150
Merged
CGFixIT merged 1 commit intoJun 21, 2026
Conversation
llm/client.py (LocalLLMClient + GrokClient) had no dedicated test — it was only ever mocked in test_graph/test_gate, so its real generate() error-translation paths were never exercised. The graph nodes depend on that contract: local_llm_node / grok_fallback_node only catch LLMServiceError / GrokServiceError, so any leaked httpx exception would escape the node handlers and surface as a raw 500. tests/test_client.py covers, with the per-instance httpx.Client monkeypatched (no live LM Studio / xAI endpoint): - config parsing in __init__ - successful generate() (endpoint, model, prompt, Bearer header) - HTTPStatusError -> LLMServiceError / GrokServiceError (+ status detail) - TimeoutException -> typed error (+ timeout_sec detail) - unexpected Exception -> typed error (message preserved) - GrokClient.is_available() and the no-API-key guard Registered tests/test_client.py in the CI pytest list and added --cov=llm.client so the new paths count toward the coverage gate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NXYYNSfqvBrAgghyNmzbHs
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.
What
Adds
tests/test_client.py— the first dedicated test forllm/client.py(LocalLLMClient+GrokClient) — and wires it into CI.Why
llm/client.pywas only ever mocked (intest_graph.py/test_gate.pyviaconftest.MockLocalLLM/MockGrokClient), so its realgenerate()error-translation code was never executed by the suite. That code is a contract the graph relies on:local_llm_nodeandgrok_fallback_nodeonlyexcept LLMServiceError/GrokServiceError. If a wire-levelhttpxexception ever leaked through unmapped, it would bypass those handlers and surface to the client as a raw 500 instead of a graceful[LLM Error: ...]. A regression here is exactly the kind of thing a unit test should catch.Coverage added
With the per-instance
httpx.Clientmonkeypatched (no live LM Studio / xAI contacted; realhttpx.Request/Responseobjects so thee.response.status_codepath runs for real):__init__config parsinggenerate()— asserts endpoint, model, prompt body, and Grok'sAuthorization: BearerheaderHTTPStatusError→LLMServiceError/GrokServiceErrorwithdetails["status"]TimeoutException→ typed error withdetails["timeout_sec"]Exception→ typed error (original message preserved)GrokClient.is_available()and the no-GROK_API_KEYguardCI
tests/test_client.pyin the workflow's pytest file list.--cov=llm.clientso the newly exercised module counts toward the coverage gate.Risk
Low — test-only plus two additive CI lines. New file passes locally (11 passed). No production code touched.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NXYYNSfqvBrAgghyNmzbHs
Generated by Claude Code