Skip to content

test: enable mypy typing checks for the test/hooks root modules - #12711

Merged
julian-risch merged 2 commits into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-hooks-root
Sep 14, 2026
Merged

julian-risch merged 2 commits into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-hooks-root

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Adds test/hooks/test_from_function.py, test_invocation.py and test_utils.py to the types target. Baseline was 56 errors; almost all of them had one cause.

  • 44 list-item / arg-type traced to six inline stub hooks — RecordingHook, ThreadRecordingHook, AsyncRecordingHook, LifecycleSpy, WarmOnlyHook, PlainHook — missing the to_dict / from_dict members the Hook protocol requires. Implemented with default_to_dict / default_from_dict, matching the LifecycleHook stubs in test/components/agents/test_agent_hooks.py. Fixed structurally, no suppressions.
  • Remaining arg-type: hook dictionaries inferred as dict[str, ...] where _run_hooks / _run_hooks_async / _serialize_hooks_dictionary want HookPoint keys. They now carry an explicit dict[HookPoint, list[Hook]] annotation.
  • 1 attr-defined: test_utils.py read .function off a Hook, which only FunctionHook declares. Narrowed with isinstance rather than suppressed, which also makes the assertion say what it means.
  • 5 suppressions remain, all in TestFunctionHookConstruction. Those tests pass a deliberately wrong callable — a coroutine into the sync slot, a zero-parameter function, an unannotated parameter — to assert FunctionHook raises. The type error is the thing under test, so a narrow # type: ignore[arg-type] / [no-untyped-def] is the honest annotation.

Per AGENTS.md, suppressions are limited to the cases where they are actually necessary; the largest group was fixed structurally instead.

How did you test it?

  • Before: mypy on the three files -> 56 errors.
  • After: zero errors, and zero for test/hooks/ within the full types target.
  • pytest test/hooks/ -> 325 passed, 1 skipped.
  • hatch run fmt-check -> clean, 6804 files.

compaction/ and tool_result_offloading/ are still outside the target — they are the larger remaining gaps and are not touched here.

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


This PR was written with AI assistance.

Adds `test/hooks/test_from_function.py`, `test_invocation.py` and
`test_utils.py` to the `types` target. Baseline was 56 errors, and almost all
of them came from one cause.

- 44 `list-item` / `arg-type` errors traced to six inline stub hooks —
  `RecordingHook`, `ThreadRecordingHook`, `AsyncRecordingHook`, `LifecycleSpy`,
  `WarmOnlyHook`, `PlainHook` — missing the `to_dict` / `from_dict` members the
  `Hook` protocol requires. Implemented with `default_to_dict` /
  `default_from_dict`, matching the `LifecycleHook` stubs in
  `test/components/agents/test_agent_hooks.py`.
- The remaining `arg-type` errors were hook dictionaries inferred as
  `dict[str, ...]` where the callee wants `HookPoint` keys; they now carry an
  explicit `dict[HookPoint, list[Hook]]` annotation.
- `test_utils.py` read `.function` off a `Hook`, which only `FunctionHook`
  has. Narrowed with `isinstance` instead of suppressing.
- Five suppressions remain, all in `TestFunctionHookConstruction`, where the
  test passes a deliberately wrong callable to assert `FunctionHook` rejects
  it — the type error is the thing under test.

`mypy` on the three files is clean, `pytest test/hooks/` is 325 passed / 1
skipped, and `fmt-check` is clean across 6804 files.
Copilot AI lite review requested due to automatic review settings September 11, 2026 12:19
@ShousenZHANG
ShousenZHANG requested a review from a team as a code owner September 11, 2026 12:19
@ShousenZHANG
ShousenZHANG requested review from julian-risch and removed request for a team September 11, 2026 12:19
@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.

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/core/pipeline
  pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

…-root

Keep both the test/hooks/budget/ target from #12710 and the three
test/hooks root modules added here.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@julian-risch julian-risch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! Thank you @ShousenZHANG !

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.

3 participants