Repository navigation
feat(pr): track Bitbucket pull requests via git-based merge detection - #3224
simonwarmup wants to merge 4 commits into
Conversation
Carves the uncontested majority of kunchenguid#3127 into a change that touches no function upstream PR kunchenguid#891 touches, so it can be reviewed and merged independently of that overlap-hold. Closes the first half of kunchenguid#3110: a Bitbucket pull request could not be tracked at all, because fm_pr_url_parse had no Bitbucket arm and so fm-pr-check.sh could never arm a poll for one. - fm-pr-lib.sh parses Bitbucket Cloud PR URLs, shares one per-segment path rule with GitLab, and carries pr_dest= through the metadata identity parse and the poll snapshot. - fm-pr-check.sh records pr_dest= at arm time and preserves it on a same-URL re-arm. - fm-pr-poll.sh gains a git-based PRIMARY landed-work detector that runs before any forge call, so detection works on every forge with no forge client at all. Its origin-identity check is independent of the copy in fm-pr-lib.sh, by design, because this script's bytes are hash-registered. A conclusive negative is cached against the (tip, HEAD) pair; a landed or inconclusive result never is, so an interrupted cycle re-detects rather than suppressing a merge forever. - fm-watch.sh passes the worktree, recorded destination and tip cache through to the poll. - fm-teardown.sh cleans up the new tip cache in remove_pr_poll_artifacts(). That is its ONLY change here; the destination-aware landed-work hunks stay in kunchenguid#3127 until kunchenguid#891 resolves. The origin path is compared case-insensitively, matching the host half: every forge addressed here resolves a repository path case-insensitively while preserving URL case, so one repository legitimately arrives spelled two ways. Comparing byte-for-byte refused that valid destination and, on a forge with no API fallback, lost the merge silently. Regression test added.
bin/fm-teardown.sh does not read pr_dest in this change - the destination-aware landed-work hunks stay in kunchenguid#3127 - so the header should not claim it does.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "test(teardown): teach the fake gh the tw..." | Re-trigger Greptile |
| if [ -z "$dest" ]; then | ||
| dest=$(git_default_branch "$wt") || return 2 | ||
| fi |
There was a problem hiding this comment.
Bitbucket destination silently defaults
When a Bitbucket pull request targets a non-default branch and is armed through the documented two-argument command, no pr_dest is recorded, so this code checks the default branch instead. Because Bitbucket has no forge fallback, the actual merge is never reported; equivalent content on the default branch can instead retire the poll prematurely.
|
Speaking as Kun's firstmate: Reviewed HEAD Class: corrective for #3110's first defect (Bitbucket PRs were untrackable). Author body names that half; inspected parse accepts Overlap: not held against #891. The only VISION.md per-rule:
First-time fork CI: after that full-diff review I approved workflow runs Attestation: author already flagged it — pipeline |
…e query bin/fm-pr-check.sh now asks for the head and the destination branch in one call, `gh pr view --json headRefOid,baseRefName`, to derive pr_dest. The stub in tests/fm-teardown.test.sh only had arms for "state,headRefOid" and "headRefOid". The generic second arm also matches the new two-field query and answers with a single field and no tab, so fm-pr-check.sh's malformed-response guard correctly declined to record pr_head at all. That made test_pr_check_does_not_refresh_stale_pr_head see zero pr_head= lines where it asserts exactly one. The production guard is not at fault: refusing to record from a malformed forge response is the intended fail-closed behaviour. This restores the stub's fidelity to the real gh, and with it the coverage the stale stub had silently removed - with no pr_head recorded, the case's second assertion (that a stale rerun must not record the later local HEAD) was passing vacuously. The specific arm must precede the generic one, since "headRefOid" is a substring of "headRefOid,baseRefName".
Two small asks, both just needing a click — and the evidence for the second is now stronger1. This PR — please approve the held runs on Both are sitting at
Everything else on our side is finished. Since your last pass I fixed the one real failure — The attestation now binds: body 2. #3126 — the two behaviour failures now have third-party evidence, from your own runners. When you released the checks on #3127 this morning, That is now three independent lines pointing the same way: unreachable from the diff by source-closure, green on the branch's parent No rush on either, and nothing is blocked at your end by us — both are one click whenever it suits. |
|
Speaking as Kun's firstmate: Reviewed HEAD Class: corrective (closes first half of #3110 — Bitbucket PRs were untrackable). VISION.md per-rule: prior pass still holds — honest merge reading; refuse-on-inconclusive; scripts own URL/git mechanics; tip-cache prefers duplicate wake over lost merge; forge-agnostic git primary; scope aligns. Attestation: now matches this HEAD ( Fork CI: approved |
|
Speaking as Kun's firstmate: Follow-up on the just-approved no-mistakes run Behavior CI on |
Both re-sign routes are no-ops here — evidence, and what I'd suggest insteadThanks for digging into that yourself and confirming the body still binds
A fresh pipeline pass — re-attaches rather than re-publishing. I also don't think re-running the failed job helps: GitHub replays a run against its original event payload, so an empty payload stays empty. I assume that's why you asked for a new event rather than a re-run. What I'd suggestAn empty commit — Alternatively, close-and-reopen mints a Happy to do either, or neither. It's your repo and your review — you should pick which small ugliness you'd rather carry. Say the word and I'll action it; otherwise I'll leave it parked. For completeness: everything else on |
…ed (kunchenguid#3224) Stable span-based row ids + text hashes + C05 cache keys per row; BM25 stays derived from stored rows; --clip scopes partial updates. Measured: one correction re-embeds 2/420 rows, matrices byte-identical, query reports identical.
Intent
Carve the uncontested majority of our existing PR #3127 into a NEW pull request that touches no function upstream PR #891 touches, so the maintainer can merge it without waiting on his overlap-hold. This closes the first half of upstream issue #3110: Bitbucket pull requests cannot be tracked at all, because the URL parser has no Bitbucket arm and so no merge poll can ever be armed for one.
Ships in this PR: bin/fm-pr-lib.sh (Bitbucket URL parse arm, fm_pr_path_segment_valid path-segment validation shared with GitLab, pr_dest= in the metadata identity parse, and the poll snapshot destination); bin/fm-pr-check.sh (record pr_dest= at arm time, carry it over on a same-URL re-arm); bin/fm-pr-poll.sh (the git-based primary merge detector and its tip-cache durability); bin/fm-watch.sh (pass worktree, destination and tip-cache through to the poll); bin/fm-teardown.sh (ONLY the single line in remove_pr_poll_artifacts() adding the tip-cache file to the cleanup list, and nothing else in that file); docs/architecture.md, docs/scripts.md and docs/gitlab-merge-watch.md (poll signature and transcript updates); AGENTS.md (the new state row and the pr_dest= operator line); and tests/fm-pr-check-security.test.sh plus tests/fm-pr-merge.test.sh.
Deliberately excluded - do not add any of these back, they are the whole reason for the split: the three contested bin/fm-teardown.sh hunks (the header paragraph, content_in_default -> content_in_branch, and work_is_landed); the five contested cases in tests/fm-teardown.test.sh that test those hunks; bin/fm-backend.sh, which is unrelated scope drift that arrived via a CI-fix commit and needs its own PR; fm_pr_git_origin_matches_repo in bin/fm-pr-lib.sh, whose only caller is the held content_in_branch so it would land here with no caller; and the teardown PR_DEST metadata read, whose only consumer is that same held function.
The carved code was already written and adversarially reviewed on #3127, so prefer faithful extraction over rewriting. A behaviour change hidden inside a split is the worst possible outcome here.
This also fixes a reviewer P1 raised on #3127 against bin/fm-pr-poll.sh: git_origin_matches_repo compared repository paths byte-for-byte while already case-folding the host half, so one repository legitimately spelled with different capitalization in the origin URL and the pull request URL was refused as a different repository. Because a failed identity check falls through to the forge API and Bitbucket has no forge API integration here at all, that silently lost the merge entirely. Both sides of the path comparison are now case-folded, matching the host half, with a regression test that fails before the fix and passes after.
Three comment and documentation cross-references were scoped down because the carve, not the original code, made them inaccurate: they claimed bin/fm-teardown.sh consumes pr_dest or has content_in_branch, neither of which is true in this PR.
Expect the CI stage to park: every fork pull request to this repository has its workflow runs held at action_required for maintainer approval on every push, so CI checks never run. A parked CI gate is the expected end state, not a failure of the work.
FOLLOW-UP ALREADY COMMITTED IN THIS BRANCH (do not redo, do not revert): tests/fm-teardown.test.sh's fake gh stub gained one arm for the two-field query
gh pr view --json headRefOid,baseRefName. bin/fm-pr-check.sh uses that call to derive pr_dest, but the stub only had arms for "state,headRefOid" and "headRefOid"; the generic one also matched the two-field query and answered with a single field and no tab, so fm-pr-check.sh's malformed-response guard correctly declined to record pr_head and test_pr_check_does_not_refresh_stale_pr_head saw zero pr_head= lines where it asserts exactly one. This surfaced as CI "Behavior portable serial 3" failing. The production guard is correct and must NOT be changed; the fix is the stub's fidelity to real gh, and it restores coverage that was previously passing vacuously. The specific arm must stay ahead of the generic one because "headRefOid" is a substring of "headRefOid,baseRefName". Verified locally: without the line the case fails exactly as CI did, with it the whole file passes.STILL EXCLUDED, unchanged: everything else from #3127's tests/fm-teardown.test.sh diff - the GIT_FAKE_SSH harness, the ssh origin URL in make_case, the land_on_origin_branch helper, the z1-z5 comment block, and the five content_in_branch test functions and their registrations. bin/fm-teardown.sh must keep exactly ONE changed line, the pr-poll-git-tip entry in remove_pr_poll_artifacts().
ONE MORE THING THIS RUN MUST ACHIEVE: the previous run left the PR body's pipeline attestation bound to an older head (967077c) while the branch had moved on, so the required check "PR must be raised via no-mistakes" failed with "Pipeline attestation head_sha does not match the current PR head". This run must publish an attestation that binds to its own final head. Do NOT hand-edit the PR body or the attestation to achieve that.
What Changed
bin/fm-pr-lib.sh(fixedbitbucket.orghost, flat workspace/repository path), refactored the shared path-segment validation intofm_pr_path_segment_validfor reuse between GitLab and Bitbucket, and extended the GitLab host guard to also refusebitbucket.org.pr_dest=as a recognized, revalidated field in the metadata identity parse and poll snapshot capture inbin/fm-pr-lib.sh, so a pull request's actual destination branch (not just the default branch) can be tracked.bin/fm-pr-check.shnow accepts an optional destination-branch argument, auto-derives it fromgh pr view --json headRefOid,baseRefNamefor GitHub, records it aspr_dest=, carries it over on a same-URL re-arm, and clears any stale tip-cache file on re-arm.bin/fm-pr-poll.shgained a git-based primary merge detector (landed-work test against the recorded or default destination branch) with a durable tip-cache file for detection performance, plus a fix for a P1 where the origin/PR repository path comparison was byte-for-byte instead of case-folded on both sides (matching the already-case-folded host), which previously caused a legitimately differently-cased repository to be misidentified and silently fall through with no merge ever detected; a regression test now covers this.bin/fm-watch.shnow resolves and passes the task's worktree, recorded destination, and tip-cache file path through tofm-pr-poll.sh.bin/fm-teardown.sh: added thepr-poll-git-tipcache file to the cleanup list inremove_pr_poll_artifacts()(single-line change).docs/architecture.md,docs/scripts.md,docs/gitlab-merge-watch.md, andAGENTS.mdfor the new poll signature,pr_dest=operator line, and Bitbucket support; corrected doc/comment references that no longer apply tofm-teardown.shpost-split.tests/fm-pr-check-security.test.shandtests/fm-pr-merge.test.shwith coverage for Bitbucket URL parsing,pr_dest=handling, and the case-fold fix; added aheadRefOid,baseRefNamearm to the fakeghstub intests/fm-teardown.test.shahead of its substring-overlapping generic arm, restoring thepr_headstaleness test's intended coverage.Risk Assessment
✅ Low: The carve faithfully matches the stated scope (all shipped files present, all excluded hunks/functions/tests absent, fm-teardown.sh has exactly the one authorized line), the already-decided CI fix for the gh two-field stub is correctly and minimally applied, the claimed P1 case-folding fix is implemented on both sides of the comparison with a dedicated regression test, and the new Bitbucket/git-based merge detector is exercised by thorough behavioral tests (real git fixtures covering landed, not-landed, conflict, cache HEAD-sensitivity, and multiple origin-identity spoofing attempts) with no source-content-only assertions and no bugs found on trace-through.
Testing
All three test files shipped by this PR pass in full (fm-pr-merge.test.sh 61/61, fm-pr-check-security.test.sh 56/56, and every fm-teardown.test.sh case relevant to this branch), and the one pre-existing failure elsewhere in fm-teardown.test.sh was confirmed present at the base commit too, so it is not a regression from this change; diff scope was independently verified to match the intended carve.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-pr-merge.test.sh (61/61 ok)bash tests/fm-pr-check-security.test.sh (56/56 ok) — covers the Bitbucket URL parse arm, pr_dest arm/carry-over/auto-derive, the git-based primary merge detector and tip-cache, and the case-fold regression test 'an origin path differing only in capitalization is matched, not refused as a different repository' (the reviewer P1 fix)bash tests/fm-teardown.test.sh with two known-unrelated herdr-preflight cases skipped in a scratch copy — all other cases pass, including 'fm-pr-check does not refresh PR head after HEAD moves' and 'fm-pr-check records the remote PR head when the local worktree lags' (the committed follow-up fix for the gh stub)confirmed the herdr-preflight-missing-adapter failure also occurs at base commit 1fd7ea2 via a disposablegit worktree add, establishing it as pre-existing and unrelated to this branchgit diff --stat 1fd7ea2 114a0bd and per-file diffs of bin/fm-teardown.sh and tests/fm-teardown.test.sh to confirm the diff scope matches the user intent exactly✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.