fix(api): honor upstream docker repair success
Some checks failed
CD Pipeline / tests (push) Successful in 1m22s
Code Review / ai-code-review (push) Successful in 13s
CD Pipeline / build-and-deploy (push) Has started running
CD Pipeline / post-deploy-checks (push) Has been cancelled

This commit is contained in:
Your Name
2026-06-01 14:53:34 +08:00
parent 861894fd3a
commit 45dc7e52cf
3 changed files with 77 additions and 2 deletions

View File

@@ -497,6 +497,44 @@ class TestAutoRepairService:
assert route is None
@pytest.mark.asyncio
async def test_execute_legacy_ssh_restart_noops_when_upstream_repair_succeeded(
self,
service,
monkeypatch,
):
"""Do not restart twice when the host monitor already repaired it."""
incident = create_test_incident(
severity=Severity.P2,
alert_category="infrastructure",
alert_name="DockerContainerUnhealthy",
)
incident.signals[0].labels.update({
"host": "wooo",
"container": "stockplatform-v2-edge-1",
"source": "docker-health-monitor",
"repair_action": "restarted",
"repair_result": "success",
})
step = RepairStep(
step_number=1,
action_type=ActionType.SSH_COMMAND,
command='ssh {host} \'docker inspect {container} --format="{{.State.Health.Status}}" && docker restart {container}\'',
risk_level=RiskLevel.MEDIUM,
requires_approval=False,
)
async def fail_if_called(*args, **kwargs):
raise AssertionError("MCP Gateway should not be called after upstream repair success")
monkeypatch.setattr(service, "_execute_ssh_mcp_route", fail_if_called)
result = await service._execute_step(incident, step)
assert result.startswith("SUCCESS: upstream repair already completed")
assert "docker-health-monitor" in result
assert "stockplatform-v2-edge-1" in result
@pytest.mark.asyncio
async def test_execute_legacy_ssh_diagnostic_uses_mcp_gateway(
self,