Skip to content

test: enable mypy typing checks for test/hooks/compaction - #12749

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

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

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Adds test/hooks/compaction/ to the types target. Baseline was 29 errors; over half had one cause.

  • 15 abstract — every instantiation of _RecordingCompactor in test_hooks.py failed because the stub never implemented to_dict, which the Compactor protocol declares. Implemented with default_to_dict, matching KeepIterating in test/hooks/budget/test_hooks.py from test: enable mypy typing checks for test/hooks/budget #12710. Fixed structurally, no suppression.
  • 6 arg-type — the two settings dicts splatted into CompactionHook were inferred as dict[str, object], but its keyword arguments are int, float and TokenCounter | None. They now carry an explicit dict[str, Any] annotation.
  • 2 no-untyped-def — _hook and _agent are annotated. _agent takes dict[HookPoint, list[Hook]] | None, matching Agent.__init__, because one test calls _agent(None).
  • 4 union-attr / arg-type on optional access — compacted is narrowed with assert compacted is not None before len(), and tool_call_result is bound to a local before .origin / .result is read off it. assert x is not None on a subscript expression does not narrow, which is why the loop in test_tool_result_pruning.py needed the local.
  • 2 attr-defined — SlidingWindowCompactor.from_dict is typed as returning the protocol, so min_keep_steps and omission_note are not visible on it. Narrowed with isinstance rather than suppressed, which also makes the assertion check that from_dict returns the concrete compactor.

Zero suppressions added. The optional-access and protocol-return cases are the ones where a # type: ignore would have been quickest and would also have stopped the assertions from proving anything.

How did you test it?

  • Before: mypy on test/hooks/compaction/ -> 29 errors.
  • After: zero errors, and hatch run test:types is clean for everything this PR touches.
  • pytest test/hooks/ -> 325 passed, 1 skipped. pytest test/hooks/compaction/ -> 136 passed.
  • Full unit suite -> 6390 passed. The two failures on my machine (test_byte_stream.py mime guessing, test_openai_responses_conversion.py) reproduce identically on a clean main checkout — Windows mime registry and a newer local openai than the tests expect, neither related to this change.
  • hatch run fmt-check -> clean, 6804 files. check_imports.py -> 262 modules imported.

tool_result_offloading/ is left alone — #12720 is already on it. After that lands, test/hooks/ is fully covered.

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


This PR was written with AI assistance.

Copilot AI lite review requested due to automatic review settings September 14, 2026 10:19
@ShousenZHANG
ShousenZHANG requested a review from a team as a code owner September 14, 2026 10:19
@ShousenZHANG
ShousenZHANG requested review from julian-risch and removed request for a team September 14, 2026 10:19
@vercel

vercel Bot commented Sep 14, 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 14, 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

Adds `test/hooks/compaction/` to the `types` script and fixes the 29 errors it
surfaces.

The bulk of them, 15 of 29, are one root cause: `_RecordingCompactor` did not
implement `to_dict`, which `Compactor` declares, so every instantiation of the
stub was an abstract-class error. It now serializes through `default_to_dict`,
the same way `KeepIterating` does in `test/hooks/budget`.

The rest:

- annotate `_hook` and `_agent`, and type the two `settings` dicts that are
  splatted into `CompactionHook`, whose keyword arguments are not all `object`;
- narrow `compacted` before `len()`, and bind `tool_call_result` to a local
  before reading `.origin` / `.result` off it, rather than suppressing the
  optional-access errors;
- assert `isinstance(restored, SlidingWindowCompactor)` after `from_dict`, which
  is typed as returning the protocol and so does not expose `min_keep_steps` or
  `omission_note`.

Part of #10396.
@ShousenZHANG
ShousenZHANG force-pushed the test/type-check-hooks-compaction branch from 185f93e to 40a5878 Compare September 14, 2026 13:46

@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.

LGTM! Thank you for another PR @ShousenZHANG !

Resolve pyproject.toml conflict: keep both test/hooks/compaction/ and test/components/converters/image/ in the mypy types target.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@julian-risch
julian-risch enabled auto-merge (squash) September 14, 2026 14:07
@julian-risch
julian-risch merged commit f1e61b5 into deepset-ai:main Sep 14, 2026
21 of 22 checks passed
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