Fall back to installed lower-scope SDK versions when higher-priority config is missing#661
Fall back to installed lower-scope SDK versions when higher-priority config is missing#661
Conversation
Agent-Logs-Url: https://github.com/version-fox/vfox/sessions/f9ac9663-b05f-43e1-aa20-4abf8b1e5255 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
Agent-Logs-Url: https://github.com/version-fox/vfox/sessions/f9ac9663-b05f-43e1-aa20-4abf8b1e5255 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #661 +/- ##
==========================================
+ Coverage 24.09% 24.16% +0.07%
==========================================
Files 82 83 +1
Lines 7084 7104 +20
==========================================
+ Hits 1707 1717 +10
- Misses 5201 5209 +8
- Partials 176 178 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates SDK version resolution so that activate/env prefer the highest-priority installed configured version across scopes, instead of letting a higher-priority but missing version effectively remove the SDK from PATH.
Changes:
- Added
VfoxTomlChain.GetToolConfigsByPriority(name)to retrieve per-scope tool configs in priority order (Project → Session → Global). - Introduced shared installed-aware resolution helper (
resolveInstalledToolConfig) and integrated it intoactivateandenvsymlink/env generation paths. - Added unit test coverage for ordered per-scope config retrieval in
VfoxTomlChain.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/env/vfox_toml_chain.go | Adds ScopedToolConfig and GetToolConfigsByPriority for ordered multi-scope lookup. |
| internal/env/vfox_toml_chain_test.go | Adds test verifying priority ordering of tool configs across scopes. |
| cmd/commands/tool_resolution.go | New helper to pick the first installed configured version by scope priority. |
| cmd/commands/env.go | Switches envFlag path to installed-aware resolution (no longer trusts merged version when missing). |
| cmd/commands/activate.go | Switches activation symlink/env generation to installed-aware resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Resolve to the highest-priority installed version across scopes | ||
| toolConfig, scope, sdkVersion, ok := resolveInstalledToolConfig(chain, sdkObj, sdkName) | ||
| if !ok { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
env --json still resolves SDK versions using the merged chain.GetAllTools() values and GetRuntimePackage(version), which means it will continue to drop tools when the highest-priority configured version is missing—even though envFlag now falls back to lower-scope installed versions via resolveInstalledToolConfig. Consider updating the JSON path to use the same installed-aware resolution helper so vfox env and vfox env --json produce consistent results.
| func resolveInstalledToolConfig(chain env.VfoxTomlChain, sdkObj sdk.Sdk, sdkName string) (*pathmeta.ToolConfig, env.UseScope, sdk.Version, bool) { | ||
| toolConfigs := chain.GetToolConfigsByPriority(sdkName) | ||
| if len(toolConfigs) == 0 { | ||
| return nil, env.Global, "", false | ||
| } | ||
|
|
||
| for _, toolConfig := range toolConfigs { | ||
| version := sdk.Version(toolConfig.Config.Version) | ||
| if sdkObj.CheckRuntimeExist(version) { | ||
| return toolConfig.Config, toolConfig.Scope, version, true | ||
| } | ||
| logger.Debugf("SDK %s@%s from %s scope not installed, trying lower-priority config", | ||
| sdkName, version, toolConfig.Scope.String()) | ||
| } | ||
|
|
||
| logger.Debugf("No installed configured version found for SDK %s", sdkName) | ||
| return nil, env.Global, "", false | ||
| } |
There was a problem hiding this comment.
resolveInstalledToolConfig introduces new resolution behavior (skip missing versions and fall back by scope), but there are no unit tests covering the fallback selection logic (e.g., project configured but uninstalled, global installed => choose global). Adding targeted tests here (with a small fake sdk.Sdk implementation for CheckRuntimeExist) would help prevent regressions.
A project-local
.vfox.tomlentry (e.g.golang = "1.24.0") currently overrides global config even when that version is not installed, which can removegofrom PATH inside the workspace. This change keeps scope priority while skipping uninstalled candidates and selecting the highest-priority installed configured version.Resolution behavior: prefer installed config by scope order
Project -> Session -> Global) and pick the first installed runtime.Activation/env pipeline integration
activateandenvcommand paths to use installed-aware resolution before symlink/env generation.Chain API support for ordered lookup
VfoxTomlChainwithGetToolConfigsByPriority(name)to return all scope configs for a tool from high to low priority.Targeted coverage