Skip to content

Conversation

@Amolith
Copy link
Contributor

@Amolith Amolith commented Dec 13, 2025

Like cd defaults to $HOME without args, I thought it would be nice if wtp cd took the user to the main worktree, @, when invoked without args instead of emitting an error.

Assisted-by: Claude Opus 4.5 via Crush

Summary by CodeRabbit

  • New Features

    • The cd command now defaults to the main worktree when no worktree is specified; usage and examples updated to show the worktree argument as optional.
  • Tests

    • Removed a test that validated user-facing error output via the CLI; core behavior and other tests remain.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

Walkthrough

The cd command now defaults to the main worktree ("@") when no worktree-name argument is provided; usage text marks the argument as optional. A CLI test that asserted user-facing error output for the no-argument case was removed; remaining tests focus on resolution helpers and core behavior.

Changes

Cohort / File(s) Summary
cd command logic
cmd/wtp/cd.go
Usage text changed to show optional [worktree-name]; description updated; cdToWorktree logic now defaults to the main worktree ("@") when no argument is supplied instead of requiring a name.
cd command tests
cmd/wtp/cd_test.go
Removed the CLI user-facing error test that exercised error output via bytes/CLI invocation; test suite now relies on direct resolution/helper-based tests for the no-argument/default behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review cdToWorktree defaulting to "@" and any associated path-resolution calls.
  • Confirm tests removed/modified still cover core behavior and that no CLI-specific regressions remain.

Possibly related PRs

Suggested labels

codex

Poem

🐰 I hopped into code, no name in my hat,
The command said "@" — and just like that,
Home found without fuss, a soft little bound,
The rabbit trails lead to worktree ground.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: the cd command now defaults to the main worktree when no arguments are provided, which is the primary purpose of this PR.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd3019 and ff70dda.

📒 Files selected for processing (2)
  • cmd/wtp/cd.go (1 hunks)
  • cmd/wtp/cd_test.go (0 hunks)
💤 Files with no reviewable changes (1)
  • cmd/wtp/cd_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/wtp/cd.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/wtp/cd.go (1)

47-54: Defaulting to "@" is the right place, but consider covering it directly in tests.
The logic is simple and correct, but current tests mostly validate "@" → main resolution, not the no-args → "@" selection itself.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca7d736 and 6bd3019.

📒 Files selected for processing (2)
  • cmd/wtp/cd.go (1 hunks)
  • cmd/wtp/cd_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Follow standard Go style with tabs and gofmt; package names must be short and lowercase
Keep import groups tidy; use goimports for organization with local prefix following module path github.com/satococoa/wtp/v2
Adhere to linting rules in .golangci.yml (vet, staticcheck, gosec, mnd, lll=120)
Wrap errors with context; avoid ignoring errors in Go code
Use snake_case for Go filenames (e.g., remove.go, shell_integration.go)
Document exported items in Go when non-trivial; follow godoc conventions

Files:

  • cmd/wtp/cd_test.go
  • cmd/wtp/cd.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*_test.go: Unit tests must be placed alongside packages as *_test.go files in the same directory
Target 70% code coverage with unit tests focusing on fast feedback and mocked git interactions using table-driven test cases

Files:

  • cmd/wtp/cd_test.go
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Worktree naming convention: main worktree is rendered as `@`; non-main worktrees display path relative to `base_dir` (e.g., `.worktrees/feat/hoge` → `feat/hoge`)
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Shell integration must separate completion and hooks for clarity; `wtp cd` outputs absolute worktree path with no side effects
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`)
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Toggle shell integration paths with `WTP_SHELL_INTEGRATION=1` when testing cd behavior
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to **/*_test.go : Target 70% code coverage with unit tests focusing on fast feedback and mocked git interactions using table-driven test cases

Applied to files:

  • cmd/wtp/cd_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Run commands from inside a worktree to mimic real usage (e.g., `go run ../cmd/wtp add feature/new-feature`)

Applied to files:

  • cmd/wtp/cd_test.go
  • cmd/wtp/cd.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Shell integration must separate completion and hooks for clarity; `wtp cd` outputs absolute worktree path with no side effects

Applied to files:

  • cmd/wtp/cd_test.go
  • cmd/wtp/cd.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Applies to test/e2e/**/*.go : End-to-end tests must be placed in `test/e2e` and exercise real git workflows using the built binary

Applied to files:

  • cmd/wtp/cd_test.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: CLI entrypoint is located at `cmd/wtp`; new command implementations must integrate with the main CLI structure

Applied to files:

  • cmd/wtp/cd_test.go
  • cmd/wtp/cd.go
📚 Learning: 2025-12-02T13:33:48.693Z
Learnt from: CR
Repo: satococoa/wtp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-02T13:33:48.693Z
Learning: Toggle shell integration paths with `WTP_SHELL_INTEGRATION=1` when testing cd behavior

Applied to files:

  • cmd/wtp/cd_test.go
🧬 Code graph analysis (1)
cmd/wtp/cd.go (1)
internal/command/types.go (1)
  • Command (4-8)
🔇 Additional comments (1)
cmd/wtp/cd.go (1)

31-41: Help text and argument usage formatting are consistent with the actual behavior. The ArgsUsage: "[worktree-name]" correctly indicates an optional argument using square brackets (a documentation convention in urfave/cli), and the examples in Description accurately reflect the behavior when invoked with no arguments (Args().Len() == 0). Good alignment with the "@ is main worktree" convention.

Comment on lines 125 to 144
// Test that bare "wtp cd" navigates to main worktree (like cd goes to $HOME)
func TestCdCommand_NoArgsDefaultsToMainWorktree(t *testing.T) {
worktreeList := `worktree /Users/dev/project/main
HEAD abc123
branch refs/heads/main
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
app := &cli.Command{
Commands: []*cli.Command{
NewCdCommand(),
},
}
worktree /Users/dev/project/worktrees/feature/auth
HEAD def456
branch refs/heads/feature/auth
var buf bytes.Buffer
app.Writer = &buf
`

ctx := context.Background()
cmdArgs := []string{"wtp", "cd"}
cmdArgs = append(cmdArgs, tt.args...)
worktrees := parseWorktreesFromOutput(worktreeList)
mainPath := findMainWorktreePath(worktrees)

err := app.Run(ctx, cmdArgs)
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
})
}
// Empty worktree name should resolve to main worktree via "@"
resolvedPath := resolveCdWorktreePath("@", worktrees, mainPath)
assert.Equal(t, "/Users/dev/project/main", resolvedPath,
"bare wtp cd should resolve to main worktree")
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Test name/comment don’t match what’s actually asserted (it tests "@" resolution, not no-args).
Either rename + adjust the comment, or add a small helper to unit-test “no args ⇒ @”. (As per test guidelines, keeping this table-driven is optional but nice.) Based on coding guidelines.

Suggested minimal rename/comment fix:

-// Test that bare "wtp cd" navigates to main worktree (like cd goes to $HOME)
-func TestCdCommand_NoArgsDefaultsToMainWorktree(t *testing.T) {
+// Test that "@" resolves to the main worktree path.
+func TestCdCommand_AtResolvesToMainWorktree(t *testing.T) {
@@
-	// Empty worktree name should resolve to main worktree via "@"
+	// cdToWorktree defaults to "@", so ensure "@" resolves to main.
 	resolvedPath := resolveCdWorktreePath("@", worktrees, mainPath)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Test that bare "wtp cd" navigates to main worktree (like cd goes to $HOME)
func TestCdCommand_NoArgsDefaultsToMainWorktree(t *testing.T) {
worktreeList := `worktree /Users/dev/project/main
HEAD abc123
branch refs/heads/main
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
app := &cli.Command{
Commands: []*cli.Command{
NewCdCommand(),
},
}
worktree /Users/dev/project/worktrees/feature/auth
HEAD def456
branch refs/heads/feature/auth
var buf bytes.Buffer
app.Writer = &buf
`
ctx := context.Background()
cmdArgs := []string{"wtp", "cd"}
cmdArgs = append(cmdArgs, tt.args...)
worktrees := parseWorktreesFromOutput(worktreeList)
mainPath := findMainWorktreePath(worktrees)
err := app.Run(ctx, cmdArgs)
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
})
}
// Empty worktree name should resolve to main worktree via "@"
resolvedPath := resolveCdWorktreePath("@", worktrees, mainPath)
assert.Equal(t, "/Users/dev/project/main", resolvedPath,
"bare wtp cd should resolve to main worktree")
}
// Test that "@" resolves to the main worktree path.
func TestCdCommand_AtResolvesToMainWorktree(t *testing.T) {
worktreeList := `worktree /Users/dev/project/main
HEAD abc123
branch refs/heads/main
worktree /Users/dev/project/worktrees/feature/auth
HEAD def456
branch refs/heads/feature/auth
`
worktrees := parseWorktreesFromOutput(worktreeList)
mainPath := findMainWorktreePath(worktrees)
// cdToWorktree defaults to "@", so ensure "@" resolves to main.
resolvedPath := resolveCdWorktreePath("@", worktrees, mainPath)
assert.Equal(t, "/Users/dev/project/main", resolvedPath,
"bare wtp cd should resolve to main worktree")
}
🤖 Prompt for AI Agents
In cmd/wtp/cd_test.go around lines 125 to 144, the test name and comment claim
to verify that bare "wtp cd" (no args) defaults to the main worktree but the
assertion actually tests resolution of "@" to the main worktree; rename the test
and update the top-line comment to reflect that it verifies "@" resolution
(e.g., TestCdCommand_AtResolvesToMainWorktree) or alternatively add a tiny
helper/unit test that verifies empty string resolves via "@" (call
resolveCdWorktreePath("", worktrees, mainPath) and assert same path) and keep
the current test name focusing on "@" — choose one approach and update the
function name/comment or add the helper accordingly.

Like `cd` defaults to $HOME, `wtp cd` now defaults to the main worktree
(@) when invoked without arguments.

Assisted-by: Claude Opus 4.5 via Crush
@Amolith Amolith force-pushed the bare-cd-to-main-worktree branch from 6bd3019 to ff70dda Compare December 13, 2025 19:44
@satococoa satococoa self-requested a review December 16, 2025 15:36
Copy link
Owner

@satococoa satococoa left a comment

Choose a reason for hiding this comment

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

Nice improvement, thanks! Merging. 👍

@satococoa satococoa merged commit 85f338f into satococoa:main Dec 16, 2025
7 checks passed
@Amolith Amolith deleted the bare-cd-to-main-worktree branch December 16, 2025 15:53
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.

2 participants