mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(doctor): recognize Azure Foundry routing for Claude Code (#1339)
## Description `headroom doctor` only inspected `ANTHROPIC_BASE_URL` when checking Claude Code routing. In Azure Foundry mode, Claude Code routes through `ANTHROPIC_FOUNDRY_BASE_URL` when `CLAUDE_CODE_USE_FOUNDRY=1`, so a correctly wired setup was reported as `claude: not routed`. This PR falls back to `ANTHROPIC_FOUNDRY_BASE_URL` only when the Foundry flag is present, then sends that URL through the existing routing classifier. Non-Foundry Claude routing behavior is unchanged. ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Documentation - [ ] Refactor - [ ] Tests only ## Changes Made - `headroom/cli/doctor.py`: recognize `ANTHROPIC_FOUNDRY_BASE_URL` when `CLAUDE_CODE_USE_FOUNDRY=1` and `ANTHROPIC_BASE_URL` is absent. - `tests/test_cli_doctor.py`: add coverage for a valid Foundry route, missing Foundry URL, and a Foundry URL without the Foundry flag. ## Testing - [x] Unit tests - [x] Lint/static checks - [ ] Integration tests ### Test Output ```text uv run --extra dev python -m pytest tests/test_cli_doctor.py -q 44 passed in 0.96s uv run --extra dev ruff check headroom/cli/doctor.py tests/test_cli_doctor.py All checks passed! ``` ## Real Behavior Proof - Environment: macOS; Claude Code with `CLAUDE_CODE_USE_FOUNDRY=1` and `ANTHROPIC_FOUNDRY_BASE_URL` set in `~/.claude/settings.json`; Headroom proxy on `:8787` with the Foundry URL pointed at an Azure APIM upstream. - Exact command / steps: set `ANTHROPIC_FOUNDRY_BASE_URL` to `http://localhost:8787` in the Claude settings env block, then run `uv run headroom doctor`. - Observed result: the Claude row changed from a false `not routed` warning to a routed/pass result, and a live `/v1/messages` request forwarded through the proxy to the Azure upstream and returned 200. - Not tested: non-loopback Foundry URLs; those reuse the existing `_classify_routing_url` warning path. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review Co-authored-by: Juri Kern <juri.kern@illumio.com> Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
co-authored by
Juri Kern
JerrettDavis
parent
bb1ab6afd3
commit
d5318ac235
@@ -316,7 +316,7 @@ def check_version_drift(livez: dict[str, Any] | None, installed: str) -> CheckRe
|
||||
|
||||
|
||||
def _claude_base_url_in(path: Path) -> tuple[str, CheckResult | None]:
|
||||
"""Read ``env.ANTHROPIC_BASE_URL`` from one Claude settings file.
|
||||
"""Read the active Claude routing URL from one settings file.
|
||||
|
||||
Returns ``(base_url, error)``. A parse problem comes back as a WARN so the
|
||||
caller surfaces it verbatim instead of skipping the file and reporting the
|
||||
@@ -340,7 +340,10 @@ def _claude_base_url_in(path: Path) -> tuple[str, CheckResult | None]:
|
||||
)
|
||||
env_block = payload.get("env")
|
||||
if isinstance(env_block, dict):
|
||||
return str(env_block.get("ANTHROPIC_BASE_URL", "") or ""), None
|
||||
base_url = str(env_block.get("ANTHROPIC_BASE_URL", "") or "")
|
||||
if not base_url and str(env_block.get("CLAUDE_CODE_USE_FOUNDRY", "") or ""):
|
||||
base_url = str(env_block.get("ANTHROPIC_FOUNDRY_BASE_URL", "") or "")
|
||||
return base_url, None
|
||||
return "", None
|
||||
|
||||
|
||||
|
||||
@@ -185,6 +185,42 @@ class TestClaudeRouting:
|
||||
assert result.status == WARN
|
||||
assert "gateway.corp.example" in result.summary
|
||||
|
||||
def test_foundry_url_passes(self, tmp_path):
|
||||
# In Foundry mode ANTHROPIC_BASE_URL is absent by design; routing lives
|
||||
# in ANTHROPIC_FOUNDRY_BASE_URL. doctor must recognize it as routed.
|
||||
path = tmp_path / "settings.json"
|
||||
path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"env": {
|
||||
"CLAUDE_CODE_USE_FOUNDRY": "1",
|
||||
"ANTHROPIC_FOUNDRY_BASE_URL": "http://127.0.0.1:8787",
|
||||
}
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert check_claude_routing(path, 8787).status == PASS
|
||||
|
||||
def test_foundry_without_base_url_warns(self, tmp_path):
|
||||
# Foundry mode on but no upstream URL configured: still unrouted.
|
||||
path = tmp_path / "settings.json"
|
||||
path.write_text(
|
||||
json.dumps({"env": {"CLAUDE_CODE_USE_FOUNDRY": "1"}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert check_claude_routing(path, 8787).status == WARN
|
||||
|
||||
def test_foundry_url_ignored_without_flag(self, tmp_path):
|
||||
# Without CLAUDE_CODE_USE_FOUNDRY the foundry URL is not consulted, so a
|
||||
# settings file carrying only the foundry key reads as unrouted.
|
||||
path = tmp_path / "settings.json"
|
||||
path.write_text(
|
||||
json.dumps({"env": {"ANTHROPIC_FOUNDRY_BASE_URL": "http://127.0.0.1:8787"}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert check_claude_routing(path, 8787).status == WARN
|
||||
|
||||
|
||||
class TestClaudeDesktop:
|
||||
def test_no_desktop_dir_produces_no_row(self, tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user