Files
manual_slop/tests/visual_mma_verification.py

185 lines
7.2 KiB
Python

import subprocess
import time
import sys
import os
import glob # Will be used to find api_hook_client.py path if needed, though sys.path modification is better.
# --- Configuration ---
GUI_SCRIPT = 'gui_2.py'
TEST_HOOKS_FLAG = '--enable-test-hooks'
API_HOOK_CLIENT_MODULE = 'api_hook_client'
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) # Calculate project root
# Ensure project root is in sys.path to import modules like api_hook_client
if PROJECT_ROOT not in sys.path:
sys.path.insert(0, PROJECT_ROOT)
print(f"Added '{PROJECT_ROOT}' to sys.path for imports.")
try:
from api_hook_client import ApiHookClient
except ImportError as e:
print(f"Error: Could not import ApiHookClient from '{API_HOOK_CLIENT_MODULE}'.")
print(f"Please ensure '{API_HOOK_CLIENT_MODULE}.py' is accessible and '{PROJECT_ROOT}' is correctly added to sys.path.")
print(f"Import error: {e}")
sys.exit(1)
def run_visual_mma_verification():
print("Starting visual MMA verification test...")
# Change current directory to project root to ensure relative paths are correct for gui_2.py
original_dir = os.getcwd()
if original_dir != PROJECT_ROOT:
try:
os.chdir(PROJECT_ROOT)
print(f"Changed current directory to: {PROJECT_ROOT}")
except FileNotFoundError:
print(f"Error: Project root directory '{PROJECT_ROOT}' not found.")
return
# 1. Launch gui_2.py with --enable-test-hooks
gui_command = [sys.executable, GUI_SCRIPT, TEST_HOOKS_FLAG]
print(f"Launching GUI with command: {' '.join(gui_command)}")
try:
gui_process = subprocess.Popen(
gui_command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
cwd=PROJECT_ROOT # Explicitly set working directory
)
print(f"GUI process started with PID: {gui_process.pid}")
except FileNotFoundError:
print(f"Error: Could not find Python executable '{sys.executable}' or script '{GUI_SCRIPT}'.")
return
except Exception as e:
print(f"Error starting GUI process: {e}")
return
# Give the GUI a moment to start and open the hook server.
print("Waiting for GUI to initialize and hook server to start (5 seconds)...")
time.sleep(5)
# Check if the GUI process exited prematurely
if gui_process.poll() is not None:
print(f"Error: GUI process exited prematurely with return code {gui_process.returncode}.")
stderr_output = gui_process.stderr.read()
if stderr_output:
print("--- GUI Stderr ---")
print(stderr_output)
print("------------------")
return
# 2. Use api_hook_client.ApiHookClient to push events
try:
client = ApiHookClient()
print("ApiHookClient initialized successfully.")
except Exception as e:
print(f"Failed to initialize ApiHookClient. Ensure the hook server is running on port 8999. Error: {e}")
if gui_process:
gui_process.terminate()
gui_process.wait()
return
# 3. Include at least 5 tickets in different states
track_data = {
"id": "visual_test_track",
"title": "Visual Verification Track",
"description": "A track to verify MMA UI components"
}
tickets_data = [
{"id": "TICKET-001", "target_file": "core.py", "status": "todo"},
{"id": "TICKET-002", "target_file": "utils.py", "status": "running"},
{"id": "TICKET-003", "target_file": "tests.py", "status": "complete"},
{"id": "TICKET-004", "target_file": "api.py", "status": "blocked"},
{"id": "TICKET-005", "target_file": "gui.py", "status": "paused"},
]
print("\nPushing MMA state update...")
try:
payload = {
"status": "running",
"active_tier": "Tier 3",
"track": track_data,
"tickets": tickets_data
}
client.push_event("mma_state_update", payload)
print(" - MMA state update pushed.")
except Exception as e:
print(f" - Warning: Failed to push mma_state_update: {e}")
# 4. After a short delay, push an 'mma_step_approval' event
print("\nWaiting for GUI to render ticket queue and progress bar (3 seconds)...")
time.sleep(3)
print("Pushing 'mma_step_approval' event to trigger HITL modal...")
try:
approval_payload = {
"ticket_id": "TICKET-002",
"payload": "powershell -Command \"Write-Host 'Hello from Tier 3'\""
}
client.push_event("mma_step_approval", approval_payload)
print("mma_step_approval event pushed successfully.")
except Exception as e:
print(f"Error pushing mma_step_approval event: {e}")
# 5. Provide clear print statements for manual verification
print("
--- Manual Verification Instructions ---")
print("Please visually inspect the running GUI application:")
print("1. MMA Dashboard: Ensure the 'MMA Dashboard' panel is visible and active.")
print("2. Ticket Queue: Verify the 'Ticket Queue' section displays all 5 tickets with correct statuses:")
print(" - TICKET-001: Should be 'todo'")
print(" - TICKET-002: Should be 'running'")
print(" - TICKET-003: Should be 'complete'")
print(" - TICKET-004: Should be 'blocked'")
print(" - TICKET-005: Should be 'paused'")
print(" Observe the distinct status colors for each ticket.")
print("3. Progress Bar: Check that the progress bar correctly reflects the completed/total tickets (e.g., 1/5).")
print("4. Approval Modal: Confirm that an 'MMA Step Approval' modal has appeared.")
print(" - Verify it contains a 'Proposed Tool Call' section (e.g., showing 'powershell -Command...').")
print(" - Ensure there is an option/button to 'Edit Payload'.")
print("
--------------------------------------")
print("The test script has finished its automated actions.")
print("The GUI application is still running. Please perform manual verification.")
print("Press Enter in this terminal to stop the GUI process and exit the test script.")
try:
input()
except EOFError:
print("EOF received, exiting.")
pass
print("
Stopping GUI process...")
if gui_process:
try:
gui_process.terminate()
gui_process.wait(timeout=10)
print("GUI process terminated gracefully.")
except subprocess.TimeoutExpired:
print("GUI process did not terminate within the timeout. Killing it forcefully.")
gui_process.kill()
gui_process.wait()
except Exception as e:
print(f"Error during GUI process termination: {e}")
else:
print("GUI process was not started or already terminated.")
print("Visual MMA verification test script finished.")
# Restore original directory
if original_dir != PROJECT_ROOT:
try:
os.chdir(original_dir)
print(f"Restored original working directory: {original_dir}")
except FileNotFoundError:
print(f"Warning: Could not restore original working directory '{original_dir}'.")
# --- Main execution ---
if __name__ == "__main__":
# When the script is executed directly, ensure it runs from the correct context.
run_visual_mma_verification()