## Description
Fixes#3976. On `uv tool` installs and other environments where certifi
is not
wired into the stdlib OpenSSL trust path, `headroom update` and
bundled-binary
downloads can fail behind corporate TLS inspection. These urllib calls
now use
the configured Headroom trust context, matching the proxy's TLS policy.
The lazy helper import still falls back to urllib's default when the
optional
trust module cannot be imported. Errors while constructing an explicitly
configured context now propagate instead of silently replacing the
requested
trust roots with stdlib defaults. The update checker retains its outer
error-handling behavior and returns no update on failure.
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring
## Changes Made
- Pass `build_urlopen_context()` to the PyPI version check and
release-binary
download paths.
- Catch only `ImportError` around the lazy helper import; let
trust-context
construction errors reach the caller.
- Add valid and invalid replacement-bundle tests for both helpers and
verify
the update check still handles the error through its existing outer
handler.
- Update mocked `urlopen` functions to accept the `context` keyword used
by the
production call path.
## Testing
- [x] Targeted unit tests pass
- [ ] Full test suite run
- [x] Ruff lint and format checks pass for changed files
- [x] New tests added for the requested behavior
- [ ] Type checking run
- [ ] Manual live-network testing performed
### Test Output
```text
python -m pytest --disable-plugin-autoload -p pytest_asyncio.plugin tests/test_ssl_context.py tests/test_binaries.py tests/test_update_check.py
95 passed in 5.10s
python -m ruff check headroom/binaries.py headroom/update_check.py tests/test_ssl_context.py tests/test_binaries.py
All checks passed!
python -m ruff format --check headroom/binaries.py headroom/update_check.py tests/test_ssl_context.py tests/test_binaries.py
4 files already formatted
git diff --check
passed
```
## Real Behavior Proof
**Original reproduction:** On macOS behind a corporate TLS-inspecting
network,
`headroom update` failed with `CERTIFICATE_VERIFY_FAILED` when the
inspection
root was present in the OS trust store but absent from Python's stdlib
OpenSSL
bundle. The same machine's proxy reached its upstream through the
configured
root. The original fix routed the direct urllib calls through
`build_urlopen_context()`.
**Review regression checks:** On Windows with Python 3.13.13, tests
using a
valid `REQUESTS_CA_BUNDLE` confirm both helpers return a verifying
`SSLContext`. With an existing file containing invalid PEM, both helpers
now
raise `ssl.SSLError`; the update-check caller still returns `None`
through its
outer error handler. All 95 tests in the affected TLS, binary-download,
and
update-check suites pass.
**Not tested:** A live corporate TLS-inspection connection, Windows `uv
tool`
end-to-end behavior behind such a network, the full repository test
suite, and
the separate eval dataset download path.
## Runtime Rollout Safety
- Rollout-managed feature(s): None.
- Minimum rollout channel: Not applicable.
- Stable/default behavior changed: An invalid explicitly configured
trust
bundle now fails visibly rather than silently falling back to stdlib
roots;
unconfigured default behavior is unchanged.
- Kill switch / disable path: No new switch; existing TLS environment
settings
remain available.
- Unsafe override required: No.
- Qualification impact: None.
- Rollback path: Revert this PR's changes.
## 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 added comments where the code needs additional explanation.
- [ ] I have made corresponding documentation changes (none needed for
this
internal error-handling change).
- [x] The changed files pass Ruff checks and the focused tests add no
warnings.
- [x] I have added tests that prove the requested behavior.
- [ ] The full repository unit-test suite was run.
- [x] I did not edit `CHANGELOG.md`.
---------
Co-authored-by: dajiaohuang <dajiaohuang@users.noreply.github.com>
Co-authored-by: JD Davis <mxjerrett@gmail.com>