refactor(api-proxy): extract guard enforcement into proxy-guards.js#5520
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the API proxy’s HTTP guard enforcement by moving the guard decision and blocked-response logic out of proxy-request.js into a dedicated proxy-guards.js module, making the enforcement path easier to audit and independently test without changing behavior.
Changes:
- Extracted
enforceGuards,sendGuardBlockedResponse, andextractModelFromBodyinto newcontainers/api-proxy/proxy-guards.js. - Updated
proxy-request.jsto call the extractedenforceGuards()during the HTTP request flow. - Added
proxy-guards.jsto the api-proxy Docker imageCOPYlist to ensure it’s bundled at runtime.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/proxy-request.js | Replaces in-file guard enforcement with enforceGuards() imported from proxy-guards.js. |
| containers/api-proxy/proxy-guards.js | New module encapsulating HTTP guard evaluation and blocked-response/diagnostic emission. |
| containers/api-proxy/Dockerfile | Ensures proxy-guards.js is copied into the image alongside other individually-copied modules. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
|
✅ Copilot review passed with no inline comments. @copilot Add the |
|
🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅ |
|
❌ Security Guard failed. Please review the logs for details. |
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤 |
|
✅ Build Test Suite completed successfully! |
|
Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded. |
|
✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟 |
|
✅ Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓 |
|
✅ Smoke Claude passed |
|
📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅ |
|
✅ Contribution Check completed successfully! Contribution guidelines review complete: PR #5520 follows the applicable CONTRIBUTING.md guidelines, so no PR comment was needed. |
|
🔌 Smoke Services — All services reachable! ✅ |
|
✅ Smoke Gemini completed. All facets verified. 💎 |
|
✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓 |
|
✅ Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓 |
Smoke Test: Claude Engine Validation
Overall result: PASS
|
🔍 Smoke Test: Copilot PAT Auth — PR #5520
Overall: PASS (MCP + HTTP confirmed; file test skipped due to unresolved workflow template variables) Auth mode: PAT (COPILOT_GITHUB_TOKEN)
|
🔬 Smoke Test Results
PR: refactor(api-proxy): extract guard enforcement into proxy-guards.js Overall: PASS
|
Smoke Test: Copilot BYOK (Direct) Mode ✅Direct BYOK Mode: COPILOT_PROVIDER_API_KEY → api-proxy sidecar → api.githubcopilot.com
Overall: PASS
|
🔍 Smoke Test: API Proxy OpenTelemetry Tracing
Overall: All scenarios pass. The
|
🧪 Chroot Version Comparison Results
Overall: ❌ Tests did not pass — Python and Node.js versions differ between host and chroot.
|
|
Smoke test summary for
Overall: PASS 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.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
|
Smoke Test Results
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 Results
Overall: FAIL
|
|
Smoke Test: Copilot BYOK (Direct) Mode — Azure OpenAI (Foundry)
Overall: PASS
|
|
cc GitHub MCP Testing: ✅ Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra
|
proxy-request.jsmixed quota/token guard enforcement with proxy orchestration, making the guard decision path harder to audit and test in isolation.Changes
New
containers/api-proxy/proxy-guards.js: ExtractssendGuardBlockedResponseandenforceGuardsfromproxy-request.js, along with theextractModelFromBodyhelper they depend on. Imports directly from the existing./guards/sub-modules. Includes graceful-degradation stub for optionalotel, matching the pattern in the rest of the proxy.proxy-request.js(−~100 lines): Removes the extracted functions and their exclusive imports (buildCommonGuardChecks,writeBlockedRequestDiag). Guard state getters/builders shared withproxyWebSocketremain. Addsrequire('./proxy-guards')forenforceGuards.Dockerfile: Addsproxy-guards.jsto theCOPYlist — required since the image copies source files individually; omitting it would trigger the graceful-degradation stubs and silently break guard enforcement at runtime.