[codex] Add meaningful apply coverage tests#18
Conversation
📝 WalkthroughWalkthroughAdded test coverage for CLI and engine functionality, including two CLI integration tests validating Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
internal/cli/cli_unit_test.go (1)
233-247: Prefer avoiding process-wideos.Chdirin tests.
chdirForTestintroduces global mutable state that can become flaky under future parallel test execution. For these cases, using explicit--from <path>avoids CWD mutation entirely.♻️ Example refactor (remove CWD dependency in these tests)
func TestRunApplyQuietSuppressesActionLines(t *testing.T) { fx := setupCLIRepoFixture(t) - restore := chdirForTest(t, fx.wt) - defer restore() var stdout bytes.Buffer var stderr bytes.Buffer app := New(&stdout, &stderr) - code := app.Run([]string{"apply", "--from", "auto", "--include", testIncludeFile, "--quiet"}) + code := app.Run([]string{"apply", "--from", fx.root, "--include", testIncludeFile, "--quiet"}) @@ func TestRunApplyVerboseReportsTargetOnlyIncludeHint(t *testing.T) { fx := setupCLIRepoFixture(t) - restore := chdirForTest(t, fx.wt) - defer restore() @@ - code := app.Run([]string{"apply", "--from", "auto", "--include", testIncludeFile, "--verbose"}) + code := app.Run([]string{"apply", "--from", fx.root, "--include", testIncludeFile, "--verbose"})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/cli/cli_unit_test.go` around lines 233 - 247, The helper chdirForTest mutates process-global CWD which breaks parallel tests; remove usage of chdirForTest in tests in cli_unit_test.go and refactor those tests to avoid os.Chdir by passing explicit paths (e.g. use the CLI's --from/<fromFlag> or supply absolute/temp directory paths to the command under test) so they no longer rely on current working directory; update any test helpers that build paths to accept a baseDir parameter and eliminate or delete chdirForTest to avoid global state.internal/cli/cli_integration_test.go (1)
399-413: Consider asserting emptystderrfor verbose success path as well.Adding this makes output-channel expectations explicit and consistent with the quiet-path checks.
♻️ Suggested assertion addition
func TestApplyVerboseReportsNoMatches(t *testing.T) { @@ stdout, stderr, code := runCmd(t, fx.wt, nil, testBinary, "apply", "--from", "auto", "--include", ".empty.worktreeinclude", "--verbose") if code != 0 { t.Fatalf("apply --verbose exit code = %d stderr=%s", code, stderr) } + if strings.TrimSpace(stderr) != "" { + t.Fatalf("apply --verbose should not write stderr on success: %q", stderr) + } if !strings.Contains(stdout, "No matched ignored files.") { t.Fatalf("apply --verbose should explain empty match set: %s", stdout) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/cli/cli_integration_test.go` around lines 399 - 413, TestApplyVerboseReportsNoMatches currently checks exit code and stdout but not stderr; after the runCmd call and verifying code == 0, add an assertion that stderr is empty (e.g. if stderr != "" { t.Fatalf("apply --verbose unexpected stderr=%s", stderr) }) to mirror the quiet-path checks; locate the test function TestApplyVerboseReportsNoMatches and update the block after the runCmd invocation (variables stdout, stderr, code) to include this stderr emptiness assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/cli/cli_integration_test.go`:
- Around line 399-413: TestApplyVerboseReportsNoMatches currently checks exit
code and stdout but not stderr; after the runCmd call and verifying code == 0,
add an assertion that stderr is empty (e.g. if stderr != "" { t.Fatalf("apply
--verbose unexpected stderr=%s", stderr) }) to mirror the quiet-path checks;
locate the test function TestApplyVerboseReportsNoMatches and update the block
after the runCmd invocation (variables stdout, stderr, code) to include this
stderr emptiness assertion.
In `@internal/cli/cli_unit_test.go`:
- Around line 233-247: The helper chdirForTest mutates process-global CWD which
breaks parallel tests; remove usage of chdirForTest in tests in cli_unit_test.go
and refactor those tests to avoid os.Chdir by passing explicit paths (e.g. use
the CLI's --from/<fromFlag> or supply absolute/temp directory paths to the
command under test) so they no longer rely on current working directory; update
any test helpers that build paths to accept a baseDir parameter and eliminate or
delete chdirForTest to avoid global state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1bd59045-e176-4610-9915-f085ca1490cc
📒 Files selected for processing (3)
internal/cli/cli_integration_test.gointernal/cli/cli_unit_test.gointernal/engine/engine_integration_test.go
There was a problem hiding this comment.
Pull request overview
This PR adds additional test coverage around apply behavior to ensure correct handling of common safety/UX edge cases when propagating ignored files between Git worktrees.
Changes:
- Added engine integration tests covering same-content skips, source-symlink skips, and target-directory conflicts.
- Added CLI unit tests validating
apply --quietoutput suppression and verbose include-missing hint behavior. - Added CLI integration tests for
apply --quietandapply --verboseno-match reporting (including empty include files).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/engine/engine_integration_test.go | Adds integration coverage for Apply edge cases (same-content skip, symlink source skip, directory conflict). |
| internal/cli/cli_unit_test.go | Adds CLI-level tests for quiet/verbose output behavior using a real worktree fixture. |
| internal/cli/cli_integration_test.go | Adds end-to-end binary tests ensuring quiet output is fully suppressed and verbose mode reports no-match details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What changed
maincontractWhy
These cases represent real safety and UX expectations for ignored-file propagation between worktrees, and they were not covered before.
Impact
This raises confidence around apply behavior without adding coverage-only tests that lock in irrelevant implementation details.
Validation
make testSummary by CodeRabbit
applycommand's--quietand--verboseflag behaviors.