refactor(model-resolver): decompose resolveModel into focused sub-functions; move version utils tests#4938
Conversation
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This PR refactors the API proxy’s model alias resolution logic by decomposing the previously monolithic resolveModel implementation into focused helper functions, and relocates the pure “version/glob” utility tests into a dedicated test file for clearer separation of concerns.
Changes:
- Split
resolveModelinto_resolveDirectMatch(no-alias path) and_resolveAliasPatterns(alias/pattern expansion path), leavingresolveModelas an orchestrator with loop detection + alias lookup. - Added
model-utils.test.jsto directly testglobMatch,extractVersionNumbers, andcompareByVersion. - Removed duplicated version-utility tests from
model-resolver.test.jsand updated imports/comments accordingly.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/model-resolver.js | Decomposes resolveModel into smaller helpers while preserving recursive alias resolution, logging, and fallback behavior. |
| containers/api-proxy/model-utils.test.js | Introduces dedicated unit coverage for pure glob/version utility helpers. |
| containers/api-proxy/model-resolver.test.js | Removes duplicated utility tests and keeps resolver tests focused on alias/fallback behavior. |
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
|
✅ Smoke Test: Copilot BYOK (Direct) Mode
Status: PASS — Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY)
|
🔥 Smoke Test Results — PASS
PR: refactor(model-resolver): decompose resolveModel into focused sub-functions; move version utils tests Overall: PASS
|
🔐 Smoke Test: Copilot PAT Auth — PASS
Auth mode: PAT (COPILOT_GITHUB_TOKEN)
|
|
✅ Add interactive workflow designer agent 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 Test: API Proxy OpenTelemetry Tracing
All 5 scenarios passed. OTEL tracing integration is working correctly on this branch.
|
🔬 Chroot Version Comparison Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.
|
|
Smoke Test Results:
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
|
Smoke Test: GitHub Actions Services Connectivity
Overall: FAIL —
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results: Gemini
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.
|
|
Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) Overall: PASS
|
resolveModelinmodel-resolver.jswas a 156-line monolith handling 7 distinct logical paths inline, making individual paths difficult to test or modify in isolation. The version utilities (globMatch,extractVersionNumbers,compareByVersion) were already extracted tomodel-utils.js; this PR completes the refactoring.Changes
model-resolver.js—resolveModeldecomposed into three functions_resolveDirectMatch(key, requestedModel, currentProvider, availableModels, fallbackConfig, log)— no-alias path: direct match → GPT-5 family version fallback → middle-power fallback_resolveAliasPatterns(aliasKey, aliasDefinition, requestedModel, aliases, availableModels, currentProvider, newChain, fallbackConfig, log)— pattern expansion: iterates patterns, recurses into alias references, glob-matches against provider models, deduplicates, version-sorts, picks best candidateresolveModel(~36 lines) — orchestrator only: loop detection → alias lookup (with gpt-5 family alias fallback) → dispatch to one of the aboveThe
logarray is passed by reference through all sub-functions to preserve the existing log-accumulation contract. Themodule.exportssurface is unchanged (re-exports of version utils kept for caller compatibility).model-utils.test.js(new)Dedicated test file for
globMatch,extractVersionNumbers,compareByVersionimported directly from./model-utils.model-resolver.test.jsRemoved the duplicate version-utility test sections (now in
model-utils.test.js); updated imports accordingly. All 1044 tests across 48 suites continue to pass.