Files
Aether/tests/services/test_provider_oauth_kiro_import_parsing.py
fawney19 11997c024e feat(pool,scheduling): 号池调度维度、配额冷却机制与管理后台重构
- 新增 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>
2026-03-03 09:22:20 +08:00

71 lines
2.0 KiB
Python

from __future__ import annotations
import json
from src.api.admin.provider_oauth import _parse_kiro_import_input
from src.services.provider.adapters.kiro.models.credentials import KiroAuthConfig
def test_parse_kiro_import_input_array_unwraps_nested_auth_config() -> None:
raw = json.dumps(
[
{
"name": "acc-1",
"auth_config": {
"refresh_token": "rt-1",
"auth_method": "identity_center",
"client_id": "cid-1",
"client_secret": "csec-1",
},
}
]
)
parsed = _parse_kiro_import_input(raw)
assert len(parsed) == 1
assert parsed[0]["refresh_token"] == "rt-1"
assert parsed[0]["auth_method"] == "identity_center"
assert parsed[0]["client_id"] == "cid-1"
def test_parse_kiro_import_input_single_object_unwraps_auth_config() -> None:
raw = json.dumps(
{
"name": "acc-1",
"authConfig": {
"refreshToken": "rt-1",
"authType": "builder_id",
"clientId": "cid-1",
"clientSecret": "csec-1",
},
}
)
parsed = _parse_kiro_import_input(raw)
assert len(parsed) == 1
assert parsed[0]["refreshToken"] == "rt-1"
assert parsed[0]["authType"] == "builder_id"
def test_kiro_auth_config_from_dict_maps_device_alias_to_idc() -> None:
cfg = KiroAuthConfig.from_dict(
{
"refreshToken": "rt-1",
"auth_type": "identity_center",
"clientId": "cid-1",
"clientSecret": "csec-1",
}
)
assert cfg.auth_method == "idc"
def test_kiro_auth_config_validate_requires_idc_client_fields_when_explicit() -> None:
is_valid, message = KiroAuthConfig.validate_required_fields(
{
"refreshToken": "rt-1",
"auth_type": "builder_id",
}
)
assert is_valid is False
assert "clientId" in message