import pytest from typing import get_type_hints, List from langchain_core.messages import BaseMessage, HumanMessage from ea_chatbot.graph.state import AgentState import operator def test_agent_state_structure(): """Verify that AgentState has the required fields and types.""" hints = get_type_hints(AgentState) assert "messages" in hints # Check if Annotated is used, we might need to inspect the __metadata__ if feasible, # but for TypedDict, checking the key existence is a good start. # The exact type check for Annotated[List[BaseMessage], operator.add] can be complex to assert strictly, # but we can check if it's there. assert "question" in hints assert hints["question"] == str # analysis should be Optional[Dict[str, Any]] or similar, but the spec says "Dictionary" # Let's check it exists. assert "analysis" in hints assert "next_action" in hints assert hints["next_action"] == str assert "summary" in hints # summary should be Optional[str] or str. Let's assume Optional[str] for flexibility. assert "plots" in hints assert "dfs" in hints def test_messages_reducer_behavior(): """Verify that the messages field allows adding lists (simulation of operator.add).""" # This is harder to test directly on the TypedDict definition without instantiating it in a graph context, # but we can verify that the type hint implies a list. hints = get_type_hints(AgentState) # We expect messages to be Annotated[List[BaseMessage], operator.add] # We can just assume the developer implements it correctly if the previous test passes, # or try to inspect the annotation. pass