Skip to content

Fall back to installed lower-scope SDK versions when higher-priority config is missing#661

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-go-version-compatibility
Open

Fall back to installed lower-scope SDK versions when higher-priority config is missing#661
Copilot wants to merge 2 commits intomainfrom
copilot/fix-go-version-compatibility

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

A project-local .vfox.toml entry (e.g. golang = "1.24.0") currently overrides global config even when that version is not installed, which can remove go from 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

    • Added shared tool-resolution logic to walk configured versions in priority order (Project -> Session -> Global) and pick the first installed runtime.
    • If a higher-priority scope points to a missing version, resolution now falls through to lower-priority installed versions instead of failing effective tool availability.
  • Activation/env pipeline integration

    • Updated activate and env command paths to use installed-aware resolution before symlink/env generation.
    • Existing scope semantics are preserved; only candidate selection changes when configured versions are missing.
  • Chain API support for ordered lookup

    • Extended VfoxTomlChain with GetToolConfigsByPriority(name) to return all scope configs for a tool from high to low priority.
    • This avoids ad-hoc lookup duplication and centralizes multi-scope tool selection inputs.
  • Targeted coverage

    • Added chain-level test coverage for ordered per-scope config retrieval used by fallback selection.
// high -> low priority, choose first installed
toolConfigs := chain.GetToolConfigsByPriority("golang")
for _, tc := range toolConfigs {
    if sdkObj.CheckRuntimeExist(sdk.Version(tc.Config.Version)) {
        // use tc.Config.Version at tc.Scope
        break
    }
}

@bytemain bytemain marked this pull request as ready for review April 23, 2026 08:01
Copilot AI review requested due to automatic review settings April 23, 2026 08:01
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 27.77778% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.16%. Comparing base (4b5c932) to head (08544c0).

Files with missing lines Patch % Lines
cmd/commands/tool_resolution.go 0.00% 14 Missing ⚠️
cmd/commands/activate.go 0.00% 4 Missing ⚠️
cmd/commands/env.go 0.00% 4 Missing ⚠️
internal/env/vfox_toml_chain.go 71.42% 2 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into activate and env symlink/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.

Comment thread cmd/commands/env.go
Comment on lines +226 to 230
// Resolve to the highest-priority installed version across scopes
toolConfig, scope, sdkVersion, ok := resolveInstalledToolConfig(chain, sdkObj, sdkName)
if !ok {
return nil
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +43
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
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants