Skip to content

CopyDir may skip persisted working directory contents on Windows #672

Description

@massimomazzariol

Current main at commit 264df19.

Environment
Windows 11 Pro 10.0.26200
Go 1.25.12 and Go 1.26.5
Terraform 1.15.8
Git 2.54.0.windows.1
Expected behavior

When TF_ACC_PERSIST_WORKING_DIR is enabled, each persisted step_N directory should contain the copied Terraform working directory contents.

Actual behavior

On Windows, the persisted step_1 and step_2 directories are created, but the expected working directory child and its contents are missing. The related PersistWorkingDir tests in helper/resource fail.

This was reproduced on a clean worktree of upstream/main, so it is unrelated to any local code changes.

Reproduction

From a clean checkout on Windows:

$env:TF_ACC_PERSIST_WORKING_DIR='1'; go test ./helper/resource -run PersistWorkingDir -count=1
Possible cause

copyWorkingDir derives rootBaseDir from native filesystem paths and passes it to plugintest.CopyDir.

CopyDir currently builds filesystem paths with path.Join and then filters entries with:

if !strings.Contains(srcFilepath, baseDirName) {
continue
}

On Windows, this can compare paths containing different separators, / and . The filter can therefore skip entries without returning an error.

Using filepath.Join and a separator-aware relative path check instead of substring matching may make the copy logic portable.

Additional context

The issue was discovered while running the full test suite for an unrelated change. The same failure occurs on unmodified main

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions