checkpoint: massive refactor
This commit is contained in:
@@ -7,141 +7,126 @@ 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
|
||||
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 hasattr(app_instance, 'mma_streams')
|
||||
assert app_instance.ui_epic_input == ""
|
||||
assert app_instance.proposed_tracks == []
|
||||
assert app_instance._show_track_proposal_modal is False
|
||||
assert app_instance.mma_streams == {}
|
||||
"""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 hasattr(app_instance, 'mma_streams')
|
||||
assert app_instance.ui_epic_input == ""
|
||||
assert app_instance.proposed_tracks == []
|
||||
assert app_instance._show_track_proposal_modal is False
|
||||
assert app_instance.mma_streams == {}
|
||||
|
||||
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
|
||||
"""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)
|
||||
max_wait = 5
|
||||
start_time = time.time()
|
||||
while len(app_instance._pending_gui_tasks) < 2 and time.time() - start_time < max_wait:
|
||||
time.sleep(0.1)
|
||||
|
||||
assert len(app_instance._pending_gui_tasks) == 2
|
||||
|
||||
task1 = app_instance._pending_gui_tasks[0]
|
||||
assert task1['action'] == 'handle_ai_response'
|
||||
assert task1['payload']['stream_id'] == 'Tier 1'
|
||||
assert task1['payload']['text'] == json.dumps(mock_tracks, indent=2)
|
||||
|
||||
task2 = app_instance._pending_gui_tasks[1]
|
||||
assert task2['action'] == 'show_track_proposal'
|
||||
assert task2['payload'] == mock_tracks
|
||||
|
||||
mock_get_history.assert_called_once()
|
||||
mock_gen_tracks.assert_called_once()
|
||||
"""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)
|
||||
max_wait = 5
|
||||
start_time = time.time()
|
||||
while len(app_instance._pending_gui_tasks) < 2 and time.time() - start_time < max_wait:
|
||||
time.sleep(0.1)
|
||||
assert len(app_instance._pending_gui_tasks) == 2
|
||||
task1 = app_instance._pending_gui_tasks[0]
|
||||
assert task1['action'] == 'handle_ai_response'
|
||||
assert task1['payload']['stream_id'] == 'Tier 1'
|
||||
assert task1['payload']['text'] == json.dumps(mock_tracks, indent=2)
|
||||
task2 = app_instance._pending_gui_tasks[1]
|
||||
assert task2['action'] == 'show_track_proposal'
|
||||
assert task2['payload'] == mock_tracks
|
||||
mock_get_history.assert_called_once()
|
||||
mock_gen_tracks.assert_called_once()
|
||||
|
||||
def test_process_pending_gui_tasks_mma_spawn_approval(app_instance):
|
||||
"""Verifies that the 'mma_spawn_approval' action correctly updates the UI state."""
|
||||
task = {
|
||||
"action": "mma_spawn_approval",
|
||||
"ticket_id": "T1",
|
||||
"role": "Tier 3 Worker",
|
||||
"prompt": "Test Prompt",
|
||||
"context_md": "Test Context",
|
||||
"dialog_container": [None]
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
|
||||
app_instance._process_pending_gui_tasks()
|
||||
|
||||
assert app_instance._pending_mma_spawn == task
|
||||
assert app_instance._mma_spawn_prompt == "Test Prompt"
|
||||
assert app_instance._mma_spawn_context == "Test Context"
|
||||
assert app_instance._mma_spawn_open is True
|
||||
assert app_instance._mma_spawn_edit_mode is False
|
||||
assert task["dialog_container"][0] is not None
|
||||
assert task["dialog_container"][0]._ticket_id == "T1"
|
||||
"""Verifies that the 'mma_spawn_approval' action correctly updates the UI state."""
|
||||
task = {
|
||||
"action": "mma_spawn_approval",
|
||||
"ticket_id": "T1",
|
||||
"role": "Tier 3 Worker",
|
||||
"prompt": "Test Prompt",
|
||||
"context_md": "Test Context",
|
||||
"dialog_container": [None]
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
assert app_instance._pending_mma_spawn == task
|
||||
assert app_instance._mma_spawn_prompt == "Test Prompt"
|
||||
assert app_instance._mma_spawn_context == "Test Context"
|
||||
assert app_instance._mma_spawn_open is True
|
||||
assert app_instance._mma_spawn_edit_mode is False
|
||||
assert task["dialog_container"][0] is not None
|
||||
assert task["dialog_container"][0]._ticket_id == "T1"
|
||||
|
||||
def test_handle_ai_response_with_stream_id(app_instance):
|
||||
"""Verifies routing to mma_streams."""
|
||||
task = {
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": "Tier 1 Strategy Content",
|
||||
"stream_id": "Tier 1",
|
||||
"status": "Thinking..."
|
||||
}
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
|
||||
assert app_instance.mma_streams.get("Tier 1") == "Tier 1 Strategy Content"
|
||||
assert app_instance.ai_status == "Thinking..."
|
||||
assert app_instance.ai_response == ""
|
||||
"""Verifies routing to mma_streams."""
|
||||
task = {
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": "Tier 1 Strategy Content",
|
||||
"stream_id": "Tier 1",
|
||||
"status": "Thinking..."
|
||||
}
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
assert app_instance.mma_streams.get("Tier 1") == "Tier 1 Strategy Content"
|
||||
assert app_instance.ai_status == "Thinking..."
|
||||
assert app_instance.ai_response == ""
|
||||
|
||||
def test_handle_ai_response_fallback(app_instance):
|
||||
"""Verifies fallback to ai_response when stream_id is missing."""
|
||||
task = {
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": "Regular AI Response",
|
||||
"status": "done"
|
||||
}
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
|
||||
assert app_instance.ai_response == "Regular AI Response"
|
||||
assert app_instance.ai_status == "done"
|
||||
assert len(app_instance.mma_streams) == 0
|
||||
"""Verifies fallback to ai_response when stream_id is missing."""
|
||||
task = {
|
||||
"action": "handle_ai_response",
|
||||
"payload": {
|
||||
"text": "Regular AI Response",
|
||||
"status": "done"
|
||||
}
|
||||
}
|
||||
app_instance._pending_gui_tasks.append(task)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
assert app_instance.ai_response == "Regular AI Response"
|
||||
assert app_instance.ai_status == "done"
|
||||
assert len(app_instance.mma_streams) == 0
|
||||
|
||||
Reference in New Issue
Block a user