Files
headroom/tests/test_wrap_quiet_cli.py
Abhay Singh 3a3a465bb1 feat(wrap): extend reduce-at-source quiet defaults to telemetry/nag banners (#2550)
## Description

Extends the reduce-at-source quiet-CLI env defaults added in #2548. That
set covered git/pip/npm chatter (pager framing, progress bars,
funding/audit banners, version nags). But coding agents constantly shell
out to other common tools that print **zero-signal** telemetry pings,
version nags, and first-run / logo banners into `tool_result` output —
tokens the agent never acts on and the proxy then has to carry.

This adds SAFE defaults for those, following the exact criterion in
#2548's comment: only knobs that suppress chatter, never anything that
could hide diffs, errors, summaries, or search results.

New entries:

- `npm_config_update_notifier=false` — npm's boxed "update available"
notice
- `DO_NOT_TRACK=1` — the cross-tool telemetry opt-out standard
(consoledonottrack.com), honored by turbo, netlify, gatsby, and many
others
- `DOTNET_CLI_TELEMETRY_OPTOUT=1`, `DOTNET_NOLOGO=1` — .NET SDK
telemetry ping + the "Welcome to .NET" logo/copyright banner
- `NEXT_TELEMETRY_DISABLED=1`, `GATSBY_TELEMETRY_DISABLED=1`,
`ASTRO_TELEMETRY_DISABLED=1` — JS framework build/dev telemetry banners
- `NG_CLI_ANALYTICS=false` — Angular CLI analytics ping + first-run
prompt
- `HOMEBREW_NO_ENV_HINTS=1` — Homebrew's `==> ... hints` chatter (not
warnings/errors)

Each is the canonical, widely-documented "disable telemetry / nag"
variable for its tool. As with the existing set, a value the user
already set always wins (defaults fill only when absent), and the whole
feature is opt-out via `HEADROOM_WRAP_QUIET=0`.

## 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

- `headroom/cli/wrap.py`: add the telemetry/nag/banner env defaults to
`_QUIET_CLI_DEFAULTS`.
- `tests/test_wrap_quiet_cli.py`: assert the new suppressors are
injected into an empty env (and, via the existing tests, still respect
user overrides and the opt-out switch).

## Testing

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

### Test Output

```text
$ python -m pytest tests/test_wrap_quiet_cli.py -q
6 passed

# with the new defaults reverted, the telemetry-suppressor test fails
# (the keys are absent from the injected env)

$ uvx ruff@0.15.17 check headroom/cli/wrap.py tests/test_wrap_quiet_cli.py
All checks passed!
```

## Real Behavior Proof

- Environment: Windows 11, Python 3.12, project venv (`uv sync --extra
proxy`), `uvx ruff@0.15.17`, pytest in the venv.
- Exact command / steps: called `_configure_quiet_cli_env({})` with
`HEADROOM_WRAP_QUIET` unset and inspected the resulting env; also
exercised the existing user-override and opt-out tests; then reverted
the source and re-ran.
- Observed result: with the change the new keys (`DO_NOT_TRACK`,
`DOTNET_CLI_TELEMETRY_OPTOUT`, `DOTNET_NOLOGO`,
`NEXT_/GATSBY_/ASTRO_TELEMETRY_DISABLED`, `NG_CLI_ANALYTICS`,
`HOMEBREW_NO_ENV_HINTS`, `npm_config_update_notifier`) are present with
their documented values and reported in the written list; a user-set
value is left untouched; and with `HEADROOM_WRAP_QUIET=0` nothing is
injected. With the change reverted the new keys are absent. Ran against
the actual module.
- Not tested: launching each real CLI to observe the reduced output (the
env variables are each tool's own documented telemetry/nag switch).

## 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
- [ ] 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
- [ ] I have updated the CHANGELOG.md if applicable

cc @chopratejas
2026-10-03 00:12:44 -05:00

83 lines
3.3 KiB
Python

"""`headroom wrap` reduce-at-source: SAFE quiet-CLI env defaults for the launched
agent. They fill in only when the user hasn't set the value, augment (never
clobber) PYTEST_ADDOPTS, and are fully opt-out via HEADROOM_WRAP_QUIET."""
from __future__ import annotations
from headroom.cli.wrap import _configure_quiet_cli_env, _quiet_cli_enabled
def test_defaults_injected_into_empty_env(monkeypatch) -> None:
monkeypatch.delenv("HEADROOM_WRAP_QUIET", raising=False)
env: dict[str, str] = {}
written = _configure_quiet_cli_env(env)
assert env["GIT_PAGER"] == "cat"
assert env["PIP_QUIET"] == "1"
assert env["PIP_DISABLE_PIP_VERSION_CHECK"] == "1"
assert env["npm_config_fund"] == "false"
assert env["npm_config_audit"] == "false"
assert env["npm_config_progress"] == "false"
assert env["PYTEST_ADDOPTS"] == "-q"
assert "GIT_PAGER" in written and "PYTEST_ADDOPTS" in written
def test_telemetry_and_nag_suppressors_injected(monkeypatch) -> None:
# Telemetry pings, version nags, and first-run/logo banners are zero-signal
# tokens; the SAFE reduce-at-source set suppresses them across common tools.
monkeypatch.delenv("HEADROOM_WRAP_QUIET", raising=False)
env: dict[str, str] = {}
written = _configure_quiet_cli_env(env)
expected = {
"npm_config_update_notifier": "false",
"DO_NOT_TRACK": "1",
"DOTNET_CLI_TELEMETRY_OPTOUT": "1",
"DOTNET_NOLOGO": "1",
"NEXT_TELEMETRY_DISABLED": "1",
"GATSBY_TELEMETRY_DISABLED": "1",
"ASTRO_TELEMETRY_DISABLED": "1",
"NG_CLI_ANALYTICS": "false",
"HOMEBREW_NO_ENV_HINTS": "1",
}
for name, value in expected.items():
assert env[name] == value
assert name in written
def test_user_value_always_wins(monkeypatch) -> None:
monkeypatch.delenv("HEADROOM_WRAP_QUIET", raising=False)
env = {"GIT_PAGER": "less -R", "PIP_QUIET": "0"}
written = _configure_quiet_cli_env(env)
assert env["GIT_PAGER"] == "less -R" # untouched
assert env["PIP_QUIET"] == "0" # untouched
assert "GIT_PAGER" not in written and "PIP_QUIET" not in written
# ...but absent ones are still filled.
assert env["npm_config_fund"] == "false"
def test_pytest_addopts_augmented_not_clobbered(monkeypatch) -> None:
monkeypatch.delenv("HEADROOM_WRAP_QUIET", raising=False)
env = {"PYTEST_ADDOPTS": "-p no:cacheprovider"}
_configure_quiet_cli_env(env)
assert env["PYTEST_ADDOPTS"] == "-p no:cacheprovider -q" # preserved + augmented
# already-quiet stays as-is (no duplicate -q)
env2 = {"PYTEST_ADDOPTS": "-q --tb=short"}
written = _configure_quiet_cli_env(env2)
assert env2["PYTEST_ADDOPTS"] == "-q --tb=short"
assert "PYTEST_ADDOPTS" not in written
def test_opt_out_disables_injection(monkeypatch) -> None:
for off in ("0", "false", "no", "OFF"):
monkeypatch.setenv("HEADROOM_WRAP_QUIET", off)
assert _quiet_cli_enabled() is False
env: dict[str, str] = {}
assert _configure_quiet_cli_env(env) == []
assert env == {} # nothing injected
def test_enabled_by_default_and_on_truthy(monkeypatch) -> None:
monkeypatch.delenv("HEADROOM_WRAP_QUIET", raising=False)
assert _quiet_cli_enabled() is True
monkeypatch.setenv("HEADROOM_WRAP_QUIET", "1")
assert _quiet_cli_enabled() is True