Spaces:
Running
Running
Srushti-Kamble commited on
Commit ·
abd04d5
1
Parent(s): 6d8890c
test: align graphrag agent expectations with strict output parsing
Browse files
backend/tests/test_graphrag_agent.py
CHANGED
|
@@ -16,7 +16,7 @@ def test_generate_answer_appends_graph_context_without_changing_sources(monkeypa
|
|
| 16 |
|
| 17 |
# Mock the executor and the tool
|
| 18 |
mock_executor = MagicMock()
|
| 19 |
-
mock_executor.invoke.return_value = {"output": "Agent answer"}
|
| 20 |
|
| 21 |
mock_pdf_tool = MagicMock()
|
| 22 |
mock_pdf_tool.last_sources = chunks
|
|
@@ -58,7 +58,7 @@ def test_generate_answer_stream_appends_graph_context(monkeypatch):
|
|
| 58 |
mock_executor.stream.return_value = iter([
|
| 59 |
{"actions": [MagicMock(log="Thought: I should search. Action: pdf_search")]},
|
| 60 |
{"intermediate_steps": []}, # This triggers source yielding in my implementation if last_sources is set
|
| 61 |
-
{"output":
|
| 62 |
])
|
| 63 |
|
| 64 |
mock_pdf_tool = MagicMock()
|
|
@@ -69,7 +69,7 @@ def test_generate_answer_stream_appends_graph_context(monkeypatch):
|
|
| 69 |
events = list(agent.generate_answer_stream("OpenAI Microsoft", "user-1", "doc-1"))
|
| 70 |
|
| 71 |
# Verify event types and data
|
| 72 |
-
assert any("Thinking" in e for e in events)
|
| 73 |
assert any("Streamed answer" in e for e in events)
|
| 74 |
assert any("Vector stream context" in e for e in events)
|
| 75 |
assert events[-1] == f"data: {json.dumps({'type': 'done'})}\n\n"
|
|
|
|
| 16 |
|
| 17 |
# Mock the executor and the tool
|
| 18 |
mock_executor = MagicMock()
|
| 19 |
+
mock_executor.invoke.return_value = {"output": '{"answer":"Agent answer"}'}
|
| 20 |
|
| 21 |
mock_pdf_tool = MagicMock()
|
| 22 |
mock_pdf_tool.last_sources = chunks
|
|
|
|
| 58 |
mock_executor.stream.return_value = iter([
|
| 59 |
{"actions": [MagicMock(log="Thought: I should search. Action: pdf_search")]},
|
| 60 |
{"intermediate_steps": []}, # This triggers source yielding in my implementation if last_sources is set
|
| 61 |
+
{"output": 'Final Answer: {"answer":"Streamed answer"}'}
|
| 62 |
])
|
| 63 |
|
| 64 |
mock_pdf_tool = MagicMock()
|
|
|
|
| 69 |
events = list(agent.generate_answer_stream("OpenAI Microsoft", "user-1", "doc-1"))
|
| 70 |
|
| 71 |
# Verify event types and data
|
| 72 |
+
assert not any("Thinking" in e for e in events)
|
| 73 |
assert any("Streamed answer" in e for e in events)
|
| 74 |
assert any("Vector stream context" in e for e in events)
|
| 75 |
assert events[-1] == f"data: {json.dumps({'type': 'done'})}\n\n"
|