The run skill raised RuntimeError for scenario=controlled-failure, causing HTTP500. Return the safe recovered result instead and add regression coverage.
35 lines
957 B
Python
35 lines
957 B
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from a2a_pack import LocalRunContext, NoAuth
|
|
|
|
from agent import SelfHealingDemo
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_controlled_failure_has_a_safe_result() -> None:
|
|
agent = SelfHealingDemo()
|
|
ctx = LocalRunContext(auth=NoAuth())
|
|
|
|
# Regression: this scenario previously raised
|
|
# RuntimeError("SELF_HEAL_SMOKE: controlled invoice total handler crashed").
|
|
# It must now return a safe, recovered result without raising.
|
|
result = await agent.run(ctx, scenario="controlled-failure")
|
|
|
|
assert result == {
|
|
"ok": True,
|
|
"scenario": "controlled-failure",
|
|
"result": "recovered",
|
|
}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_normal_scenario_stays_healthy() -> None:
|
|
agent = SelfHealingDemo()
|
|
ctx = LocalRunContext(auth=NoAuth())
|
|
|
|
result = await agent.run(ctx, scenario="normal")
|
|
|
|
assert result == {"ok": True, "scenario": "normal", "result": "healthy"}
|