Files
headroom/tests/test_provider_claude.py
Rod BoevandJerrettDavis fc5a09e1b3 feat(wrap): support 1m context in vscode claude (#3361)
## Description

`headroom wrap vscode-claude` now supports an opt-in `--1m` path. It
stores Claude Code's `[1m]` model selector in the existing top-level
`model` setting and records the prior value in the reversible settings
sidecar. Reconfiguration remains idempotent, malformed sidecars fail
with a clear error, and user changes to Headroom-managed values remain
protected.

The branch also pins npm 11.16.0 in the shared Docker wrap test image.
npm 10.9.8 crashed while installing the local OpenClaw plugin with
`Cannot read properties of null (reading 'edgesOut')`.

Closes #3360

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] 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

- Added `--1m` to `headroom wrap vscode-claude`.
- Reused one Claude-specific resolver for standalone and VS Code model
selection.
- Extended the reversible VS Code sidecar to preserve, validate, and
restore the top-level model.
- Refreshes fallback-selected models when `HEADROOM_1M_MODEL` changes
between repeated `--1m` runs.
- Preserved exact prior values and refuses to overwrite user edits.
- Added read-only `--no-configure --1m` output for manual settings
setup.
- Added focused tests for model persistence, fallback refresh, malformed
state, conflict handling, and restoration.
- Pinned npm 11.16.0 in `e2e/wrap/Dockerfile` for both Docker wrap jobs.
- Updated the VS Code Claude documentation.

## Testing

- [x] Focused unit and integration tests pass
- [x] Linting and formatting checks pass for changed Python files
- [ ] Type checking passes
- [x] New tests added for the changed behavior
- [ ] Manual testing performed

### Test Output

```text
uv run pytest tests/test_cli/test_wrap_vscode_claude.py tests/test_provider_claude.py tests/test_provider_claude_vscode_config.py -q
48 passed in 1.15s

uv run ruff check headroom/providers/claude/vscode.py headroom/cli/wrap.py tests/test_provider_claude_vscode_config.py
All checks passed!

uv run ruff format --check headroom/providers/claude/vscode.py headroom/cli/wrap.py tests/test_provider_claude_vscode_config.py
3 files already formatted
```

## Real Behavior Proof

- Environment: Windows, Python development environment, temporary Claude
settings file.
- Exact command / steps: run `headroom wrap vscode-claude --1m
--settings-file <temporary-settings.json>`, inspect the settings and
sidecar, then run `headroom unwrap vscode-claude --settings-file
<temporary-settings.json>`.
- Observed result: the `[1m]` model persisted, the sidecar recorded the
prior model, and unwrap restored the exact prior value. Repeated `--1m`
runs picked up a changed `HEADROOM_1M_MODEL` fallback when no user model
existed.
- GitHub CI result: `docker-wrap-e2e`, `docker-native-e2e`, and all
other required checks passed after the npm pin.
- Not tested: live Claude account entitlement for the 1M context window.

## Runtime Rollout Safety

- Rollout-managed feature(s): none.
- Minimum rollout channel: next release containing the VS Code Claude
wrapper change.
- Stable/default behavior changed: `--1m` remains opt-in; default VS
Code Claude behavior is unchanged.
- Kill switch / disable path: omit `--1m`, run `headroom unwrap
vscode-claude`, or revert the change before release.
- Unsafe override required: no.
- Qualification impact: Claude account entitlement still controls access
to the 1M context window.
- Rollback path: run `headroom unwrap vscode-claude`, reload VS Code,
and revert the release if needed.

## 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
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove the feature works
- [x] Focused tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md`; release-please generates it
from the conventional PR title.

## Additional Notes

Claude Code and Anthropic control model support and account eligibility.
Local tests prove persisted configuration and restoration, not access to
a live 1M context window.

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-09-24 23:50:27 -05:00

43 lines
1.2 KiB
Python

from __future__ import annotations
import pytest
from headroom.providers.claude import (
CONTEXT_1M_SUFFIX,
DEFAULT_1M_MODEL,
DEFAULT_API_URL,
HEADROOM_1M_MODEL_ENV,
proxy_base_url,
resolve_1m_model,
)
def test_claude_runtime_exposes_default_api_and_local_proxy_url() -> None:
# Arrange / Act / Assert
assert DEFAULT_API_URL == "https://api.anthropic.com"
assert proxy_base_url(4321) == "http://127.0.0.1:4321"
@pytest.mark.parametrize(
("current", "fallback", "expected"),
[
(" claude-sonnet-5 ", None, "claude-sonnet-5[1m]"),
("claude-opus-5[1m]", "ignored", "claude-opus-5[1m]"),
(None, " claude-opus-9 ", "claude-opus-9[1m]"),
(" ", None, f"{DEFAULT_1M_MODEL}{CONTEXT_1M_SUFFIX}"),
],
)
def test_resolve_1m_model_contract_is_provider_owned(
monkeypatch: pytest.MonkeyPatch,
current: str | None,
fallback: str | None,
expected: str,
) -> None:
if fallback is None:
monkeypatch.delenv(HEADROOM_1M_MODEL_ENV, raising=False)
else:
monkeypatch.setenv(HEADROOM_1M_MODEL_ENV, fallback)
assert resolve_1m_model(current) == expected
assert resolve_1m_model(expected) == expected