Files
headroom/tests/test_provider_grok.py
APandJerrettDavis cd4367b040 feat(antigravity): add native Google Antigravity IDE integration (#3817)
## Description

Native Google Antigravity IDE integration for Headroom. Antigravity
reads its
model endpoints from its own model-provider settings (not env vars), so
this
follows the existing proxy-only `wrap` pattern: start the Headroom proxy
and
print the custom OpenAI-compatible provider settings to add in the IDE.
A new
MCP registrar installs Headroom into Antigravity's global
`mcp_config.json`.

Closes #727

## Type of Change

- [x] New feature (non-breaking change that adds functionality)

## Changes Made

- `headroom wrap antigravity` — starts the proxy and prints the custom
OpenAI-compatible model-provider settings for Antigravity (same
proxy-only
pattern as `wrap cursor`; per-project `/p/<name>` base-URL prefixes for
  dashboard attribution).
- `headroom mcp install --agent antigravity` — new
`AntigravityRegistrar` for
the global `mcp_config.json` under `~/.gemini/`. Prefers an
already-existing
config location, refuses to overwrite unparseable JSON, clears
Antigravity's
  per-surface MCP cache dirs on uninstall.
- Registers the `antigravity` slice in the persistent install env
registry.
- Docs: `proxy.mdx` gains an Antigravity IDE section covering `wrap`,
  `mcp install`, and the existing `/v1internal:streamGenerateContent`
Cloud Code compatibility endpoint for native google-antigravity clients.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ pytest tests/test_cli/test_wrap_antigravity.py \
         tests/test_mcp_registry/test_antigravity_registrar.py \
         tests/test_provider_antigravity.py
34 passed, 1 warning in 0.75s
(the warning is a pre-existing `asyncio_mode` config notice, unrelated)

$ ruff check <changed files>
All checks passed!

$ ruff format --check <changed files>
7 files already formatted
```

## Real Behavior Proof

- Environment: Linux, Python 3.12, branch
`fix/727-antigravity-integration`
- Exact command / steps: `wrap --help` (lists `antigravity`, exit 0);
`wrap antigravity --help` (prints the Antigravity IDE setup instructions
for the custom OpenAI-compatible model-provider flow); `wrap antigravity
--prepare-only` (exit 0).
- Observed result: the new command is wired into the CLI and its help
text
  documents the custom-provider setup flow.
- Not tested: end-to-end `mcp install` against a real Antigravity IDE
(the MCP
SDK extra is not installed in this environment; registrar behavior is
covered
by its unit tests); live proxy traffic from an actual Antigravity
client.

## Runtime Rollout Safety

- Rollout-managed feature(s): none (new additive commands only)
- Minimum rollout channel: n/a
- Stable/default behavior changed: no — existing `wrap` / `mcp install`
  flows are untouched
- Kill switch / disable path: do not run the new commands;
`headroom mcp uninstall --agent antigravity` removes the MCP
registration
- Unsafe override required: no
- Qualification impact: none
- Rollback path: revert the single commit

## 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] 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 my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please
      from my Conventional Commit PR title

## Additional Notes

- `mypy` was not run (not installed in this environment); `ruff check`
and
  `ruff format` are clean on all changed files.
- Antigravity reads endpoints from its model-provider settings, not env
vars,
so `wrap antigravity` prints setup instructions instead of launching the
IDE.

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/3817"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-10-07 13:33:59 -05:00

62 lines
2.5 KiB
Python

from __future__ import annotations
from headroom.providers.grok import (
PROXY_ENV_KEY,
build_launch_env,
is_grok_cli_request,
proxy_base_url,
)
from headroom.providers.grok.install import build_install_env
def test_grok_proxy_base_url_uses_local_headroom_proxy() -> None:
assert proxy_base_url(8787) == "http://127.0.0.1:8787/v1"
def test_is_grok_cli_request_matches_xai_token_auth() -> None:
# Official Grok CLI stamps x-xai-token-auth: xai-grok-cli on inference.
assert is_grok_cli_request({"x-xai-token-auth": "xai-grok-cli"}) is True
assert is_grok_cli_request({"X-Xai-Token-Auth": "xai-grok-cli"}) is True
assert is_grok_cli_request({"x-xai-token-auth": "other"}) is False
def test_is_grok_cli_request_matches_known_user_agents() -> None:
assert (
is_grok_cli_request(
{"user-agent": "grok-pager/0.2.117 grok-shell/0.2.117 (macos; aarch64)"}
)
is True
)
assert is_grok_cli_request({"user-agent": "grok-shell/0.2.112"}) is True
# Grok Build stamps grok/<version>; per-request xAI routing must recognize
# it too, matching the repo's own client classification (CLIENT_UA_MAP).
assert is_grok_cli_request({"user-agent": "grok/1.2.3"}) is True
# Non-Grok OpenAI-compatible clients must not match, including wrappers
# whose name merely contains "grok" — they carry OpenAI credentials. The
# prefix anchor keeps them out: only a token starting with "grok/" matches.
assert is_grok_cli_request({"user-agent": "codex-tui/0.146.0"}) is False
assert is_grok_cli_request({"user-agent": "litellm-grok/1.0"}) is False
assert is_grok_cli_request({"user-agent": "my-grok-shell/1.0"}) is False
assert is_grok_cli_request({}) is False
def test_grok_build_launch_env_sets_models_base_url() -> None:
env, display = build_launch_env(9999, environ={})
assert env[PROXY_ENV_KEY] == "http://127.0.0.1:9999/v1"
assert "GROK_CLI_CHAT_PROXY_BASE_URL" not in env
assert display == [f"{PROXY_ENV_KEY}=http://127.0.0.1:9999/v1"]
def test_grok_build_launch_env_applies_project_prefix() -> None:
env, _display = build_launch_env(8787, environ={}, project="frontend")
assert env[PROXY_ENV_KEY] == "http://127.0.0.1:8787/p/frontend/v1"
assert "GROK_CLI_CHAT_PROXY_BASE_URL" not in env
def test_grok_build_install_env_returns_proxy_url() -> None:
assert build_install_env(port=7654, backend="ignored") == {
PROXY_ENV_KEY: "http://127.0.0.1:7654/v1",
}