Repository navigation
test: unit tests for response_api + tracking (99% coverage, 5 xfail'd bugs) - #60
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
…cost logic 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 hermetic unit tests for
agentlab.llm.response_apiandagentlab.llm.tracking. Two new files only, nosrc/changes. Child 3/11 of the unit-test fan-out.tests/llm/test_response_api_unit.py:ToolCall/ToolCalls, theMessageBuilderbase (to_markdownwith tool calls,add_image_url,add_responded_tool_calls), and all three provider builders (prepare_message,handle_tool_call, content transforms, cache markers). AlsoAPIPayloadvalidation,tool_call_to_python_code,AgentlabAction, and the_call_apiparam mapping (tool_choice / force_call_tool / cache flags) plus_parse_responseforOpenAIResponseModel,OpenAIChatCompletionModelandClaudeResponseModel, and every*ModelArgsfactory. Thecall_*_api_with_retrieshelpers are patched, so no HTTP calls are made.tests/llm/test_tracking_unit.py:LLMTracker;set_trackernesting and restore-on-exception, plus a two-threadBarriertest showing thread-local trackers don't leak into each other;cost_tracker_decorator. All fourget_pricing_*functions are covered:requests.getis mocked for OpenRouter, and the langchain/litellm tables are faked. Also covers_remove_version_suffix, the wholeTrackAPIPricingMixin(pricing fallback chain, token extraction,__call__stats), and table tests of effective cost: Anthropic cache read/write and OpenAI chatprompt_tokens_detailsvs responsesinput_tokens_details, using exact numbers and real SDK usage objects. The module-level langchain import fallbacks are covered by running a copy of the module.Coverage (target modules)
agentlab.llm.response_apiagentlab.llm.trackingLines still uncovered:
response_api.py426, 431 (passbodies of abstract methods) andtracking.py378-379 (anelsethat can't be reached becauseapi_typeis always"chatcompletion"or"response").Tests: 169 collected (164 pass + 5 strict xfail). Both files together take about 5s. They pass serially, with
-n 4, and in random order (pytest-randomly, several seeds, together with the existingtests/llm).Source bugs found (tests are
xfail(strict=True);src/not modified)get_effective_cost_from_antrophic_apireadsusage.cache_input_tokens, but Anthropic names this fieldcache_read_input_tokens, so cache-read tokens are never billed.anthropic.types.Usageleavescache_creation_input_tokens/cache_read_input_tokensasNonewhen caching isn't used.None * floatthen raisesTypeErrorwhere the cost should be 0.OpenAIChatCompletionModel._extract_thinking_content_from_response: tool-call-only responses havecontent=None, and it ends up as the literal string"None"inLLMOutput.think.ClaudeResponseModel.filter_system_messageschecksc.get("type") == "image", but builder content looks like{"image": ...}, so an image added to a system message withadd_imageis never rejected.OpenAIChatCompletionModel.__init__doesn't passapi_keytosuper(), somodel.api_keyisNoneeven when a key was given (the client still gets it).Run
Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/3d7d885106884ebe8bca1efe65c5bfa4
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/3d7d885106884ebe8bca1efe65c5bfa4?variant=devin
Requested by: @danigrim
Devin Review