Skip to content

feat(code-review, test-planning): detect the diff base across multiple remotes and git-flow - #151

Open
taminomara wants to merge 4 commits into
testdouble:han-v5.0.0-alpha-1from
taminomara:sync/multi-remote-detect-context
Open

feat(code-review, test-planning): detect the diff base across multiple remotes and git-flow#151
taminomara wants to merge 4 commits into
testdouble:han-v5.0.0-alpha-1from
taminomara:sync/multi-remote-detect-context

Conversation

@taminomara

Copy link
Copy Markdown
Contributor

Summary

The code-review and test-planning git-context detectors pick the base branch to diff against from origin/HEAD alone. On a fork whose origin default is stale, on a git-flow branch cut from an integration branch, or on a branch that merged another candidate in, that base is wrong, so the review or test plan is scoped to an inflated, empty, or mis-attributed diff.

This ports review-skill-or-agent's base detection to both detectors. The base is now the branch's own line of work: the candidate whose fork point is nearest the current commit, measured along first-parent history, chosen across a multi-remote candidate pool.

What changed

  • detect-review-context.sh, detect-test-context.sh. Replace the single origin/HEAD lookup with a candidate pool: every remote's declared default branch, plus well-known trunk and integration names (main, master, trunk, mainline, next, develop, devel, development, default, dev), looked up as local branches and as each remote's tracking branch. The nearest own-line coincidence wins; a declared default breaks an equal-distance tie; refs are deduplicated. A candidate the branch merely merged in cannot win on its absorbed commits, because those commits are not on the branch's first-parent line.
  • Output contract unchanged. The scripts emit the same key: value keys, still fail open to default-branch: none, and always exit 0. No consuming skill prose or long-form docs change.
  • Tests. Add test/detect-review-context.bats and test/detect-test-context.bats (16 cases each), which these detectors previously lacked: stale-origin-vs-fresh-remote, git-flow integration branch, local trunk, merged-in demotion, unrelated-candidate exclusion, none / unborn / detached fallbacks, and the declared-default tie-break priority.

Scope

The build-target-diff.sh change-scope helper and the SKILL.md PR-base override are review-skill-or-agent-specific and stay on #119. This PR is the shared detector plus its tests only.

Testing

  • npm test (bats --recursive test/): 33 passing (16 + 16 + the existing sanity check).
  • npm run lint (prek run --all-files): every hook passes.

Related

Completes the OI-1 follow-up flagged in #119, whose detect-git-context.sh intentionally ran ahead of these copies. Once both land, all three detectors match, and #119's "intentionally ahead" header note gets reconciled to name all three.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NfTexc8iv7XAqt3ksH9zNP

@taminomara
taminomara force-pushed the sync/multi-remote-detect-context branch from 9614338 to a24a802 Compare July 28, 2026 00:42
@taminomara taminomara changed the title feat(code-review, test-planning): multi-remote own-line base detection feat(code-review, test-planning): detect the diff base across multiple remotes and git-flow Jul 28, 2026
@taminomara
taminomara force-pushed the sync/multi-remote-detect-context branch from a24a802 to 80244a8 Compare July 28, 2026 00:48
@taminomara
taminomara marked this pull request as ready for review July 28, 2026 13:32
@taminomara

Copy link
Copy Markdown
Contributor Author

Merging needs coordination with #132, one of them should move added .bats files.

@mxriverlynn

Copy link
Copy Markdown
Collaborator

👋🏻 @taminomara i opened the Discussions tab for the repo just now, and posted #152 - i'm really far behind in getting your PRs merged in, and i want to get that resolved. thought it would be easiest to coordinate all of this in that discussion, instead of trying to do it in PRs

taminomara and others added 3 commits July 28, 2026 18:39
…e remotes and git-flow

The code-review and test-planning git-context detectors chose the branch to
diff changes against from origin/HEAD alone. On a fork whose origin default is
stale, on a git-flow branch cut from an integration branch, or on a branch that
merged another branch in, that base was wrong, so the review or test plan was
scoped to an inflated, empty, or mis-attributed diff.

Port review-skill-or-agent's base selection to both detectors: the base is now
the candidate whose fork point is nearest the current commit, measured along the
branch's own first-parent line, chosen across a multi-remote candidate pool.

- Candidate pool: every remote's declared default branch plus well-known
  trunk/integration names (main, master, trunk, mainline, next, develop, devel,
  development, default, dev), looked up as local and per-remote branches;
  nearest own-line coincidence wins, declared defaults break ties.
- A candidate the branch merely merged in cannot win on its absorbed commits.
- Output contract shape unchanged; fail-open to `default-branch: none` preserved.
- Adds test/detect-review-context.bats and test/detect-test-context.bats
  (16 tests each) under test/, which these detectors previously lacked.

Completes the OI-1 follow-up flagged in review-skill-or-agent (PR testdouble#119),
which intentionally ran ahead of these copies.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NfTexc8iv7XAqt3ksH9zNP
…base detection

Replace the per-own-line-commit `git merge-base --is-ancestor` probe in
base-branch selection with a single `git rev-list --count --first-parent
HEAD ^candidate` per candidate. This cuts subprocess spawns across the
candidate pool from O(C*H) to O(C), so a long first-parent history no longer
forces a subprocess per own-line commit.

Behavior-preserving: the base chosen and the changed-files listing are
unchanged, and the detector test suites pass untouched. Verified equivalent
across topologies including a candidate reachable only via a merge's second
parent and off-spine-only shared history in a multi-root repo.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NfTexc8iv7XAqt3ksH9zNP
…5 rename

The v5 line split test-planning into automated-test-planning, so the moved
detect-test-context.sh and its Bats test now live under
han-coding/skills/automated-test-planning/. Update the test's SRC path and the
detector sync-note comments to match the new location.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NEQjJUi7ZHVXGfVGXKUVJ
@taminomara
taminomara force-pushed the sync/multi-remote-detect-context branch from 6a3bd79 to 37afaaa Compare July 28, 2026 14:42
@taminomara
taminomara changed the base branch from main to han-v5.0.0-alpha-1 July 28, 2026 14:42
…nd-parent base detection

Address code-review findings on the base-branch detectors:
- Freeze HEAD to a commit up front (HEAD_SHA) so every candidate and the
  changed-files diff measure against the same point, not a live ref re-read
  per candidate (SUGG-002).
- Expand the selection comment with the reasoning the count rests on:
  first-parent monotonicity, and that "^candidate" excludes by the candidate's
  full reachability while "--first-parent" limits only the walk from HEAD
  (SUGG-001).
- Add a regression test for a candidate that reaches an own-line commit only
  through its own merge second parent, the topology that distinguishes
  full-reachability exclusion from a first-parent-limited one (WARN-001).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NfTexc8iv7XAqt3ksH9zNP
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