mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
feat(pool): 引入多维评分调度策略与账号状态检测
- 新增 multi_score 调度模式,支持 LRU/延迟/健康度/剩余额度多维加权评分 - 新增调度预设维度系统(free_team_first, quota_balanced, recent_refresh, single_account),支持有序对象列表配置格式并兼容旧字符串列表 - 新增 account_state 模块,统一账号封禁/受限检测逻辑,替代分散在 routes 中的判断代码 - 新增 health_cache 模块和 latency 采样(redis_ops.record_latency / batch_get_latency_avgs) - RequestDispatcher 返回 ttfb_ms,PoolManager.on_request_success 记录延迟样本 - 前端:PoolConfigDialog 替换为 PoolSchedulingDialog,支持预设维度可视化配置;号池管理页增加调度模式标签与账号异常 Badge 显示 - 提取前端 accountBlock 工具函数,ProviderDetailDrawer 复用统一判断 - scheduling_dimensions 增加 account_state 和 latency 维度评估 - 补充 account_state、health_cache、multi_score 策略、preset 维度、redis latency 等测试
This commit is contained in:
92
tests/services/test_pool_account_state.py
Normal file
92
tests/services/test_pool_account_state.py
Normal file
@@ -0,0 +1,92 @@
|
||||
"""Tests for pool account-state resolution helpers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from src.services.provider.pool.account_state import resolve_pool_account_state
|
||||
|
||||
|
||||
def test_resolve_from_kiro_banned_metadata() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="kiro",
|
||||
upstream_metadata={"kiro": {"is_banned": True, "ban_reason": "account suspended"}},
|
||||
oauth_invalid_reason=None,
|
||||
)
|
||||
assert state.blocked is True
|
||||
assert state.code == "account_banned"
|
||||
assert state.label == "账号封禁"
|
||||
assert state.reason == "account suspended"
|
||||
|
||||
|
||||
def test_resolve_from_antigravity_forbidden_metadata() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="antigravity",
|
||||
upstream_metadata={"antigravity": {"is_forbidden": True, "forbidden_reason": "403"}},
|
||||
oauth_invalid_reason=None,
|
||||
)
|
||||
assert state.blocked is True
|
||||
assert state.code == "account_forbidden"
|
||||
assert state.label == "访问受限"
|
||||
assert state.reason == "403"
|
||||
|
||||
|
||||
def test_resolve_from_structured_oauth_reason() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="codex",
|
||||
upstream_metadata=None,
|
||||
oauth_invalid_reason="[ACCOUNT_BLOCK] Google requires verification",
|
||||
)
|
||||
assert state.blocked is True
|
||||
assert state.code == "account_blocked"
|
||||
assert state.label == "账号异常"
|
||||
assert state.reason == "Google requires verification"
|
||||
|
||||
|
||||
def test_resolve_from_keyword_oauth_reason() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type=None,
|
||||
upstream_metadata={},
|
||||
oauth_invalid_reason="organization has been disabled by admin",
|
||||
)
|
||||
assert state.blocked is True
|
||||
assert state.code == "account_blocked"
|
||||
assert state.label == "账号异常"
|
||||
|
||||
|
||||
def test_resolve_healthy_state() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="codex",
|
||||
upstream_metadata={"codex": {"primary_used_percent": 30}},
|
||||
oauth_invalid_reason="Token expired",
|
||||
)
|
||||
assert state.blocked is False
|
||||
assert state.code is None
|
||||
|
||||
|
||||
def test_bare_forbidden_not_treated_as_account_block() -> None:
|
||||
"""HTTP 403 'Forbidden' from token refresh should not be misclassified."""
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="codex",
|
||||
upstream_metadata={},
|
||||
oauth_invalid_reason="Forbidden",
|
||||
)
|
||||
assert state.blocked is False
|
||||
|
||||
|
||||
def test_kiro_oauth_reason_text_detected_as_block() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="kiro",
|
||||
upstream_metadata={},
|
||||
oauth_invalid_reason="账户已封禁: Terms of Service violation",
|
||||
)
|
||||
assert state.blocked is True
|
||||
assert state.code == "account_blocked"
|
||||
|
||||
|
||||
def test_antigravity_oauth_reason_text_detected_as_block() -> None:
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="antigravity",
|
||||
upstream_metadata={},
|
||||
oauth_invalid_reason="账户访问被禁止: 403 Forbidden",
|
||||
)
|
||||
assert state.blocked is True
|
||||
assert state.code == "account_blocked"
|
||||
Reference in New Issue
Block a user