mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 15:07:29 +08:00
## Description
Make an explicit HEADROOM_TELEMETRY=off or --no-telemetry choice stop
the anonymous upload beacon as well as local telemetry, while preserving
the separately configured HEADROOM_BEACON=on override and existing
offline/DO_NOT_TRACK policy.
Existing persistent manifests already contain explicit off values
written by the old installer defaults. Those installs stay opted out
after upgrading unless deliberately reconfigured or reinstalled. The PR
does not guess which saved off values were intentional. New installs
omit an unspecified telemetry choice so they retain the existing default
beacon policy.
## Type of Change
- [x] Bug fix (telemetry opt-out behavior)
- [x] Documentation update
## Changes Made
- Apply an explicit local-telemetry opt-out to the beacon enable
decision and report the reason in telemetry status.
- Recheck enablement before sending buffered session telemetry.
- Preserve unspecified, enabled, and disabled telemetry choices when
generating installation manifests.
- Update operator documentation and regression coverage.
## Testing
- [x] Maintainer telemetry, beacon, and snapshot suites passed after the
current-main sync.
- [x] Whitespace check passed.
### Test Output
```text
python -m pytest tests/test_telemetry_warning.py tests/test_proxy_telemetry_env.py tests/test_beacon_schema_v2.py tests/test_beacon_gzip.py tests/test_original_snapshot_in_place_hook.py -q
122 passed, 1 warning in 21.19s
```
A previous broader installer run also reproduced the persistent-service
embedder assertion on current main independently; that baseline failure
was not attributed to this PR. The other 34 planner tests passed in that
qualification. Hosted CI is qualifying head
d2f8582f97.
## Real Behavior Proof
- Environment: isolated Windows/Python 3.12.13 maintainer worktree with
actual telemetry/beacon decision logic and proxy fixtures.
- Exact command / steps: run the five pytest suites shown above,
including explicit opt-out, override, and buffered-session regressions.
- Observed result: all 122 selected tests passed after incorporating
current main. Earlier installer-choice regression coverage and the
independent main comparison are recorded in the qualification evidence.
- Not tested: independent maintainer live upload traffic to the
production collector or migration of real persistent installs. The
author's live status/proxy before/after observations are preserved below
and remain attributed to the author.
## Runtime Rollout Safety
- Rollout-managed feature(s): existing telemetry and beacon controls; no
new rollout framework toggle.
- Minimum rollout channel: existing deployment policy applies.
- Stable/default behavior changed: an explicit telemetry opt-out also
disables beacon uploads unless a permissible explicit beacon-on override
is configured. Saved legacy off values remain off; new unspecified
install choices are no longer persisted as off.
- Kill switch / disable path: HEADROOM_BEACON=off, DO_NOT_TRACK=1, or
offline mode under the existing policy.
- Unsafe override required: no.
- Qualification impact: operator intent and existing manifest behavior
must be considered during upgrade; hosted CI and human review remain
required.
- Rollback path: retain the prior qualified release; configure
HEADROOM_BEACON explicitly where appropriate rather than rewriting saved
user intent.
## Review Readiness
- [ ] I have performed a self-review
- [ ] This PR is ready for human review
Maintainer verification is documented above; author readiness
attestations have not been filled on the author's behalf.
## Additional Notes
The original author warning, description, follow-up exclusions, and
supplied evidence are preserved below.
> **Behaviour change for existing installs.** Read this before merging.
Every manifest that `headroom install` saved before this change already
contains `HEADROOM_TELEMETRY=off` and `--no-telemetry`, because the
planner wrote them by default. Those manifests are replayed as-is, so
**existing persistent installs will report the beacon OFF after
upgrading** until they are reinstalled. A loader migration can't tell
those defaults apart from a real opt-out, and turning uploads back on
for people who opted out would be worse, so this PR doesn't migrate. New
installs keep the beacon on by default.
#### The test we ran
A Daytona sandbox running Headroom Enterprise 0.4.3 (core 0.39.1), with
Codex CLI 0.162.1 and Claude Code connected to real GitHub, Context7 and
Fetch MCP servers, working through the workshop tasks.
#### What we found
`headroom telemetry --show` and the README say telemetry can be turned
off, and users reasonably set **`HEADROOM_TELEMETRY=off`** (or pass
`--no-telemetry`). But the anonymous upload beacon was gated only on
`HEADROOM_BEACON` / `DO_NOT_TRACK` / offline mode. With
`HEADROOM_TELEMETRY=off` it kept uploading, and `headroom telemetry`
still printed `Upload beacon: ON (opt-out)`.
#### The fix
- New `beacon_off_reason()` in `headroom/telemetry/beacon.py` names the
setting that turns the beacon off. `is_beacon_enabled()` delegates to
it. The order is:
1. offline mode;
2. `DO_NOT_TRACK`;
3. `HEADROOM_BEACON`, whose explicit `on` still wins over local stats
being off;
4. an explicit **`HEADROOM_TELEMETRY` off-value**: off / false / 0 / no
/ disable / disabled, the same `_OFF_VALUES` the module already uses.
`HEADROOM_TELEMETRY=on` still means only "local stats". It never
authorises upload.
- A session buffered before an opt-out is not sent afterwards:
`post_session_event` (heartbeat, idle close) and the exit flush re-check
`is_beacon_enabled()` at send time.
- `headroom telemetry` prints `Upload beacon: OFF
(HEADROOM_TELEMETRY=off)` (or whichever switch is in effect), and the
proxy startup log does the same.
- `headroom install`: since `off` now stops the beacon, the planner
writes `HEADROOM_TELEMETRY` / `--telemetry` / `--no-telemetry` only for
an explicit choice (`telemetry_enabled` is now tri-state, `None` = no
choice). Local stats stay off without the env var because they are
opt-in. `scripts/install.sh` and `install.ps1` already passed
`--no-telemetry` only on an explicit flag.
- Docs: README, proxy, security-model and limitations pages, the
dashboard tooltip, and the `--no-telemetry` help text.
- `test_banner_beacon_default_on_is_surfaced` asserted the old policy
(`--no-telemetry` leaves the beacon on). It now checks the default case
instead.
#### Before / after
| env | `is_beacon_enabled()` on origin/main | this PR | `headroom
telemetry` (this PR) |
|---|---|---|---|
| none | True | True | `ON (opt-out)` |
| `HEADROOM_TELEMETRY=off` | **True** | **False** | `OFF
(HEADROOM_TELEMETRY=off)` |
| `HEADROOM_TELEMETRY=off` + `HEADROOM_BEACON=on` | True | True | `ON
(opt-out)` |
| `HEADROOM_BEACON=off` | False | False | `OFF (HEADROOM_BEACON=off)` |
| `headroom install` with no flag → manifest | `HEADROOM_TELEMETRY=off`
+ `--no-telemetry` | neither written | — |
#### Tests
-
`tests/test_telemetry_warning.py::test_telemetry_off_turns_the_beacon_off_and_says_so`,
parametrized over the 7 off spellings: fails on origin/main, passes
here.
-
`tests/test_telemetry_warning.py::test_beacon_on_overrides_telemetry_off`.
-
`tests/test_telemetry_warning.py::test_buffered_session_is_not_sent_after_telemetry_off`:
fails on the first commit of this PR, passes now.
-
`tests/test_install/test_planner.py::test_install_writes_telemetry_only_when_chosen`,
through the CLI's `_build_deployment_manifest`: the no-flag case fails
on origin/main.
- Related suites pass: install, telemetry warning, beacon schema v2,
install CLI and proxy health (435 passed).
- ruff check, ruff format --check and mypy pass.
#### Follow-ups (not in this PR)
- `headroom init` passes `telemetry_enabled=True`, so its manifests turn
local stats on (`cli/init.py:718`). This doesn't affect the beacon.
- The `--telemetry` help text still says "anonymous telemetry", but the
flag only turns on local stats.
#### Real behavior proof
- **Setup:** macOS 26.7, Python 3.12.13. origin/main and this branch
were run side by side with `HEADROOM_BEACON` and `DO_NOT_TRACK` unset.
- `HEADROOM_TELEMETRY=off headroom telemetry`:
- origin/main: `Upload beacon: ON (opt-out)`, `is_beacon_enabled():
True`
- this branch: `Upload beacon: OFF (HEADROOM_TELEMETRY=off)`,
`is_beacon_enabled(): False`
- `headroom proxy --no-telemetry --no-optimize`, startup log:
- origin/main: `Anonymous upload beacon: ENABLED (default — session
summaries are sent to Headroom Labs). Opt out: HEADROOM_BEACON=off or
DO_NOT_TRACK=1`
- this branch: `Anonymous upload beacon: DISABLED
(HEADROOM_TELEMETRY=off)`
- **Not tested:** a real `headroom install apply` of a persistent
service on this branch; the manifest change is covered through
`_build_deployment_manifest`. Upgrading an existing install was not
tested either; see the warning at the top.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
510 lines
18 KiB
Python
510 lines
18 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import click
|
|
import pytest
|
|
|
|
from headroom.install.models import ConfigScope, InstallPreset, ProviderSelectionMode, ToolTarget
|
|
from headroom.install.planner import PROVIDER_SCOPE_TARGETS, build_manifest, resolve_targets
|
|
|
|
|
|
def test_resolve_targets_auto_falls_back_when_detection_empty(monkeypatch) -> None:
|
|
monkeypatch.setattr("headroom.install.planner.detect_targets", lambda: [])
|
|
|
|
targets = resolve_targets(ProviderSelectionMode.AUTO.value, [])
|
|
|
|
assert targets == [
|
|
ToolTarget.CLAUDE.value,
|
|
ToolTarget.CODEX.value,
|
|
ToolTarget.COPILOT.value,
|
|
]
|
|
|
|
|
|
def test_build_manifest_for_persistent_docker_sets_expected_defaults() -> None:
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_DOCKER.value,
|
|
runtime_kind="docker",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=["claude", "copilot"],
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=True,
|
|
telemetry_enabled=False,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
)
|
|
|
|
assert manifest.supervisor_kind == "none"
|
|
assert manifest.runtime_kind == "docker"
|
|
assert manifest.health_url == "http://127.0.0.1:8787/readyz"
|
|
assert manifest.base_env["HEADROOM_PORT"] == "8787"
|
|
assert manifest.base_env["HEADROOM_TELEMETRY"] == "off"
|
|
assert "--no-telemetry" in manifest.proxy_args
|
|
assert manifest.tool_envs["claude"]["ANTHROPIC_BASE_URL"] == "http://127.0.0.1:8787"
|
|
assert manifest.tool_envs["copilot"]["COPILOT_PROVIDER_TYPE"] == "anthropic"
|
|
assert "--memory" in manifest.proxy_args
|
|
# A container runtime must NOT carry the host memory DB path: it does not
|
|
# exist inside the container and would keep /readyz at 503 (#2803). The proxy
|
|
# resolves the DB under its own cwd, which is the bind-mounted ~/.headroom.
|
|
assert "--memory-db-path" not in manifest.proxy_args
|
|
assert "HEADROOM_EMBEDDER_RUNTIME" not in manifest.base_env
|
|
assert "HEADROOM_KOMPRESS_BACKEND" not in manifest.base_env
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("telemetry", "no_telemetry", "env", "flag"),
|
|
[
|
|
(False, False, None, None),
|
|
(True, False, "on", "--telemetry"),
|
|
(False, True, "off", "--no-telemetry"),
|
|
(True, True, "off", "--no-telemetry"),
|
|
],
|
|
)
|
|
def test_install_writes_telemetry_only_when_chosen(telemetry, no_telemetry, env, flag) -> None:
|
|
"""``HEADROOM_TELEMETRY=off`` now stops the upload beacon, so an install with
|
|
no telemetry flag must not write it (or ``--no-telemetry``) by default."""
|
|
from headroom.cli.install import _build_deployment_manifest
|
|
|
|
manifest = _build_deployment_manifest(
|
|
preset=InstallPreset.PERSISTENT_DOCKER.value,
|
|
runtime="docker",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=(),
|
|
profile="default",
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory=False,
|
|
telemetry=telemetry,
|
|
no_telemetry=no_telemetry,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
no_http2=False,
|
|
)
|
|
|
|
assert manifest.base_env.get("HEADROOM_TELEMETRY") == env
|
|
flags = {"--telemetry", "--no-telemetry"} & set(manifest.proxy_args)
|
|
assert flags == ({flag} if flag else set())
|
|
|
|
|
|
def test_build_manifest_docker_runtime_never_installs_native_supervisor() -> None:
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_SERVICE.value,
|
|
runtime_kind="docker",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=[],
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=False,
|
|
telemetry_enabled=False,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
)
|
|
|
|
assert manifest.supervisor_kind == "none"
|
|
expected_preset = (
|
|
InstallPreset.PERSISTENT_TASK.value
|
|
if sys.platform.startswith("win")
|
|
else InstallPreset.PERSISTENT_SERVICE.value
|
|
)
|
|
assert manifest.preset == expected_preset
|
|
|
|
|
|
def test_build_manifest_python_runtime_keeps_explicit_memory_db_path() -> None:
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_SERVICE.value,
|
|
runtime_kind="python",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=["claude"],
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=True,
|
|
telemetry_enabled=False,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
)
|
|
|
|
# On the host the resolved path is correct, so it is still passed explicitly.
|
|
assert "--memory" in manifest.proxy_args
|
|
assert "--memory-db-path" in manifest.proxy_args
|
|
|
|
|
|
def test_build_manifest_falls_back_from_windows_service_to_task(monkeypatch) -> None:
|
|
monkeypatch.setattr("headroom.install.planner.sys.platform", "win32")
|
|
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_SERVICE.value,
|
|
runtime_kind="python",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=["claude"],
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=False,
|
|
telemetry_enabled=False,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
)
|
|
|
|
assert manifest.preset == InstallPreset.PERSISTENT_TASK.value
|
|
assert manifest.supervisor_kind == "task"
|
|
assert "HEADROOM_EMBEDDER_RUNTIME" not in manifest.base_env
|
|
assert "HEADROOM_KOMPRESS_BACKEND" not in manifest.base_env
|
|
|
|
|
|
def test_build_manifest_uses_provider_slice_env_builders_for_all_supported_targets() -> None:
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_SERVICE.value,
|
|
runtime_kind="python",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=["claude", "copilot", "codex", "aider", "cursor"],
|
|
port=9999,
|
|
backend="anyllm",
|
|
anyllm_provider="groq",
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=False,
|
|
telemetry_enabled=True,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
)
|
|
|
|
# telemetry_enabled=True must write the explicit opt-in value + flag.
|
|
assert manifest.base_env["HEADROOM_TELEMETRY"] == "on"
|
|
assert "--telemetry" in manifest.proxy_args
|
|
assert manifest.tool_envs["claude"]["ANTHROPIC_BASE_URL"] == "http://127.0.0.1:9999"
|
|
assert manifest.tool_envs["codex"]["OPENAI_BASE_URL"] == "http://127.0.0.1:9999/v1"
|
|
assert manifest.tool_envs["aider"] == {
|
|
"OPENAI_API_BASE": "http://127.0.0.1:9999/v1",
|
|
"ANTHROPIC_BASE_URL": "http://127.0.0.1:9999",
|
|
}
|
|
assert manifest.tool_envs["cursor"] == {
|
|
"OPENAI_BASE_URL": "http://127.0.0.1:9999/v1",
|
|
"ANTHROPIC_BASE_URL": "http://127.0.0.1:9999",
|
|
}
|
|
assert manifest.tool_envs["copilot"] == {
|
|
"COPILOT_PROVIDER_TYPE": "openai",
|
|
"COPILOT_PROVIDER_BASE_URL": "http://127.0.0.1:9999/v1",
|
|
"COPILOT_PROVIDER_WIRE_API": "completions",
|
|
}
|
|
|
|
|
|
def test_resolve_targets_provider_scope_auto_excludes_copilot(monkeypatch) -> None:
|
|
monkeypatch.setattr("headroom.install.planner.detect_targets", lambda: [])
|
|
|
|
targets = resolve_targets(
|
|
ProviderSelectionMode.AUTO.value,
|
|
[],
|
|
scope=ConfigScope.PROVIDER.value,
|
|
)
|
|
|
|
assert targets == [ToolTarget.CLAUDE.value, ToolTarget.CODEX.value]
|
|
|
|
|
|
def test_resolve_targets_manual_dedupes_and_filters_invalid() -> None:
|
|
targets = resolve_targets(
|
|
ProviderSelectionMode.MANUAL.value,
|
|
["claude", "copilot", "claude", "invalid"],
|
|
)
|
|
|
|
assert targets == [ToolTarget.CLAUDE.value, ToolTarget.COPILOT.value]
|
|
|
|
|
|
def test_build_manifest_omits_no_http2_by_default() -> None:
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_SERVICE.value,
|
|
runtime_kind="python",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=["claude"],
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=False,
|
|
telemetry_enabled=True,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
)
|
|
|
|
assert "--no-http2" not in manifest.proxy_args
|
|
|
|
|
|
def test_build_manifest_persists_no_http2_override() -> None:
|
|
manifest = build_manifest(
|
|
profile="default",
|
|
preset=InstallPreset.PERSISTENT_SERVICE.value,
|
|
runtime_kind="python",
|
|
scope="user",
|
|
provider_mode="manual",
|
|
targets=["claude"],
|
|
port=8787,
|
|
backend="anthropic",
|
|
anyllm_provider=None,
|
|
region=None,
|
|
proxy_mode="token",
|
|
memory_enabled=False,
|
|
telemetry_enabled=True,
|
|
image="ghcr.io/headroomlabs-ai/headroom:latest",
|
|
no_http2=True,
|
|
)
|
|
|
|
assert manifest.proxy_args.count("--no-http2") == 1
|
|
assert "HEADROOM_HTTP2" not in manifest.base_env
|
|
|
|
|
|
def test_resolve_targets_provider_scope_all_ignores_unsupported_requested() -> None:
|
|
"""`all` mode never consults the requested list, so an unsupported entry
|
|
like `cursor` must not make it raise — it should return the full provider
|
|
target set (regression: this used to raise a ClickException)."""
|
|
targets = resolve_targets(
|
|
ProviderSelectionMode.ALL.value,
|
|
["cursor"],
|
|
scope=ConfigScope.PROVIDER.value,
|
|
)
|
|
|
|
assert targets == [t.value for t in PROVIDER_SCOPE_TARGETS]
|
|
|
|
|
|
def test_resolve_targets_provider_scope_auto_ignores_unsupported_requested(monkeypatch) -> None:
|
|
"""`auto` mode also ignores the requested list, so an unsupported entry
|
|
must not raise."""
|
|
monkeypatch.setattr("headroom.install.planner.detect_targets", lambda: [])
|
|
|
|
targets = resolve_targets(
|
|
ProviderSelectionMode.AUTO.value,
|
|
["cursor"],
|
|
scope=ConfigScope.PROVIDER.value,
|
|
)
|
|
|
|
assert targets == [ToolTarget.CLAUDE.value, ToolTarget.CODEX.value]
|
|
|
|
|
|
def test_resolve_targets_provider_scope_manual_rejects_unsupported() -> None:
|
|
"""The manual path DOES consult the requested list, so an unsupported
|
|
target under provider scope must still be rejected."""
|
|
with pytest.raises(click.ClickException, match="cursor"):
|
|
resolve_targets(
|
|
ProviderSelectionMode.MANUAL.value,
|
|
["cursor"],
|
|
scope=ConfigScope.PROVIDER.value,
|
|
)
|
|
|
|
|
|
def _base_manifest_kwargs(**overrides):
|
|
kwargs = {
|
|
"profile": "default",
|
|
"preset": InstallPreset.PERSISTENT_SERVICE.value,
|
|
"runtime_kind": "python",
|
|
"scope": "user",
|
|
"provider_mode": "manual",
|
|
"targets": ["claude"],
|
|
"port": 8787,
|
|
"backend": "bedrock",
|
|
"anyllm_provider": None,
|
|
"region": "eu-west-1",
|
|
"proxy_mode": "token",
|
|
"memory_enabled": False,
|
|
"telemetry_enabled": False,
|
|
"image": "ghcr.io/chopratejas/headroom:latest",
|
|
}
|
|
kwargs.update(overrides)
|
|
return kwargs
|
|
|
|
|
|
def test_build_manifest_omits_new_bedrock_flags_by_default() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs())
|
|
|
|
assert "--code-aware" not in manifest.proxy_args
|
|
assert "--no-code-aware" not in manifest.proxy_args
|
|
assert "--intercept-tool-results" not in manifest.proxy_args
|
|
assert "--protect-tool-results" not in manifest.proxy_args
|
|
assert "--bedrock-profile" not in manifest.proxy_args
|
|
|
|
|
|
def test_build_manifest_persists_code_aware_true() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(code_aware=True))
|
|
|
|
assert "--code-aware" in manifest.proxy_args
|
|
assert "--no-code-aware" not in manifest.proxy_args
|
|
|
|
|
|
def test_build_manifest_persists_code_aware_false() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(code_aware=False))
|
|
|
|
assert "--no-code-aware" in manifest.proxy_args
|
|
assert "--code-aware" not in manifest.proxy_args
|
|
|
|
|
|
def test_build_manifest_persists_intercept_tool_results() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(intercept_tool_results=True))
|
|
|
|
assert "--intercept-tool-results" in manifest.proxy_args
|
|
assert manifest.base_env["HEADROOM_ROLLOUT_CHANNEL"] == "canary"
|
|
|
|
|
|
def test_build_manifest_rejects_interceptor_below_required_rollout_channel() -> None:
|
|
with pytest.raises(click.ClickException, match="requires HEADROOM_ROLLOUT_CHANNEL=canary"):
|
|
build_manifest(
|
|
**_base_manifest_kwargs(
|
|
intercept_tool_results=True,
|
|
extra_env={"HEADROOM_ROLLOUT_CHANNEL": "stable"},
|
|
)
|
|
)
|
|
|
|
|
|
def test_build_manifest_persists_protect_tool_results() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(protect_tool_results="Bash,WebFetch"))
|
|
|
|
idx = manifest.proxy_args.index("--protect-tool-results")
|
|
assert manifest.proxy_args[idx + 1] == "Bash,WebFetch"
|
|
|
|
|
|
def test_build_manifest_persists_bedrock_profile() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(bedrock_profile="sso-bedrock"))
|
|
|
|
idx = manifest.proxy_args.index("--bedrock-profile")
|
|
assert manifest.proxy_args[idx + 1] == "sso-bedrock"
|
|
|
|
|
|
def test_build_manifest_merges_extra_env_into_base_env() -> None:
|
|
manifest = build_manifest(
|
|
**_base_manifest_kwargs(extra_env={"HEADROOM_WORKSPACE_DIR": "/custom/workspace"})
|
|
)
|
|
|
|
assert manifest.base_env["HEADROOM_WORKSPACE_DIR"] == "/custom/workspace"
|
|
|
|
|
|
def test_build_manifest_extra_env_overrides_derived_defaults() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(extra_env={"HEADROOM_TELEMETRY": "on"}))
|
|
|
|
# telemetry_enabled=False in _base_manifest_kwargs would normally set "off";
|
|
# an explicit --env must win.
|
|
assert manifest.base_env["HEADROOM_TELEMETRY"] == "on"
|
|
|
|
|
|
def test_build_manifest_grok_build_only_sets_xai_upstream() -> None:
|
|
"""Persistent install for Grok Build alone must route proxy upstream to xAI."""
|
|
from headroom.providers.grok import DEFAULT_API_URL
|
|
|
|
manifest = build_manifest(**_base_manifest_kwargs(targets=["grok_build"], backend="openai"))
|
|
|
|
assert manifest.base_env.get("OPENAI_TARGET_API_URL") == DEFAULT_API_URL
|
|
idx = manifest.proxy_args.index("--openai-api-url")
|
|
assert manifest.proxy_args[idx + 1] == DEFAULT_API_URL
|
|
|
|
|
|
def test_build_manifest_grok_with_codex_does_not_force_xai() -> None:
|
|
"""Do not override OpenAI upstream when OpenAI-native tools share the proxy."""
|
|
manifest = build_manifest(
|
|
**_base_manifest_kwargs(targets=["grok_build", "codex"], backend="openai")
|
|
)
|
|
|
|
assert "OPENAI_TARGET_API_URL" not in manifest.base_env
|
|
assert "--openai-api-url" not in manifest.proxy_args
|
|
|
|
|
|
def test_build_manifest_extra_env_wins_over_grok_xai_default() -> None:
|
|
manifest = build_manifest(
|
|
**_base_manifest_kwargs(
|
|
targets=["grok_build"],
|
|
backend="openai",
|
|
extra_env={"OPENAI_TARGET_API_URL": "https://gateway.example/v1"},
|
|
)
|
|
)
|
|
|
|
assert manifest.base_env["OPENAI_TARGET_API_URL"] == "https://gateway.example/v1"
|
|
idx = manifest.proxy_args.index("--openai-api-url")
|
|
assert manifest.proxy_args[idx + 1] == "https://gateway.example/v1"
|
|
|
|
|
|
def test_build_manifest_for_persistent_service_uses_safe_model_backends() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs())
|
|
|
|
assert manifest.base_env["HEADROOM_EMBEDDER_RUNTIME"] == "cpu"
|
|
assert manifest.base_env["HEADROOM_KOMPRESS_BACKEND"] == "onnx"
|
|
|
|
|
|
def test_persistent_service_explicit_model_backends_override_safe_defaults() -> None:
|
|
manifest = build_manifest(
|
|
**_base_manifest_kwargs(
|
|
extra_env={
|
|
"HEADROOM_EMBEDDER_RUNTIME": "pytorch_mps",
|
|
"HEADROOM_KOMPRESS_BACKEND": "pytorch_mps",
|
|
}
|
|
)
|
|
)
|
|
|
|
assert manifest.base_env["HEADROOM_EMBEDDER_RUNTIME"] == "pytorch_mps"
|
|
assert manifest.base_env["HEADROOM_KOMPRESS_BACKEND"] == "pytorch_mps"
|
|
|
|
|
|
def test_persistent_task_does_not_inherit_service_backend_defaults() -> None:
|
|
manifest = build_manifest(**_base_manifest_kwargs(preset=InstallPreset.PERSISTENT_TASK.value))
|
|
|
|
assert "HEADROOM_EMBEDDER_RUNTIME" not in manifest.base_env
|
|
assert "HEADROOM_KOMPRESS_BACKEND" not in manifest.base_env
|
|
|
|
|
|
def test_build_manifest_grok_with_antigravity_does_not_force_xai() -> None:
|
|
"""Do not route Antigravity's OpenAI-compatible traffic to xAI.
|
|
|
|
Antigravity uses the proxy as a custom OpenAI-compatible model provider,
|
|
so a Grok + Antigravity deployment must keep the shared OpenAI upstream
|
|
instead of switching it to xAI.
|
|
"""
|
|
manifest = build_manifest(
|
|
**_base_manifest_kwargs(targets=["grok_build", "antigravity"], backend="openai")
|
|
)
|
|
|
|
assert "OPENAI_TARGET_API_URL" not in manifest.base_env
|
|
assert "--openai-api-url" not in manifest.proxy_args
|
|
|
|
|
|
def test_detect_targets_ignores_shared_gemini_home(monkeypatch, tmp_path) -> None:
|
|
"""A Gemini-CLI-only home must not detect Antigravity.
|
|
|
|
Gemini CLI keeps session data under ``~/.gemini/tmp/``; that shared home
|
|
directory alone must not register as an Antigravity install, or an
|
|
``auto`` deployment would pick up Antigravity and skip the usual
|
|
Claude/Codex/Copilot defaults.
|
|
"""
|
|
(tmp_path / ".gemini" / "tmp" / "chats").mkdir(parents=True)
|
|
monkeypatch.setattr("pathlib.Path.home", classmethod(lambda cls: tmp_path))
|
|
monkeypatch.setattr("headroom.install.planner.shutil.which", lambda *_args, **_kwargs: None)
|
|
|
|
from headroom.install.planner import detect_targets
|
|
|
|
assert ToolTarget.ANTIGRAVITY.value not in detect_targets()
|
|
|
|
|
|
def test_detect_targets_finds_antigravity_config_dir(monkeypatch, tmp_path) -> None:
|
|
"""The Antigravity ``~/.gemini/config`` directory still counts as a hit."""
|
|
(tmp_path / ".gemini" / "config").mkdir(parents=True)
|
|
monkeypatch.setattr("pathlib.Path.home", classmethod(lambda cls: tmp_path))
|
|
monkeypatch.setattr("headroom.install.planner.shutil.which", lambda *_args, **_kwargs: None)
|
|
|
|
from headroom.install.planner import detect_targets
|
|
|
|
assert ToolTarget.ANTIGRAVITY.value in detect_targets()
|