From 0a9b1b5a56d1b379d5f369f8806f24779733370c Mon Sep 17 00:00:00 2001 From: Kelvin Sundli Date: Fri, 17 Apr 2026 16:46:31 -0700 Subject: [PATCH 1/2] test(agents): branch on expected_type in agent tool tests Tests were branching on isinstance(loaded_tool, ...), which is the object under test. A loader regression returning the wrong subtype could silently skip entire assertion blocks and still pass. Branching on the parametrized expected_type keeps the isinstance check as a real assertion. --- .../test_agents/test_agent_tools.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py b/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py index a87904e2f8..58a8829474 100644 --- a/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py +++ b/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py @@ -70,23 +70,22 @@ def test_agent_tool_load_returns_correct_subtype(self, tool_data: dict, expected assert loaded_tool.name == tool_data["name"] assert loaded_tool.description == tool_data["description"] - if isinstance(loaded_tool, UnknownAgentTool): + if expected_type is UnknownAgentTool: + assert isinstance(loaded_tool, UnknownAgentTool) assert loaded_tool.type == tool_data["type"] else: assert loaded_tool._type == expected_type._type - # Handle configuration comparison based on tool type if "configuration" in tool_data: - if isinstance(loaded_tool, QueryKnowledgeGraphAgentTool): - # For QueryKnowledgeGraph, we expect a structured configuration object + if expected_type is QueryKnowledgeGraphAgentTool: + assert isinstance(loaded_tool, QueryKnowledgeGraphAgentTool) assert isinstance(loaded_tool.configuration, QueryKnowledgeGraphAgentToolConfiguration) - # Compare by serializing the structured object back to dict assert loaded_tool.configuration.dump(camel_case=True) == tool_data["configuration"] - elif isinstance(loaded_tool, UnknownAgentTool): - # For other tools (like UnknownAgentTool), configuration should be a dict + elif expected_type is UnknownAgentTool: + assert isinstance(loaded_tool, UnknownAgentTool) assert loaded_tool.configuration == tool_data["configuration"] else: - raise TypeError(f"Unhandled tool type in test case: {type(loaded_tool)}") + raise TypeError(f"Unhandled tool type in test case: {expected_type}") def test_unknown_agent_tool_preserves_custom_type(self) -> None: """Test that UnknownAgentTool preserves the original type string.""" @@ -113,7 +112,8 @@ def test_agent_tool_dump_returns_correct_type(self, tool_data: dict, expected_ty loaded_tool = AgentTool._load(tool_data) dumped_tool = loaded_tool.dump(camel_case=True) - if isinstance(loaded_tool, UnknownAgentTool): + if expected_type is UnknownAgentTool: + assert isinstance(loaded_tool, UnknownAgentTool) assert dumped_tool["type"] == unknown_example["type"] else: assert dumped_tool["type"] == expected_type._type @@ -158,7 +158,8 @@ def test_agent_tool_upsert_returns_correct_type(self, tool_data: dict, expected_ loaded_tool = AgentTool._load(tool_data) dumped_tool = loaded_tool.as_write().dump(camel_case=True) - if isinstance(loaded_tool, UnknownAgentTool): + if expected_type is UnknownAgentTool: + assert isinstance(loaded_tool, UnknownAgentTool) assert dumped_tool["type"] == unknown_example["type"] else: assert dumped_tool["type"] == expected_type._type From a4924df8c12203997ed12d92fdc7104be7057bc6 Mon Sep 17 00:00:00 2001 From: Kelvin Sundli Date: Fri, 17 Apr 2026 17:29:43 -0700 Subject: [PATCH 2/2] test(agents): assert loaded_tool type up front in dump and upsert tests Mirrors the pattern already used by test_agent_tool_load_returns_correct_subtype, so a loader regression returning a wrong subtype fails loudly here instead of relying on _type string equality alone. --- .../test_data_classes/test_agents/test_agent_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py b/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py index 58a8829474..d0215314b6 100644 --- a/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py +++ b/tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py @@ -110,10 +110,10 @@ class TestAgentToolDump: def test_agent_tool_dump_returns_correct_type(self, tool_data: dict, expected_type: type[AgentTool]) -> None: """Test that AgentTool.dump() returns the correct type.""" loaded_tool = AgentTool._load(tool_data) + assert isinstance(loaded_tool, expected_type) dumped_tool = loaded_tool.dump(camel_case=True) if expected_type is UnknownAgentTool: - assert isinstance(loaded_tool, UnknownAgentTool) assert dumped_tool["type"] == unknown_example["type"] else: assert dumped_tool["type"] == expected_type._type @@ -156,10 +156,10 @@ class TestAgentToolUpsert: def test_agent_tool_upsert_returns_correct_type(self, tool_data: dict, expected_type: type[AgentTool]) -> None: """Test that AgentToolUpsert.dump() returns the correct type.""" loaded_tool = AgentTool._load(tool_data) + assert isinstance(loaded_tool, expected_type) dumped_tool = loaded_tool.as_write().dump(camel_case=True) if expected_type is UnknownAgentTool: - assert isinstance(loaded_tool, UnknownAgentTool) assert dumped_tool["type"] == unknown_example["type"] else: assert dumped_tool["type"] == expected_type._type