Skip to content

Commit 41f0f52

Browse files
committed
Move imports to module level and expand test coverage
- Move StructuredTool and build_result_envelope imports to top of chat_agent.py - Add tests for ChatAgent._build_workflow emitter parameter - Add test for MCP provider description templating with {original} placeholder - Apply ruff format to modified files
1 parent 8e0eaa2 commit 41f0f52

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

redis_sre_agent/agent/chat_agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import Any, Awaitable, Callable, Dict, List, Optional, TypedDict
1313

1414
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage, ToolMessage
15+
from langchain_core.tools import StructuredTool
1516
from langchain_openai import ChatOpenAI
1617
from langgraph.checkpoint.memory import MemorySaver
1718
from langgraph.graph import END, StateGraph
@@ -28,6 +29,8 @@
2829
from redis_sre_agent.tools.manager import ToolManager
2930
from redis_sre_agent.tools.models import ToolCapability
3031

32+
from .helpers import build_result_envelope
33+
3134
logger = logging.getLogger(__name__)
3235
tracer = trace.get_tracer(__name__)
3336

@@ -220,10 +223,6 @@ def _build_workflow(
220223
adapters: List of tool adapters for the ToolNode
221224
emitter: Optional progress emitter for status updates
222225
"""
223-
from langchain_core.tools import StructuredTool
224-
225-
from .helpers import build_result_envelope
226-
227226
tooldefs_by_name = {t.name: t for t in tool_mgr.get_tools()}
228227

229228
# We'll dynamically add expand_evidence tool when envelopes are available

tests/unit/agent/test_chat_agent.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,55 @@ def test_state_has_required_fields(self):
212212
assert "iteration_count" in state
213213
assert "max_iterations" in state
214214
assert "signals_envelopes" in state
215+
216+
217+
class TestChatAgentWorkflowBuild:
218+
"""Test the _build_workflow method and emitter parameter."""
219+
220+
@patch("redis_sre_agent.agent.chat_agent.ChatOpenAI")
221+
def test_build_workflow_accepts_emitter(self, mock_chat_openai):
222+
"""Test that _build_workflow accepts an emitter parameter."""
223+
mock_llm = MagicMock()
224+
mock_chat_openai.return_value = mock_llm
225+
226+
agent = ChatAgent()
227+
228+
# Create a mock tool manager
229+
mock_tool_mgr = MagicMock()
230+
mock_tool_mgr.get_tools.return_value = []
231+
mock_tool_mgr.get_status_update.return_value = None
232+
233+
# Create a mock emitter
234+
emitter = NullEmitter()
235+
236+
# Should not raise - emitter is now accepted
237+
workflow = agent._build_workflow(
238+
tool_mgr=mock_tool_mgr,
239+
llm_with_tools=mock_llm,
240+
adapters=[],
241+
emitter=emitter,
242+
)
243+
244+
assert workflow is not None
245+
246+
@patch("redis_sre_agent.agent.chat_agent.ChatOpenAI")
247+
def test_build_workflow_works_without_emitter(self, mock_chat_openai):
248+
"""Test that _build_workflow works when emitter is None."""
249+
mock_llm = MagicMock()
250+
mock_chat_openai.return_value = mock_llm
251+
252+
agent = ChatAgent()
253+
254+
# Create a mock tool manager
255+
mock_tool_mgr = MagicMock()
256+
mock_tool_mgr.get_tools.return_value = []
257+
258+
# Should not raise when emitter is None
259+
workflow = agent._build_workflow(
260+
tool_mgr=mock_tool_mgr,
261+
llm_with_tools=mock_llm,
262+
adapters=[],
263+
emitter=None,
264+
)
265+
266+
assert workflow is not None

tests/unit/tools/mcp_provider/test_mcp_provider.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ def test_get_description_with_override(self):
9696
assert provider._get_description("no_override", "MCP desc") == "MCP desc"
9797
assert provider._get_description("unknown", "MCP desc") == "MCP desc"
9898

99+
def test_get_description_with_original_template(self):
100+
"""Test that {original} placeholder is replaced with MCP description."""
101+
config = MCPServerConfig(
102+
command="test",
103+
tools={
104+
"templated_tool": MCPToolConfig(description="Custom context. {original}"),
105+
"prepended": MCPToolConfig(
106+
description="WARNING: Use carefully. {original} See docs for details."
107+
),
108+
},
109+
)
110+
provider = MCPToolProvider(server_name="test", server_config=config)
111+
112+
# Template should replace {original} with the MCP description
113+
assert (
114+
provider._get_description("templated_tool", "Original MCP description")
115+
== "Custom context. Original MCP description"
116+
)
117+
assert (
118+
provider._get_description("prepended", "Search for files.")
119+
== "WARNING: Use carefully. Search for files. See docs for details."
120+
)
121+
99122
def test_get_tool_config(self):
100123
"""Test getting tool config."""
101124
tool_config = MCPToolConfig(

0 commit comments

Comments
 (0)