checkpoint: mma_orchestrator track
This commit is contained in:
80
tests/test_mma_orchestration_gui.py
Normal file
80
tests/test_mma_orchestration_gui.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
import threading
|
||||
import time
|
||||
from gui_2 import App
|
||||
|
||||
@pytest.fixture
|
||||
def app_instance():
|
||||
with (
|
||||
patch('gui_2.load_config', return_value={'ai': {}, 'projects': {}}),
|
||||
patch('gui_2.save_config'),
|
||||
patch('gui_2.project_manager'),
|
||||
patch('gui_2.session_logger'),
|
||||
patch('gui_2.immapp.run'),
|
||||
patch.object(App, '_load_active_project'),
|
||||
patch.object(App, '_fetch_models'),
|
||||
patch.object(App, '_load_fonts'),
|
||||
patch.object(App, '_post_init')
|
||||
):
|
||||
app = App()
|
||||
# Initialize the new state variables if they aren't there yet (they won't be until we implement them)
|
||||
if not hasattr(app, 'ui_epic_input'): app.ui_epic_input = ""
|
||||
if not hasattr(app, 'proposed_tracks'): app.proposed_tracks = []
|
||||
if not hasattr(app, '_show_track_proposal_modal'): app._show_track_proposal_modal = False
|
||||
yield app
|
||||
|
||||
def test_mma_ui_state_initialization(app_instance):
|
||||
"""Verifies that the new MMA UI state variables are initialized correctly."""
|
||||
assert hasattr(app_instance, 'ui_epic_input')
|
||||
assert hasattr(app_instance, 'proposed_tracks')
|
||||
assert hasattr(app_instance, '_show_track_proposal_modal')
|
||||
assert app_instance.ui_epic_input == ""
|
||||
assert app_instance.proposed_tracks == []
|
||||
assert app_instance._show_track_proposal_modal is False
|
||||
|
||||
def test_process_pending_gui_tasks_show_track_proposal(app_instance):
|
||||
"""Verifies that the 'show_track_proposal' action correctly updates the UI state."""
|
||||
mock_tracks = [{"id": "track_1", "title": "Test Track"}]
|
||||
task = {
|
||||
"action": "show_track_proposal",
|
||||
"payload": mock_tracks
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
|
||||
app_instance._process_pending_gui_tasks()
|
||||
|
||||
assert app_instance.proposed_tracks == mock_tracks
|
||||
assert app_instance._show_track_proposal_modal is True
|
||||
|
||||
def test_cb_plan_epic_launches_thread(app_instance):
|
||||
"""Verifies that _cb_plan_epic launches a thread and eventually queues a task."""
|
||||
app_instance.ui_epic_input = "Develop a new feature"
|
||||
app_instance.active_project_path = "test_project.toml"
|
||||
|
||||
mock_tracks = [{"id": "track_1", "title": "Test Track"}]
|
||||
|
||||
with patch('orchestrator_pm.get_track_history_summary', return_value="History summary") as mock_get_history,
|
||||
patch('orchestrator_pm.generate_tracks', return_value=mock_tracks) as mock_gen_tracks,
|
||||
patch('aggregate.build_file_items', return_value=[]) as mock_build_files:
|
||||
|
||||
# We need to mock project_manager.flat_config and project_manager.load_project
|
||||
with patch('project_manager.load_project', return_value={}),
|
||||
patch('project_manager.flat_config', return_value={}):
|
||||
|
||||
app_instance._cb_plan_epic()
|
||||
|
||||
# Wait for the background thread to finish (it should be quick with mocks)
|
||||
# In a real test, we might need a more robust way to wait, but for now:
|
||||
max_wait = 5
|
||||
start_time = time.time()
|
||||
while len(app_instance._pending_gui_tasks) == 0 and time.time() - start_time < max_wait:
|
||||
time.sleep(0.1)
|
||||
|
||||
assert len(app_instance._pending_gui_tasks) > 0
|
||||
task = app_instance._pending_gui_tasks[0]
|
||||
assert task['action'] == 'show_track_proposal'
|
||||
assert task['payload'] == mock_tracks
|
||||
|
||||
mock_get_history.assert_called_once()
|
||||
mock_gen_tracks.assert_called_once()
|
||||
Reference in New Issue
Block a user