test: make Tool/Agent serialization assertions version-agnostic for Haystack 2.x/3.x#3533
Merged
Merged
Conversation
Haystack 3.0 extends the serialized format of Tool (async_function) and Agent (tool_concurrency_limit, hooks, ...), breaking tests that compare to_dict() output against hard-coded dicts. Build the expected tool entries with tool.to_dict()/toolset.to_dict() at runtime and, in the github pipeline test, accept init parameters added by the installed haystack-ai version. Also replaces the per-field hasattr/pop compat shims these tests had accumulated for earlier format changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Contributor
Contributor
Contributor
Contributor
This was referenced Jul 2, 2026
Open
Same fix as the first commit for seven more chat-generator suites whose serde tests were masked by the ToolInvoker collection error when this PR was opened: build the expected tools entry with tool.to_dict() and drop the per-field hasattr compat shims. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
julian-risch
commented
Jul 2, 2026
| if not hasattr(pipeline, "_connection_type_validation"): | ||
| expected_dict.pop("connection_type_validation") | ||
|
|
||
| # add outputs_to_string, inputs_from_state and outputs_to_state tool parameters for compatibility with |
Member
Author
There was a problem hiding this comment.
no longer needed thanks to "tools": [tool.to_dict()],
sjrl
reviewed
Jul 2, 2026
| } | ||
| ], | ||
| # serialize the tool with the installed haystack-ai version so the expected fields match it | ||
| "tools": [tool.to_dict()], |
Contributor
There was a problem hiding this comment.
In principal this is okay but it is kind of asserting that pipeline.to_dict equals pipeline.to_dict which isn't necessarily that helpful.
Maybe converting these tests to do Pipeline.from_dict(pipeline.to_dict)) and asserting the newly loaded pipeline equals the old one?
…rison Review feedback: comparing to_dict output against tool.to_dict() partly asserts to_dict equals itself. Exclude the haystack-ai-owned tools entry from the pinned-dict comparisons and rely on round-trips instead: the serde-in-pipeline tests already dump and load the pipeline and assert equality, and the plain to_dict tests now deserialize the serialized component and compare the recovered tools with the originals. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1dd8e79 to
0621a99
Compare
julian-risch
commented
Jul 3, 2026
Comment on lines
506
to
508
| pipeline_yaml = pipeline.dumps() | ||
| new_pipeline = Pipeline.loads(pipeline_yaml) | ||
| assert new_pipeline == pipeline |
Member
Author
There was a problem hiding this comment.
This is the roundtrip test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Serialization tests in five integrations compared
to_dict()output against hard-coded expected dicts that pin the exactTool/Toolset/Agentserialization format of one haystack-ai version. Haystack 3.0 adds fields (e.g.Tool.to_dict()now includesasync_function;Agentgainedtool_concurrency_limit,hooks,tool_streaming_callback_passthrough), which broke these tests. This PR makes them version-agnostic so they pass on both 2.x and the currentv3branch:Proposed Changes:
to_dicttests no longer pin the haystack-owned tools serialization format at all. They exclude the tools entries from the pinned-dict comparison and instead do a realfrom_dict(component.to_dict())round-trip, asserting the recovered tools equal the originals.test_serde_in_pipelinetests — the tools entries are popped from the pinned pipeline dict; tool fidelity is covered by thePipeline.loads(pipeline.dumps())round-trip (Pipeline.__eq__compares serialized forms) plus explicit attribute checks on the loaded generator.test_pipeline_serialization): the test pins the full pipeline dict includingAgentandOpenAIChatGeneratorinit parameters, which belong to haystack-ai and change between versions. It now copies any init parameters the installed haystack-ai adds beyond the expected baseline before comparing, replacing the two existing single-key compat shims (http_client_kwargs/tool_invoker_kwargspops and theconfirmation_strategies/required_variables/user_promptloop). The test keeps pinning what the integration owns: theGitHubFileEditorToolserialization. It also now assertsPipeline.from_dict(pipeline.to_dict()) == pipeline.import unittesttoimport unittest.mock— the test usesunittest.mock.ANYand only worked because haystack-ai 2.x happened to importunittest.mocktransitively; with v3 installed it fails withAttributeError: module 'unittest' has no attribute 'mock'.How did you test it?
fmt-check,test:types, and full unit suites pass for all touched integrations.git+https://github.com/deepset-ai/haystack.git@v3): the previously failing serialization tests now pass. Verified on a local merge with test: guard ToolInvoker imports so chat-generator tests run under Haystack 3.0 #3535 (needed for collection) and test: trust test modules under Haystack 3.0's deserialization allowlist #3537 (the serde tests deserialize test-module functions, soPipeline.loadsneeds the trusted-modules allowlist) — anthropic, aimlapi, transformers, watsonx, huggingface_api, and github unit suites are all fully green on that combined state.Notes for the reviewer
test_serde_in_pipelinenever deserialized anything (it compared the original generator to itself), which was hiding a real bug:CometAPIChatGeneratorcould not be deserialized in a pipeline at all. That fix, together with the missing round-trip, was extracted into fix(cometapi): make CometAPIChatGenerator deserializable in pipelines #3542 (now merged); main has been merged back into this branch, so cometapi'stest_serde_in_pipelinehere combines both changes.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.🤖 Generated with Claude Code