Repository navigation
Use t.Chdir in CLI tests - #67059
Use t.Chdir in CLI tests#67059
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Four tests now attempt deferred temporary-directory removal before t.Chdir restores the cwd, causing cleanup failures on Windows.
2 open findings
What changed in this PR
Migrates CLI tests from manual working-directory restoration to t.Chdir.
Changes:
- Replaces
os.Chdir/deferred restoration in five test files. - Simplifies related error handling.
| File | Description |
|---|---|
pkg/cli/commands_test.go |
Migrates command tests to t.Chdir. |
pkg/cli/list_workflows_command_test.go |
Uses automatic cwd restoration. |
pkg/cli/add_no_args_test.go |
Simplifies temporary-directory setup. |
pkg/cli/git_test.go |
Migrates Git tests to t.Chdir. |
pkg/cli/forecast_test.go |
Migrates cache tests to t.Chdir. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| if err := os.Chdir(tempDir); err != nil { | ||
| t.Fatalf("Failed to change to temp directory: %v", err) | ||
| } | ||
| t.Chdir(tempDir) |
| if err := os.Chdir(tmpDir); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| t.Chdir(tmpDir) |
|
Thanks for this focused refactoring! 👋 Migrating to
|
|
@copilot address the following outstanding work in one pass:
Push the necessary fixes, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved. Use the pr-finisher skill and stop when only human review or CI remains; do not trigger CI. Sous-chef head: 3bb6eab
|
|
🎉 This pull request is included in a new release. Release: |

Manual
os.Chdirand deferred restoration changed process-wide state in five CLI test files, creating a latent race with parallel tests. Replace these pairs witht.Chdir, which restores the working directory through test cleanup.commands_test.go,list_workflows_command_test.go,add_no_args_test.go,git_test.go, andforecast_test.go; remove redundant cwd restoration.