Files
roboco/tests/unit/foundation/policy/conventions/test_effective_map.py
T
01e10ad693 Feat/provider overload break (#242)
* feat(conventions): standard schema models + effective-map merge

* feat(orchestrator): park provider on persistent server overload (529/500)

A 429 rate limit already parks a provider — queue its spawns, probe until it
recovers — but a persistent 529/500/503 overload had no such break: the run
died and the orchestrator crash-retried straight back into the overload,
burning tokens in a respawn loop.

Generalize the park to provider-unavailability. On a non-graceful Anthropic
agent exit, match the API's overload markers (overloaded_error /
internal_server_error / "API Error: 5xx") against the dead container's own
output and park the provider with kind="overloaded"; the existing spawn gate
already queues any parked provider, and the probe-resume loop revives the task
when it recovers. Grok keeps its exit-75 path; both now route through one
_park_provider_unavailable helper. Markers are kept specific so an agent that
merely writes about HTTP 500/529 can't trip the break.

Fix the recovery probe to require a 2xx: it treated any non-429 as recovered,
so a probe that itself got a 529 would have resumed agents straight back into
the overload — wrong for the new path and for a 429 that lifts into a 5xx.

Gated by ROBOCO_OVERLOAD_BREAK_ENABLED (default on; off => crash-retry).

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-06-22 03:49:45 +02:00

90 lines
3.2 KiB
Python

"""Effective-map merge tests: auto-derived defaults overlaid by the file."""
from __future__ import annotations
from roboco.foundation.policy.conventions.effective_map import effective_map
from roboco.foundation.policy.conventions.models import (
ConventionsStandard,
CustomRule,
Module,
Rule,
Waiver,
)
def test_effective_map_applies_builtin_rules_when_file_absent() -> None:
eff = effective_map(ConventionsStandard(), None)
assert eff.rules["no_models_in_routers"].level == "block"
assert eff.rules["no_inline_comments"].level == "warn"
def test_file_module_overrides_derived_by_path() -> None:
derived = ConventionsStandard(
modules=[Module(path="app/routers", purpose="routes")]
)
file = ConventionsStandard(
modules=[Module(path="app/routers", purpose="routes", forbidden=["model"])]
)
eff = effective_map(derived, file)
assert len(eff.modules) == 1
assert eff.modules[0].forbidden == ["model"]
def test_file_module_appends_new_path() -> None:
derived = ConventionsStandard(
modules=[Module(path="app/routers", purpose="routes")]
)
file = ConventionsStandard(modules=[Module(path="app/models", purpose="models")])
eff = effective_map(derived, file)
assert [m.path for m in eff.modules] == ["app/routers", "app/models"]
def test_file_rule_overrides_builtin_level() -> None:
file = ConventionsStandard(
rules={"no_inline_comments": Rule(name="no_inline_comments", level="block")}
)
eff = effective_map(ConventionsStandard(), file)
assert eff.rules["no_inline_comments"].level == "block"
def test_derived_rule_overrides_builtin_then_file_overrides_derived() -> None:
derived = ConventionsStandard(
rules={"no_inline_comments": Rule(name="no_inline_comments", level="block")}
)
eff_no_file = effective_map(derived, None)
assert eff_no_file.rules["no_inline_comments"].level == "block"
file = ConventionsStandard(
rules={"no_inline_comments": Rule(name="no_inline_comments", level="warn")}
)
eff = effective_map(derived, file)
assert eff.rules["no_inline_comments"].level == "warn"
def test_languages_are_unioned() -> None:
derived = ConventionsStandard(languages=["python"])
file = ConventionsStandard(languages=["python", "typescript"])
eff = effective_map(derived, file)
assert eff.languages == ["python", "typescript"]
def test_file_custom_and_waivers_replace_derived() -> None:
derived = ConventionsStandard(
custom=[CustomRule(id="d", pattern="d", message="d", level="warn")],
waivers=[Waiver(path="d.py", rule="no_models_in_routers", reason="d")],
)
file = ConventionsStandard(
custom=[CustomRule(id="f", pattern="f", message="f", level="block")],
waivers=[Waiver(path="f.py", rule="no_helpers_in_routers", reason="f")],
)
eff = effective_map(derived, file)
assert [c.id for c in eff.custom] == ["f"]
assert [w.path for w in eff.waivers] == ["f.py"]
def test_file_none_keeps_derived_custom_and_waivers() -> None:
derived = ConventionsStandard(
custom=[CustomRule(id="d", pattern="d", message="d", level="warn")],
)
eff = effective_map(derived, None)
assert [c.id for c in eff.custom] == ["d"]