Skip to content

Commit ef6217a

Browse files
Trecekclaude
andcommitted
fix: replace mocked resolve_stale_running with real PID/boot-id liveness fields in reset_dispatch tests
Exercise the full liveness detection path (resolve_stale_running → is_dispatch_session_alive → is_session_alive) in test_reset_dispatch_running_dead_process_succeeds and test_reset_dispatch_running_alive_process_still_blocked by writing real PID/boot-id/starttime fields onto the dispatch record via CampaignStateMutator instead of mocking resolve_stale_running. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 910232e commit ef6217a

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

tests/server/test_tools_fleet_reset.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from __future__ import annotations
44

55
import json
6+
import os
67
from pathlib import Path
78
from unittest.mock import AsyncMock, patch
89

910
import pytest
1011

1112
from autoskillit.core import TerminationReason
13+
from autoskillit.core.runtime import read_boot_id, read_starttime_ticks
1214
from autoskillit.fleet import DispatchRecord, DispatchStatus, write_initial_state
1315

1416
pytestmark = [pytest.mark.layer("server"), pytest.mark.medium, pytest.mark.feature("fleet")]
@@ -263,17 +265,16 @@ async def test_reset_dispatch_running_dead_process_succeeds(
263265
) -> None:
264266
"""Test 1A: reset_dispatch must succeed for RUNNING dispatch with dead process."""
265267
state_path = _setup_state(tmp_path, status=DispatchStatus.RUNNING)
266-
tool_ctx = build_ctx_open()
267-
_setup_tool(tool_ctx, monkeypatch, state_path)
268+
from autoskillit.fleet.state import CampaignStateMutator
268269

269-
def _mock_resolve_dead(d, _m, **_kw):
270-
d.status = DispatchStatus.INTERRUPTED
271-
return False
270+
with CampaignStateMutator(state_path) as m:
271+
assert m.state is not None
272+
m.state.dispatches[0].dispatched_pid = 999999999
273+
m.state.dispatches[0].dispatched_boot_id = "fake-boot-id"
274+
m.mark_dirty()
272275

273-
monkeypatch.setattr(
274-
"autoskillit.server.tools.tools_fleet_reset.resolve_stale_running",
275-
_mock_resolve_dead,
276-
)
276+
tool_ctx = build_ctx_open()
277+
_setup_tool(tool_ctx, monkeypatch, state_path)
277278

278279
from autoskillit.server.tools.tools_fleet_reset import reset_dispatch
279280

@@ -287,14 +288,24 @@ async def test_reset_dispatch_running_alive_process_still_blocked(
287288
) -> None:
288289
"""Test 1B: reset_dispatch must still block when process is alive."""
289290
state_path = _setup_state(tmp_path, status=DispatchStatus.RUNNING)
291+
from autoskillit.fleet.state import CampaignStateMutator
292+
293+
current_pid = os.getpid()
294+
current_boot_id = read_boot_id()
295+
current_ticks = read_starttime_ticks(current_pid)
296+
if current_boot_id is None or current_ticks is None:
297+
pytest.skip("Liveness detection requires /proc (Linux only)")
298+
299+
with CampaignStateMutator(state_path) as m:
300+
assert m.state is not None
301+
m.state.dispatches[0].dispatched_pid = current_pid
302+
m.state.dispatches[0].dispatched_boot_id = current_boot_id
303+
m.state.dispatches[0].dispatched_starttime_ticks = current_ticks
304+
m.mark_dirty()
305+
290306
tool_ctx = build_ctx_open()
291307
_setup_tool(tool_ctx, monkeypatch, state_path)
292308

293-
monkeypatch.setattr(
294-
"autoskillit.server.tools.tools_fleet_reset.resolve_stale_running",
295-
lambda _d, _m, **_kw: True,
296-
)
297-
298309
from autoskillit.server.tools.tools_fleet_reset import reset_dispatch
299310

300311
raw = await reset_dispatch(dispatch_id="d-abc123")

0 commit comments

Comments
 (0)