diff --git a/.changes/unreleased/BUG FIXES-20260724-142353.yaml b/.changes/unreleased/BUG FIXES-20260724-142353.yaml new file mode 100644 index 000000000..531a095b3 --- /dev/null +++ b/.changes/unreleased/BUG FIXES-20260724-142353.yaml @@ -0,0 +1,5 @@ +kind: BUG FIXES +body: 'helper/resource: Fix persisted working directory copying on Windows.' +time: 2026-07-24T14:23:53.759+02:00 +custom: + Issue: "672" diff --git a/internal/plugintest/util.go b/internal/plugintest/util.go index 856163afe..b17d62d63 100644 --- a/internal/plugintest/util.go +++ b/internal/plugintest/util.go @@ -8,7 +8,6 @@ import ( "io" "io/fs" "os" - "path" "path/filepath" "strings" "testing" @@ -119,8 +118,8 @@ func CopyDir(src, dest, baseDirName string) error { } for _, dirEntry := range dirEntries { - srcFilepath := path.Join(src, dirEntry.Name()) - destFilepath := path.Join(dest, dirEntry.Name()) + srcFilepath := filepath.Join(src, dirEntry.Name()) + destFilepath := filepath.Join(dest, dirEntry.Name()) if !strings.Contains(srcFilepath, baseDirName) { continue diff --git a/internal/plugintest/util_test.go b/internal/plugintest/util_test.go index 287f326bc..d771c11d1 100644 --- a/internal/plugintest/util_test.go +++ b/internal/plugintest/util_test.go @@ -123,3 +123,29 @@ func dirEntryComparer(t *testing.T) cmp.Option { return true }) } + +func TestCopyDirWithBaseDirName(t *testing.T) { + t.Parallel() + + srcDir := t.TempDir() + baseDir := filepath.Join(srcDir, "work") + + if err := os.MkdirAll(baseDir, 0o755); err != nil { + t.Fatalf("cannot create base directory: %s", err) + } + + if err := os.WriteFile(filepath.Join(baseDir, "src.txt"), []byte("test"), 0o600); err != nil { + t.Fatalf("cannot create source file: %s", err) + } + + destDir := filepath.Join(t.TempDir(), "dest") + baseDirName := baseDir[len(srcDir):] + + if err := CopyDir(srcDir, destDir, baseDirName); err != nil { + t.Fatalf("cannot copy directory: %s", err) + } + + if _, err := os.Stat(filepath.Join(destDir, "work", "src.txt")); err != nil { + t.Fatalf("cannot stat copied source file: %s", err) + } +}