Skip to content

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

Merged
njbrake merged 1 commit into
mainfrom
fix/upstream-drift-unit-tests
Sep 21, 2026
Merged

njbrake merged 1 commit into
mainfrom
fix/upstream-drift-unit-tests

Conversation

@njbrake

@njbrake njbrake commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Description

Replaces #954, which GitHub auto-closed when #951 merged and deleted its base branch. Same content, now targeting main. Review feedback from #954 is applied: the real cache_write_tokens is extracted rather than hard-coded, the gateway: params are deleted rather than xfailed, and the two stale patch() targets in test_google.py are retargeted.

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, 0 failed. mypy on 3.13 reports no errors. All checks were green on the pre-merge run of #954, including run-linter.

PR Type

  • Bug Fix

Relevant issues

Supersedes #954. Upstream: mozilla-ai/tinyagent#23.

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)

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>
@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% <ø> (+4.37%) ⬆️
src/any_agent/tools/wrappers.py 92.63% <100.00%> (+37.31%) ⬆️
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%> (ø)

... and 66 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 merged commit 3d779a8 into main Sep 21, 2026
12 checks passed
@njbrake
njbrake deleted the fix/upstream-drift-unit-tests branch September 21, 2026 15:51
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