Skip to content

Use t.Chdir in CLI tests - #67059

Merged
pelikhan merged 2 commits into
mainfrom
copilot/deep-report-migrate-os-chdir-t-parallel-test-patte
Oct 9, 2026
Merged

pelikhan merged 2 commits into
mainfrom
copilot/deep-report-migrate-os-chdir-t-parallel-test-patte

Conversation

Copilot AI commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Manual os.Chdir and deferred restoration changed process-wide state in five CLI test files, creating a latent race with parallel tests. Replace these pairs with t.Chdir, which restores the working directory through test cleanup.

  • Migration: Update cwd-changing tests in commands_test.go, list_workflows_command_test.go, add_no_args_test.go, git_test.go, and forecast_test.go; remove redundant cwd restoration.
  • Pattern:
    t.Chdir(tmpDir)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate os.Chdir and t.Parallel() tests to t.Chdir in pkg/cli Use t.Chdir in CLI tests Oct 9, 2026
Copilot AI requested a review from pelikhan October 9, 2026 00:57
@pelikhan
pelikhan marked this pull request as ready for review October 9, 2026 01:11
Copilot AI balanced review requested due to automatic review settings October 9, 2026 01:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread pkg/cli/commands_test.go
if err := os.Chdir(tempDir); err != nil {
t.Fatalf("Failed to change to temp directory: %v", err)
}
t.Chdir(tempDir)
Comment thread pkg/cli/commands_test.go
if err := os.Chdir(tmpDir); err != nil {
t.Fatal(err)
}
t.Chdir(tmpDir)
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for this focused refactoring! 👋 Migrating to t.Chdir removes a latent race with parallel tests. The PR looks ready for review.

Generated by ✅ Contribution Check · copilot · auto · 43.4 AIC · ⌖ 0.611 AIC · ⊞ 9.2K · ◷

@pelikhan
pelikhan merged commit 79de41d into main Oct 9, 2026
37 checks passed
@pelikhan
pelikhan deleted the copilot/deep-report-migrate-os-chdir-t-parallel-test-patte branch October 9, 2026 01:50
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot address the following outstanding work in one pass:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/commands_test.go:413): t.Chdir restores the working directory through test cleanup, which runs after ordinary defers. The existing defer os.RemoveAll(tempDir) therefore now tries to delete the process's current directory; that fails on Windows and silently leaks this temporary tree. Register removal as an earlier cleanup (or use testutil.TempDir) so t.Chdir restores the cwd before removal. - Use t.Chdir in CLI tests #67059 (comment)
  3. Review (pkg/cli/commands_test.go:627): t.Chdir restores the cwd during test cleanup, after the existing defer os.RemoveAll(tmpDir) runs. The defer now attempts to remove the current directory, which fails on Windows and silently leaves the temporary tree behind. Convert the removal at setup to a cleanup registered before this call, or create the directory with testutil.TempDir. - Use t.Chdir in CLI tests #67059 (comment)

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
Sous-chef work: ebe1a92feb82dd13b07855242ddc86e1174adf3d6c0dca940b68128cf50f76f4 f2d96ee665d700c3ac138bc00cb7443c4907834f40e9ea0f782dc951fe34185f
Sous-chef state: f4d2f7b60b97ce132c767f5941737c4a58d4c47827788317f7eda33f834c6cd8

Generated by 👨‍🍳 PR Sous Chef · pi · haiku45 · 4.59 AIC · ⌖ 8.63 AIC · ⊞ 1K · ◷
Comment /souschef to run again

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.91.7

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[deep-report] Migrate os.Chdir+t.Parallel() test patterns to t.Chdir in 5 pkg/cli test files

4 participants