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:
@@ -2,13 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
from src.api.admin.pool.routes import (
|
||||
_build_pool_scheduling_state,
|
||||
_is_known_banned_key,
|
||||
_is_known_banned_reason,
|
||||
)
|
||||
from src.api.admin.pool.routes import _build_pool_scheduling_state
|
||||
from src.services.provider.pool.account_state import resolve_pool_account_state
|
||||
|
||||
|
||||
def test_pool_scheduling_state_manual_disabled_is_blocked() -> None:
|
||||
@@ -24,6 +19,10 @@ def test_pool_scheduling_state_manual_disabled_is_blocked() -> None:
|
||||
dimensions,
|
||||
) = _build_pool_scheduling_state(
|
||||
is_active=False,
|
||||
account_blocked=False,
|
||||
account_block_label=None,
|
||||
account_block_reason=None,
|
||||
latency_avg_ms=None,
|
||||
cooldown_reason=None,
|
||||
cooldown_ttl_seconds=None,
|
||||
circuit_breaker_open=False,
|
||||
@@ -55,6 +54,10 @@ def test_pool_scheduling_state_cooldown_detail_is_mapped() -> None:
|
||||
dimensions,
|
||||
) = _build_pool_scheduling_state(
|
||||
is_active=True,
|
||||
account_blocked=False,
|
||||
account_block_label=None,
|
||||
account_block_reason=None,
|
||||
latency_avg_ms=None,
|
||||
cooldown_reason="rate_limited_429",
|
||||
cooldown_ttl_seconds=180,
|
||||
circuit_breaker_open=False,
|
||||
@@ -84,6 +87,10 @@ def test_pool_scheduling_state_cost_soft_is_degraded() -> None:
|
||||
_dimensions,
|
||||
) = _build_pool_scheduling_state(
|
||||
is_active=True,
|
||||
account_blocked=False,
|
||||
account_block_label=None,
|
||||
account_block_reason=None,
|
||||
latency_avg_ms=None,
|
||||
cooldown_reason=None,
|
||||
cooldown_ttl_seconds=None,
|
||||
circuit_breaker_open=False,
|
||||
@@ -101,28 +108,36 @@ def test_pool_scheduling_state_cost_soft_is_degraded() -> None:
|
||||
|
||||
|
||||
def test_known_banned_reason_account_block_prefix() -> None:
|
||||
assert _is_known_banned_reason("[ACCOUNT_BLOCK] Google 要求验证账号") is True
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="codex",
|
||||
upstream_metadata={},
|
||||
oauth_invalid_reason="[ACCOUNT_BLOCK] Google 要求验证账号",
|
||||
)
|
||||
assert state.blocked is True
|
||||
|
||||
|
||||
def test_known_banned_key_detects_kiro_banned_metadata() -> None:
|
||||
key = SimpleNamespace(
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="kiro",
|
||||
upstream_metadata={"kiro": {"is_banned": True}},
|
||||
oauth_invalid_reason=None,
|
||||
)
|
||||
assert _is_known_banned_key(key, "kiro") is True
|
||||
assert state.blocked is True
|
||||
|
||||
|
||||
def test_known_banned_key_detects_reason_keywords() -> None:
|
||||
key = SimpleNamespace(
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="antigravity",
|
||||
upstream_metadata={},
|
||||
oauth_invalid_reason="AWS account temporarily suspended",
|
||||
)
|
||||
assert _is_known_banned_key(key, "antigravity") is True
|
||||
assert state.blocked is True
|
||||
|
||||
|
||||
def test_known_banned_key_does_not_treat_token_expired_as_banned() -> None:
|
||||
key = SimpleNamespace(
|
||||
state = resolve_pool_account_state(
|
||||
provider_type="kiro",
|
||||
upstream_metadata={"kiro": {"is_banned": False}},
|
||||
oauth_invalid_reason="access token expired",
|
||||
)
|
||||
assert _is_known_banned_key(key, "kiro") is False
|
||||
assert state.blocked is False
|
||||
|
||||
Reference in New Issue
Block a user