Skip to content

fix: repair unit and mypy failures caused by upstream drift - #954

Closed
njbrake wants to merge 1 commit into
fix/mcp-v2-import-breakfrom
fix/upstream-drift-unit-tests
Closed

njbrake wants to merge 1 commit into
fix/mcp-v2-import-breakfrom
fix/upstream-drift-unit-tests

Conversation

@njbrake

@njbrake njbrake commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Stacked on #951, which has to merge first. Everything here was invisible until the mcp cap let the suite collect again.

  1. openai 2.x made cache_write_tokens required on InputTokensDetails. Building one with only cached_tokens raised ValidationError, breaking test_model_args[OPENAI] and test_tool_error_llm_mocked[OPENAI]. Chat completions usage has no cache-write counterpart, so report zero. The model allows extra fields, so this stays compatible with older openai versions.

  2. any-llm 1.28 moved gateway providers into a config registry and dropped the generic gateway key. AnyLLM.split_model_provider raises before tinyagent can strip the prefix, so the strip at tinyagent/agent.py (if provider_name == "gateway") is unreachable. That logic lives upstream, so any-agent cannot fix the behavior here. The two gateway: params are xfail with strict=True and raises=UnsupportedProviderError, so when upstream handles the new naming the xfail fails and forces its own removal.

Worth a decision on point 2: is gateway: meant to keep working (fix tinyagent to recognise mzai), or is it retired and the test should go?

A third group, which only becomes visible once #950 lets pre-commit bootstrap and reach mypy:

  1. google.adk.tools resolves names through a lazy importlib loader with a TYPE_CHECKING block, so mypy treats them as imported rather than re-exported. Import from the concrete submodules. Runtime behavior is unchanged.
  2. any-llm 1.28 widened split_model_provider to return str | LLMProvider, so model._provider.value no longer typechecks.

tests/unit: 314 passed, 8 skipped, 2 xfailed, 0 failed. mypy on 3.13 reports no errors.

PR Type

  • Bug Fix

Relevant issues

Depends on #951.

Checklist

  • I understand the code I am submitting.
  • I have added unit tests that prove my fix/feature works
  • I have run this code locally and verified it fixes the issue.
  • New and existing tests pass locally
  • Documentation was updated where necessary
  • I have read and followed the contribution guidelines
  • AI Usage:
    • No AI was used.
    • AI was used for drafting/refactoring.
    • This is fully AI-generated.

On the tests box: no new test file here. Point 1 is covered by the two existing tests it unbreaks, and point 2 changes an existing test's expectation.

AI Usage Information

  • AI Model used: Claude Opus 5

  • AI Developer Tool used: Claude Code

  • Any other info you'd like to share: Written under @njbrake's direction. The reasoning and decisions are his.

  • I am an AI Agent filling out this form (check box if true)

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/any_agent/frameworks/openai.py 61.87% <ø> (+2.50%) ⬆️
src/any_agent/tools/wrappers.py 92.63% <100.00%> (+0.07%) ⬆️
tests/unit/frameworks/test_google.py 97.43% <100.00%> (ø)
tests/unit/frameworks/test_smolagents.py 100.00% <100.00%> (ø)
tests/unit/frameworks/test_tinyagent.py 98.88% <100.00%> (ø)
tests/unit/tools/test_unit_wrappers.py 96.39% <100.00%> (+0.03%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njbrake njbrake changed the title fix: repair the two unit failures caused by upstream drift fix: repair unit and mypy failures caused by upstream drift Sep 21, 2026
@njbrake
njbrake force-pushed the fix/upstream-drift-unit-tests branch from daf94cd to ed4a5f8 Compare September 21, 2026 15:24
@njbrake
njbrake force-pushed the fix/mcp-v2-import-break branch from d4410a2 to b842b7c Compare September 21, 2026 15:39
All of these became visible once the mcp cap let the suite collect again.

- openai 2.x made `cache_write_tokens` required on `InputTokensDetails`.
  `PromptTokensDetails` carries the field in both openai 2.x and any-llm, and
  any-llm's Anthropic provider populates it, so mirror the existing getattr
  chain rather than reporting a constant zero.
- any-llm 1.28 retired the `gateway` provider key in favour of `otari`, so
  `split_model_provider` raises before tinyagent reaches its strip. That strip
  lives in the tinyagent package and `otari:` cannot stand in here because the
  otari SDK is not a dependency, so the two `gateway:` params are dropped and
  the test renamed to what it now covers. Filed as mozilla-ai/tinyagent#23.
- `google.adk.tools` resolves names through a lazy importlib loader with a
  TYPE_CHECKING block, so mypy treats them as imported rather than re-exported.
  Import from the concrete submodules; runtime behavior is unchanged. Two
  `patch()` targets in test_google.py were retargeted to match.
- any-llm 1.28 widened `split_model_provider` to return `str | LLMProvider`,
  so coerce through `LLMProvider` in the smolagents assertion.

mypy on 3.13 reports no issues across 127 source files.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@njbrake
njbrake force-pushed the fix/upstream-drift-unit-tests branch from ed4a5f8 to 1cc946a Compare September 21, 2026 15:46
@njbrake
njbrake deleted the branch fix/mcp-v2-import-break September 21, 2026 15:48
@njbrake njbrake closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant