Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

54 lines
1.9 KiB
Python

"""Regression tests for #11314 — credential-pool rotation vs. fallback.
_pool_may_recover_from_rate_limit() is the hinge between credential-pool
rotation and fallback-provider activation. Rotation is only worth waiting on
when the pool exists, has an available entry, and has more than one entry to
rotate to; otherwise we should fall back to the configured fallback provider
immediately.
"""
import inspect
from unittest.mock import MagicMock
from agent import conversation_loop
from run_agent import _pool_may_recover_from_rate_limit
def _pool(entries: int = 2):
p = MagicMock()
p.has_available.return_value = True
p.entries.return_value = list(range(entries))
return p
def test_multi_entry_pool_recovers():
assert _pool_may_recover_from_rate_limit(_pool(entries=3)) is True
def test_single_entry_pool_skips_rotation():
# Single-entry-pool exception (#11314): nothing to rotate to.
assert _pool_may_recover_from_rate_limit(_pool(entries=1)) is False
def test_exhausted_pool_skips_rotation():
p = MagicMock()
p.has_available.return_value = False
assert _pool_may_recover_from_rate_limit(p) is False
def test_no_pool_skips_rotation():
assert _pool_may_recover_from_rate_limit(None) is False
def test_conversation_loop_resolves_pool_helper_through_run_agent_module():
"""Extracted conversation loop must honor tests/patches on run_agent.
conversation_loop intentionally lazy-loads run_agent via _ra(). If this
call site uses a bare imported helper, monkeypatching run_agent in tests (and
production wrappers that patch run_agent) will not propagate into the
extracted loop; older code also hit NameError in this branch.
"""
source = inspect.getsource(conversation_loop.run_conversation)
assert "_ra()._pool_may_recover_from_rate_limit(" in source
assert "pool_may_recover = _pool_may_recover_from_rate_limit(" not in source