refactor(api-proxy): split proxy-request.js into http-client.js and body-handler.js#4939
Conversation
- Extract HTTPS proxy agent into containers/api-proxy/http-client.js so model-discovery.js no longer cross-imports from the proxy core. - Extract collectRequestBody, transformRequestBody, and the _sleep indirection into containers/api-proxy/body-handler.js via a createBodyHandler(deps) factory, enabling isolated unit testing. - proxy-request.js imports from both new modules and re-exports all previous symbols for full backwards compatibility. - model-discovery.js now imports proxyAgent from http-client.js. Closes #4932
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This PR refactors the API proxy core by extracting shared HTTP client infrastructure and request body handling logic out of proxy-request.js, reducing module coupling and removing the previous reverse-dependency where model-discovery.js imported proxyAgent from the proxy core.
Changes:
- Introduces
http-client.jsto centralizeHTTPS_PROXYandproxyAgentas shared singletons. - Introduces
body-handler.jsto encapsulate request body collection + transform pipeline, using a factory for dependency injection (avoids circular imports) and exportingsleep+ test overrides for retry backoff. - Updates
proxy-request.jsandmodel-discovery.jsto import the new modules while preservingproxy-request.js’s existing public exports for compatibility.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/proxy-request.js | Wires proxy core to new http-client and body-handler modules; keeps existing exported surface while shrinking file size. |
| containers/api-proxy/model-discovery.js | Switches proxyAgent import to http-client to avoid depending on proxy core module initialization. |
| containers/api-proxy/http-client.js | New shared module exporting HTTPS_PROXY and proxyAgent singleton for outbound HTTPS usage. |
| containers/api-proxy/body-handler.js | New module implementing body read + transform pipeline and a test-overridable sleep used by retry backoff. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
These new modules were split from proxy-request.js but not added to the Dockerfile COPY directive, causing 'Cannot find module ./http-client' at container startup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Smoke Test: Copilot BYOK (Direct) Mode ✅ PASS Running in direct BYOK mode via
All tests passed.
|
🔥 Smoke Test Results — Auth mode: PAT (COPILOT_GITHUB_TOKEN)
Overall: PASS (2/2 verifiable tests passed) PR: "refactor(api-proxy): split proxy-request.js into http-client.js and body-handler.js"
|
🔍 Smoke Test: API Proxy OpenTelemetry Tracing
Overall: All statically-verifiable scenarios pass. ✅
|
🔬 Smoke Test ResultsPR: refactor(api-proxy): split proxy-request.js into http-client.js and body-handler.js
Overall: FAIL — pre-step template variables were not resolved (
|
|
|
Chroot Version Comparison Results
Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.
|
|
Smoke test results
Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
|
smoke-copilot-byok-aoai-apikey results:
Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) Overall: PASS
|
Smoke Test Results
Overall Status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
Smoke Test: GitHub Actions Services Connectivity
Overall: FAIL
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
proxy-request.jshad grown to 763 lines mixing HTTP client infrastructure, body I/O, transform pipeline, and retry timing — withmodel-discovery.jsreaching back into it just to borrowproxyAgent.New modules
http-client.js— singletonHTTPS_PROXY/proxyAgentconstantsmodel-discovery.jsinto the proxy corebody-handler.js— body I/O and transform pipelinecreateBodyHandler({ handleRequestError, otel })factory — dependency injection avoids the circular import that would arise fromcollectRequestBodycallinghandleRequestErrorcollectRequestBody— stream reader with 10 MB enforcementtransformRequestBody— pipeline: caller transform → null-tool-call sanitisation → steering injection →stream_optionsinjectionsleepindirection +_setSleepForTests/_resetSleepForTests—proxy-request.jscallssleep()for retry backoff so test overrides propagate correctlyUpdated files
proxy-request.js(763 → 608 lines)All existing
module.exportssymbols are preserved for full backwards compatibility.model-discovery.js—proxyAgentnow imported from./http-clientinstead of./proxy-request.