Fix controlled-failure crash in run skill
The run skill raised RuntimeError for scenario=controlled-failure, causing HTTP500. Return the safe recovered result instead and add regression coverage.
This commit is contained in:
6
agent.py
6
agent.py
@@ -23,7 +23,7 @@ class SelfHealingDemo(A2AAgent):
|
|||||||
scenario: str = "normal",
|
scenario: str = "normal",
|
||||||
) -> dict[str, object]:
|
) -> dict[str, object]:
|
||||||
if scenario == "controlled-failure":
|
if scenario == "controlled-failure":
|
||||||
# Intentional smoke fixture: the regression test specifies the safe
|
# Previously this handler crashed with a controlled RuntimeError.
|
||||||
# result. The production self-healing worker must repair this source.
|
# It now returns the safe, recovered result the regression test expects.
|
||||||
raise RuntimeError("SELF_HEAL_SMOKE: controlled invoice total handler crashed")
|
return {"ok": True, "scenario": scenario, "result": "recovered"}
|
||||||
return {"ok": True, "scenario": scenario, "result": "healthy"}
|
return {"ok": True, "scenario": scenario, "result": "healthy"}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ async def test_controlled_failure_has_a_safe_result() -> None:
|
|||||||
agent = SelfHealingDemo()
|
agent = SelfHealingDemo()
|
||||||
ctx = LocalRunContext(auth=NoAuth())
|
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")
|
result = await agent.run(ctx, scenario="controlled-failure")
|
||||||
|
|
||||||
assert result == {
|
assert result == {
|
||||||
@@ -19,3 +22,13 @@ async def test_controlled_failure_has_a_safe_result() -> None:
|
|||||||
"scenario": "controlled-failure",
|
"scenario": "controlled-failure",
|
||||||
"result": "recovered",
|
"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"}
|
||||||
|
|||||||
Reference in New Issue
Block a user