mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
## Description Four small proxy helpers have no caller in the product. This PR removes them. - `tenant_key._get_auth_mode_str` is not referenced anywhere, tests included. - `tool_schema_compaction.invalidate_cache` is not referenced anywhere either. The private consumers that import this module use other names: `compact_tools`, `compact_tool_descriptions` and `tool_desc_max_chars`. - `proxy_mode_policy.normalize_proxy_mode_value` is a one-line wrapper over `normalize_proxy_mode_decision(...).normalized`. Only two tests used it. They now call `normalize_proxy_mode_decision` directly and still check the same aliases. - `rate_limit_policy.stale_bucket_keys` was used only by its own test, which goes with it. `rate_limiter.py` does not call it. Evidence: I ran `grep -rnw <name>` over `headroom`, `crates`, `plugins`, `sdk`, `examples`, `benchmarks`, `scripts`, `e2e`, `docs`, `wiki`, `.github`, `pyproject.toml`, `tests` and the private consumer repos. It found only the definitions and the tests named above. Refs #4136 ## Type of Change - [ ] 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 - [x] Code refactoring (no functional changes) ## Changes Made - Delete `_get_auth_mode_str` (in `tenant_key.py`), `invalidate_cache` (in `tool_schema_compaction.py`), `normalize_proxy_mode_value` (in `proxy_mode_policy.py`) and `stale_bucket_keys` (in `rate_limit_policy.py`). - `tests/test_rate_limit_policy.py`: remove the `stale_bucket_keys` test. - `tests/test_proxy_mode_policy.py` and `tests/test_install/test_proxy_mode_default.py`: call `normalize_proxy_mode_decision(...).normalized` instead of the removed wrapper. The alias coverage is unchanged. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [ ] New tests added for new functionality - [x] Manual testing performed ### Test Output ```text $ pytest -q -p no:cacheprovider tests/test_proxy_mode_policy.py tests/test_install/test_proxy_mode_default.py tests/test_rate_limit_policy.py tests/test_tenant_key.py tests/test_proxy_tenant_key_integration.py tests/test_tool_schema_compaction.py tests/test_openai_chat_tool_desc_compaction.py tests/test_proxy_modes.py ============================== 82 passed in 3.52s ============================== $ uvx ruff@0.16.8 check <7 touched files> All checks passed! $ mypy headroom/proxy/tenant_key.py headroom/proxy/tool_schema_compaction.py headroom/proxy/proxy_mode_policy.py headroom/proxy/rate_limit_policy.py --ignore-missing-imports Success: no issues found in 4 source files ``` ## Real Behavior Proof - Environment: macOS, Python 3.12.13, this branch ata56df516, using the repo .venv. Every run used a temp `HOME`, `HEADROOM_WORKSPACE_DIR` and `CODEX_HOME`, plus `HEADROOM_OFFLINE=1`. - Exact command / steps: - (1) Ran the shared smoke harness in token mode: `smoke.sh <worktree> --mode token`. It starts a real `headroom proxy --mode token` against a local fake upstream, sends one Anthropic and one OpenAI request, reads `/stats` and greps `proxy.log`. - (2) Called the live neighbours of each removed helper directly: - `normalize_proxy_mode_decision` on aliases; - `TokenBucketRateLimiter.check_request` three times at 2 requests per minute; - `compact_tools` on a tool with a `$schema` key. - Observed result: ```text (1) branch: cleanup/proxy-core-b-unused-helpers @a56df516health: 200 POST /v1/messages -> HTTP200 smoke-ok POST /v1/chat/completions -> HTTP200 smoke-ok stats: requests=2 failed=0 tokens_saved=13574 savings_percent=99.82 proxy.log WARNING/ERROR lines: only the expected air-gap ones (offline mode, Kompress not cached). (2) mode token_savings -> token mode cache_mode -> cache mode bogus -> token rate limit [True, True, False] compact_tools modified: True 95 -> 81 ``` - Not tested: A live proxy against a real provider. None of the removed functions was on any runtime path. ## Runtime Rollout Safety - Rollout-managed feature(s): None. - Minimum rollout channel: N/A; dead-code removal. - Stable/default behavior changed: No. - Kill switch / disable path: N/A. - Unsafe override required: No. - Qualification impact: None. - Rollback path: Revert this 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 - [ ] 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 - [ ] 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 (a CI guard enforces this) ## Screenshots (if applicable) N/A ## Additional Notes Part of maintainer-requested cleanup #4136 (dead code, duplication, debuggability), split into small PRs for review. `verbosity_controller.py` is also unused, but it is left for a maintainer decision and is not touched here. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Tests for pure proxy mode normalization policy."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from headroom.proxy.proxy_mode_policy import (
|
|
PROXY_MODE_CACHE,
|
|
PROXY_MODE_TOKEN,
|
|
normalize_proxy_mode_decision,
|
|
)
|
|
|
|
|
|
def test_decision_normalizes_canonical_modes() -> None:
|
|
token = normalize_proxy_mode_decision("token")
|
|
assert token.normalized == PROXY_MODE_TOKEN
|
|
assert token.alias_used is False
|
|
assert token.unknown is False
|
|
|
|
cache = normalize_proxy_mode_decision("cache")
|
|
assert cache.normalized == PROXY_MODE_CACHE
|
|
assert cache.alias_used is False
|
|
assert cache.unknown is False
|
|
|
|
|
|
def test_decision_normalizes_aliases_and_marks_alias_used() -> None:
|
|
token = normalize_proxy_mode_decision(" token_headroom ")
|
|
assert token.key == "token_headroom"
|
|
assert token.normalized == PROXY_MODE_TOKEN
|
|
assert token.alias_used is True
|
|
|
|
cache = normalize_proxy_mode_decision("cost_savings")
|
|
assert cache.normalized == PROXY_MODE_CACHE
|
|
assert cache.alias_used is True
|
|
|
|
|
|
def test_decision_uses_default_for_blank_mode() -> None:
|
|
decision = normalize_proxy_mode_decision(" ", default=PROXY_MODE_CACHE)
|
|
assert decision.normalized == PROXY_MODE_CACHE
|
|
assert decision.used_default is True
|
|
assert decision.unknown is False
|
|
|
|
|
|
def test_decision_uses_default_and_marks_unknown_for_invalid_mode() -> None:
|
|
decision = normalize_proxy_mode_decision("wat", default=PROXY_MODE_CACHE)
|
|
assert decision.normalized == PROXY_MODE_CACHE
|
|
assert decision.used_default is True
|
|
assert decision.unknown is True
|
|
|
|
|
|
def test_aliases_normalize_to_canonical_mode() -> None:
|
|
assert normalize_proxy_mode_decision("token_savings").normalized == PROXY_MODE_TOKEN
|
|
assert normalize_proxy_mode_decision("cache_mode").normalized == PROXY_MODE_CACHE
|