headroom/tests/test_cli/test_wrap_claude.py
Rod Boev 798139608c
fix(claude): stop forcing tool search on Foundry (#2477)
## Description

Foundry sessions launched through `headroom wrap claude` currently
receive Headroom's generic `ENABLE_TOOL_SEARCH=true` default when the
user did not choose a tool-search mode. That can push Claude Code into a
deferred-tool request shape that Azure Foundry rejects with `API Error:
400 ... Some tools are not available`. This narrows the default-only
path so Foundry sessions stop forcing deferred-tool mode when the user
did not ask for it, while explicit overrides and the existing
non-Foundry custom-host behavior stay unchanged.

Closes #2464

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- add a Foundry-specific default for the no-override tool-search branch
- preserve explicit `--tool-search` values and pre-set
`ENABLE_TOOL_SEARCH` values exactly
- keep the generic non-Foundry default as `true`
- add focused helper-level regression coverage for Foundry defaulting
and adjacent negative space

## Testing

- [x] Focused unit tests pass (`uv run pytest
tests/test_cli/test_wrap_claude.py
tests/test_cli/test_wrap_claude_vertex_proxy_env.py
tests/test_issue_746_tool_search.py -q`)
- [x] Edited-file linting passes (`uv run ruff check
headroom/cli/wrap.py headroom/providers/claude/runtime.py
tests/test_cli/test_wrap_claude.py`)
- [ ] Type checking passes (`uv run mypy headroom`)
- [x] New tests added for new functionality when applicable
- [ ] Manual testing performed

### Test Output

```text
Command: uv run pytest tests/test_cli/test_wrap_claude.py tests/test_cli/test_wrap_claude_vertex_proxy_env.py tests/test_issue_746_tool_search.py -q
61 passed

Command: uv run ruff check headroom/cli/wrap.py headroom/providers/claude/runtime.py tests/test_cli/test_wrap_claude.py
All checks passed!
```

## Real Behavior Proof

- Environment: Windows, Python via `uv`, Foundry mode modeled through
the wrap helper inputs
- Exact command / steps: run the focused helper regression and
edited-file lint commands above
- Observed result: `61 passed`; `All checks passed!`; Foundry mode
without an override writes `ENABLE_TOOL_SEARCH=false`, while explicit
overrides, existing values, blank handling, and the non-Foundry default
remain covered
- Not tested: live Azure Foundry tenant run

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] I have updated the CHANGELOG.md if applicable

## Additional Notes

`CHANGELOG.md` stays untouched because Headroom generates release notes
from conventional commits. Live Foundry proof is intentionally left to a
real tenant run; the code and focused tests only claim the launch-mode
change inside Headroom.
2026-08-12 00:15:07 -05:00

59 lines
1.7 KiB
Python

"""Focused tests for Claude wrap tool-search defaults."""
from __future__ import annotations
import pytest
from headroom.cli.wrap import (
_TOOL_SEARCH_DEFAULT,
_TOOL_SEARCH_ENV,
_configure_tool_search_env,
)
def test_foundry_without_override_disables_tool_search() -> None:
env = {"CLAUDE_CODE_USE_FOUNDRY": "1"}
result = _configure_tool_search_env(env, None)
assert result == "false"
assert env[_TOOL_SEARCH_ENV] == "false"
@pytest.mark.parametrize("flag_value", ["auto", "false"])
def test_explicit_flag_wins_in_foundry(flag_value: str) -> None:
env = {"CLAUDE_CODE_USE_FOUNDRY": "1"}
result = _configure_tool_search_env(env, flag_value)
assert result == flag_value
assert env[_TOOL_SEARCH_ENV] == flag_value
def test_existing_environment_value_wins_in_foundry() -> None:
env = {"CLAUDE_CODE_USE_FOUNDRY": "1", _TOOL_SEARCH_ENV: "auto:30"}
result = _configure_tool_search_env(env, None)
assert result is None
assert env[_TOOL_SEARCH_ENV] == "auto:30"
@pytest.mark.parametrize("blank", ["", " ", "\t"])
def test_blank_environment_uses_mode_default(blank: str) -> None:
foundry_env = {"CLAUDE_CODE_USE_FOUNDRY": "1", _TOOL_SEARCH_ENV: blank}
generic_env = {_TOOL_SEARCH_ENV: blank}
assert _configure_tool_search_env(foundry_env, None) == "false"
assert foundry_env[_TOOL_SEARCH_ENV] == "false"
assert _configure_tool_search_env(generic_env, None) == _TOOL_SEARCH_DEFAULT
assert generic_env[_TOOL_SEARCH_ENV] == _TOOL_SEARCH_DEFAULT
def test_non_foundry_without_override_keeps_generic_default() -> None:
env: dict[str, str] = {}
result = _configure_tool_search_env(env, None)
assert result == _TOOL_SEARCH_DEFAULT
assert env[_TOOL_SEARCH_ENV] == _TOOL_SEARCH_DEFAULT