Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /als-apg_osprey /tests /bridges /test_retry.py
| """Table-driven coverage of the pure retry-policy decisions in osprey.bridges.core.retry. | |
| Each branch of every function gets an explicit row: retryable failure classes, | |
| the redispatch safety gate (known tool-call counts), age eligibility, the | |
| two-ceiling give-up rule, and coalesce-key normalization.""" | |
| from types import SimpleNamespace | |
| import pytest | |
| from osprey.bridges.core.retry import ( | |
| coalesce_key, | |
| give_up_due, | |
| is_eligible, | |
| is_retryable, | |
| may_redispatch, | |
| ) | |
| NOW = 1_000_000.0 | |
| def _cfg(retry_min_age=1200.0, retry_give_up=172800.0, retry_lifetime_cap=604800.0): | |
| return SimpleNamespace( | |
| retry_min_age=retry_min_age, | |
| retry_give_up=retry_give_up, | |
| retry_lifetime_cap=retry_lifetime_cap, | |
| ) | |
| def _queued(age, **extra): | |
| """An entry that entered the queue ``age`` seconds before NOW.""" | |
| return {"queued_at": NOW - age, **extra} | |
| # --- is_retryable ---------------------------------------------------------- | |
| def test_is_retryable_by_class(failure_class, expected): | |
| assert is_retryable({"failure_class": failure_class}) is expected | |
| def test_is_retryable_missing_key(): | |
| assert is_retryable({}) is False | |
| # --- is_retryable: error_code override ------------------------------------- | |
| def test_is_retryable_error_code_override(error_code, failure_class, expected): | |
| assert is_retryable({"failure_class": failure_class, "error_code": error_code}) is expected | |
| def test_is_retryable_error_code_absent_key_uses_failure_class(): | |
| # No error_code key at all -> fall through to the failure_class rule. | |
| assert is_retryable({"failure_class": "provider"}) is True | |
| assert is_retryable({"failure_class": "agent"}) is False | |
| # --- may_redispatch -------------------------------------------------------- | |
| def test_may_redispatch(result_n, entry_n, expected): | |
| entry = {} if entry_n is None else {"num_tool_calls": entry_n} | |
| result = {} if result_n is None else {"num_tool_calls": result_n} | |
| assert may_redispatch(entry, result) is expected | |
| def test_may_redispatch_refuses_whenever_tool_calls_were_made(n): | |
| """A run that made ANY tool call may never be replayed. | |
| A dispatched run can reach hardware, so a redispatch of a run with side | |
| effects repeats a machine action. The refusal must hold no matter which | |
| side reports the positive count, and no matter what the other side says. | |
| """ | |
| # Positive count observed on the fresh result. | |
| assert may_redispatch({}, {"num_tool_calls": n}) is False | |
| # Positive count remembered on the entry from a prior attempt. | |
| assert may_redispatch({"num_tool_calls": n}, {}) is False | |
| # A known-0 on the other side does NOT rescue it — every known count must be 0. | |
| assert may_redispatch({"num_tool_calls": 0}, {"num_tool_calls": n}) is False | |
| assert may_redispatch({"num_tool_calls": n}, {"num_tool_calls": 0}) is False | |
| # --- is_eligible ----------------------------------------------------------- | |
| def test_is_eligible_by_age(age, expected): | |
| assert is_eligible(_queued(age), NOW, _cfg()) is expected | |
| def test_is_eligible_missing_queued_at(): | |
| # No queued_at -> treated as just-now (age 0) -> not yet eligible. | |
| assert is_eligible({}, NOW, _cfg()) is False | |
| # --- give_up_due ----------------------------------------------------------- | |
| def test_give_up_due(age, attempts, gate_ever_open, expected): | |
| entry = _queued(age, attempts=attempts) | |
| assert give_up_due(entry, NOW, gate_ever_open, _cfg()) is expected | |
| def test_give_up_due_retried_flag_triggers(): | |
| # The drain stamps a boolean `retried` flag (not a count) on redispatch; | |
| # give_up_due honors it the same as attempts > 0. | |
| entry = _queued(172800.0, retried=True) | |
| assert give_up_due(entry, NOW, False, _cfg()) is True | |
| def test_give_up_due_retried_flag_false_extends(): | |
| entry = _queued(172800.0, retried=False) | |
| assert give_up_due(entry, NOW, False, _cfg()) is False | |
| def test_give_up_due_missing_queued_at_never_gives_up(): | |
| # Age 0 -> below both ceilings. | |
| assert give_up_due({"attempts": 3}, NOW, True, _cfg()) is False | |
| # --- ceiling anchor: first_queued_at --------------------------------------- | |
| def test_give_up_due_anchors_on_first_queued_at(): | |
| # A re-parked entry has a FRESH queued_at (per-attempt pacing) but its | |
| # first_queued_at remembers when the request originally entered the queue. | |
| # The give-up ceiling must read the original time, else a cycling entry | |
| # (park -> retry -> fail -> re-park) re-ages forever and never gives up. | |
| entry = {"queued_at": NOW - 100.0, "first_queued_at": NOW - 172800.0, "retried": True} | |
| assert give_up_due(entry, NOW, False, _cfg()) is True | |
| def test_lifetime_cap_anchors_on_first_queued_at(): | |
| entry = {"queued_at": NOW - 100.0, "first_queued_at": NOW - 604800.0} | |
| assert give_up_due(entry, NOW, False, _cfg()) is True | |
| def test_give_up_due_falls_back_to_queued_at(): | |
| # Entries persisted before first_queued_at existed keep working: the | |
| # ceilings fall back to queued_at. | |
| entry = {"queued_at": NOW - 604800.0} | |
| assert give_up_due(entry, NOW, False, _cfg()) is True | |
| def test_is_eligible_ignores_first_queued_at(): | |
| # Pacing stays per-park: a just-re-parked entry (fresh queued_at) is NOT | |
| # eligible again immediately, however old the request itself is. | |
| entry = {"queued_at": NOW - 100.0, "first_queued_at": NOW - 604800.0} | |
| assert is_eligible(entry, NOW, _cfg()) is False | |
| # --- coalesce_key ---------------------------------------------------------- | |
| def test_coalesce_key(key, expected): | |
| entry = {} if key is None else {"coalesce_key": key} | |
| assert coalesce_key(entry) == expected | |
| def test_coalesce_key_missing(): | |
| assert coalesce_key({}) == () | |
Xet Storage Details
- Size:
- 8.48 kB
- Xet hash:
- 851879b5847394f9d519238b5e306687dd49ec6e89611928b19ee31ce8de63a2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.