mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
- 新增 scheduling_dimensions 模块,为每个 Key 计算多维调度状态(手动/冷却/熔断/成本/健康) - 新增 quota_cooldown 模块,统一判定 Key 的有效冷却原因 - Pool 管理后台 API 扩展 Key 详情字段(调度状态/维度/配额/OAuth 信息) - 前端 Pool 管理页面重写,支持调度状态展示、批量清理封禁 Key - Handler 基类增加请求调度元数据采集,stream telemetry 增强 - 请求时间线组件增强,支持 attempted 候选展示 - Kiro OAuth 凭证导入解析改进 - 新增 usage 表 provider_key 索引迁移 - 补充调度维度、配额冷却、候选枚举等单元测试 Closes #197 Co-authored-by: AAEE86 <33052466+AAEE86@users.noreply.github.com>
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
from typing import Any, cast
|
|
|
|
from src.core.provider_types import ProviderType
|
|
from src.services.provider_keys.quota_cooldown import resolve_effective_cooldown_reason
|
|
|
|
|
|
def _key_with_metadata(upstream_metadata: dict[str, Any]) -> Any:
|
|
return cast(Any, SimpleNamespace(upstream_metadata=upstream_metadata))
|
|
|
|
|
|
def test_resolve_effective_cooldown_reason_prefers_redis_reason() -> None:
|
|
key = _key_with_metadata({"codex": {"primary_used_percent": 100.0}})
|
|
|
|
reason = resolve_effective_cooldown_reason(
|
|
provider_type=ProviderType.CODEX,
|
|
key=key,
|
|
redis_reason="rate_limited_429",
|
|
)
|
|
|
|
assert reason == "rate_limited_429"
|
|
|
|
|
|
def test_resolve_effective_cooldown_reason_fallbacks_to_codex_quota_exhausted() -> None:
|
|
key = _key_with_metadata({"codex": {"primary_used_percent": 100.0}})
|
|
|
|
reason = resolve_effective_cooldown_reason(
|
|
provider_type=ProviderType.CODEX,
|
|
key=key,
|
|
redis_reason=None,
|
|
)
|
|
|
|
assert reason == "quota_exhausted"
|
|
|
|
|
|
def test_resolve_effective_cooldown_reason_fallbacks_to_kiro_quota_exhausted() -> None:
|
|
key = _key_with_metadata({"kiro": {"remaining": 0}})
|
|
|
|
reason = resolve_effective_cooldown_reason(
|
|
provider_type=ProviderType.KIRO,
|
|
key=key,
|
|
redis_reason=None,
|
|
)
|
|
|
|
assert reason == "quota_exhausted"
|
|
|
|
|
|
def test_resolve_effective_cooldown_reason_returns_none_when_not_exhausted() -> None:
|
|
key = _key_with_metadata({"codex": {"primary_used_percent": 12.0}})
|
|
|
|
reason = resolve_effective_cooldown_reason(
|
|
provider_type=ProviderType.CODEX,
|
|
key=key,
|
|
redis_reason=None,
|
|
)
|
|
|
|
assert reason is None
|