Improve error handling, add tests, and migrate code review to issues#4
Improve error handling, add tests, and migrate code review to issues#4
Conversation
- Check return values of runGitSilent in processBranch for merge, update-ref, checkout, and branch -D operations - Replace fmt.Sscanf with strconv.Atoi in getCommitDifference for proper parse error handling - Add unit tests for colorizeOutput, getCommitDifference, and getDefaultBranch https://claude.ai/code/session_01Tp3JPoVFF6Kcuur3NXV4g9
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughAdd error handling around git fast-forward, checkout and branch deletion operations; replace fmt.Sscanf parsing with strconv.Atoi for commit counts; add tests (colorizeOutput, getCommitDifference, getDefaultBranch) and a test repo helper. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@main_test.go`:
- Around line 81-87: Replace the fragile manual newline stripping when computing
defaultBranch by using strings.TrimSpace on branchOut instead of
branchOut[:len(branchOut)-1]; update the code that runs git rev-parse
(variables: cmd, branchOut, defaultBranch) to set defaultBranch := "refs/heads/"
+ strings.TrimSpace(string(branchOut)) and add "strings" to the import block so
empty or platform-specific line endings are handled safely.
🧹 Nitpick comments (3)
main_test.go (3)
25-33: GlobalcolorFlagis mutated without being restored.If test ordering changes or new tests depend on
colorFlag, this will cause flaky failures. Save and restore the original value.Proposed fix
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + oldFlag := colorFlag + defer func() { colorFlag = oldFlag }() colorFlag = tt.flag got := colorizeOutput()
11-16: Theexactfield is alwaystrue— it's dead logic.Every test case sets
exact: true, so the guardif tt.exact &&on line 29 is never false. Either remove the field and simplify the check, or add a case that actually usesexact: false.
61-68:os.Chdirmutates process-global state, making these tests unsafe for parallel execution.This is a known Go testing pitfall. If
t.Parallel()is ever added, tests will interfere with each other. SincegetCommitDifferenceshells out togit(which uses the working directory), there's no easy workaround, but consider adding a comment documenting this constraint, or usingt.Setenv-style guards if Go 1.24+t.Chdiris available.
- Replace fragile branchOut[:len(branchOut)-1] with strings.TrimSpace - Save/restore global colorFlag in TestColorizeOutput to prevent flaky tests - Remove dead `exact` field from test struct (was always true) - Add comments about os.Chdir parallel test safety constraint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
processBranch()for fast-forward update, branch deletion, and checkout operationsfmt.Sscanfwithstrconv.Atoifor commit count parsing with explicit error handlingcolorizeOutput,getCommitDifference, andgetDefaultBranchbranchOut[:len(branchOut)-1]withstrings.TrimSpacefor safe newline handlingcolorFlaginTestColorizeOutputto prevent flaky testsexactfield from test struct (was alwaystrue)os.Chdirparallel test safety constraintCODE_REVIEW.mdand migrate all findings to individual GitHub issues (Return values of runGitSilent are ignored in processBranch #5-exitWithError calls os.Exit(1) directly, preventing deferred cleanup #15)Closes #5
Closes #6
Closes #7
Test plan
go test ./... -v