import pytest 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__), ".."))) from api_hook_client import ApiHookClient @pytest.mark.integration def test_mma_complete_lifecycle(live_gui) -> None: """ Tests the entire MMA lifecycle from epic planning to track loading and ticket verification in a single test case to avoid state dependency issues between separate test functions. """ client = ApiHookClient() assert client.wait_for_server(timeout=10) # 1. Set model to 'mock'. try: client.set_value('current_model', 'mock') except Exception as e: pytest.fail(f"Failed to set model to 'mock': {e}") # 2. Enter epic and click 'Plan Epic'. client.set_value('mma_epic_input', 'Develop a new feature') client.click('btn_mma_plan_epic') # 3. Wait for 'proposed_tracks'. proposed_tracks_found = False for _ in range(60): # Poll for up to 60 seconds status = client.get_mma_status() print(f"Polling status: {status}") # Assuming 'ai_status' might be a key within the status dictionary. If not, this needs adjustment. print(f"Polling ai_status: {status.get('ai_status', 'N/A')}") if status and status.get('proposed_tracks') and len(status['proposed_tracks']) > 0: proposed_tracks_found = True break time.sleep(1) assert proposed_tracks_found, "Failed to find proposed tracks after planning epic." # 4. Click 'Accept' to start tracks. client.click('btn_mma_accept_tracks') # 5. Wait for 'tracks' list to populate. tracks_populated = False for _ in range(30): # Poll for up to 30 seconds status = client.get_mma_status() if status and status.get('tracks') and len(status['tracks']) > 0: tracks_populated = True break time.sleep(1) assert tracks_populated, "Failed to populate tracks list after accepting proposed tracks." # 6. Verify that one of the new tracks can be loaded and its tickets appear in 'active_tickets'. status_after_tracks = client.get_mma_status() assert status_after_tracks is not None, "Failed to get MMA status after tracks populated." tracks_list = status_after_tracks.get('tracks') assert tracks_list is not None and len(tracks_list) > 0, "Tracks list is empty or not found." track_id_to_load = tracks_list[0]['id'] print(f"Attempting to load track with ID: {track_id_to_load}") # Load the first track client.click('btn_mma_load_track', user_data=track_id_to_load) # Poll until 'active_track' is not None and 'active_tickets' are present active_track_and_tickets_found = False for _ in range(60): # Poll for up to 60 seconds status = client.get_mma_status() if status and status.get('active_track') == track_id_to_load and \ 'active_tickets' in status and len(status['active_tickets']) > 0: active_track_and_tickets_found = True break time.sleep(1) assert active_track_and_tickets_found, f"Timed out waiting for track {track_id_to_load} to load and populate active tickets." print(f"Successfully loaded and verified track ID: {track_id_to_load} with active tickets.")