fix(agent): bound stale retry terminalization

This commit is contained in:
ogt
2026-07-11 16:18:32 +08:00
parent bd27d4e759
commit 673b0d57a4
2 changed files with 58 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
import inspect
import json
from contextlib import asynccontextmanager
from unittest.mock import AsyncMock
@@ -759,11 +760,25 @@ async def test_stale_pending_retry_is_reclaimed_without_runtime_apply(
),
),
)
monkeypatch.setattr(service, "_runtime_blockers", lambda: [])
runtime_blockers = (
["ansible_binary_missing"] if expected_terminalized else []
)
monkeypatch.setattr(
service,
"_runtime_blockers",
lambda: runtime_blockers,
)
transport_probe = AsyncMock(
return_value=(
["ansible_transport_unavailable"]
if expected_terminalized
else []
)
)
monkeypatch.setattr(
service,
"recent_ansible_transport_blockers",
AsyncMock(return_value=[]),
transport_probe,
)
monkeypatch.setattr(
service,
@@ -803,10 +818,28 @@ async def test_stale_pending_retry_is_reclaimed_without_runtime_apply(
assert "UPDATE automation_operation_log replay" in db.statements[1]
assert "reclaimed_after_stale_pending" in db.statements[1]
assert "input ->> 'retry_claim_id'" in db.statements[2]
persisted_output = json.loads(db.parameters[2]["output"])
persisted_dry_run = json.loads(db.parameters[2]["dry_run_result"])
assert persisted_output["check_mode_executed"] is (
not bool(expected_terminalized)
)
assert persisted_output["check_mode_replay_performed"] is (
not bool(expected_terminalized)
)
assert persisted_output["runtime_apply_executed"] is False
assert persisted_dry_run["check_mode_executed"] is (
not bool(expected_terminalized)
)
assert persisted_dry_run["check_mode_replay_performed"] is (
not bool(expected_terminalized)
)
assert persisted_dry_run["runtime_apply_executed"] is False
if expected_terminalized:
replay_runner.assert_not_awaited()
transport_probe.assert_not_awaited()
else:
replay_runner.assert_awaited_once()
transport_probe.assert_awaited_once()
receipt_writer.assert_awaited_once()
assert receipt_writer.await_args.kwargs[
"check_mode_replay_performed"