fix: support XDG-style multiple paths in HELM_PLUGINS (#2412)

* fix: support XDG-style multiple paths in HELM_PLUGINS

Use filepath.SplitList to properly handle XDG-style paths with multiple
directories (e.g., HELM_PLUGINS=/path/one:/path/two) when looking up
plugin versions. Previously, the code only scanned a single directory.

Fixes #2411

Signed-off-by: yxxhero <aiopsclub@163.com>

* fix: address PR review comments for XDG plugins path support

- Track and return first non-IsNotExist error from os.ReadDir
- Skip empty path elements from filepath.SplitList
- Use os.PathListSeparator for cross-platform test compatibility

Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2026-02-20 15:27:34 +08:00
committed by GitHub
parent 8fe0b6f13f
commit cd918b79d1
2 changed files with 56 additions and 20 deletions
+23
View File
@@ -1315,6 +1315,29 @@ func Test_GetPluginVersion(t *testing.T) {
}
}
func Test_GetPluginVersion_XDGPaths(t *testing.T) {
v3ExpectedVersion := "3.15.0"
v4ExpectedVersion := "4.7.4"
v3PluginDirPath := "../../test/plugins/secrets/3.15.0"
v4PluginDirPath := "../../test/plugins/secrets/4.7.4"
sep := string(os.PathListSeparator)
xdgPaths := "nonexistent/path" + sep + v3PluginDirPath + sep + "another/nonexistent"
pluginVersion, err := GetPluginVersion("secrets", xdgPaths)
require.NoError(t, err)
assert.Equal(t, v3ExpectedVersion, pluginVersion.String())
xdgPathsV4 := v4PluginDirPath + sep + "nonexistent/path"
pluginVersion, err = GetPluginVersion("secrets", xdgPathsV4)
require.NoError(t, err)
assert.Equal(t, v4ExpectedVersion, pluginVersion.String())
_, err = GetPluginVersion("nonexistent-plugin", xdgPaths)
require.Error(t, err)
assert.Contains(t, err.Error(), "plugin nonexistent-plugin not installed")
}
func Test_GetVersion(t *testing.T) {
helm2Runner := mockRunner{output: []byte("Client: v2.16.1+ge13bc94\n")}
helm, err := New("helm", HelmExecOptions{}, NewLogger(os.Stdout, "info"), "", "dev", &helm2Runner)