conductor(checkpoint): Test integrity audit complete
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
"""
|
||||
ANTI-SIMPLIFICATION: These tests verify core GUI state management and cross-thread event handling.
|
||||
They MUST NOT be simplified to just set state directly, as their entire purpose is to test the event pipeline.
|
||||
"""
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
import sys
|
||||
@@ -13,7 +17,8 @@ from src.gui_2 import App
|
||||
def test_telemetry_data_updates_correctly(app_instance: Any) -> None:
|
||||
"""
|
||||
Tests that the _refresh_api_metrics method correctly updates
|
||||
the internal state for display.
|
||||
the internal state for display by querying the ai_client.
|
||||
Verifies the boundary between GUI state and API state.
|
||||
"""
|
||||
# 1. Set the provider to anthropic
|
||||
app_instance._current_provider = "anthropic"
|
||||
@@ -29,20 +34,42 @@ def test_telemetry_data_updates_correctly(app_instance: Any) -> None:
|
||||
# 4. Call the method under test
|
||||
app_instance._refresh_api_metrics({}, md_content="test content")
|
||||
# 5. Assert the results
|
||||
# ANTI-SIMPLIFICATION: Must assert that the actual getter was called to prevent broken dependencies
|
||||
mock_get_stats.assert_called_once()
|
||||
# ANTI-SIMPLIFICATION: Must assert that the specific field is updated correctly in the GUI state
|
||||
assert app_instance._token_stats["percentage"] == 75.0
|
||||
|
||||
def test_performance_history_updates(app_instance: Any) -> None:
|
||||
"""
|
||||
Verify the data structure that feeds the sparkline.
|
||||
This ensures that the rolling buffer for performance telemetry maintains
|
||||
the correct size and default initialization to prevent GUI rendering crashes.
|
||||
"""
|
||||
# ANTI-SIMPLIFICATION: Verifying exactly 100 elements ensures the sparkline won't overflow
|
||||
assert len(app_instance.perf_history["frame_time"]) == 100
|
||||
assert app_instance.perf_history["frame_time"][-1] == 0.0
|
||||
|
||||
def test_gui_updates_on_event(app_instance: App) -> None:
|
||||
mock_stats = {"utilization_pct": 50.0, "estimated_prompt_tokens": 500, "max_prompt_tokens": 1000}
|
||||
"""
|
||||
Verifies that when an API event is received (e.g. from ai_client),
|
||||
the _on_api_event handler correctly updates internal metrics and
|
||||
queues the update to be processed by the GUI event loop.
|
||||
"""
|
||||
mock_stats = {"percentage": 50.0, "current": 500, "limit": 1000}
|
||||
app_instance.last_md = "mock_md"
|
||||
app_instance._token_stats = mock_stats
|
||||
app_instance._token_stats_dirty = True
|
||||
app_instance._process_pending_gui_tasks()
|
||||
assert app_instance._token_stats["utilization_pct"] == 50.0
|
||||
with patch('src.ai_client.get_token_stats', return_value=mock_stats):
|
||||
# Simulate receiving an event from the API client thread
|
||||
app_instance._on_api_event(payload={"text": "test"})
|
||||
|
||||
# Manually route event from background queue to GUI tasks (simulating event loop thread)
|
||||
event_name, payload = app_instance.event_queue.get()
|
||||
app_instance._pending_gui_tasks.append({
|
||||
"action": event_name,
|
||||
"payload": payload
|
||||
})
|
||||
|
||||
# Process the event queue (simulating the GUI event loop tick)
|
||||
app_instance._process_pending_gui_tasks()
|
||||
# ANTI-SIMPLIFICATION: This assertion proves that the event pipeline
|
||||
# successfully transmitted state from the background thread to the GUI state.
|
||||
assert app_instance._token_stats["percentage"] == 50.0
|
||||
|
||||
Reference in New Issue
Block a user