Repository navigation
test: hermetic unit tests for chat_api and litellm_api (mocked clients) - #52
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…ients Co-Authored-By: Daniella Grimberg <daniella@cognition.ai>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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
Adds two test-only files covering the chat-model wrappers' request building, retry/error handling, and cost tracking, with every SDK client mocked. No
src/changes.tests/llm/test_chat_api_unit.py(57 tests): message helpers,CheatMiniWoBLLM, all*ModelArgs.make_model(including theSelfHostedModelArgsbackends),_extract_wait_time/handle_error,ChatModelinit/pricing/__call__(retries,OpenRouterErroron missing usage,RetryError, n_samples, tracker), the OpenAI/OpenRouter/Azure/VLLM/HF subclasses, andAnthropicChatModel's own retry loop.tests/llm/test_litellm_api_unit.py(43 tests):LiteLLMModel._call_apiparam mapping (tools format conversion,tool_choiceany→required,force_call_tool,reasoning_effort, both cache flags),_parse_response/ thinking / tool-call extraction, full__call__viaTrackAPIPricingMixin,LiteLLMAPIMessageBuildertool replay,LiteLLMModelArgs, and the module's__main__smoke script (run viarunpywithStudy/ToolUseAgentArgsswapped for fakes).How it stays hermetic:
chat_api.OpenAI,anthropic.Anthropic,InferenceClientandAutoTokenizerare patched;tracking.get_pricing_*,litellm.get_model_infoandtracking.completion_costare stubbed;time.sleepis mocked; API-key env vars are cleared; and an autouse fixture saves and restores the thread-localtracking.TRACKER.instance. Fake responses use realopenai.types.chat.ChatCompletion/litellm.ModelResponseobjects that includeusage.Coverage (target modules)
agentlab.llm.chat_apiagentlab.llm.litellm_api100 tests: 95 pass, 5 are strict xfail. Each file runs in under 6s. Passes serially, with
-n 4, and in random order (pytest-randomly).Source bugs found (strict
xfail,src/left unchanged)SelfHostedModelArgs.make_model()(huggingface backend) never passes the requiredbase_model_nametoHuggingFaceURLChatModel, so it raisesTypeError.log_probs=True,ChatModel.__call__readschoices[0].log_probs, but the OpenAI SDK field islogprobs, so it raisesAttributeError.AnthropicChatModel.__call__callstracking.TRACKER.instance(...)even when it isNone, which is the state after anyset_tracker()block exits. Every attempt then fails and gets retried withsleep(60).ChatModelguards this with anisinstancecheck.LiteLLMModel._extract_thinking_content_from_responsereturns the literal string"None"asthinkfor tool-call responses whosecontentisNone.LiteLLMModel(use_only_first_toolcall=True):_call_apicallsmsg.prepare_message()without the flag. The replayed assistant message therefore keeps every tool call but gets only one tool response (mismatchedtool_call_ids).Run
Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/12ad20f36bdd4cb394cfef967d670aba
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/12ad20f36bdd4cb394cfef967d670aba?variant=devin
Requested by: @danigrim
Devin Review