From 0422e2e365f80143b89b58699ea782c2f7855046 Mon Sep 17 00:00:00 2001 From: "Md. Amdadul Bari Imad" Date: Fri, 4 Dec 2026 09:11:32 +0000 Subject: [PATCH] fix(plugin): keep candidate plugin name when installing from a directory When a plugin directory contains no executable file but exactly one file named notation-{plugin-name}, Install sets the executable bit on that candidate and installs it. parsePluginFromDir stored the result of parsePluginName directly in candidatePluginName for every regular file, so any file visited after the candidate whose name does not follow the notation-{plugin-name} format reset it to an empty string. As a result, installing from a directory such as notation-foo (not executable) readme.md failed with the misleading error failed to get metadata of new plugin: plugin executable file name must be "notation-foo" instead of "notation-foo" while the same directory installs fine if the extra file sorts before the candidate (e.g. LICENSE or libfoo). Only update candidatePluginName when the file name is a valid plugin executable file name. Signed-off-by: Md. Amdadul Bari Imad --- plugin/manager.go | 4 +++- plugin/manager_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/plugin/manager.go b/plugin/manager.go index 6570c805..71d8ec31 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -255,11 +255,13 @@ func parsePluginFromDir(ctx context.Context, path string) (string, string, error } // only take regular files if info.Mode().IsRegular() { - if candidatePluginName, err = parsePluginName(d.Name()); err != nil { + name, err := parsePluginName(d.Name()) + if err != nil { // file name does not follow the notation-{plugin-name} format, // continue return nil } + candidatePluginName = name filesWithValidNameFormat = append(filesWithValidNameFormat, p) isExec, err := isExecutableFile(p) if err != nil { diff --git a/plugin/manager_test.go b/plugin/manager_test.go index 4dd9aa14..6ff73713 100644 --- a/plugin/manager_test.go +++ b/plugin/manager_test.go @@ -465,6 +465,44 @@ func TestManager_Install(t *testing.T) { } }) + t.Run("success to install from plugin dir with one valid candidate file followed by other files", func(t *testing.T) { + existedPluginFilePath := "testdata/plugins/foo/notation-foo" + newPluginFilePath := "testdata/foo/notation-foo" + // the walk visits files in lexical order, so this file is visited + // after the candidate plugin executable file + newPluginDocPath := "testdata/foo/readme.md" + newPluginDir := filepath.Dir(newPluginFilePath) + if err := os.MkdirAll(newPluginDir, 0777); err != nil { + t.Fatalf("failed to create %s: %v", newPluginDir, err) + } + defer os.RemoveAll(newPluginDir) + if err := createFileAndChmod(newPluginFilePath, 0600); err != nil { + t.Fatal(err) + } + if err := createFileAndChmod(newPluginDocPath, 0600); err != nil { + t.Fatal(err) + } + executor = testInstallCommander{ + existedPluginFilePath: existedPluginFilePath, + newPluginFilePath: newPluginFilePath, + existedPluginStdout: metadataJSON(validMetadata), + newPluginStdout: metadataJSON(validMetadataHigherVersion), + } + installOpts := CLIInstallOptions{ + PluginPath: newPluginDir, + } + existingPluginMetadata, newPluginMetadata, err := mgr.Install(context.Background(), installOpts) + if err != nil { + t.Fatalf("expecting nil error, but got %v", err) + } + if existingPluginMetadata.Version != "1.0.0" { + t.Fatalf("expecting existing plugin metadata to be 1.0.0, but got %s", existingPluginMetadata.Version) + } + if newPluginMetadata.Version != "1.1.0" { + t.Fatalf("expecting new plugin metadata to be 1.1.0, but got %s", newPluginMetadata.Version) + } + }) + t.Run("success to install from plugin dir with no executable file and one valid candidate file", func(t *testing.T) { existedPluginFilePath := "testdata/plugins/foo/notation-foo" newPluginFilePath := "testdata/foo/notation-foo"