refactor(api-proxy): replace duplicate getUnconfiguredHealthResponse methods with declarative factory params#5926
Conversation
…clarative factory params Replace the four imperative getUnconfiguredHealthResponse() wrappers in anthropic.js, copilot.js, gemini.js, and vertex.js with three new declarative params on buildProviderAdapter: healthServiceName, missingCredentialMessage, and optional unavailableWhen. The factory now auto-generates getUnconfiguredHealthResponse from those values, eliminating >20 duplicate lines across 4 copies while keeping provider-specific wording close to configuration. Providers that need OIDC-state-dependent messaging (anthropic, copilot) pass an unavailableWhen callback; simple providers (gemini, vertex) just pass the two static strings. Removes makeUnconfiguredHealthResponse imports from all four provider files (now imported once inside adapter-factory.js). Adds 4 new unit tests in adapter-factory.test.js covering: - auto-generation from healthServiceName + missingCredentialMessage - unavailableWhen override path - unavailableWhen returning null falls back to missingCredentialMessage - explicit getUnconfiguredHealthResponse takes precedence over declarative params Updates ADDING-A-PROVIDER.md to document the new declarative approach. Closes #5919
There was a problem hiding this comment.
Pull request overview
Refactors the api-proxy provider adapters to remove duplicated getUnconfiguredHealthResponse() implementations by letting buildProviderAdapter() auto-generate the /health “not configured” response from declarative metadata.
Changes:
- Added
healthServiceName,missingCredentialMessage, andunavailableWheninputs tobuildProviderAdapter()and auto-generation logic forgetUnconfiguredHealthResponse. - Updated Anthropic/Copilot to express OIDC “not yet available” health states via
unavailableWhen; updated Gemini/Vertex to supply only static declarative strings. - Added unit tests for the new auto-generation behavior and documented the new parameters in the provider authoring guide.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/adapter-factory.js | Adds declarative health metadata params and factory auto-generation of getUnconfiguredHealthResponse. |
| containers/api-proxy/adapter-factory.test.js | Adds coverage for auto-generated health response behavior and precedence rules. |
| containers/api-proxy/providers/anthropic.js | Replaces imperative health wrapper with declarative metadata + unavailableWhen for OIDC. |
| containers/api-proxy/providers/copilot.js | Replaces imperative health wrapper with declarative metadata + unavailableWhen for OIDC. |
| containers/api-proxy/providers/gemini.js | Removes per-provider health helper import; supplies declarative health metadata. |
| containers/api-proxy/providers/vertex.js | Removes per-provider health helper import; supplies declarative health metadata. |
| containers/api-proxy/providers/ADDING-A-PROVIDER.md | Documents the new declarative health parameters for new providers. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Low
| // Auto-generate getUnconfiguredHealthResponse from declarative metadata when | ||
| // no explicit function is provided. The optional unavailableWhen callback | ||
| // allows providers with OIDC to surface a dynamic message/status. | ||
| if (getUnconfiguredHealthResponse === undefined && healthServiceName !== undefined && missingCredentialMessage !== undefined) { | ||
| getUnconfiguredHealthResponse = () => { | ||
| if (unavailableWhen) { | ||
| const override = unavailableWhen(); | ||
| if (override) { | ||
| return makeUnconfiguredHealthResponse(healthServiceName, override.message, override.status); | ||
| } | ||
| } | ||
| return makeUnconfiguredHealthResponse(healthServiceName, missingCredentialMessage); | ||
| }; | ||
| } |
| | `getUnconfiguredHealthResponse()` | ➖ optional | `/health` response when not enabled — prefer the declarative form below | | ||
| | `healthServiceName` | ➖ optional | Service name for auto-generated `/health` response (e.g. `'awf-api-proxy-myprovider'`); requires `missingCredentialMessage` | | ||
| | `missingCredentialMessage` | ➖ optional | Default error message when credentials are absent (requires `healthServiceName`) | | ||
| | `unavailableWhen` | ➖ optional | `() => { message, status? } \| null` — when non-null the auto-generated `/health` response uses the returned message/status (e.g. for OIDC token-not-yet-available states) | |
|
@copilot address review feedback |
Addressed the review feedback in commit
|
|
✅ Copilot review passed with no inline comments. @copilot Add the |
|
✅ Smoke Claude passed |
|
🔌 Smoke Services — All services reachable! ✅ |
|
✅ Build Test Suite completed successfully! |
|
📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅ |
|
❌ Security Guard failed. Please review the logs for details. |
|
Chroot tests failed Smoke Chroot failed - See logs for details. |
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤 |
|
🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation... |
|
✅ Contribution Check completed successfully! PR follows the applicable contribution guidelines: clear description, tests included for new factory behavior, documentation updated, and files are organized under containers/api-proxy. |
|
✅ Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓 |
|
✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓 |
|
✅ Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓 |
|
🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅ |
|
✅ Smoke Gemini completed. All facets verified. 💎 |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
|
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 Overall: PASS Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
|
Smoke Test: Copilot BYOK (Direct) Mode ✅ PASS
Running in direct BYOK mode via Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Smoke Test: Claude Engine Validation
Overall Result: PASS Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🧪 Smoke Test Results
Overall: PASS PR author: Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🔬 Smoke Test Results — PAT Auth
PR: refactor(api-proxy): replace duplicate getUnconfiguredHealthResponse methods with declarative factory params Overall: PASS ✅ Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🔭 OTEL Smoke Test Results
All 5 scenarios passed. OTEL tracing integration is functional. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Smoke Test: GitHub Actions Services Connectivity
Overall: FAIL — Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Smoke Test Results
PR Titles:
Overall status: PASS 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.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
|
Pre-fetched PRs: MCP connectivity: ✅ Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy E→F Azure OpenAI (Foundry, o4-mini-aw) cc Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Each of the four API proxy provider adapters (anthropic, copilot, gemini, vertex) contained an identical-shaped
getUnconfiguredHealthResponse()wrapper that differed only by service name, credential message, and an optional OIDC branch — 20+ duplicate lines across 4 files.Approach
Three new optional params on
buildProviderAdapterreplace the imperative methods:healthServiceName'awf-api-proxy-gemini'missingCredentialMessageunavailableWhen() => { message, status? } | nullfor OIDC statesWhen
healthServiceName+missingCredentialMessageare provided (and no explicitgetUnconfiguredHealthResponseis passed), the factory auto-generates the method. An explicit function still takes precedence for escape-hatch use.Before / After
Files changed
adapter-factory.js— importsmakeUnconfiguredHealthResponseonce; adds the three new params and auto-generation logicproviders/anthropic.js,copilot.js— OIDC branch expressed viaunavailableWhen;makeUnconfiguredHealthResponseimport removedproviders/gemini.js,vertex.js— reduced to two static strings;makeUnconfiguredHealthResponseimport removedadapter-factory.test.js— 4 new tests covering auto-generation,unavailableWhenoverride, null fallback, and explicit-function precedenceADDING-A-PROVIDER.md— documents the new declarative params with usage tip