feat: Antigravity 和 Codex 服务支持

- 新增 Antigravity 服务:签名缓存、URL 可用性检测、信封处理
- 新增 Codex 服务:信封处理、元数据收集器
- 重构 provider transport 支持新的服务架构
- 新增 stream_bridge 和 upstream_stream_bridge 处理流式响应
- 优化 OAuth 工具函数
- 添加相关测试用例
This commit is contained in:
fawney19
2026-02-05 15:57:52 +08:00
parent ed2ff5c1d7
commit 440721368f
44 changed files with 3498 additions and 134 deletions

View File

@@ -0,0 +1,46 @@
from __future__ import annotations
import json
import time
from types import SimpleNamespace
from unittest.mock import patch
import pytest
from src.api.handlers.base.request_builder import get_provider_auth
@pytest.mark.asyncio
async def test_get_provider_auth_oauth_returns_decrypted_auth_config() -> None:
now = int(time.time())
token_meta = {
"provider_type": "antigravity",
"expires_at": now + 3600,
"refresh_token": "rt-1",
"project_id": "project-1",
}
endpoint = SimpleNamespace(api_format="gemini:cli")
key = SimpleNamespace(
id="k1",
auth_type="oauth",
api_key="enc_access",
auth_config="enc_cfg",
provider=None,
)
def _decrypt(v): # noqa: ANN001
if v == "enc_access":
return "access-token"
if v == "enc_cfg":
return json.dumps(token_meta)
return ""
with patch("src.api.handlers.base.request_builder.crypto_service.decrypt", side_effect=_decrypt):
auth = await get_provider_auth(endpoint, key) # type: ignore[arg-type]
assert auth is not None
assert auth.auth_header == "Authorization"
assert auth.auth_value == "Bearer access-token"
assert auth.decrypted_auth_config == token_meta