mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
test(copilot): use the real httpx in the hooks test instead of a stub (#3968)
## Description `tests/test_proxy_copilot_auth_hooks.py` fails on `main` with `AttributeError: module 'httpx' has no attribute 'TransportError'` whenever it runs before the real `httpx` is imported (alone, or early in a shard). #3851 made `headroom/proxy/public_errors.py` catch `httpx.TransportError`. This test replaced `httpx` with a minimal stub that lacked it. A stub that matches only what one handler uses also breaks every other cold import of `httpx` (review: MCP's SSE client needs `httpx.Response`). httpx is a core dependency, so the test now uses the real module, which also keeps the exception hierarchy the proxy catches exactly as shipped. Test-only; no product code changes. ## Type of Change - [x] 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 - [ ] Code refactoring (no functional changes) ## Changes Made - `tests/test_proxy_copilot_auth_hooks.py`: drop the httpx stub and use the real `httpx` (and stop isolating `httpx` in the module-restore fixture). The headroom.proxy / fastapi.responses doubles are unchanged. - Isolation check: the file passes run alone (3/3), each test passes run alone, and 165 tests pass with the other Copilot test files in either order. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [ ] Type checking passes (`mypy headroom`) — test-only change - [ ] New tests added for new functionality — fixes an existing test - [x] Manual testing performed ### Test Output ```text # main (befdb52f), file alone FAILED tests/test_proxy_copilot_auth_hooks.py::test_openai_passthrough_applies_copilot_auth FAILED tests/test_proxy_copilot_auth_hooks.py::test_openai_chat_routes_copilot_requests_per_model E AttributeError: module 'httpx' has no attribute 'TransportError' # this branch (f419f533), mcp 1.28.1, Python 3.12 — real httpx, no stub tests/test_proxy_copilot_auth_hooks.py alone: 3 passed (with the earlier stub fix: 2 failed / 1 passed on a cold CCR/MCP import) each test alone: passed + the other Copilot test files, both orders: 165 passed ``` ## Real Behavior Proof - Environment: macOS, Python 3.12 (repo `.venv`, mcp 1.28.1), `main` merged in. - Exact command / steps: `pytest tests/test_proxy_copilot_auth_hooks.py` - Observed result: 2 failures on `main`; 3 passed on this branch run alone, each test passes alone, and 165 pass with the other Copilot test files in either order. - Not tested: n/a ## Runtime Rollout Safety - Rollout-managed feature(s): none - Minimum rollout channel: n/a - Stable/default behavior changed: no (test only) - Kill switch / disable path: n/a - Unsafe override required: no - Qualification impact: none - Rollback path: revert ## 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 — not needed - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works — the existing tests now run - [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) ## Additional Notes Found while fixing #1136, whose agent saw the same two failures on a clean `main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/3968" 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: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: JD Davis <mxjerrett@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
JD Davis
parent
97680e7782
commit
0126fba63f
@@ -13,7 +13,6 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
_ISOLATED_MODULE_NAMES = (
|
||||
"headroom.proxy",
|
||||
"headroom.proxy.handlers",
|
||||
"httpx",
|
||||
"fastapi.responses",
|
||||
"tests.headroom_proxy_handlers_openai",
|
||||
"tests.headroom_proxy_handlers_streaming",
|
||||
@@ -42,12 +41,10 @@ def _load_handler_module(monkeypatch: pytest.MonkeyPatch, module_name: str, rela
|
||||
handlers_pkg.__path__ = [str(ROOT / "headroom" / "proxy" / "handlers")]
|
||||
monkeypatch.setitem(sys.modules, "headroom.proxy.handlers", handlers_pkg)
|
||||
|
||||
httpx_mod = types.ModuleType("httpx")
|
||||
httpx_mod.ConnectError = type("ConnectError", (Exception,), {})
|
||||
httpx_mod.ConnectTimeout = type("ConnectTimeout", (Exception,), {})
|
||||
httpx_mod.PoolTimeout = type("PoolTimeout", (Exception,), {})
|
||||
httpx_mod.ReadTimeout = type("ReadTimeout", (Exception,), {})
|
||||
monkeypatch.setitem(sys.modules, "httpx", httpx_mod)
|
||||
# The real httpx, not a stub: it is a core dependency, and a partial stub
|
||||
# breaks whatever else imports httpx during a cold import (the CCR/MCP SSE
|
||||
# client needs httpx.Response). It also keeps the exception hierarchy the
|
||||
# proxy catches (TransportError and its subclasses) exactly as in production.
|
||||
|
||||
responses_mod = types.ModuleType("fastapi.responses")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user