Skip to content

fix(review): use merge-base for branch diffs - #847

Closed
yzxcj797 wants to merge 1 commit into
tirth8205:stagingfrom
yzxcj797:fix/842-detect-changes-merge-base
Closed

yzxcj797 wants to merge 1 commit into
tirth8205:stagingfrom
yzxcj797:fix/842-detect-changes-merge-base

Conversation

@yzxcj797

Copy link
Copy Markdown
Contributor

Fixes #842.

Summary

  • resolve local and remote branch bases to their merge base with HEAD, matching pull-request review semantics
  • preserve explicit commit IDs, tags, and revision expressions as exact comparison points, with the previous behavior retained when a merge base cannot be resolved
  • apply the resolved base consistently across CLI, MCP tools, minimal context, prompts, changed-file discovery, and line-range analysis
  • add a real divergent Git history regression plus caller and fallback coverage

Testing

  • uv run pytest tests/test_integration_git.py tests/test_changes.py tests/test_cli.py tests/test_prompts.py tests/test_tools.py -q - 108 passed, 1 skipped
  • uv run ruff check code_review_graph/
  • uv run mypy code_review_graph/cli.py code_review_graph/incremental.py code_review_graph/prompts.py code_review_graph/tools/context.py code_review_graph/tools/query.py code_review_graph/tools/review.py --ignore-missing-imports --no-strict-optional --follow-imports=skip
  • uv run bandit -q -r code_review_graph/
  • git diff --check

The complete Windows suite also ran: 2,355 passed, 14 skipped, 2 xpassed, with 37 pre-existing Windows path/symlink/D3-fixture failures unrelated to this change.

AI assistance

OpenAI Codex assisted with issue analysis, implementation, tests, and review. I reviewed the final diff and verified the commands and results above locally.

@tirth8205

Copy link
Copy Markdown
Owner

The approach is right and matches the three-dot semantics asked for in #842. Tags, SHAs, and rev expressions stay exact, branch and remote-tracking refs get the merge base, and the fallbacks for shallow clones, unrelated histories, and missing refs behave sensibly. I also ran extra edge cases locally (detached HEAD, base equal to HEAD, base strictly ahead of HEAD, ambiguous tag plus branch names, dirty working tree) and the implementation held up on all of them.

One blocker: tests/test_tools.py test_review_base_is_shared_by_probe_discovery_and_analysis fails on macOS. tempfile.mkdtemp() returns /var/folders/..., a symlink to /private/var/..., and _get_store resolves the root, so resolve_review_base gets the resolved path and the assert against self.root does not match. Please change the three mock asserts in that test (resolve, has_changes, get_changed) to compare against self.root.resolve().

With that fixed the suite is green here, and ruff and mypy are clean. Happy to merge after that one change.

@tirth8205

Copy link
Copy Markdown
Owner

Integrated on integration/token-efficiency-hardening as f3bdb72, 61300d8. Branch and remote-branch reviews now use their merge base consistently, while tags, commit SHAs and revision expressions remain exact. A real divergent-Git regression confirms that get_review_context excludes a base-only file and retains the feature file; the rebase preserves current read-only behaviour and corrects canonical-path expectations on macOS.

tirth8205 added a commit that referenced this pull request Sep 13, 2026
detect-changes resolves a branch ref to its merge base with HEAD, but the
brief panel printed by `update --brief --base <branch>` still diffed
against the branch tip, so the two summaries disagreed on divergent
branches. Apply the same rule in the brief path.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016yGn8rDJSeJCRcRf4cmciH
@tirth8205
tirth8205 changed the base branch from main to staging September 15, 2026 13:12
@tirth8205

Copy link
Copy Markdown
Owner

Merged into staging through the integration PR #988 (merge commit 3030ca8). Your change is carried by commit f3bdb72, which keeps you as the author (yzxcj797). It will be promoted staging → testing → main and released from there. Thank you for the contribution! Closing this PR since its content is now on staging.

@tirth8205 tirth8205 closed this Sep 15, 2026
Bakul2006 pushed a commit to Bakul2006/code-review-graph that referenced this pull request Sep 15, 2026
Port the reviewed token-efficiency implementation with targeted regression coverage.

Source-PR: tirth8205#847
Maintainer corrections and scope extraction applied where needed.
Bakul2006 pushed a commit to Bakul2006/code-review-graph that referenced this pull request Sep 15, 2026
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.

[Bug]: detect-changes --base <branch> uses a two-dot diff, misattributing base-branch commits to the reviewed branch

2 participants