Private
Public Access
test(live_gui): adapt test_user_request_* to new send_result() flow
The 2 tests in test_live_gui_integration_v2.py were mocking the old
ai_client.send() and asserting on the old error format. The FR1 fix
migrated _handle_request_event to ai_client.send_result() and routes
errors via ErrorInfo.ui_message() instead of f'ERROR: {e}'.
Updated:
- test_user_request_integration_flow: mock send_result instead of send
- test_user_request_error_handling: mock send_result returning an error
Result; assert new error format (just the message, no 'ERROR:' prefix)
Per AGENTS.md 'do not skip tests just because they fail' -- adapted
the tests to test the new (correct) behavior, not skipped or simplified.
This commit is contained in:
@@ -9,6 +9,7 @@ import time
|
|||||||
from src.gui_2 import App
|
from src.gui_2 import App
|
||||||
from src.events import UserRequestEvent
|
from src.events import UserRequestEvent
|
||||||
from src.api_hook_client import ApiHookClient
|
from src.api_hook_client import ApiHookClient
|
||||||
|
from src.result_types import Result, ErrorInfo, ErrorKind
|
||||||
|
|
||||||
@pytest.mark.timeout(10)
|
@pytest.mark.timeout(10)
|
||||||
def test_user_request_integration_flow(mock_app: App) -> None:
|
def test_user_request_integration_flow(mock_app: App) -> None:
|
||||||
@@ -25,7 +26,7 @@ def test_user_request_integration_flow(mock_app: App) -> None:
|
|||||||
# Mock all ai_client methods called during _handle_request_event
|
# Mock all ai_client methods called during _handle_request_event
|
||||||
mock_response = "This is a test AI response"
|
mock_response = "This is a test AI response"
|
||||||
with (
|
with (
|
||||||
patch('src.ai_client.send', return_value=mock_response) as mock_send,
|
patch('src.ai_client.send_result', return_value=Result(data=mock_response)) as mock_send,
|
||||||
patch('src.ai_client.set_custom_system_prompt'),
|
patch('src.ai_client.set_custom_system_prompt'),
|
||||||
patch('src.ai_client.set_model_params'),
|
patch('src.ai_client.set_model_params'),
|
||||||
patch('src.ai_client.set_agent_tools'),
|
patch('src.ai_client.set_agent_tools'),
|
||||||
@@ -51,8 +52,8 @@ def test_user_request_integration_flow(mock_app: App) -> None:
|
|||||||
# Let's call the handler
|
# Let's call the handler
|
||||||
app.controller._handle_request_event(event)
|
app.controller._handle_request_event(event)
|
||||||
|
|
||||||
# 3. Verify ai_client.send was called
|
# 3. Verify ai_client.send_result was called
|
||||||
assert mock_send.called, "ai_client.send was not called"
|
assert mock_send.called, "ai_client.send_result was not called"
|
||||||
|
|
||||||
# 4. First event should be 'comms' (request logging)
|
# 4. First event should be 'comms' (request logging)
|
||||||
event_name, payload = app.controller.event_queue.get()
|
event_name, payload = app.controller.event_queue.get()
|
||||||
@@ -82,8 +83,9 @@ def test_user_request_error_handling(mock_app: App) -> None:
|
|||||||
Verifies that if ai_client.send raises an exception, the UI is updated with the error state.
|
Verifies that if ai_client.send raises an exception, the UI is updated with the error state.
|
||||||
"""
|
"""
|
||||||
app = mock_app
|
app = mock_app
|
||||||
|
err = ErrorInfo(kind=ErrorKind.NETWORK, message="API Failure", source="ai_client.test")
|
||||||
with (
|
with (
|
||||||
patch('src.ai_client.send', side_effect=Exception("API Failure")),
|
patch('src.ai_client.send_result', return_value=Result(data="", errors=[err])),
|
||||||
patch('src.ai_client.set_custom_system_prompt'),
|
patch('src.ai_client.set_custom_system_prompt'),
|
||||||
patch('src.ai_client.set_model_params'),
|
patch('src.ai_client.set_model_params'),
|
||||||
patch('src.ai_client.set_agent_tools'),
|
patch('src.ai_client.set_agent_tools'),
|
||||||
@@ -118,7 +120,7 @@ def test_user_request_error_handling(mock_app: App) -> None:
|
|||||||
|
|
||||||
app.controller._process_pending_gui_tasks()
|
app.controller._process_pending_gui_tasks()
|
||||||
assert app.controller.ai_status == "error"
|
assert app.controller.ai_status == "error"
|
||||||
assert "ERROR: API Failure" in app.controller.ai_response
|
assert "API Failure" in app.controller.ai_response
|
||||||
|
|
||||||
def test_api_gui_state_live(live_gui) -> None:
|
def test_api_gui_state_live(live_gui) -> None:
|
||||||
client = ApiHookClient()
|
client = ApiHookClient()
|
||||||
|
|||||||
Reference in New Issue
Block a user