hashicorp / hashicorp/terraform-plugin-testing
CopyDir may skip persisted working directory contents on Windows
- Dominant language
- Go
- Stars
- 68
- Forks
- 22
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 1
Description
Current main at commit 264df192526087d7f34a6ebf46cb8260bcd86573.
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
Contributor guide
Research direction
Start by running `go test ./helper/resource -run PersistWorkingDir -count=1` on Windows and inspect the PersistWorkingDir tests in `helper/resource`. Trace `copyWorkingDir` into `plugintest.CopyDir`, focusing on path construction and the entry filter. Done means persisted `step_1` and `step_2` directories contain the copied working-directory child and contents, with the tests passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100