Private
Public Access
0
0

test(ai_client): rename send_result to send in test_conductor_engine_v2

22 references renamed (mostly monkeypatch.setattr calls + comments).
Test file state: GREEN. All 10 tests in this file now pass.
This commit is contained in:
2026-06-17 00:29:21 -04:00
parent d714d10fd4
commit 3e2b4f74ba
2 changed files with 46 additions and 22 deletions
+24
View File
@@ -0,0 +1,24 @@
"""Rename send_result -> send in a single test file (idempotent: only renames occurrences of send_result)."""
from __future__ import annotations
import sys
from pathlib import Path
def main() -> int:
rel = sys.argv[1]
p = Path(rel)
with p.open("r", encoding="utf-8", newline="") as f:
content = f.read()
has_crlf = "\r\n" in content
new_content = content.replace("send_result", "send")
with p.open("w", encoding="utf-8", newline="") as f:
f.write(new_content)
remaining = new_content.count("send_result")
before = content.count("send_result")
print(f"{rel}: renamed {before - remaining} occurrences; remaining={remaining}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+22 -22
View File
@@ -35,9 +35,9 @@ def test_conductor_engine_run_executes_tickets_in_order(monkeypatch: pytest.Monk
vlogger.log_state("T1 Status", "todo", "todo")
vlogger.log_state("T2 Status", "todo", "todo")
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
# We mock run_worker_lifecycle as it is expected to be in the same module
with patch("src.multi_agent_conductor.run_worker_lifecycle") as mock_lifecycle:
# Mocking lifecycle to mark ticket as complete so dependencies can be resolved
@@ -76,15 +76,15 @@ def test_run_worker_lifecycle_calls_ai_client_send(monkeypatch: pytest.MonkeyPat
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
from src.multi_agent_conductor import run_worker_lifecycle
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
mock_send.return_value = Result(data="Task complete. I have updated the file.")
result = run_worker_lifecycle(ticket, context)
assert result == "Task complete. I have updated the file."
assert ticket.status == "completed"
mock_send.assert_called_once()
# Check if description was passed to send_result()
# Check if description was passed to send()
args, kwargs = mock_send.call_args
# user_message is passed as a keyword argument
assert ticket.description in kwargs["user_message"]
@@ -99,9 +99,9 @@ def test_run_worker_lifecycle_context_injection(monkeypatch: pytest.MonkeyPatch)
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
context_files = ["primary.py", "secondary.py"]
from src.multi_agent_conductor import run_worker_lifecycle
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
# We mock ASTParser which is expected to be imported in multi_agent_conductor
with patch("src.multi_agent_conductor.ASTParser") as mock_ast_parser_class, \
patch("builtins.open", new_callable=MagicMock) as mock_open:
@@ -145,9 +145,9 @@ def test_run_worker_lifecycle_handles_blocked_response(monkeypatch: pytest.Monke
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1")
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
from src.multi_agent_conductor import run_worker_lifecycle
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
# Simulate a response indicating a block
mock_send.return_value = Result(data="I am BLOCKED because I don't have enough information.")
run_worker_lifecycle(ticket, context)
@@ -158,16 +158,16 @@ def test_run_worker_lifecycle_step_mode_confirmation(monkeypatch: pytest.MonkeyP
"""
Test that run_worker_lifecycle passes confirm_execution to ai_client.send_result when step_mode is True.
Verify that if confirm_execution is called (simulated by mocking ai_client.send_result to call its callback),
Test that run_worker_lifecycle passes confirm_execution to ai_client.send when step_mode is True.
Verify that if confirm_execution is called (simulated by mocking ai_client.send to call its callback),
the flow works as expected.
"""
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1", step_mode=True)
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
from src.multi_agent_conductor import run_worker_lifecycle
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
# Important: confirm_spawn is called first if event_queue is present!
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
@@ -202,9 +202,9 @@ def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.MonkeyPatc
ticket = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker1", step_mode=True)
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
from src.multi_agent_conductor import run_worker_lifecycle
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
patch("src.multi_agent_conductor.confirm_execution") as mock_confirm:
mock_spawn.return_value = (True, "mock prompt", "mock context")
@@ -214,7 +214,7 @@ def test_run_worker_lifecycle_step_mode_rejection(monkeypatch: pytest.MonkeyPatc
mock_event_queue = MagicMock()
run_worker_lifecycle(ticket, context, event_queue=mock_event_queue)
# Verify it was passed to send_result
# Verify it was passed to send
args, kwargs = mock_send.call_args
assert kwargs["pre_tool_callback"] is not None
@@ -258,9 +258,9 @@ def test_conductor_engine_dynamic_parsing_and_execution(monkeypatch: pytest.Monk
assert engine.track.tickets[0].id == "T1"
assert engine.track.tickets[1].id == "T2"
assert engine.track.tickets[2].id == "T3"
# Mock ai_client.send_result using monkeypatch
# Mock ai_client.send using monkeypatch
mock_send = MagicMock()
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
# Mock run_worker_lifecycle to mark tickets as complete
with patch("src.multi_agent_conductor.run_worker_lifecycle") as mock_lifecycle:
def side_effect(ticket, context, *args, **kwargs):
@@ -298,7 +298,7 @@ def test_run_worker_lifecycle_pushes_response_via_queue(monkeypatch: pytest.Monk
context = WorkerContext(ticket_id="T1", model_name="test-model", messages=[])
mock_event_queue = MagicMock()
mock_send = MagicMock(return_value=Result(data="Task complete."))
monkeypatch.setattr(ai_client, 'send_result', mock_send)
monkeypatch.setattr(ai_client, 'send', mock_send)
monkeypatch.setattr(ai_client, 'reset_session', MagicMock())
from src.multi_agent_conductor import run_worker_lifecycle
with patch("src.multi_agent_conductor.confirm_spawn") as mock_spawn, \
@@ -327,11 +327,11 @@ def test_run_worker_lifecycle_token_usage_from_comms_log(monkeypatch: pytest.Mon
{"direction": "OUT", "kind": "request", "payload": {"message": "hello"}},
{"direction": "IN", "kind": "response", "payload": {"usage": {"input_tokens": 120, "output_tokens": 45}}},
]
monkeypatch.setattr(ai_client, 'send_result', MagicMock(return_value=Result(data="Done.")))
monkeypatch.setattr(ai_client, 'send', MagicMock(return_value=Result(data="Done.")))
monkeypatch.setattr(ai_client, 'reset_session', MagicMock())
monkeypatch.setattr(ai_client, 'get_comms_log', MagicMock(side_effect=[
[], # baseline call (before send_result)
fake_comms, # after-send_result call
[], # baseline call (before send)
fake_comms, # after-send call
]))
from src.multi_agent_conductor import run_worker_lifecycle, ConductorEngine
track = Track(id="test_track", description="Test")