Skip to content

bug: test_orphaned_execution_recovery mocks stale after CapacityManager refactor #533

Description

@vybe

Summary

The CapacityManager refactor (commit 76a6a10, shipped in 202e2d4) deleted services/slot_service.py and replaced it with services/capacity_manager.py. The unit tests in test_orphaned_execution_recovery.py still mock services.slot_service, so all four recovery scenario tests now fail with 'Mock' object can't be awaited. The orphaned execution recovery code has no working unit test coverage as a result.

Component

Backend / Cleanup Service / Tests

Priority

P3 — no runtime impact; tests fail locally and in CI

Error

ERROR  cleanup_service.py:772 [Recovery] Error recovering execution exec-1: 
       'Mock' object can't be awaited
assert 0 == 1  # recovered count

Location

  • File: tests/unit/test_orphaned_execution_recovery.py
  • Line: ~30 (_SYS_MOCKS definition)
  • Function: _SYS_MOCKS dict / TestRecoverOrphanedExecutions

Root Cause

test_orphaned_execution_recovery.py injects a sys-module mock for services.slot_service:

_SYS_MOCKS = {
    ...
    'services.slot_service': Mock(get_slot_service=Mock(return_value=_mock_slot_service)),
    ...
}

After the refactor, cleanup_service.py no longer imports from services.slot_service. It now calls get_capacity_manager() from services.capacity_manager and awaits capacity.release(agent_name, execution_id). The test's mock dict doesn't include services.capacity_manager, so capacity is an un-mocked None-like object and await capacity.release(...) raises TypeError: 'Mock' object can't be awaited.

Affected Tests

All four orphaned-recovery scenario tests fail:

  • test_container_down_marks_orphaned
  • test_not_in_registry_marks_orphaned
  • test_multiple_agents_mixed
  • test_agent_unreachable_treats_as_orphaned

(test_no_running_executions still passes because the recovery path is never entered.)

Suggested Fix

Replace the stale slot_service mock with a capacity_manager mock:

# REMOVE:
_mock_slot_service = AsyncMock()
...
'services.slot_service': Mock(get_slot_service=Mock(return_value=_mock_slot_service)),

# ADD:
_mock_capacity = AsyncMock()
_mock_capacity.release = AsyncMock()
_mock_capacity.release_if_matches = AsyncMock(return_value=True)
...
'services.capacity_manager': Mock(get_capacity_manager=Mock(return_value=_mock_capacity)),

Any assertions that previously checked _mock_slot_service.release_slot calls should be updated to check _mock_capacity.release instead.

Reproduction Steps

  1. Check out commit 202e2d4 or later
  2. Run: cd tests && python -m pytest unit/test_orphaned_execution_recovery.py -v
  3. Observe 4 failures with 'Mock' object can't be awaited

Environment

  • Trinity version: 202e2d4
  • Introduced by: 76a6a10 (CapacityManager consolidation)

Related

  • src/backend/services/cleanup_service.py — function _recover_execution() (uses capacity.release)
  • src/backend/services/capacity_manager.py — new consolidated service
  • tests/unit/test_capacity_manager.py — new test file (all passing)

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions