Skip to content

fix(shell): avoid false fuzzy matches in branch names#14

Merged
tobiase merged 1 commit into
mainfrom
fix/switch-output-newline-and-wrapper
Mar 30, 2026
Merged

fix(shell): avoid false fuzzy matches in branch names#14
tobiase merged 1 commit into
mainfrom
fix/switch-output-newline-and-wrapper

Conversation

@tobiase
Copy link
Copy Markdown
Owner

@tobiase tobiase commented Mar 30, 2026

Summary

  • parse shell wrapper flags exactly instead of substring-matching -f
  • keep branch names containing -f on the normal non-interactive path
  • cover the s alias and explicit fuzzy mode with integration tests

Repro

wt s 2026-03-04-form-tracking-debug-floating-report printed a raw CD:/... line instead of switching, because the wrapper treated the branch name as if -f had been passed.

Testing

  • go test ./test/integration -run 'TestShellWrapperScript|TestShellWrapper'
  • go test ./...
  • make install-local

Parse shell wrapper flags exactly so branch names containing '-f' do not trigger the interactive path.

Also cover the 's' alias in wrapper tests and ensure explicit fuzzy mode still resolves the target worktree correctly.
@claude
Copy link
Copy Markdown

claude Bot commented Mar 30, 2026

Claude finished @tobiase's task —— View job


PR Review: fix(shell): avoid false fuzzy matches in branch names

Todo List:

  • Read and analyze cmd/wt/main.go changes
  • Read and analyze test/integration/shell_test.go changes
  • Review implementation approach and logic
  • Assess test coverage adequacy
  • Check for potential bugs or edge cases
  • Evaluate security and performance implications
  • Provide final review feedback

Summary

This PR fixes a critical bug where branch names containing -f were incorrectly parsed as fuzzy flags, causing the shell wrapper to malfunction. The solution implements exact flag parsing instead of substring matching.

✅ Code Quality & Best Practices

Excellent implementation approach:

  • Exact Flag Parsing: The new logic in cmd/wt/main.go:61-80 properly parses shell arguments using a case statement rather than substring matching
  • Clear Logic Flow: The argument parsing separates flags (--fuzzy|-f, -*) from positional arguments systematically
  • Consistent Style: Follows existing Go and shell conventions in the codebase

Good separation of concerns:

  • Flag parsing logic is isolated and well-commented
  • Maintains existing shell wrapper architecture
  • Preserves all existing functionality while fixing the bug

✅ Bug Analysis & Fix Quality

Root cause correctly identified:

  • The issue was substring matching treating branch names like 2026-03-04-form-tracking-debug-floating-report as containing the -f flag
  • The fix addresses this by parsing arguments positionally rather than searching for substrings

Robust solution:

  • Handles all flag variations (--fuzzy, -f)
  • Correctly ignores other dash-prefixed arguments (-*)
  • Preserves navigation target extraction logic

✅ Test Coverage & Integration Tests

Comprehensive test scenarios in test/integration/shell_test.go:

New test cases (lines 224-235):

{
    name:         "branch names containing -f do not trigger fuzzy mode",
    command:      "wt s 2026-03-04-form-tracking-debug-floating-report", 
    checkScript:  `pwd`,
    expectOutput: "/test/branch-with-f",
    rejectOutput: "CD:/test/branch-with-f", // Ensures no raw output
}

Excellent test design:

  • Tests the exact reproduction case from the issue
  • Verifies both positive (correct CD behavior) and negative (no raw output) conditions
  • Includes the s alias coverage mentioned in the PR description
  • Uses mock binary pattern for reliable, fast testing

Mock binary approach (lines 310-368):

  • Creates a controlled test environment
  • Tests shell wrapper integration without filesystem dependencies
  • Covers error conditions and different output types

✅ Security & Performance

Security considerations:

  • No security vulnerabilities introduced
  • Shell command injection risks remain properly mitigated by existing %q quoting
  • EXEC command security note preserved (lines 452-454)

Performance impact:

  • Minimal performance overhead from the new parsing loop
  • More efficient than previous substring matching approach
  • No regression in shell wrapper responsiveness

✅ Edge Cases & Robustness

Well-handled edge cases:

  • Empty arguments
  • Multiple flags in combination
  • Branch names with various dash patterns
  • Mix of flags and positional arguments

Potential considerations (minor):

  1. Long argument lists: The parsing loop is O(n) but this is negligible for typical CLI usage
  2. Unusual branch names: Should handle branches with spaces, special characters correctly due to shell quoting

✅ Documentation & Comments

Good inline documentation:

  • Clear comment on line 61: "Parse args exactly so branch names like 'feature/foo-form' do not trigger fuzzy mode"
  • Shell wrapper logic is well-documented
  • Test case names are descriptive

🎯 Recommendations

  1. Consider adding one more test case for branches with multiple dashes: feature-foo-form-bar-f-something
  2. The implementation is ready to merge - this is a solid, well-tested fix

Final Assessment

This is an excellent PR that:

  • ✅ Correctly identifies and fixes the root cause
  • ✅ Implements a clean, maintainable solution
  • ✅ Includes comprehensive integration tests
  • ✅ Maintains backward compatibility
  • ✅ Has no security or performance regressions
  • ✅ Follows project coding standards

Recommendation: APPROVE

The fix is production-ready and significantly improves the reliability of the shell wrapper for users with dash-containing branch names.


@tobiase tobiase merged commit 7f1d4e8 into main Mar 30, 2026
7 checks passed
@tobiase tobiase deleted the fix/switch-output-newline-and-wrapper branch March 30, 2026 12:55
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.

1 participant