mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
fix(copilot): address round-6 review nits
- Remove redundant inner `ChatConfig` import in `_prewarm_cli` — it was already imported at module scope on line 16 (style guide: inner imports only for heavy optional deps) - Correct stale comment in `sdk_compat_test.py`: 2.1.63/2.1.70 pre-date the context-management regression and are OpenRouter-safe without any env var; only 2.1.97+ requires CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 - Update `_assert_no_forbidden_patterns` error message in `cli_openrouter_compat_test.py`: remove the stale "above 0.1.45" ceiling (we've already upgraded to 0.1.58) and point at the correct remediation steps (add to _KNOWN_GOOD_BUNDLED_CLI_VERSIONS after bisect verification) - Plug test coverage gap in `env_test.py`: add `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS == "1"` assertions to three OpenRouter test methods that were missing it (test_strips_trailing_v1, test_strips_trailing_v1_and_slash, test_no_v1_suffix_left_alone) — guards against the env var being accidentally dropped from a code path that the main test didn't exercise
This commit is contained in:
@@ -183,8 +183,6 @@ class CoPilotProcessor:
|
||||
back to the bundled binary when no override is set.
|
||||
"""
|
||||
try:
|
||||
from backend.copilot.config import ChatConfig
|
||||
|
||||
cfg = ChatConfig()
|
||||
cli_path: str | None = cfg.claude_agent_cli_path
|
||||
if not cli_path:
|
||||
|
||||
@@ -443,14 +443,15 @@ def _assert_no_forbidden_patterns(
|
||||
f"Bundled Claude Code CLI sent OpenRouter-incompatible features in "
|
||||
f"{len(all_findings)} request(s):\n - "
|
||||
+ "\n - ".join(all_findings)
|
||||
+ "\n\nThis is the regression that prevents us from upgrading "
|
||||
"`claude-agent-sdk` above 0.1.45. See "
|
||||
"https://github.com/Significant-Gravitas/AutoGPT/pull/12294 and "
|
||||
+ "\n\nThe bundled CLI is sending OpenRouter-incompatible features. "
|
||||
"See https://github.com/Significant-Gravitas/AutoGPT/pull/12294 and "
|
||||
"https://github.com/anthropics/claude-agent-sdk-python/issues/789. "
|
||||
"If you intended to upgrade, ensure "
|
||||
"`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` is set in the SDK env "
|
||||
"or use a known-good CLI binary via `claude_agent_cli_path` (env: "
|
||||
"`CLAUDE_AGENT_CLI_PATH` or `CHAT_CLAUDE_AGENT_CLI_PATH`)."
|
||||
"If you bumped `claude-agent-sdk`, verify the new bundled CLI works "
|
||||
"with `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` set (injected by "
|
||||
"``build_sdk_env()`` in ``env.py``), then add the CLI version to "
|
||||
"`_KNOWN_GOOD_BUNDLED_CLI_VERSIONS` in `sdk_compat_test.py`. "
|
||||
"Alternatively, pin a known-good binary via `claude_agent_cli_path` "
|
||||
"(env: `CLAUDE_AGENT_CLI_PATH` or `CHAT_CLAUDE_AGENT_CLI_PATH`)."
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -138,6 +138,7 @@ class TestBuildSdkEnvOpenRouter:
|
||||
result = build_sdk_env()
|
||||
|
||||
assert result["ANTHROPIC_BASE_URL"] == "https://openrouter.ai/api"
|
||||
assert result.get("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS") == "1"
|
||||
|
||||
def test_strips_trailing_v1_and_slash(self):
|
||||
"""Trailing slash before /v1 strip is handled."""
|
||||
@@ -149,6 +150,7 @@ class TestBuildSdkEnvOpenRouter:
|
||||
|
||||
# rstrip("/") first, then remove /v1
|
||||
assert result["ANTHROPIC_BASE_URL"] == "https://openrouter.ai/api"
|
||||
assert result.get("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS") == "1"
|
||||
|
||||
def test_no_v1_suffix_left_alone(self):
|
||||
"""A base URL without /v1 is used as-is."""
|
||||
@@ -159,6 +161,7 @@ class TestBuildSdkEnvOpenRouter:
|
||||
result = build_sdk_env()
|
||||
|
||||
assert result["ANTHROPIC_BASE_URL"] == "https://custom-proxy.example.com"
|
||||
assert result.get("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS") == "1"
|
||||
|
||||
def test_session_id_header(self):
|
||||
cfg = self._openrouter_config()
|
||||
|
||||
@@ -215,17 +215,19 @@ def test_sdk_exports_hook_event_type(hook_event: str):
|
||||
# message that points the next person at the OpenRouter compat issue
|
||||
# instead of letting them silently re-break production.
|
||||
|
||||
# CLI versions verified to work against OpenRouter when the
|
||||
# ``CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`` env var is set --
|
||||
# bisected via the reproduction test in ``cli_openrouter_compat_test.py``.
|
||||
# CLI versions bisect-verified as OpenRouter-safe. 2.1.63 and 2.1.70 pre-date
|
||||
# the context-management beta regression and work without any env var. 2.1.97+
|
||||
# requires ``CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`` (injected by
|
||||
# ``build_sdk_env()`` in ``env.py``) to strip the beta header.
|
||||
_KNOWN_GOOD_BUNDLED_CLI_VERSIONS: frozenset[str] = frozenset(
|
||||
{
|
||||
"2.1.63", # claude-agent-sdk 0.1.45 -- original pin from PR #12294.
|
||||
"2.1.70", # claude-agent-sdk 0.1.47 -- first version with the
|
||||
# tool_reference proxy detection fix; bisect-verified
|
||||
# OpenRouter-safe in #12742.
|
||||
"2.1.97", # claude-agent-sdk 0.1.58 -- works with the
|
||||
# CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 env var.
|
||||
"2.1.97", # claude-agent-sdk 0.1.58 -- OpenRouter-safe only with
|
||||
# CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 (injected by
|
||||
# build_sdk_env() in env.py).
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user