mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 04:31:02 +02:00
Fixing tests
This commit is contained in:
parent
3e9e2aa35f
commit
6c0147feda
1 changed files with 39 additions and 39 deletions
|
|
@ -112,15 +112,15 @@ Args: {
|
||||||
# Arrange
|
# Arrange
|
||||||
thought_chunks = []
|
thought_chunks = []
|
||||||
|
|
||||||
async def think_callback(chunk):
|
async def think(chunk):
|
||||||
thought_chunks.append(chunk)
|
thought_chunks.append(chunk)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
await agent_manager.react(
|
await agent_manager.react(
|
||||||
question="What is machine learning?",
|
question="What is machine learning?",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=think_callback,
|
think=think,
|
||||||
observe_callback=AsyncMock(),
|
observe=AsyncMock(),
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
@ -139,15 +139,15 @@ Args: {
|
||||||
# Arrange
|
# Arrange
|
||||||
observation_chunks = []
|
observation_chunks = []
|
||||||
|
|
||||||
async def observe_callback(chunk):
|
async def observe(chunk):
|
||||||
observation_chunks.append(chunk)
|
observation_chunks.append(chunk)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
await agent_manager.react(
|
await agent_manager.react(
|
||||||
question="What is machine learning?",
|
question="What is machine learning?",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=AsyncMock(),
|
think=AsyncMock(),
|
||||||
observe_callback=observe_callback,
|
observe=observe,
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
@ -156,7 +156,7 @@ Args: {
|
||||||
# Note: Observations come from tool execution, which may or may not be streamed
|
# Note: Observations come from tool execution, which may or may not be streamed
|
||||||
# depending on the tool implementation
|
# depending on the tool implementation
|
||||||
# For now, verify callback was set up
|
# For now, verify callback was set up
|
||||||
assert observe_callback is not None
|
assert observe is not None
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_agent_streaming_vs_non_streaming(self, agent_manager, mock_flow_context):
|
async def test_agent_streaming_vs_non_streaming(self, agent_manager, mock_flow_context):
|
||||||
|
|
@ -169,8 +169,8 @@ Args: {
|
||||||
non_streaming_result = await agent_manager.react(
|
non_streaming_result = await agent_manager.react(
|
||||||
question=question,
|
question=question,
|
||||||
history=history,
|
history=history,
|
||||||
think_callback=None,
|
think=AsyncMock(),
|
||||||
observe_callback=None,
|
observe=AsyncMock(),
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=False
|
streaming=False
|
||||||
)
|
)
|
||||||
|
|
@ -179,17 +179,17 @@ Args: {
|
||||||
thought_chunks = []
|
thought_chunks = []
|
||||||
observation_chunks = []
|
observation_chunks = []
|
||||||
|
|
||||||
async def think_cb(chunk):
|
async def think(chunk):
|
||||||
thought_chunks.append(chunk)
|
thought_chunks.append(chunk)
|
||||||
|
|
||||||
async def observe_cb(chunk):
|
async def observe(chunk):
|
||||||
observation_chunks.append(chunk)
|
observation_chunks.append(chunk)
|
||||||
|
|
||||||
streaming_result = await agent_manager.react(
|
streaming_result = await agent_manager.react(
|
||||||
question=question,
|
question=question,
|
||||||
history=history,
|
history=history,
|
||||||
think_callback=think_cb,
|
think=think,
|
||||||
observe_callback=observe_cb,
|
observe=observe,
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
@ -202,24 +202,24 @@ Args: {
|
||||||
async def test_agent_streaming_callback_invocation(self, agent_manager, mock_flow_context):
|
async def test_agent_streaming_callback_invocation(self, agent_manager, mock_flow_context):
|
||||||
"""Test that callbacks are invoked with correct parameters"""
|
"""Test that callbacks are invoked with correct parameters"""
|
||||||
# Arrange
|
# Arrange
|
||||||
think_callback = AsyncMock()
|
think = AsyncMock()
|
||||||
observe_callback = AsyncMock()
|
observe = AsyncMock()
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
await agent_manager.react(
|
await agent_manager.react(
|
||||||
question="What is machine learning?",
|
question="What is machine learning?",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=think_callback,
|
think=think,
|
||||||
observe_callback=observe_callback,
|
observe=observe,
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assert - Think callback should be invoked
|
# Assert - Think callback should be invoked
|
||||||
assert think_callback.call_count > 0
|
assert think.call_count > 0
|
||||||
|
|
||||||
# Verify all callback invocations had string arguments
|
# Verify all callback invocations had string arguments
|
||||||
for call in think_callback.call_args_list:
|
for call in think.call_args_list:
|
||||||
assert len(call.args) > 0
|
assert len(call.args) > 0
|
||||||
assert isinstance(call.args[0], str)
|
assert isinstance(call.args[0], str)
|
||||||
|
|
||||||
|
|
@ -230,10 +230,10 @@ Args: {
|
||||||
result = await agent_manager.react(
|
result = await agent_manager.react(
|
||||||
question="What is machine learning?",
|
question="What is machine learning?",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=None,
|
think=AsyncMock(),
|
||||||
observe_callback=None,
|
observe=AsyncMock(),
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True # Streaming enabled but no callbacks
|
streaming=True # Streaming enabled with mock callbacks
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assert - Should complete without error
|
# Assert - Should complete without error
|
||||||
|
|
@ -245,21 +245,21 @@ Args: {
|
||||||
"""Test streaming with existing conversation history"""
|
"""Test streaming with existing conversation history"""
|
||||||
# Arrange
|
# Arrange
|
||||||
history = sample_agent_responses[:1] # Use first response as history
|
history = sample_agent_responses[:1] # Use first response as history
|
||||||
think_callback = AsyncMock()
|
think = AsyncMock()
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
result = await agent_manager.react(
|
result = await agent_manager.react(
|
||||||
question="Tell me more about neural networks",
|
question="Tell me more about neural networks",
|
||||||
history=history,
|
history=history,
|
||||||
think_callback=think_callback,
|
think=think,
|
||||||
observe_callback=AsyncMock(),
|
observe=AsyncMock(),
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert result is not None
|
assert result is not None
|
||||||
assert think_callback.call_count > 0
|
assert think.call_count > 0
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_agent_streaming_error_propagation(self, agent_manager, mock_flow_context):
|
async def test_agent_streaming_error_propagation(self, agent_manager, mock_flow_context):
|
||||||
|
|
@ -268,16 +268,16 @@ Args: {
|
||||||
mock_prompt_client = mock_flow_context("prompt-request")
|
mock_prompt_client = mock_flow_context("prompt-request")
|
||||||
mock_prompt_client.agent_react.side_effect = Exception("Prompt service error")
|
mock_prompt_client.agent_react.side_effect = Exception("Prompt service error")
|
||||||
|
|
||||||
think_callback = AsyncMock()
|
think = AsyncMock()
|
||||||
observe_callback = AsyncMock()
|
observe = AsyncMock()
|
||||||
|
|
||||||
# Act & Assert
|
# Act & Assert
|
||||||
with pytest.raises(Exception) as exc_info:
|
with pytest.raises(Exception) as exc_info:
|
||||||
await agent_manager.react(
|
await agent_manager.react(
|
||||||
question="test question",
|
question="test question",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=think_callback,
|
think=think,
|
||||||
observe_callback=observe_callback,
|
observe=observe,
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
@ -312,36 +312,36 @@ Final Answer: AI is the simulation of human intelligence in machines."""
|
||||||
|
|
||||||
mock_prompt_client_streaming.agent_react.side_effect = multi_step_agent_react
|
mock_prompt_client_streaming.agent_react.side_effect = multi_step_agent_react
|
||||||
|
|
||||||
think_callback = AsyncMock()
|
think = AsyncMock()
|
||||||
observe_callback = AsyncMock()
|
observe = AsyncMock()
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
result = await agent_manager.react(
|
result = await agent_manager.react(
|
||||||
question="What is artificial intelligence?",
|
question="What is artificial intelligence?",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=think_callback,
|
think=think,
|
||||||
observe_callback=observe_callback,
|
observe=observe,
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert result is not None
|
assert result is not None
|
||||||
assert think_callback.call_count > 0
|
assert think.call_count > 0
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_agent_streaming_preserves_tool_config(self, agent_manager, mock_flow_context):
|
async def test_agent_streaming_preserves_tool_config(self, agent_manager, mock_flow_context):
|
||||||
"""Test that streaming preserves tool configuration and context"""
|
"""Test that streaming preserves tool configuration and context"""
|
||||||
# Arrange
|
# Arrange
|
||||||
think_callback = AsyncMock()
|
think = AsyncMock()
|
||||||
observe_callback = AsyncMock()
|
observe = AsyncMock()
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
await agent_manager.react(
|
await agent_manager.react(
|
||||||
question="What is machine learning?",
|
question="What is machine learning?",
|
||||||
history=[],
|
history=[],
|
||||||
think_callback=think_callback,
|
think=think,
|
||||||
observe_callback=observe_callback,
|
observe=observe,
|
||||||
context=mock_flow_context,
|
context=mock_flow_context,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue