From 4e9eea13fd2355c1218c95574e45cf41a1fbf2df Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 22 Aug 2026 13:30:20 +0800 Subject: [PATCH] test: inject agent protocol config snapshots --- tests/test_agent_protocol_lifecycle.py | 39 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/test_agent_protocol_lifecycle.py b/tests/test_agent_protocol_lifecycle.py index e2475b368..2175a2224 100644 --- a/tests/test_agent_protocol_lifecycle.py +++ b/tests/test_agent_protocol_lifecycle.py @@ -8,7 +8,6 @@ from fastapi.security import HTTPAuthorizationCredentials from app import schemas from app.api.endpoints import anthropic, openai -from app.runtime.config import settings _API_TOKEN = "test-agent-protocol-token" @@ -73,10 +72,18 @@ def test_streaming_protocols_reject_config_disable_before_manager_lookup() -> No ), ) - with patch.object(settings, "AI_AGENT_ENABLE", False), patch.object( - settings, - "API_TOKEN", - _API_TOKEN, + runtime_config = SimpleNamespace( + ai_agent_enable=False, + api_token=_API_TOKEN, + ) + with patch.object( + openai, + "get_api_runtime_config_snapshot", + return_value=runtime_config, + ), patch.object( + anthropic, + "get_api_runtime_config_snapshot", + return_value=runtime_config, ), patch.object( openai, "get_running_agent_manager", @@ -111,10 +118,13 @@ def test_openai_stream_rejects_shutdown_race_and_cleans_request_session() -> Non ) return await _collect(response) - with patch.object(settings, "AI_AGENT_ENABLE", True), patch.object( - settings, - "API_TOKEN", - _API_TOKEN, + with patch.object( + openai, + "get_api_runtime_config_snapshot", + return_value=SimpleNamespace( + ai_agent_enable=True, + api_token=_API_TOKEN, + ), ), patch.object( openai, "get_running_agent_manager", @@ -145,10 +155,13 @@ def test_anthropic_stream_rejects_shutdown_race_and_cleans_request_session() -> ) return await _collect(response) - with patch.object(settings, "AI_AGENT_ENABLE", True), patch.object( - settings, - "API_TOKEN", - _API_TOKEN, + with patch.object( + anthropic, + "get_api_runtime_config_snapshot", + return_value=SimpleNamespace( + ai_agent_enable=True, + api_token=_API_TOKEN, + ), ), patch.object( anthropic, "get_running_agent_manager",