feat(mma): Implement context injection using ASTParser in run_worker_lifecycle
This commit is contained in:
@@ -69,6 +69,58 @@ def test_run_worker_lifecycle_calls_ai_client_send():
|
||||
# user_message is passed as a keyword argument
|
||||
assert ticket.description in kwargs["user_message"]
|
||||
|
||||
def test_run_worker_lifecycle_context_injection():
|
||||
"""
|
||||
Test that run_worker_lifecycle can take a context_files list and injects AST views into the prompt.
|
||||
"""
|
||||
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
|
||||
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
|
||||
context_files = ["primary.py", "secondary.py"]
|
||||
|
||||
from multi_agent_conductor import run_worker_lifecycle
|
||||
|
||||
# We mock ASTParser which is expected to be imported in multi_agent_conductor
|
||||
with patch("ai_client.send") as mock_send, \
|
||||
patch("multi_agent_conductor.ASTParser") as mock_ast_parser_class, \
|
||||
patch("builtins.open", new_callable=MagicMock) as mock_open:
|
||||
|
||||
# Setup open mock to return different content for different files
|
||||
file_contents = {
|
||||
"primary.py": "def primary(): pass",
|
||||
"secondary.py": "def secondary(): pass"
|
||||
}
|
||||
|
||||
def mock_open_side_effect(file, *args, **kwargs):
|
||||
content = file_contents.get(file, "")
|
||||
mock_file = MagicMock()
|
||||
mock_file.read.return_value = content
|
||||
mock_file.__enter__.return_value = mock_file
|
||||
return mock_file
|
||||
|
||||
mock_open.side_effect = mock_open_side_effect
|
||||
|
||||
# Setup ASTParser mock
|
||||
mock_ast_parser = mock_ast_parser_class.return_value
|
||||
mock_ast_parser.get_curated_view.return_value = "CURATED VIEW"
|
||||
mock_ast_parser.get_skeleton.return_value = "SKELETON VIEW"
|
||||
|
||||
mock_send.return_value = "Success"
|
||||
|
||||
run_worker_lifecycle(ticket, context, context_files=context_files)
|
||||
|
||||
# Verify ASTParser calls:
|
||||
# First file (primary) should get curated view, others (secondary) get skeleton
|
||||
mock_ast_parser.get_curated_view.assert_called_once_with("def primary(): pass")
|
||||
mock_ast_parser.get_skeleton.assert_called_once_with("def secondary(): pass")
|
||||
|
||||
# Verify user_message contains the views
|
||||
_, kwargs = mock_send.call_args
|
||||
user_message = kwargs["user_message"]
|
||||
assert "CURATED VIEW" in user_message
|
||||
assert "SKELETON VIEW" in user_message
|
||||
assert "primary.py" in user_message
|
||||
assert "secondary.py" in user_message
|
||||
|
||||
def test_run_worker_lifecycle_handles_blocked_response():
|
||||
"""
|
||||
Test that run_worker_lifecycle marks the ticket as blocked if the AI indicates it cannot proceed.
|
||||
|
||||
Reference in New Issue
Block a user