From e76de849049c11e3e2fef7846e61e5d6aa06fbec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 28 Nov 2025 13:37:50 +0000 Subject: [PATCH] fix: handle case where basePath is "." or current directory Add check to skip directory change when basePath is "." or already the current working directory. This fixes test failures with mock filesystems that don't have "." in their directory list. Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --- go.mod | 2 +- pkg/state/envvals_loader.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d1577c7c..42a11883 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( go.yaml.in/yaml/v3 v3.0.4 golang.org/x/sync v0.18.0 golang.org/x/term v0.37.0 + gopkg.in/yaml.v3 v3.0.1 helm.sh/helm/v3 v3.19.2 helm.sh/helm/v4 v4.0.1 k8s.io/apimachinery v0.34.2 @@ -323,7 +324,6 @@ require ( gopkg.in/gookit/color.v1 v1.1.6 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.34.2 // indirect k8s.io/apiextensions-apiserver v0.34.1 // indirect k8s.io/apiserver v0.34.1 // indirect diff --git a/pkg/state/envvals_loader.go b/pkg/state/envvals_loader.go index 78bf9a0b..4c3b5823 100644 --- a/pkg/state/envvals_loader.go +++ b/pkg/state/envvals_loader.go @@ -139,9 +139,15 @@ func (ld *EnvironmentValuesLoader) renderInBasePath(value any, r tmpl.TextRender return nil, fmt.Errorf("failed to get current working directory: %v", err) } + // If basePath is "." or already the current directory, no need to change + basePath := ld.storage.basePath + if basePath == "." || basePath == cwd { + return ld.renderTemplateExpressions(value, r) + } + // Change to basePath for rendering using the filesystem abstraction - if err := ld.fs.Chdir(ld.storage.basePath); err != nil { - return nil, fmt.Errorf("failed to change to base directory %q: %v", ld.storage.basePath, err) + if err := ld.fs.Chdir(basePath); err != nil { + return nil, fmt.Errorf("failed to change to base directory %q: %v", basePath, err) } // Ensure we change back to the original directory