mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 08:27:46 +08:00
feat(codex): 增强 OAuth 导入解析与账号信息提取,优化维护调度器线程模型
Codex OAuth: - 导入解析支持附加账号字段(account_id/plan_type/user_id/email) - enrich_codex 扩展从 access_token 和直接字段提取账号信息 - parse_codex_id_token 支持 JWT/JSON 字符串/dict 三种输入格式 - request patching 新增 openai:compact 格式支持 - codex_usage_parser 新增 credits_unlimited 字段解析 维护调度器: - 同步 DB 操作迁移到线程池执行,避免阻塞事件循环 - 新增 request_candidates 定期清理任务 - 新增每周 VACUUM ANALYZE 数据库表维护任务 - 新增 enable_db_maintenance 配置项 前端: - ElapsedTimeText 从 setInterval 改为 requestAnimationFrame - 时间线过滤 available/unused 占位记录 - Usage 页面默认关闭全局自动刷新 - 移除号池管理中的配额更新时间显示
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import jwt
|
||||
import pytest
|
||||
|
||||
from src.services.provider.adapters.codex.request_patching import (
|
||||
maybe_patch_request_for_codex,
|
||||
patch_openai_cli_request_for_codex,
|
||||
@@ -143,3 +146,37 @@ def test_codex_envelope_extra_headers_uses_account_id_header() -> None:
|
||||
headers = codex_oauth_envelope.extra_headers() or {}
|
||||
assert headers.get("Chatgpt-Account-Id") == "acc_123"
|
||||
set_codex_request_context(None)
|
||||
|
||||
|
||||
def _encode_unsigned_jwt(payload: dict[str, object]) -> str:
|
||||
token = jwt.encode(payload, key="", algorithm="none")
|
||||
return token.decode("utf-8") if isinstance(token, bytes) else token
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_enrich_codex_uses_access_token_when_id_token_missing() -> None:
|
||||
from src.services.provider.adapters.codex.plugin import enrich_codex
|
||||
|
||||
access_token = _encode_unsigned_jwt(
|
||||
{
|
||||
"email": "[email protected]",
|
||||
"https://api.openai.com/auth": {
|
||||
"chatgpt_account_id": "acc-access",
|
||||
"chatgpt_plan_type": "team",
|
||||
"chatgpt_user_id": "user-access",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
auth_config: dict[str, object] = {}
|
||||
out = await enrich_codex(
|
||||
auth_config=auth_config,
|
||||
token_response={"access_token": access_token},
|
||||
access_token=access_token,
|
||||
proxy_config=None,
|
||||
)
|
||||
|
||||
assert out["email"] == "[email protected]"
|
||||
assert out["account_id"] == "acc-access"
|
||||
assert out["plan_type"] == "team"
|
||||
assert out["user_id"] == "user-access"
|
||||
|
||||
@@ -417,6 +417,31 @@ def test_parse_codex_usage_missing_plan_type_infers_paid_windows() -> None:
|
||||
assert parsed["secondary_window_minutes"] == 300
|
||||
|
||||
|
||||
def test_parse_codex_usage_blank_credits_balance_is_ignored() -> None:
|
||||
parsed = parse_codex_wham_usage_response(
|
||||
{
|
||||
"plan_type": "team",
|
||||
"rate_limit": {
|
||||
"primary_window": {
|
||||
"used_percent": 10,
|
||||
"reset_after_seconds": 100,
|
||||
"reset_at": 1700000000,
|
||||
"limit_window_seconds": 18000,
|
||||
}
|
||||
},
|
||||
"credits": {
|
||||
"has_credits": False,
|
||||
"balance": "",
|
||||
"unlimited": "false",
|
||||
},
|
||||
}
|
||||
)
|
||||
assert parsed is not None
|
||||
assert parsed["has_credits"] is False
|
||||
assert parsed["credits_unlimited"] is False
|
||||
assert "credits_balance" not in parsed
|
||||
|
||||
|
||||
def test_parse_codex_usage_invalid_type_raises_diagnostic_error() -> None:
|
||||
with pytest.raises(CodexUsageParseError, match="rate_limit.primary_window 类型错误"):
|
||||
parse_codex_wham_usage_response({"rate_limit": {"primary_window": []}})
|
||||
|
||||
Reference in New Issue
Block a user