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:
@@ -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