diff --git a/test_stream_agent.py b/test_stream_agent.py index 901a0a2..f3d2cb8 100644 --- a/test_stream_agent.py +++ b/test_stream_agent.py @@ -1,18 +1,24 @@ -from stream_agent import StreamingAIAgent +from langchain_core.messages import AIMessage + +from stream_agent import format_message -def test_stream_returns_chunks(monkeypatch): - monkeypatch.delenv("OPENAI_API_KEY", raising=False) - agent = StreamingAIAgent() +def test_format_message_with_content(): + message = AIMessage(content="hello") - chunks = list(agent.stream("test question")) - - assert len(chunks) > 3 - assert "".join(chunks).strip() + assert format_message(message) == "hello" -def test_invoke_matches_stream(monkeypatch): - monkeypatch.delenv("OPENAI_API_KEY", raising=False) - agent = StreamingAIAgent() +def test_format_message_with_tool_call(): + message = AIMessage( + content="", + tool_calls=[ + { + "name": "get_demo_price", + "args": {"product": "молоко", "city": "Казань"}, + "id": "call-1", + } + ], + ) - assert agent.invoke("hello") == "".join(agent.stream("hello")) + assert "get_demo_price" in format_message(message)