Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

The PreUse hook's ctx.installedSdks was changed to key by SDK name instead of version string in 1.0.0, breaking existing plugins (vfox-elixir, vfox-erlang) that index by version.

Changes

Core fix:

  • internal/sdk/sdk.go:459: Changed map key from sdk.Runtime.Name to string(sdk.Runtime.Version)

Supporting changes:

  • Test plugins: Updated to use version-based keys with nil checks
  • plugin_impl_test.go: Changed test key from "xxxx" to "1.0.0" to validate correct keying
  • Documentation: Clarified that ctx.installedSdks keys are version strings (e.g., "1.19.2-elixir-otp-28")

Test coverage:

  • Added comprehensive test suite in internal/plugin/preuse_test.go with 7 test cases:
    • Version string keying validation (simple, complex versions, vendor suffixes)
    • Empty installedSdks handling
    • Non-existent version access safety
    • Multiple SDK versions scenario (simulating vfox-elixir use case)
    • All InstalledPackageItem fields validation
    • Different scopes testing (global/project/session)
    • Explicit verification that SDK name is NOT used as key

Example

Plugins can now access installed SDKs as documented:

function PLUGIN:PreUse(ctx)
    local input_version = ctx.version
    -- Works: keyed by version string
    local sdkInfo = ctx.installedSdks[input_version]
    return { version = sdkInfo.version }
end

Previously this would fail because the map was keyed by SDK name (e.g., "elixir") instead of version string (e.g., "1.19.2-elixir-otp-28").

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG]: Changes in vfox 1.0.0 cause incompatible behavior in plugin's pre_use.lua implementation</issue_title>
<issue_description>Version
The version you are currently using
OS
macOS、Linux、Windows

Describe the bug
relate issue: version-fox/vfox-elixir#15

Screenshots[optional]
If applicable, add screenshots to help explain your problem.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix incompatible behavior in plugin's pre_use.lua Fix PreUse hook ctx.installedSdks keying to use version strings Jan 19, 2026
Copilot AI requested a review from bytemain January 19, 2026 12:51
@aooohan aooohan marked this pull request as ready for review January 19, 2026 13:39
Copilot AI review requested due to automatic review settings January 19, 2026 13:39
@aooohan
Copy link
Member

aooohan commented Jan 19, 2026

@copilot please add more tests for preUse hook of plugin.

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 22.60%. Comparing base (a138738) to head (21b7d51).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/sdk/sdk.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #615   +/-   ##
=======================================
  Coverage   22.60%   22.60%           
=======================================
  Files          80       80           
  Lines        5406     5406           
=======================================
  Hits         1222     1222           
  Misses       4044     4044           
  Partials      140      140           

☔ 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
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 fixes a regression introduced in version 1.0.0 where the PreUse hook's ctx.installedSdks map was incorrectly keyed by SDK name instead of version string, breaking existing plugins (vfox-elixir, vfox-erlang) that expected version-based indexing.

Changes:

  • Changed ctx.installedSdks map keying from SDK name to version string in the preUse function
  • Updated test plugins to use version-based keys ("1.0.0" instead of "xxxx") with nil checks
  • Updated documentation in English and Chinese to clarify version-based keying with examples

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/sdk/sdk.go Core fix: changed map key from sdk.Runtime.Name to string(sdk.Runtime.Version)
internal/plugin/plugin_impl_test.go Updated test to use version string "1.0.0" as key instead of SDK name "xxxx"
internal/plugin/testdata/plugins/missing_required_hook/main.lua Updated to use version-based key with nil check
internal/plugin/testdata/plugins/java_with_metadata/hooks/pre_use.lua Updated to use version-based key with nil check
internal/plugin/testdata/plugins/java_with_main/main.lua Updated to use version-based key with nil check
internal/plugin/testdata/plugins/invalid_name/main.lua Updated to use version-based key with nil check
docs/plugins/create/howto.md Added clarification and examples for version-based keying
docs/zh-hans/plugins/create/howto.md Added clarification and examples for version-based keying (Chinese)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot please add more tests for preUse hook of plugin.

Added comprehensive test suite for PreUse hook in commit 21b7d51.

Created 7 new test cases covering:

  • Version string keying (simple versions, complex versions like 1.19.2-elixir-otp-28, vendor suffixes)
  • Empty installedSdks handling
  • Non-existent version access safety
  • Multiple SDK versions scenario (simulating vfox-elixir use case)
  • All InstalledPackageItem fields validation
  • Different scopes (global/project/session)
  • Explicit verification that SDK name is NOT used as key

All tests pass ✅

Copilot AI requested a review from aooohan January 19, 2026 13:44
@aooohan
Copy link
Member

aooohan commented Jan 19, 2026

@copilot Please refer to the howto instructions and add unit tests for each hook function which put into plugins_hook_test.go and remove preuse_test.go

Copilot stopped work on behalf of aooohan due to an error January 19, 2026 13:47
@aooohan aooohan merged commit 7e46e2b into main Jan 19, 2026
8 of 9 checks passed
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.

[BUG]: Changes in vfox 1.0.0 cause incompatible behavior in plugin's pre_use.lua implementation

3 participants