feat(api): Add /api/gui/state endpoint and live_gui integration tests
This commit is contained in:
@@ -4,6 +4,7 @@ import asyncio
|
||||
import time
|
||||
from gui_2 import App
|
||||
from events import UserRequestEvent
|
||||
from api_hook_client import ApiHookClient
|
||||
|
||||
@pytest.mark.timeout(10)
|
||||
@pytest.mark.asyncio
|
||||
@@ -38,7 +39,9 @@ async def test_user_request_integration_flow(mock_app: App) -> None:
|
||||
mock_send.assert_called_once_with(
|
||||
"Context", "Hello AI", ".", [], "History",
|
||||
pre_tool_callback=ANY,
|
||||
qa_callback=ANY
|
||||
qa_callback=ANY,
|
||||
stream=ANY,
|
||||
stream_callback=ANY
|
||||
)
|
||||
# 4. Wait for the response to propagate to _pending_gui_tasks and update UI
|
||||
# We call _process_pending_gui_tasks manually to simulate a GUI frame update.
|
||||
@@ -85,3 +88,22 @@ async def test_user_request_error_handling(mock_app: App) -> None:
|
||||
break
|
||||
await asyncio.sleep(0.1)
|
||||
assert success, f"Error state was not reflected in UI. status: {app.ai_status}, response: {app.ai_response}"
|
||||
|
||||
def test_api_gui_state_live(live_gui) -> None:
|
||||
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:
|
||||
state = client.get_gui_state()
|
||||
if state and state.get('current_provider') == 'anthropic' and state.get('current_model') == 'claude-3-haiku-20240307':
|
||||
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'
|
||||
assert final_state['current_model'] == 'claude-3-haiku-20240307'
|
||||
|
||||
Reference in New Issue
Block a user