Repository navigation
Labels
P2Medium priority, add to the next sprint if no P1 available
Description
While working on changes to haystack-experimental (deepset-ai/haystack-experimental#430) I wanted to ensure that the protocol I was developing was working as expected with the respective implementations.
I realized though that we never actually test whether our implementations satisfy our protocols since we don't do any type checks on actual test-like code.
Therefore, I think it would be a good idea if we add type checking to our test code in our repos so we can better catch these issues. This will be quite a bit work to get our tests fully compliant but perhaps we could do it in a piece-meal approach where we only turn on type checking in a small part of tests and grow from there.
Components
-
test/components/audio/ -
test/components/builders/ -
test/components/caching/ -
test/components/classifiers/ -
test/components/connectors/ -
test/components/converters/ -
test/components/embedders/ -
test/components/evaluators/ -
test/components/extractors/ -
test/components/fetchers/ -
test/components/generators/ -
test/components/joiners/ -
test/components/preprocessors/ -
test/components/query/ -
test/components/rankers/ -
test/components/readers/ -
test/components/retrievers/ -
test/components/routers/ -
test/components/samplers/ -
test/components/tools/ -
test/components/validators/ -
test/components/websearch/ -
test/components/writers/
Document Stores
-
test/document_stores/
Agents
-
test/components/agents/
Other
-
test/core/ -
test/dataclasses/ -
test/evaluation/ -
test/fuzz/ -
test/hooks/ -
test/human_in_the_loop/ -
test/marshal/ -
test/skill_stores/ -
test/testing/ -
test/token_counters/ -
test/tools/(top-level, distinct fromtest/components/tools/) -
test/tracing/ -
test/utils/
Activity
chore: add type checking to test/tracing/, test/marshal/, and test/te…
chore: Add type checking to test/tracing/, test/marshal/, and test/te…
Jventajas commentedon Jul 1, 2026
Hi, is this still relevant? Should I take it?
omborda2002 commentedon Jul 3, 2026
I took the next piece of this, test/components/embedders/. Most of the errors there were tests passing a wrong type on purpose to check the raised TypeError, plus a few missing annotations. Opening a PR now.
yaodong-shen commentedon Aug 2, 2026
I can take the next small increment for this issue: add
test/components/caching/to the existing mypy target, fix only the type errors needed in its two CacheChecker test modules, and run the focused mypy/pytest checks before opening a PR. I checked that the existing recent contribution coveredtest/components/embedders/; I will keep this scope disjoint.Aryan-Pardeshi commentedon Aug 7, 2026
Working on adding typing checks for \ est/components/writers/!
14 remaining items
ShousenZHANG commentedon Aug 25, 2026
I can take the next disjoint increment:
test/components/builders/.It is not in the current
typestarget onmain, and no open or closed PR or comment covers it. The increments in flight areextractors/(#12343),samplers/(#12433) andfetchers/(#12435), so this doesn't overlap any of them.Baseline is 25 errors across 2 of the 3 test modules:
attr-definedon__haystack_input__/__haystack_output__, which the@componentdecorator attaches at runtime.index/union-attrfrom readingbuilder.template[0].text, wheretemplateis typedlist[ChatMessage] | str | None. Those get narrowed with an assert rather than silenced.list-itemon a deliberate mixed-type template inside a validation test, so that one gets a narrow# type: ignore[list-item].no-untyped-deffor missing return annotations.Scoped to the minimal typing fixes plus the
typestarget entry, with no change to what any test asserts.Note for whoever picks the next one: every increment edits the same single
types = "..."line inpyproject.toml, so whichever lands first leaves the others conflicting. #12433 and #12435 are both showing conflicts right now and just need a rebase of that one line.test: enable mypy typing checks for test/components/samplers/
ShousenZHANG commentedon Aug 27, 2026
I can take the next disjoint increment:
test/components/retrievers/.It is not in the current
typestarget onmain, and no open or closed PR or comment covers it. It also doesn't overlapfetchers/(#12435), the only increment still in flight.Baseline is 78 errors across 11 of the 16 test modules, concentrated in three files:
test_auto_merging_retriever.py/_async.py(20 each) — mostlycall-overloadfrom adocsvariable that is first thedictreturned byHierarchicalDocumentSplitter.runand then reassigned to a retriever result, so mypy can't keep one type for it. Fixed by giving the two values separate names.test_multi_retriever.py(18) —no-untyped-defandassignment.type-varonsortedoverfloat | None,method-assignon monkeypatchedto_dict, and ano-redefon a re-annotated local.Scoped to the minimal typing fixes plus the
typestarget entry, with no change to what any test asserts.ShousenZHANG commentedon Aug 27, 2026
I can take
test/components/extractors/next. It doesn't overlapfetchers/(#12435), the only other increment in flight.One thing worth flagging: this directory is already clean.
mypy test/components/extractors/reportsSuccess: no issues found in 5 source filesagainst currentmain, but the path was never added to thetypestarget, so CI isn't actually checking it — any typing regression introduced there today would go unnoticed.So this increment is a one-line change to
pyproject.toml, with no source edits needed. Happy to fold it into someone else's PR instead if that's tidier; it seemed worth closing the gap either way.ShousenZHANG commentedon Aug 29, 2026
I can take the next disjoint increment:
test/components/preprocessors/.It is not in the current
typestarget onmain, and no open or closed PR or comment covers it —fetchers/(#12435) andretrievers/(#12481) are the only increments in flight, and neither overlaps.Baseline is 265 errors across 9 of the 13 files, but that number is misleading. 206 of them are in
test_recursive_splitter.pyalone, and they all cascade from one pattern repeated seven times, where the dict returned byrun()is rebound to the list it holds:Giving the two values separate names drops that file to 26 and the directory to 85 — in line with the recent increments.
Nine open PRs add tests to these files, but all of them are pure additions; a three-way merge against each produces zero conflicts, so this shouldn't step on any of them.
Opened #12504.
ShousenZHANG commentedon Sep 11, 2026
Taking
test/hooks/budget/— the smallest of thetest/hooks/gaps. Thetypestarget currently covers onlytest/hooks/human_in_the_loop, sobudget/,compaction/,tool_result_offloading/and the threetest/hooks/*.pyroot files are all still unchecked.Baseline is 3 errors in
test_hooks.py, and neither group is a blanket-annotation case:KeepIterating, the inline stub passed as anon_exithook, is missing theto_dict/from_dictmembers theHookprotocol requires (list-itemat L106). Implementing them viadefault_to_dict/default_from_dictmatches theLifecycleHookstubs test: type-check agent hook and confirmation tests #12681 just added intest/components/agents/test_agent_hooks.py.agent.chat_generator.run = MagicMock(...)lines aremethod-assign. Replacing a bound method on a mock generator is the intended pattern here, so those get a narrow# type: ignore[method-assign]rather than a restructure.No overlap with
compaction/,tool_result_offloading/or theagents//converters/remainders — happy to take another of those next if nobody else has.ShousenZHANG commentedon Sep 11, 2026
Taking the three
test/hooks/root modules next —test_from_function.py,test_invocation.py,test_utils.py— as a follow-up to #12710 (test/hooks/budget/).Baseline is 56 errors, but 44 of them come from a single cause: six inline stub hooks (
RecordingHook,ThreadRecordingHook,AsyncRecordingHook,LifecycleSpy,WarmOnlyHook,PlainHook) are missing theto_dict/from_dictmembers theHookprotocol requires, so every list they appear in failslist-item. Implementing the pair viadefault_to_dict/default_from_dict— the shape #12681 used forLifecycleHook— clears all 44.The rest: a handful of hook dictionaries inferred as
dict[str, ...]where the callee wantsHookPointkeys, fixed with an explicit annotation; and one.functionread off aHook, narrowed withisinstancerather than suppressed.Five suppressions remain, all in
TestFunctionHookConstruction, where the test deliberately passes a wrong callable to assertFunctionHookrejects it — there the type error is the thing under test.Still not touching
compaction/ortool_result_offloading/; those are the larger remainingtest/hooks/gaps and I'd rather land these two first.Anurag-M1 commentedon Sep 12, 2026
Taking
test/hooks/tool_result_offloading/.Opened #12720 with the minimal typing fixes plus the
typestarget entry inpyproject.toml:test/hooks/tool_result_offloading/to thetypesscript line inpyproject.toml.test/hooks/tool_result_offloading/test_policies.py: addedisinstance(restored, OffloadOverChars)assertion to narrow the restored policy before accessing.threshold.test/hooks/tool_result_offloading/test_hooks.py:TextOnlyToolResultStore.writeparametercontenttostr | bytesto satisfyToolResultStoreprotocol under LSP.content: list[TextContent | ImageContent | FileContent]in test cases.# type: ignore[method-assign]and# type: ignore[attr-defined]for mock generator setup.Passed all 40 unit tests,
hatch run test:types(508 source files), andhatch run fmt-checklocally.ShousenZHANG commentedon Sep 24, 2026
Taking the last piece. After #12758 and #12761, the only tracked
.pyfiles undertest/that thetypestarget still skips aretest/conftest.pyand three__init__.pyfiles holding nothing but the license header. The unchecked directories in the list above (classifiers/,connectors/,readers/,tools/,websearch/) no longer exist onmain.So this switches the target to
{args:haystack test}and drops the# TODO We want to eventually type the whole test folder. Baseline is 3 errors, all inconftest.py:request_blockeris missing itsmonkeypatch: pytest.MonkeyPatchand-> Noneannotations.spying_tracersetstracer.is_content_tracing_enabled = Trueon aSpyingTracer, which has no such attribute. The flag lives on the globalProxyTracer(haystack/tracing/tracer.py:118, read at:65), andSpyingSpan.set_content_tagrecords unconditionally, so the line has no effect and goes.Opening the PR shortly.
bogdankostic commentedon Sep 25, 2026
#12930 replaced the hand-maintained path list with
{args:haystack test}, so the wholetest/folder is now type-checked.