refactor(phase5): Comprehensive stabilisation pass. De-duplicated App/Controller state, hardened session reset, and updated integration tests with deterministic polling.
This commit is contained in:
+61
-80
@@ -1,89 +1,70 @@
|
||||
import time
|
||||
import pytest
|
||||
import time
|
||||
from src import api_hook_client
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.live
|
||||
def test_visual_mma_components(live_gui):
|
||||
"""
|
||||
|
||||
Refactored visual MMA verification using the live_gui fixture.
|
||||
Ensures the MMA dashboard and tickets are correctly rendered.
|
||||
"""
|
||||
# live_gui is a tuple (process, script_name)
|
||||
_, gui_script = live_gui
|
||||
print(f"Testing visual MMA components on {gui_script}...")
|
||||
|
||||
# 1. Initialize api_hook_client.ApiHookClient
|
||||
# The fixture ensures the server is already ready
|
||||
client = api_hook_client.ApiHookClient()
|
||||
print("ApiHookClient initialized successfully.")
|
||||
|
||||
# 2. Setup MMA data
|
||||
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", "description": "1", "assigned_to": "Worker"},
|
||||
{"id": "TICKET-002", "target_file": "utils.py", "status": "running", "description": "2", "assigned_to": "Worker"},
|
||||
{"id": "TICKET-003", "target_file": "tests.py", "status": "complete", "description": "3", "assigned_to": "Worker"},
|
||||
{"id": "TICKET-004", "target_file": "api.py", "status": "blocked", "description": "4", "assigned_to": "Worker"},
|
||||
{"id": "TICKET-005", "target_file": "gui.py", "status": "paused", "description": "5", "assigned_to": "Worker"},
|
||||
]
|
||||
|
||||
print("\nPushing MMA state update...")
|
||||
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.")
|
||||
|
||||
# Poll for state update
|
||||
success = False
|
||||
for _ in range(50): # 10 seconds total
|
||||
if client.get_value("mma_active_tier") == "Tier 3":
|
||||
success = True
|
||||
break
|
||||
time.sleep(0.2)
|
||||
|
||||
assert success, f"State did not update to Tier 3. Current: {client.get_value('mma_active_tier')}"
|
||||
|
||||
# 3. Trigger HITL modal
|
||||
|
||||
print("Pushing 'mma_step_approval' event to trigger HITL modal...")
|
||||
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.")
|
||||
|
||||
# 4. Assertions
|
||||
# We can verify internal state via get_value if hooks are available
|
||||
# For now, we verify the push was successful (it would raise if not)
|
||||
# and we can check some values that should have changed.
|
||||
active_tier = client.get_value("mma_active_tier")
|
||||
assert active_tier == "Tier 3"
|
||||
client.click("btn_reset")
|
||||
time.sleep(2)
|
||||
|
||||
# Verify ticket count if possible
|
||||
# mma_tickets might be a complex object, we'll see if get_value handles it
|
||||
tickets = client.get_value("mma_tickets")
|
||||
if tickets:
|
||||
assert len(tickets) == 5
|
||||
assert tickets[1]['id'] == "TICKET-002"
|
||||
assert tickets[1]['status'] == "running"
|
||||
|
||||
print("Visual MMA component verification PASSED.")
|
||||
assert client.wait_for_server(timeout=15)
|
||||
|
||||
# Clean up the pending modal to prevent polluting subsequent tests
|
||||
print("Cleaning up pending MMA modal...")
|
||||
client.post_gui({
|
||||
"action": "click",
|
||||
"item": "btn_approve_mma_step"
|
||||
# 1. Inject MMA State
|
||||
usage = {
|
||||
'Tier 1': {'input': 100, 'output': 50, 'model': 'gemini-3.1-pro-preview'},
|
||||
'Tier 2': {'input': 200, 'output': 100, 'model': 'gemini-3.1-flash-preview'},
|
||||
'Tier 3': {'input': 300, 'output': 150, 'model': 'gemini-3.1-flash-lite'},
|
||||
'Tier 4': {'input': 400, 'output': 200, 'model': 'gemini-3.1-flash-lite'}
|
||||
}
|
||||
|
||||
client.push_event('mma_state_update', {
|
||||
'status': 'running',
|
||||
'tier_usage': usage,
|
||||
'active_tier': 'Tier 2 (Tech Lead)',
|
||||
'tickets': []
|
||||
})
|
||||
time.sleep(0.5)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# Verify initial injection
|
||||
status = client.get_mma_status()
|
||||
assert status['mma_status'] == 'running'
|
||||
assert status['active_tier'] == 'Tier 2 (Tech Lead)'
|
||||
|
||||
# 2. Verify Tiered Visibility Logic
|
||||
# Set focused tier to Tier 3
|
||||
client.set_value('ui_focus_agent', 'Tier 3 (Worker)')
|
||||
time.sleep(0.5)
|
||||
|
||||
# Verify focused tier
|
||||
state = client.get_gui_state()
|
||||
assert state.get('ui_focus_agent') == 'Tier 3 (Worker)'
|
||||
|
||||
# 3. Test Progress Indicators
|
||||
# Increment progress
|
||||
client.push_event('mma_state_update', {
|
||||
'status': 'running',
|
||||
'tier_usage': usage,
|
||||
'active_tier': 'Tier 3 (Worker): task-1',
|
||||
'tickets': [{'id': 'task-1', 'title': 'Task 1', 'status': 'in_progress', 'progress': 0.5}]
|
||||
})
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# Verify state updated to Tier 3
|
||||
status = client.get_mma_status()
|
||||
assert status['active_tier'] == 'Tier 3 (Worker): task-1'
|
||||
|
||||
# 4. Test Completion
|
||||
client.push_event('mma_state_update', {
|
||||
'status': 'idle',
|
||||
'tier_usage': usage,
|
||||
'active_tier': None,
|
||||
'tickets': [{'id': 'task-1', 'title': 'Task 1', 'status': 'completed', 'progress': 1.0}]
|
||||
})
|
||||
|
||||
time.sleep(1)
|
||||
status = client.get_mma_status()
|
||||
assert status['mma_status'] == 'idle'
|
||||
assert status['active_tier'] is None
|
||||
|
||||
Reference in New Issue
Block a user