WIP: STILL FIXING FUNDAMENTAL TRASH

This commit is contained in:
2026-03-05 14:04:17 -05:00
parent 70d18347d7
commit a13a6c5cd0
11 changed files with 113 additions and 162 deletions

View File

@@ -1,20 +1,14 @@
from src import ai_client
from src import api_hook_client
from src import events
from src import gui_2
import pytest
from unittest.mock import patch, ANY
import time
from src import ai_client
from src import api_hook_client
from src import events
from src import gui_2
from src.gui_2 import App
from src.events import UserRequestEvent
from src.api_hook_client import ApiHookClient
@pytest.mark.timeout(10)
def test_user_request_integration_flow(mock_app: gui_2.App) -> None:
def test_user_request_integration_flow(mock_app: App) -> None:
"""
Verifies that pushing a events.UserRequestEvent to the event_queue:
Verifies that pushing a UserRequestEvent to the event_queue:
1. Triggers ai_client.send
2. Results in a 'response' event back to the queue
3. Eventually updates the UI state (ai_response, ai_status) after processing GUI tasks.
@@ -28,8 +22,8 @@ def test_user_request_integration_flow(mock_app: gui_2.App) -> None:
patch('src.ai_client.set_model_params'),
patch('src.ai_client.set_agent_tools')
):
# 1. Create and push a events.UserRequestEvent
event = events.UserRequestEvent(
# 1. Create and push a UserRequestEvent
event = UserRequestEvent(
prompt="Hello AI",
stable_md="Context",
file_items=[],
@@ -39,7 +33,7 @@ def test_user_request_integration_flow(mock_app: gui_2.App) -> None:
# 2. Call the handler directly since start_services is mocked (no event loop thread)
app.controller._handle_request_event(event)
# 3. Verify ai_client.send was called
assert mock_send.called, "src.ai_client.send was not called"
assert mock_send.called, "ai_client.send was not called"
mock_send.assert_called_once_with(
"Context", "Hello AI", ".", [], "History",
pre_tool_callback=ANY,
@@ -52,17 +46,17 @@ def test_user_request_integration_flow(mock_app: gui_2.App) -> None:
start_time = time.time()
success = False
while time.time() - start_time < 3:
app._process_pending_gui_tasks()
if app.ai_response == mock_response and app.ai_status == "done":
app.controller._process_pending_gui_tasks()
if app.controller.ai_response == mock_response and app.controller.ai_status == "done":
success = True
break
time.sleep(0.1)
assert success, f"UI state was not updated. ai_response: '{app.ai_response}', status: '{app.ai_status}'"
assert app.ai_response == mock_response
assert app.ai_status == "done"
assert success, f"UI state was not updated. ai_response: '{app.controller.ai_response}', status: '{app.controller.ai_status}'"
assert app.controller.ai_response == mock_response
assert app.controller.ai_status == "done"
@pytest.mark.timeout(10)
def test_user_request_error_handling(mock_app: gui_2.App) -> None:
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.
"""
@@ -73,7 +67,7 @@ def test_user_request_error_handling(mock_app: gui_2.App) -> None:
patch('src.ai_client.set_model_params'),
patch('src.ai_client.set_agent_tools')
):
event = events.UserRequestEvent(
event = UserRequestEvent(
prompt="Trigger Error",
stable_md="",
file_items=[],
@@ -85,18 +79,18 @@ def test_user_request_error_handling(mock_app: gui_2.App) -> None:
start_time = time.time()
success = False
while time.time() - start_time < 5:
app._process_pending_gui_tasks()
if app.ai_status == "error" and "ERROR: API Failure" in app.ai_response:
app.controller._process_pending_gui_tasks()
if app.controller.ai_status == "error" and "ERROR: API Failure" in app.controller.ai_response:
success = True
break
time.sleep(0.1)
assert success, f"Error state was not reflected in UI. status: {app.ai_status}, response: {app.ai_response}"
assert success, f"Error state was not reflected in UI. status: {app.controller.ai_status}, response: {app.controller.ai_response}"
def test_api_gui_state_live(live_gui) -> None:
client = api_hook_client.ApiHookClient()
client = ApiHookClient()
client.set_value('current_provider', 'anthropic')
client.set_value('current_model', 'claude-3-haiku-20240307')
start_time = time.time()
success = False
while time.time() - start_time < 10:
@@ -105,7 +99,7 @@ def test_api_gui_state_live(live_gui) -> None:
success = True
break
time.sleep(0.5)
assert success, f"GUI state did not update. Got: {client.get_gui_state()}"
final_state = client.get_gui_state()
assert final_state['current_provider'] == 'anthropic'