Repository navigation
feat(changes): review a branch against a chosen base - #1857
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Branch comparison contracts shared/repo-diff.ts, shared/protocol.ts, DESIGN.md, changelog.d/branch-review-base.md |
Adds the branch scope, comparison identity and refs response types, and documents the branch comparison flow and API behavior. |
Server comparison and refs API server/repo-diff.ts, server/workspace-routes.ts, server/machine-api.ts, server/repo-diff.test.ts, server/api.contract.test.ts, server/device-access.contract.test.ts, server/machine-proxy.test.ts |
Lists eligible refs and computes branch file lists from the merge base. Patch requests use the returned comparison identity and reject stale repository or HEAD state. Routes, proxy handling, and contract tests cover refs requests. |
Branch selection and pinned patch display src/components/RepoChanges.tsx, src/components/RepoChanges.css, src/components/RepoDiffViewer.tsx, src/lib/api.ts, src/lib/machineContext.tsx, src/lib/repoDiff.ts, src/lib/repoDiff.test.ts, src/lib/i18n/files.*.ts |
Adds ref selection and filtering, explicit Compare submission, target-change resets, identity-aware patch loading, comparison status messages, and localized responsive controls. |
Demo and browser coverage site/demo/transport.ts, scripts/repo-diff-browser-qa.ts |
Adds branch comparison behavior to the static demo and browser tests for branch selection, patch identity, moved refs, refusal cases, stale responses, localization, and layouts. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Feature
Merge Risk: 
Minimal · up to 3b779
-
No actionable merge-blocking risk remains; the branch comparison is ready for normal merge checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the feature, API behavior, error cases, issue reference, review context, validation results, and HTTP contract-test coverage. It uses different headings from the template, but it contains the required Change and Validation information.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 71.70% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 53 functions across 20 files. (3 skipped: 3 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
Code-review agent review (stands in while CodeRabbit is rate-limited)CodeRabbit answered "Review limit reached", so it has not reviewed this PR. Two independent agent reviews ran on the full diff against main ( omo-native-code-reviewer: APPROVE. No CRITICAL or HIGH findings.
Argument injection, ref validation, merge-base semantics, the shared contract after the rebase, the proxy and watch-only gates on This PR adds an HTTP contract ( |
|
Merge pass review-work for 9b0ddf1: REVIEW FAILED on the pinned-comparison promise. This PR adds HTTP routes and CodeRabbit was rate-limited, so this comment records the independent review. Blocker: a checkout while a patch is being read returns 200 with the old identity and the new branch's patch. The description says "a HEAD that moved answers 409 Checked and passing:
Non-blocking:
|
|
Fixed the blocker in 3b77967: a branch patch is now refused when HEAD moves during its read.
The non-blocking notes (older-bridge picker wording, RepoChanges size, the fixture-length test, the frame-based stale assertion) are left as they are. |
|
Merge pass review-work for 3b77967: the wrong-patch race is fixed. A checkout during the read now returns 409 Blocker: a checkout that empties the diff returns 404
Passing: 56 tests pass, the typecheck passes, and the contract tests pass. Only the two declared files changed. |
|
Fixed in e61d529: a moved HEAD is now 409
|
|
Merge pass: #1849 (find literal text in the loaded patch) is merged (54b4db3). This PR now conflicts with main in |
Files > Changes gains a Branch scope, following the Codex app's review pane: the working tree, untracked files included, is compared against the merge base of a chosen base and HEAD, so what the base went on to change stays out. - server/repo-diff.ts: scope=branch resolves the base and HEAD to full commit ids and computes git merge-base with no fallback. A detached HEAD works; an unborn HEAD, an unknown or malformed base and unrelated histories are refused as unborn_head, revision_not_found / invalid_revision and no_common_ancestor. The list pins a comparison identity (repository root, HEAD, base, merge base); a patch carries it back as a bounded JSON query parameter, is read from the pinned merge base, and answers 409 comparison_changed once HEAD or the repository moved. Untracked files use the existing bounded ls-files and --no-index paths. Nothing fetches, checks out or writes. - GET /api/workspace/diff/refs lists local and remote branches (full refname and oid, remote symbolic HEAD omitted, at most 200, existing byte and time limits) behind the same pane, machine, cross-site and watch-only gates; it is forwarded to other PCs. - shared/protocol.ts: the branch scope, RepoBranchComparison, RepoDiffRefs and the comparison field on list and patch. - RepoChanges: a Branch segment with a base combobox (typed or picked, refs read on open and fenced per PC/pane/folder, loading, empty, no-match, truncated and refused states), Compare only on request, an identity line, and a viewer that discards a patch for another identity. On a phone the four scopes share the bar. - Demo transport answers the refs route and a fictional branch comparison; ko/ja/zh strings; DESIGN.md entry; changelog fragment. Checked with bun run check fast; bun test of server/repo-diff.test.ts and src/lib/repoDiff.test.ts (branch, detached HEAD, unborn and unrelated histories, pinned base, moved HEAD, bounded refs, no fetch/checkout/write); the API, device-access and machine-proxy tests on the isolated herdr; and scripts/repo-diff-browser-qa.ts on real temporary repositories and the demo build at 1440 and 390 (DPR 3), light and dark, plus Korean. Refs #1048
A base list opened while the phone's Files sheet was still sliding in kept the position it was given mid-animation and could land over Compare. The list is now placed again when an ancestor's animation or transition ends. The branch review browser check also captures every state the visual review names under its own name: disabled Compare, loading branches, list and patch, a picked base, Compare pressed, a long branch name, the cut branch list, invalid ancestry, an older PC and an offline PC. Checked with bun run check fast and scripts/repo-diff-browser-qa.ts.
- Another PC, pane or folder clears the base, the picked row and the last listing, and waits for Compare there; a list still on its way for the target left behind, or for a scope that waits for Compare, is dropped. - The base list sits in the form's flow under the field and Compare at every width instead of a popover placed by script, so it never covers Compare or the scopes, and closes on a finished click so nothing moves under a press. - Before the first Compare the Branch scope says what it waits for instead of showing a loading skeleton; the base field is a full touch target on a phone. - A full branch name the refs route offers (a plus sign, Hangul, a long name) is accepted when git's refname rules hold it to a name; ranges, reflog and peel suffixes, paths, spaces and options stay refused.
A pinned branch comparison accepted any hex id of 40 through 64 characters, so a 41-character head_oid answered 409 comparison_changed and base_oid 404 revision_not_found. Full git ids are exactly 40 (SHA-1) or 64 (SHA-256), and every other length is now 400 invalid_comparison before git is asked.
Branch names, their hashes and the list's notes were caption sizes (11-12px). They are now --fs-md on desktop and, on a touch screen, --fs-xl for the name and --fs-lg for the hash and notes. No global token changes.
…uring The demo ends its opening agent turn on a 4.5 s timer, so the demo captures raced it behind the Files sheet. The browser check now installs the page clock and runs it past that timer before the first capture.
main renamed the history entry and settings keys to ovis: (#1648); the branch scope's history test and browser check still wrote the old ones.
The demo's base picker listed feat/idempotent-payments and origin/release/2026.10, which its Compare then refused as "No commit by that name". It now offers main and origin/main, the bases it answers.
A branch patch checked HEAD against the pinned comparison before git read the working tree, never after, so a checkout landing during the read was answered 200 with the old identity and the other branch's content, and the viewer accepted it. The repository and HEAD are now read again once the patch is, and a change answers 409 comparison_changed. A git stand-in that checks out another branch right before the read covers it.
A checkout during a branch patch read that left nothing changed at the path (to the base before the patch, or before its own listing) answered 404 not_found without looking at HEAD again. The listing now runs inside the read, and HEAD is checked after it whatever it answered, errors included, so a moved HEAD is always 409 comparison_changed. The race test covers both empty cases beside the changed-content one.
e61d529 to
06270da
Compare
|
Rebased onto main after #1849 and pushed 06270da (was e61d529). The conflicts in
Known follow-up, still listed in the description: a deleted then recreated untracked file shows as deleted. This is a rebase only, so it doesn't need another CodeRabbit review. |
|
Merge pass review-work report. Overall: PASSED. This PR adds HTTP routes and CodeRabbit was rate-limited, so per AGENTS.md this comment, together with the two earlier ones, records the independent review.
What was checked
Follow-ups (MINOR)
All required checks are green and no review thread is open. CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it. |
…3028) ## What Since #3002, `scripts/repo-diff-browser-qa.ts` times out on main (and on every PR's Integration and browser job) waiting for the **Choose a branch** button in the step "a branch list still on its way is dropped when the reader switches PC". #3002 keyed `RepoChanges` in `FilesDialog` by PC and pane (`key={`${machineId}:${paneId}`}`). A switch of pane or PC while Files is open (Next pane, the sidebar) now remounts the changes list, so the **Branch** scope the reader picked falls back to **Working tree**. That also happens with the new setting off (the dialog), so it is a product regression, not a stale locator: #1857 made Changes keep its Branch scope across a pane, folder or PC switch (it starts the comparison over with no base) and drop answers for the target left behind by itself, and its tests assert exactly that (`branchPressed: "true"` after each switch). The fix removes only that key. The `DirectoryBrowser` and `PullRequestPanel` keys from #3002 stay, so the same pane id on another PC still lists that PC's folder (the PC-switch step in `scripts/files-panel-demo-regression.ts`). ## Validation - `bun scripts/repo-diff-browser-qa.ts` on origin/main 6b72c09 (after `bun install --frozen-lockfile` and `bun run build`): fails with `TimeoutError: click: Timeout 15000ms exceeded ... waiting for getByRole('button', { name: 'Choose a branch', exact: true })` right after the Korean branch review, as in CI. - Same script with this change: passes (`repository diff: browser OK ...`, exit 0). - `bun scripts/files-panel-demo-regression.ts` with this change: PASS 1280/390, light/dark (the PC-switch folder step included). - `bun run check fast`: passed on 6349cd7 (unit 12200 pass, 0 fail; typecheck, build, generated files). No new test: the existing browser regression is the failing-first check.
What it does
Files → Changes gains a Branch scope, following the Codex app's review pane: pick a base (local or remote branch, or type a branch/commit) and press Compare to see what this branch changed since its merge base with that base. The working tree is compared, untracked files included, so what the base went on to change stays out.
GET /api/workspace/diff/filesand/diff/fileacceptscope=branchwith abase. The list pins a comparison identity (repository root, HEAD, base and merge base). Each patch read carries that identity back and is read from the pinned merge base. A HEAD that moved answers 409comparison_changed.GET /api/workspace/diff/refslists local and remote branches for the picker, at most 200, from the refs on disk (nothing is fetched). It sits behind the same pane, machine, cross-site and watch-only gates and is forwarded to other PCs.unborn_head,revision_not_found/invalid_revision,no_common_ancestor), with nothing compared in their place. Nothing fetches, checks out or writes.src/lib/i18n/files.{ko,ja,zh}.ts; the PR adds a DESIGN.md entry, the demo transport answers the new route, and a changelog fragment.Refs #1048
Why
Reviewing a branch before a PR meant leaving the app for
git diff main.... The Codex app's review pane shows this view, and users asked for it.Real review needed
This adds an HTTP contract: the new
/api/workspace/diff/refsroute, abranchscope, and acomparisonfield on the list and patch answers. Per AGENTS.md it waits for a real review.How it was verified
shared/repo-diff.ts, the strings moved tosrc/lib/i18n/files.*.ts, and the tests use main'sovis:storage keys.bun test server/repo-diff.test.ts src/lib/repoDiff.test.ts server/machine-proxy.test.tscover branch, detached HEAD, unborn and unrelated histories, a pinned base, a moved HEAD, bounded refs, and no fetch, checkout or write.bun run check fastpassed.comparison_changed. A git stand-in that checks out another branch right before the read covers this, and the test fails without the check.scripts/repo-diff-browser-qa.tspassed against real temporary repositories and the demo build. It covers 1440 and 390 (DPR 3), dark, English and Korean, and every Branch state: picker, compared, pinned patch, refresh required, invalid base, unrelated histories, unborn, watching device, older PC and offline.Known follow-up (Codex, MEDIUM, not fixed here)
git diff <merge-base>reports it the same way.