mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-13 06:31:47 +00:00
* fix(models): close Codex async HTTP requests on cancellation * test(models): isolate loopback cancellation checks from proxies * docs: record Codex cancellation fix in changelog * docs: translate Codex cancellation changelog entry --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: Claude Code <noreply@anthropic.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
"""Codex async requests load TLS trust outside the event loop."""
|
|
|
|
import json
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from deerflow.models import openai_codex_provider as provider
|
|
from deerflow.models.credential_loader import CodexCliCredential
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_codex_async_http_with_real_tls_setup(monkeypatch):
|
|
monkeypatch.setattr(provider, "load_codex_cli_credential", lambda: CodexCliCredential("synthetic-token", "synthetic-account"))
|
|
model = provider.CodexChatModel(retry_max_attempts=1)
|
|
client_class = httpx.AsyncClient
|
|
clients = []
|
|
|
|
def respond(request):
|
|
event = {"type": "response.completed", "response": {"output": [{"type": "message", "content": [{"type": "output_text", "text": "OK"}]}]}}
|
|
return httpx.Response(200, text=f"data: {json.dumps(event)}\n\n")
|
|
|
|
def client(**kwargs):
|
|
instance = client_class(transport=httpx.MockTransport(respond), **kwargs)
|
|
clients.append(instance)
|
|
return instance
|
|
|
|
monkeypatch.setattr(provider.httpx, "AsyncClient", client)
|
|
result = await model.ainvoke("Synthetic nonblocking request")
|
|
assert result.content == "OK"
|
|
assert len(clients) == 1
|
|
assert clients[0].is_closed
|