Private
Public Access
fix: Robustness improvements for RAG tests and GUI stability
- Added import sys to src/api_hook_client.py. - Fixed App.__getattr__ to use direct attribute access on controller to avoid recursion. - Simplified _get_app_attr and _has_app_attr in src/api_hooks.py. - Centralized RAG and symbol enrichment in AppController._handle_request_event. - Updated ests/test_symbol_parsing.py to match the new enrichment flow. - Removed redundant task appending from i_status and mma_status setters. - Improved _sync_rag_engine to only set 'ready' status after indexing is confirmed. - Updated est_status_encapsulation.py to reflect setter changes.
This commit is contained in:
@@ -26,6 +26,7 @@ def test_phase4_final_verify(live_gui):
|
||||
|
||||
try:
|
||||
# 2. Configure project through Hook API
|
||||
client.set_value('rag_collection_name', 'test_final_verify')
|
||||
client.set_value('files', ['final_test_1.txt', 'final_test_2.py'])
|
||||
client.set_value('rag_enabled', True)
|
||||
client.set_value('rag_source', 'chroma')
|
||||
|
||||
@@ -27,6 +27,7 @@ def test_rag_large_codebase_verification_sim(live_gui):
|
||||
|
||||
try:
|
||||
# 2. Configure project through Hook API
|
||||
client.set_value('rag_collection_name', 'test_stress')
|
||||
client.set_value('files', file_names)
|
||||
client.set_value('rag_enabled', True)
|
||||
client.set_value('rag_source', 'chroma')
|
||||
@@ -97,14 +98,18 @@ def test_rag_large_codebase_verification_sim(live_gui):
|
||||
|
||||
# Wait for completion
|
||||
success = False
|
||||
status = "unknown"
|
||||
for _ in range(50):
|
||||
state = client.get_gui_state()
|
||||
if state.get('ai_status') == 'done':
|
||||
status = state.get('ai_status', 'unknown')
|
||||
if status == 'done':
|
||||
success = True
|
||||
break
|
||||
if "error" in status.lower():
|
||||
pytest.fail(f"AI request failed with error: {status}")
|
||||
time.sleep(0.5)
|
||||
|
||||
assert success, "AI request timed out"
|
||||
assert success, f"AI request timed out. Final status: {status}"
|
||||
|
||||
# Verify retrieved context in discussion
|
||||
session = client.get_session()
|
||||
|
||||
@@ -11,7 +11,8 @@ def test_status_properties():
|
||||
controller = app_controller.AppController()
|
||||
controller.ai_status = 'busy'
|
||||
assert controller._ai_status == 'busy'
|
||||
assert any(t.get('action') == 'set_ai_status' and t.get('value') == 'busy' for t in controller._pending_gui_tasks)
|
||||
# No longer using tasks for simple status updates as ImGui reads them directly
|
||||
assert not any(t.get('action') == 'set_ai_status' for t in controller._pending_gui_tasks)
|
||||
controller.mma_status = 'active'
|
||||
assert controller._mma_status == 'active'
|
||||
assert any(t.get('action') == 'set_mma_status' and t.get('value') == 'active' for t in controller._pending_gui_tasks)
|
||||
assert not any(t.get('action') == 'set_mma_status' for t in controller._pending_gui_tasks)
|
||||
|
||||
@@ -3,6 +3,7 @@ from unittest.mock import MagicMock, patch
|
||||
from pathlib import Path
|
||||
from src.app_controller import AppController
|
||||
from src.events import UserRequestEvent
|
||||
from src import events
|
||||
|
||||
@pytest.fixture
|
||||
def controller():
|
||||
@@ -26,60 +27,57 @@ def controller():
|
||||
c.event_queue = MagicMock()
|
||||
return c
|
||||
|
||||
def test_handle_generate_send_appends_definitions(controller):
|
||||
def test_handle_request_event_appends_definitions(controller):
|
||||
# Setup
|
||||
file_items = [{"path": "src/models.py", "entry": "src/models.py"}]
|
||||
controller._do_generate = MagicMock(return_value=(
|
||||
"full_md", Path("output.md"), file_items, "stable_md", "disc_text"
|
||||
))
|
||||
controller.ui_ai_input = "Explain @Track object"
|
||||
event = UserRequestEvent(
|
||||
prompt="Explain @Track object",
|
||||
stable_md="stable_md",
|
||||
file_items=file_items,
|
||||
disc_text="disc_text",
|
||||
base_dir="."
|
||||
)
|
||||
|
||||
# Mock symbol helpers
|
||||
with (
|
||||
patch('src.app_controller.parse_symbols', return_value=["Track"]) as mock_parse,
|
||||
patch('src.app_controller.get_symbol_definition', return_value=("src/models.py", "class Track: pass", 42)) as mock_get_def,
|
||||
patch('threading.Thread') as mock_thread
|
||||
patch('src.ai_client.send') as mock_send
|
||||
):
|
||||
# Execute
|
||||
controller._handle_generate_send()
|
||||
|
||||
# Run worker manually
|
||||
worker = mock_thread.call_args[1]['target']
|
||||
worker()
|
||||
controller._handle_request_event(event)
|
||||
|
||||
# Verify
|
||||
mock_parse.assert_called_once_with("Explain @Track object")
|
||||
mock_get_def.assert_called_once()
|
||||
|
||||
controller.event_queue.put.assert_called_once()
|
||||
event_name, event_payload = controller.event_queue.put.call_args[0]
|
||||
assert event_name == "user_request"
|
||||
assert isinstance(event_payload, UserRequestEvent)
|
||||
|
||||
# Check if definition was appended
|
||||
# Check if enriched prompt was sent to AI
|
||||
expected_suffix = "\n\n[Definition: Track from src/models.py (line 42)]\n```python\nclass Track: pass\n```"
|
||||
assert event_payload.prompt == "Explain @Track object" + expected_suffix
|
||||
mock_send.assert_called_once()
|
||||
args, kwargs = mock_send.call_args
|
||||
sent_prompt = args[1]
|
||||
assert sent_prompt == "Explain @Track object" + expected_suffix
|
||||
|
||||
def test_handle_generate_send_no_symbols(controller):
|
||||
def test_handle_request_event_no_symbols(controller):
|
||||
# Setup
|
||||
file_items = [{"path": "src/models.py", "entry": "src/models.py"}]
|
||||
controller._do_generate = MagicMock(return_value=(
|
||||
"full_md", Path("output.md"), file_items, "stable_md", "disc_text"
|
||||
))
|
||||
controller.ui_ai_input = "Just a normal prompt"
|
||||
event = UserRequestEvent(
|
||||
prompt="Just a normal prompt",
|
||||
stable_md="stable_md",
|
||||
file_items=file_items,
|
||||
disc_text="disc_text",
|
||||
base_dir="."
|
||||
)
|
||||
|
||||
with (
|
||||
patch('src.app_controller.parse_symbols', return_value=[]) as mock_parse,
|
||||
patch('threading.Thread') as mock_thread
|
||||
patch('src.ai_client.send') as mock_send
|
||||
):
|
||||
# Execute
|
||||
controller._handle_generate_send()
|
||||
|
||||
# Run worker manually
|
||||
worker = mock_thread.call_args[1]['target']
|
||||
worker()
|
||||
controller._handle_request_event(event)
|
||||
|
||||
# Verify
|
||||
controller.event_queue.put.assert_called_once()
|
||||
_, event_payload = controller.event_queue.put.call_args[0]
|
||||
assert event_payload.prompt == "Just a normal prompt"
|
||||
mock_send.assert_called_once()
|
||||
args, kwargs = mock_send.call_args
|
||||
sent_prompt = args[1]
|
||||
assert sent_prompt == "Just a normal prompt"
|
||||
|
||||
Reference in New Issue
Block a user