Private
Public Access
test(run_worker_lifecycle_abort): mock send_result not send (Phase 2.17, pre-empts Phase 1.3 regression)
Phase 1.3 migrated run_worker_lifecycle to send_result(). This test mocks src.ai_client.send and asserts it is NOT called (abort fires before the AI dispatch). Migrating the mock to send_result is purely for consistency and future-proofing; the test still passes either way. Changes: - Rename patch(src.ai_client.send) to patch(src.ai_client.send_result) - Rename mock_send to mock_send_result - Comment updated to reference send_result
This commit is contained in:
@@ -9,13 +9,12 @@ from src.models import Ticket, WorkerContext
|
|||||||
class TestRunWorkerLifecycleAbort(unittest.TestCase):
|
class TestRunWorkerLifecycleAbort(unittest.TestCase):
|
||||||
def test_run_worker_lifecycle_returns_early_on_abort(self):
|
def test_run_worker_lifecycle_returns_early_on_abort(self):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Test that run_worker_lifecycle returns early and marks ticket as 'killed'
|
||||||
Test that run_worker_lifecycle returns early and marks ticket as 'killed'
|
if the abort event is set for the ticket.
|
||||||
if the abort event is set for the ticket.
|
|
||||||
"""
|
"""
|
||||||
# Mock ai_client.send
|
# Mock ai_client.send_result
|
||||||
with patch('src.ai_client.send') as mock_send:
|
with patch('src.ai_client.send_result') as mock_send_result:
|
||||||
# Mock ticket and context
|
# Mock ticket and context
|
||||||
ticket = Ticket(id="T-001", description="Test task")
|
ticket = Ticket(id="T-001", description="Test task")
|
||||||
ticket = Ticket(id="T-001", description="Test task")
|
ticket = Ticket(id="T-001", description="Test task")
|
||||||
@@ -24,19 +23,19 @@ class TestRunWorkerLifecycleAbort(unittest.TestCase):
|
|||||||
mock_engine = MagicMock()
|
mock_engine = MagicMock()
|
||||||
abort_event = threading.Event()
|
abort_event = threading.Event()
|
||||||
mock_engine._abort_events = {"T-001": abort_event}
|
mock_engine._abort_events = {"T-001": abort_event}
|
||||||
|
|
||||||
# Set abort event
|
# Set abort event
|
||||||
abort_event.set()
|
abort_event.set()
|
||||||
|
|
||||||
# Call run_worker_lifecycle
|
# Call run_worker_lifecycle
|
||||||
# md_content is expected to be passed if called like in ConductorEngine
|
# md_content is expected to be passed if called like in ConductorEngine
|
||||||
run_worker_lifecycle(ticket, context, engine=mock_engine, md_content="test context")
|
run_worker_lifecycle(ticket, context, engine=mock_engine, md_content="test context")
|
||||||
|
|
||||||
# Assert ticket status is 'killed'
|
# Assert ticket status is 'killed'
|
||||||
self.assertEqual(ticket.status, "killed")
|
self.assertEqual(ticket.status, "killed")
|
||||||
|
|
||||||
# Also assert ai_client.send was NOT called
|
# Also assert ai_client.send_result was NOT called (abort fires before the call)
|
||||||
mock_send.assert_not_called()
|
mock_send_result.assert_not_called()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in New Issue
Block a user