Skip to content

test: enable mypy typing checks for test/hooks/budget - #12710

Merged
sjrl merged 3 commits into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-hooks-budget
Sep 14, 2026
Merged

sjrl merged 3 commits into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-hooks-budget

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Adds test/hooks/budget/ to the types target in pyproject.toml and fixes the three errors it surfaces.

test/hooks/ is only partially covered today — the argument list carries test/hooks/human_in_the_loop and nothing else, so budget/, compaction/, tool_result_offloading/ and the three root test_*.py files are unchecked. This takes the smallest of those.

Baseline: 3 errors in test/hooks/budget/test_hooks.py.

  • 1 list-item at L106. KeepIterating, an inline stub passed as an on_exit hook, lacks the to_dict / from_dict members the Hook protocol requires. Implemented with default_to_dict / default_from_dict — the same shape as the LifecycleHook stubs test: type-check agent hook and confirmation tests #12681 added in test/components/agents/test_agent_hooks.py. Fixed structurally, no suppression.
  • 2 method-assign at L91 and L109, both agent.chat_generator.run = MagicMock(...). Replacing a bound method on a mock chat generator is the intended pattern in these tests, so each carries a narrow # type: ignore[method-assign] rather than being restructured.

Per AGENTS.md I kept type: ignore to the cases where it is actually necessary.

How did you test it?

  • Before: mypy test/hooks/budget/ -> 3 errors in 1 file.
  • After: zero errors inside the directory, and zero when run against the full types target.
  • pytest test/hooks/budget/ -> 10 passed.
  • hatch run fmt-check -> clean, 6804 files.

One note on my environment: the full types target reports 14 errors under test/components/generators/, but they reproduce identically on clean main — my local openai package is older than CI's, so those are environment noise rather than anything this PR touches.

No release note: test-only, which AGENTS.md excludes from the release-note requirement.


This PR was written with AI assistance.

Adds `test/hooks/budget/` to the `types` target and fixes the three errors it
surfaces in `test_hooks.py`:

- `KeepIterating`, the inline stub passed as an `on_exit` hook, was missing the
  `to_dict` / `from_dict` members the `Hook` protocol requires. Implemented via
  `default_to_dict` / `default_from_dict`, matching the `LifecycleHook` stubs in
  `test/components/agents/test_agent_hooks.py`.
- the two `agent.chat_generator.run = MagicMock(...)` lines carry a narrow
  `# type: ignore[method-assign]`; replacing a bound method on a mock generator
  is the intended pattern here, not something to restructure.

`mypy test/hooks/budget/` is clean, and `pytest test/hooks/budget/` is 10 passed.
Copilot AI lite review requested due to automatic review settings September 11, 2026 11:41
@ShousenZHANG
ShousenZHANG requested a review from a team as a code owner September 11, 2026 11:41
@ShousenZHANG
ShousenZHANG requested review from sjrl and removed request for a team September 11, 2026 11:41
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

@ShousenZHANG is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sjrl sjrl self-assigned this Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

Ricky-7-Yan

This comment was marked as spam.

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants