AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
test(backend/copilot): Fix reasoning + community-rebuild tests for fork PRs (#13406)
Reinier van der Leer2053485b6444
diff --git a/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py b/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.pyindex 3389a5ee98..a3a873fa20 100644--- a/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py+++ b/autogpt_platform/backend/backend/copilot/baseline/service_unit_test.py@@ -2033,9 +2033,22 @@ class TestBaselineReasoningStreaming:return_value=_make_stream_mock())- with patch(- "backend.copilot.baseline.service._get_main_client",- return_value=mock_client,+ # Pin the OpenRouter transport so ``extra_body`` is always built:+ # ``openrouter_active`` needs a non-empty ``api_key``, which on fork-PR+ # CI is absent (secrets — incl. ``OPENAI_API_KEY`` — aren't exposed),+ # flipping the transport to ``direct_anthropic`` and dropping+ # ``extra_body`` entirely. Without this the assertion KeyErrors in CI.+ with (+ patch(+ "backend.copilot.baseline.service._get_main_client",+ return_value=mock_client,+ ),+ patch("backend.copilot.baseline.service.config.use_openrouter", True),+ patch("backend.copilot.baseline.service.config.api_key", "or-key"),+ patch(+ "backend.copilot.baseline.service.config.base_url",+ "https://openrouter.ai/api/v1",+ ),):await _baseline_llm_caller(messages=[{"role": "user", "content": "hi"}],@@ -2172,6 +2185,10 @@ class TestBaselineReasoningStreaming:return_value=_make_stream_mock())+ # Pin the OpenRouter transport so ``extra_body`` is always built (and+ # the kill switch's suppression is observable on a populated dict) —+ # fork-PR CI has no LLM creds, which would otherwise drop the transport+ # to direct_anthropic and omit ``extra_body``, KeyErroring the assert.with (patch("backend.copilot.baseline.service._get_main_client",@@ -2181,6 +2198,12 @@ class TestBaselineReasoningStreaming:"backend.copilot.baseline.service.config.claude_agent_max_thinking_tokens",0,),+ patch("backend.copilot.baseline.service.config.use_openrouter", True),+ patch("backend.copilot.baseline.service.config.api_key", "or-key"),+ patch(+ "backend.copilot.baseline.service.config.base_url",+ "https://openrouter.ai/api/v1",+ ),):await _baseline_llm_caller(messages=[{"role": "user", "content": "hi"}],diff --git a/autogpt_platform/backend/backend/copilot/graphiti/communities_test.py b/autogpt_platform/backend/backend/copilot/graphiti/communities_test.pyindex d4d439551b..33524d0d00 100644--- a/autogpt_platform/backend/backend/copilot/graphiti/communities_test.py+++ b/autogpt_platform/backend/backend/copilot/graphiti/communities_test.py@@ -30,6 +30,30 @@ def _free_rebuild_lock():yield redis[email protected](autouse=True)+def _pin_openrouter_transport():+ """Pin the chat transport to OpenRouter so the flex-tier path is taken+ deterministically. ``rebuild_communities_for_user`` only takes the flex+ branch when ``chat_cfg.transport.supports_flex_tier`` is True, which holds+ only for the OpenRouter transport. That resolves from+ ``config.openrouter_active``, which needs a non-empty ``api_key`` — absent+ on fork-PR CI, where repo secrets (incl. ``OPENAI_API_KEY``) aren't exposed.+ Without this pin the transport silently drops to ``direct_anthropic`` (no+ flex), and tests that only patch ``make_flex_graphiti_client`` fall through+ to the real sync client. The flag-driven sync test patches+ ``community_rebuild_use_flex_tier`` itself, so it still takes the sync path.+ """+ with (+ patch("backend.copilot.sdk.env.config.use_openrouter", True),+ patch("backend.copilot.sdk.env.config.api_key", "or-key"),+ patch(+ "backend.copilot.sdk.env.config.base_url",+ "https://openrouter.ai/api/v1",+ ),+ ):+ yield++def _neighbor(uuid: str, edge_count: int = 1):"""Mimic graphiti's Neighbor namedtuple — only attributes touched by LP."""return SimpleNamespace(node_uuid=uuid, edge_count=edge_count)