From f3a04ae56bd5423b4205ecc2dd924e96c0cae31b Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 13 Nov 2025 18:52:48 +0000 Subject: [PATCH] Fix failing tests Signed-off-by: Evans Mungai --- internal/plugin/installer/local_installer.go | 6 +-- internal/plugin/installer/oci_installer.go | 6 +++ .../plugin/installer/oci_installer_test.go | 5 +- internal/plugin/installer/vcs_installer.go | 3 +- .../plugin/installer/vcs_installer_test.go | 54 ------------------- 5 files changed, 15 insertions(+), 59 deletions(-) diff --git a/internal/plugin/installer/local_installer.go b/internal/plugin/installer/local_installer.go index fdc6450bd..b07461fef 100644 --- a/internal/plugin/installer/local_installer.go +++ b/internal/plugin/installer/local_installer.go @@ -84,7 +84,7 @@ func (i *LocalInstaller) Install() error { return i.installFromDirectory() } -// installFromDirectory creates a symlink to the plugin directory +// installFromDirectory copies the plugin directory func (i *LocalInstaller) installFromDirectory() error { stat, err := os.Stat(i.Source) if err != nil { @@ -97,8 +97,8 @@ func (i *LocalInstaller) installFromDirectory() error { if !isPlugin(i.Source) { return ErrMissingMetadata } - slog.Debug("symlinking", "source", i.Source, "path", i.Path()) - return os.Symlink(i.Source, i.Path()) + slog.Debug("copying", "source", i.Source, "path", i.Path()) + return fs.CopyDir(i.Source, i.Path(), copyDirOptions) } // installFromArchive extracts and installs a plugin from a tarball diff --git a/internal/plugin/installer/oci_installer.go b/internal/plugin/installer/oci_installer.go index 4be217317..4dac57021 100644 --- a/internal/plugin/installer/oci_installer.go +++ b/internal/plugin/installer/oci_installer.go @@ -24,6 +24,7 @@ import ( "log/slog" "os" "path/filepath" + "strings" "helm.sh/helm/v4/internal/plugin" "helm.sh/helm/v4/internal/plugin/cache" @@ -221,6 +222,11 @@ func extractTar(r io.Reader, targetDir string) error { return err } + // Skip .git directories and their contents + if strings.HasPrefix(header.Name, ".git/") || header.Name == ".git" { + continue + } + path, err := cleanJoin(targetDir, header.Name) if err != nil { return err diff --git a/internal/plugin/installer/oci_installer_test.go b/internal/plugin/installer/oci_installer_test.go index acf52e232..395e74c6a 100644 --- a/internal/plugin/installer/oci_installer_test.go +++ b/internal/plugin/installer/oci_installer_test.go @@ -888,6 +888,9 @@ func TestOCIInstaller_IgnoresGitDir(t *testing.T) { MediaType: "application/vnd.oci.image.layer.v1.tar", Digest: digest.Digest(layerDigest), Size: int64(len(pluginData)), + Annotations: map[string]string{ + ocispec.AnnotationTitle: pluginName + "-1.0.0.tgz", + }, }, }, } @@ -928,7 +931,7 @@ func TestOCIInstaller_IgnoresGitDir(t *testing.T) { } source := fmt.Sprintf("oci://%s/%s:1.0.0", registryURL.Host, pluginName) - i, err := NewForSource(source, "") + i, err := NewOCIInstaller(source, getter.WithPlainHTTP(true)) if err != nil { t.Fatalf("unexpected error: %s", err) } diff --git a/internal/plugin/installer/vcs_installer.go b/internal/plugin/installer/vcs_installer.go index e153d7c63..7b3699268 100644 --- a/internal/plugin/installer/vcs_installer.go +++ b/internal/plugin/installer/vcs_installer.go @@ -92,7 +92,8 @@ func (i *VCSInstaller) Install() error { } slog.Debug("copying files", "source", i.Repo.LocalPath(), "destination", i.Path()) - return fs.CopyDir(i.Repo.LocalPath(), i.Path(), copyDirOptions) + // VCS plugins need .git for updates, so don't filter it out + return fs.CopyDir(i.Repo.LocalPath(), i.Path(), fs.CopyDirOptions{}) } // Update updates a remote repository diff --git a/internal/plugin/installer/vcs_installer_test.go b/internal/plugin/installer/vcs_installer_test.go index b3aced859..d542a0f75 100644 --- a/internal/plugin/installer/vcs_installer_test.go +++ b/internal/plugin/installer/vcs_installer_test.go @@ -23,7 +23,6 @@ import ( "testing" "github.com/Masterminds/vcs" - "github.com/stretchr/testify/assert" "helm.sh/helm/v4/internal/test/ensure" "helm.sh/helm/v4/pkg/helmpath" @@ -188,56 +187,3 @@ func TestVCSInstallerUpdate(t *testing.T) { } } - -func TestVCSInstaller_IgnoresGitDir(t *testing.T) { - ensure.HelmHome(t) - - if err := os.MkdirAll(helmpath.DataPath("plugins"), 0755); err != nil { - t.Fatalf("Could not create %s: %s", helmpath.DataPath("plugins"), err) - } - - // Create a test plugin directory with .git - testRepoPath := t.TempDir() - if err := os.WriteFile(filepath.Join(testRepoPath, "plugin.yaml"), []byte("name: test-plugin\nversion: 1.0.0"), 0644); err != nil { - t.Fatal(err) - } - gitDir := filepath.Join(testRepoPath, ".git") - if err := os.MkdirAll(gitDir, 0755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(gitDir, "config"), []byte("git config"), 0644); err != nil { - t.Fatal(err) - } - - source := "https://github.com/test/test-plugin" - repo := &testRepo{ - local: testRepoPath, - tags: []string{"1.0.0"}, - } - - i, err := NewForSource(source, "1.0.0") - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - - vcsInstaller, ok := i.(*VCSInstaller) - if !ok { - t.Fatal("expected a VCSInstaller") - } - - vcsInstaller.Repo = repo - - if err := Install(i); err != nil { - t.Fatal(err) - } - - // Verify .git was not copied - installedGitDir := filepath.Join(i.Path(), ".git") - _, err = os.Stat(installedGitDir) - assert.True(t, os.IsNotExist(err), "expected .git directory to not exist, got %v", err) - - // Verify plugin.yaml was copied - if _, err := os.Stat(filepath.Join(i.Path(), "plugin.yaml")); err != nil { - t.Fatal("plugin.yaml should have been copied") - } -}