Private
Public Access
0
0
Files
manual_slop/tests/test_extended_sims.py
T
ed 72f8f466fe fix(sim+api): proper wait loops, project switch endpoint, drop stale check
Three real fixes for the sim test + the live_gui coordination layer:

1. /api/project_switch_status endpoint in src/app_controller.py.
   The wait helper had been calling this endpoint but it did not exist;
   the helper always received a 404, fell back to {in_progress: False},
   and returned immediately even when a switch was in flight. Added the
   endpoint that reads _project_switch_in_progress, active_project_path,
   and _project_switch_error from the controller.

2. simulation/sim_base.py: replace time.sleep(2.0)/time.sleep(1.5) in
   the setup() with wait_io_pool_idle and wait_for_project_switch so
   the test does not click btn_md_only while a project switch is in
   flight. Also added the wait calls to sim_context.py for the same
   reason.

3. src/app_controller.py _handle_md_only: removed the is_project_stale()
   early-return. The stale state is a transient window during which the
   previous code dropped the click on the floor with a misleading
   'stale ui' status. The MD generation worker is safe to run from any
   project state; the action handler now always proceeds.

4. tests/test_extended_sims.py: set current_model to 'gemini-cli' so
   _do_generate does not raise KeyError('model') when the test
   overrides provider to gemini_cli.

KNOWN ISSUE: test_context_sim_live still fails with status
'switching to: temp_livecontextsim' after a 60s wait. The click
appears to be re-triggering a project switch via the GUI's render
loop. Root cause investigation deferred; the sim is async and the
test path is fragile.
2026-06-10 00:31:22 -04:00

75 lines
3.0 KiB
Python

import pytest
from typing import Any
import time
import sys
import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient
from simulation.sim_context import ContextSimulation
from simulation.sim_ai_settings import AISettingsSimulation
from simulation.sim_tools import ToolsSimulation
from simulation.sim_execution import ExecutionSimulation
@pytest.mark.integration
def test_context_sim_live(live_gui: Any) -> None:
"""Run the Context & Chat simulation against a live GUI."""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
sim = ContextSimulation(client)
sim.setup("LiveContextSim")
client.set_value('current_provider', 'gemini_cli')
# The gemini_cli adapter does not use the model name, but the controller's
# _do_generate path still reads it. Use an explicit placeholder so the
# downstream code does not raise KeyError on a stale 'model' field.
client.set_value('current_model', 'gemini-cli')
client.set_value('gcli_path', f'"{sys.executable}" "{os.path.abspath("tests/mock_gemini_cli.py")}"')
client.set_value('auto_add_history', True)
sim.run()
time.sleep(2)
sim.teardown()
@pytest.mark.integration
def test_ai_settings_sim_live(live_gui: Any) -> None:
"""Run the AI Settings simulation against a live GUI."""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
sim = AISettingsSimulation(client)
sim.setup("LiveAISettingsSim")
client.set_value('current_provider', 'gemini_cli')
client.set_value('gcli_path', f'"{sys.executable}" "{os.path.abspath("tests/mock_gemini_cli.py")}"') # Expect gemini_cli as the provider
client.set_value('auto_add_history', True)
assert client.get_value('current_provider') == 'gemini_cli'
sim.run()
sim.teardown()
@pytest.mark.integration
def test_tools_sim_live(live_gui: Any) -> None:
"""Run the Tools & Search simulation against a live GUI."""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
sim = ToolsSimulation(client)
sim.setup("LiveToolsSim")
client.set_value('current_provider', 'gemini_cli')
client.set_value('gcli_path', f'"{sys.executable}" "{os.path.abspath("tests/mock_gemini_cli.py")}"')
client.set_value('auto_add_history', True)
sim.run() # Ensure history is updated via the async queue
time.sleep(2)
sim.teardown()
@pytest.mark.integration
def test_execution_sim_live(live_gui: Any) -> None:
"""Run the Execution & Modals simulation against a live GUI."""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
sim = ExecutionSimulation(client)
sim.setup("LiveExecutionSim")
# Enable manual approval to test modals
client.set_value('manual_approve', True)
client.set_value('current_provider', 'gemini_cli')
client.set_value('gcli_path', f'"{sys.executable}" "{os.path.abspath("tests/mock_gemini_cli.py")}"')
client.set_value('auto_add_history', True)
sim.run()
time.sleep(2)
sim.teardown()