Skip to content

test: cover getBranchName fallback#119

Open
nightcityblade wants to merge 1 commit into
404-PF:mainfrom
nightcityblade:fix/issue-106
Open

test: cover getBranchName fallback#119
nightcityblade wants to merge 1 commit into
404-PF:mainfrom
nightcityblade:fix/issue-106

Conversation

@nightcityblade
Copy link
Copy Markdown
Contributor

@nightcityblade nightcityblade commented Jun 6, 2026

Fixes #106

Summary

  • add a success-path test for getBranchName in a temp git repo
  • add a fallback test that verifies unknown is returned outside a git repo

Tests

  • npm run build && node --test tests/git-diff.test.mjs
  • npm test

Note: npm run format:check currently fails on pre-existing formatting warnings in src/commands/init.ts, src/commands/suggest.ts, src/git/hook.ts, and src/llm/client.ts.

Summary by CodeRabbit

  • Tests
    • Added test coverage for Git branch name detection functionality, validating correct operation in initialized repositories and error handling when Git operations fail.

Copy link
Copy Markdown
Contributor

@404-Page-Found 404-Page-Found left a comment

Choose a reason for hiding this comment

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

Review: test: cover getBranchName fallback

What's good

The two new tests are correct and well-structured. I verified both pass against current main:

  • Success path — creates a temp repo, makes an initial commit, asserts getBranchName() matches the real branch name.
  • Fallback path — runs getBranchName() from a non-git directory, asserts it returns "unknown".
  • ✅ Both tests follow the existing patterns in this file (initRepo(), withCwd(), try/finally with rmSync cleanup).
  • ✅ Test names are descriptive and follow the "functionName expected behavior" convention.

Blocking issue: branch needs rebase

The fix/issue-106 fork branch is significantly behind main. The branch diverges early, and GitHub shows mergeable_state: "blocked". The fork hasn't been rebased on top of recent work (including the SSE refactor, stream event naming, etc.).

Please rebase on main and force-push so the PR reflects only the 28 lines you actually added.

Minor note

The PR description correctly notes that npm run format:check fails on pre-existing files — those are not introduced by this PR.


Verdict: Request changes — rebase required to unblock merge.

@nightcityblade
Copy link
Copy Markdown
Contributor Author

Rebased fix/issue-106 onto the current main and force-pushed the updated branch so the PR now reflects just the targeted test addition.

Validation:

  • npm run build
  • node --test tests/git-diff.test.mjs

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9ea36431-8bb3-48aa-84e8-7fcd540ee97f

📥 Commits

Reviewing files that changed from the base of the PR and between 8fc83e1 and b2e1be2.

📒 Files selected for processing (1)
  • tests/git-diff.test.mjs

📝 Walkthrough

Walkthrough

This PR adds test coverage for the getBranchName() function. The test suite imports getBranchName from the distributed module and adds two test cases: one verifying the function returns the current Git branch name within a repository, and another verifying it returns "unknown" when Git commands fail outside a repository.

Changes

getBranchName test coverage

Layer / File(s) Summary
getBranchName test cases
tests/git-diff.test.mjs
Import getBranchName and add two test cases covering the success path (returns current branch via git rev-parse --abbrev-ref HEAD) and failure path (returns "unknown" when Git command fails in non-repo directory).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A little test hops into the fray,
Checking branches by night and by day,
When Git is around, it knows the way,
When Git is not—"unknown" comes to play!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: cover getBranchName fallback' directly describes the main change—adding test coverage for the getBranchName function's fallback behavior when git fails.
Linked Issues check ✅ Passed The PR satisfies all acceptance criteria from issue #106: adds a success test verifying getBranchName returns the current branch in a temp repo, adds a failure-path test verifying it returns 'unknown' when git fails, and maintains all existing tests.
Out of Scope Changes check ✅ Passed All changes are within scope—only test additions to tests/git-diff.test.mjs directly aligned with issue #106's requirements for getBranchName test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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.

Add unit tests for getBranchName fallback behavior

2 participants