import pytest from ea_chatbot.graph.workflow import create_workflow, data_analyst_worker_node from ea_chatbot.graph.state import AgentState from unittest.mock import MagicMock, patch from langchain_core.messages import HumanMessage, AIMessage def test_worker_merge_sets_summary_for_reflector(): """Verify that worker node (wrapper) sets the 'summary' field for the Reflector.""" state = AgentState( messages=[HumanMessage(content="test")], question="test", checklist=[{"task": "Analyze data", "worker": "data_analyst"}], current_step=0, iterations=0, vfs={}, plots=[], dfs={}, next_action="", analysis={}, summary="Initial Planner Summary" # Stale summary ) # Mock the compiled worker subgraph to return a specific result with patch("ea_chatbot.graph.workflow._DATA_ANALYST_WORKER") as mock_worker: mock_worker.invoke.return_value = { "result": "Actual Worker Findings", "messages": [AIMessage(content="Internal")], "vfs_state": {}, "plots": [] } # Execute the wrapper node updates = data_analyst_worker_node(state) # Verify that 'summary' is in updates and has the worker result assert "summary" in updates assert updates["summary"] == "Actual Worker Findings" # When applied to state, it should overwrite the stale summary state.update(updates) assert state["summary"] == "Actual Worker Findings"