Repository navigation
fix(bin): refuse an unmergeable upstream pull request as a landing path - #4
Conversation
Validation status - READ BEFORE MERGE: this PR is RED and must not be merged as-isCorrecting the record precisely, because a previous instruction assumed the validation pipeline had not been started and that assumption is now out of date. What actually ran. The no-mistakes pipeline DID run (run CI genuinely fired. 13 checks reported, not zero: 10 passed, 3 failed. These are the real repository-owned suites, not a review bot. The 3 failures are caused by this change. I traced each to its exact cause rather than assuming they were flakes, and one is reproduced locally:
The guard itself is behaving as designed in all three. What the change missed is pre-existing callers that arm fake pull requests without stubbing the forge, plus one hardcoded test count. The fix is small and well understood - stub the forge on PATH the way Also outstanding: the PR reports merge conflicts with the base branch, since main moved underneath it. Local suites I ran myself, which passed - naming them precisely so they are not mistaken for the pipeline: Bottom line: needs the CI failures fixed and a re-run before it can be considered. Do not merge on the strength of the pipeline having reached its CI gate. |
Arming a merge poll is this repo declaring a pull request a landing path. bin/fm-pr-check.sh now asks the forge whether the viewer can merge into the repository hosting the pull request and refuses when it cannot, naming the fork the work has to land on instead. Mergeability comes from the forge's own viewer permission, never from a repository name, so a second fork or a rename does not rot the guard. bin/fm-pr-merge.sh inherits the refusal because it records through the same script before calling the forge. Raising or pushing a pull request against a read-only upstream is untouched; only treating one as a landing path is refused. The verdict is persisted as pr_landing= and carried by every path that reports a task's pull request: the fleet snapshot and view, the bearings projection, and inactive terminal-outcome reconciliation. Those paths read the record rather than the forge, keeping their documented zero-network contract, and a URL scraped out of a status log reads as unverified. An unchecked pull request therefore cannot reach the captain worded as a merge decision. An unreachable forge refuses to arm rather than arming anyway. The cost is a loud, retryable stop on a poll that was never armed, against silently re-admitting the exact case this guard exists for; it matches the existing missing-glab refusal in the same script. pr_landing= is written before pr= because fm_pr_metadata_identity_parse rejects any unrecognized key that follows pr=, so that parser is unchanged and a forged trailing pr_landing= line still fails closed. GitLab returns an unchecked verdict and is unaffected: a member access level does not by itself decide merge rights when protected-branch merge access is separately configurable, and glab is not installed here to verify against.
…-watch.md GitHub transcript
tests/fm-teardown.test.sh's default and merged-PR gh-axi fakes did not answer the new "api /repos/" landing-permission query fm-pr-check.sh now makes, so every case that reaches it fell through to unreachable. Both fakes answer true: every PR_CHECK call these tests make is against a repository this machine can merge into. The Stock macOS Bash snapshot job pins an exact ok-count per suite so a silently miscounted test never slips through; the landing-guard reporting test added to fm-fleet-snapshot-view.test.sh raised that count from 15 to 16 and the pinned expectation had not caught up.
67b6cb7 to
0a8f1af
Compare
Intent
Refuse to treat an unmergeable upstream pull request as a landing path.
WHY this exists, because it changes what "correct" means here. On 2026-08-23 firstmate put a pull request hosted on a read-only upstream repository to the captain as a merge decision and recommended he merge it. He cannot merge anything in that repository, has no relationship with its maintainer, and had already said so; the constraint was in this home's durable notes and had been read aloud from the session digest in that same session. Prose did not hold it, which is exactly the case where a mechanically checkable rule must become a guard rather than a line of text.
The distinction: the upstream repository is pull-only; the fork is the only landing target. The same shape applies anywhere the fleet has a read-only upstream, so this must NOT be written as a check on any particular repository names.
Scope requested:
Explicitly NOT to be blocked, and this is deliberate: opening or pushing a pull request against the read-only upstream. The captain's position is that we raise them and hope without expectation, so they stay legitimate. What is blocked is treating one as a landing path, or presenting one to the captain as a merge decision. A reviewer seeing only the diff might read the untouched push/open path as an oversight; it is a requirement.
Decisions and tradeoffs made while doing the work, all deliberate:
UNREACHABLE FORGE - the captain explicitly asked for this judgement to be made rather than guessed at, and stated in the PR body. Chosen: an unreachable forge REFUSES to arm, rather than arming anyway. Both answers are defensible and they are not equally safe. Refusing costs a loud, retryable stop on a poll that was never armed and nothing is lost. Arming anyway silently re-admits the exact case this guard exists for, and the failure it produces is the captain being asked to merge something he cannot, which is the incident that caused this work. It also matches the existing missing-glab refusal already in the same script. This is a considered choice, not the easier code path, and it is covered by its own test.
GITHUB uses the REST repository object's .permissions.push, because merging a pull request on GitHub requires push access. Only the exact booleans true/false are trusted; any other reply (an error page, an empty body, a null from a response carrying no permissions object) is treated as an answer we did NOT get, so it becomes unreachable rather than being read permissively.
GITLAB deliberately returns "unchecked" and callers leave that path exactly as it was. A member's numeric access level does not by itself decide merge rights, because a project's merge access is separately configurable per protected branch. Guessing a threshold would ship an unverified rule. glab is not installed here, so this could not be verified against a real forge. This asymmetry is a coverage fact, not a policy inconsistency.
The verdict is persisted once as pr_landing= in the task's durable record, and every reporting path (fleet snapshot, fleet view, bearings projection, inactive terminal-outcome reconciliation) READS THAT RECORD rather than calling the forge. This deliberately preserves those paths' documented zero-network contract. A pull request URL scraped out of a status log has no verdict and therefore reads as unverified, so an unchecked pull request cannot reach the captain worded as a merge decision.
pr_landing= is written BEFORE pr= in the metadata, because fm_pr_metadata_identity_parse rejects any unrecognized key that follows pr=. This ordering leaves that parser unchanged and means a forged trailing pr_landing= line still fails closed. This looks arbitrary in the diff and is not.
bin/fm-pr-merge.sh inherits the refusal for free because it records through fm-pr-check.sh before calling the forge; no separate check was added there on purpose, to keep one owner for the question.
The logic lives in one new sourced library, bin/fm-pr-landing-lib.sh, so no caller re-derives the question. Tests prove both directions (upstream refused, fork unaffected) and the unreachable-forge behaviour, and fail without the change.
This is firstmate's own shared tracked material, so the firstmate-coding-guidelines skill applies: one sentence per line in prose, plain dash never an em dash, shellcheck-clean bin scripts, colocated tests, no agent co-author.
What Changed
bin/fm-pr-landing-lib.sh, the single source of truth for whether the forge lets this machine merge into the repository hosting a given pull request: it queries GitHub's REST.permissions.push(trusting only literaltrue/false, anything else becomesunreachable), returnsuncheckedfor GitLab (no verified viewer-permission source), and exposes a fork hint plus refusal message derived from the worktree's own origin rather than any hardcoded repository name.bin/fm-pr-check.shcalls this library before arming a merge poll and refuses (naming the fork as the landing target) when the forge reportsunmergeable, or when the forge is unreachable; it persists the verdict aspr_landing=in task metadata, written beforepr=so the existing metadata parser is unaffected.bin/fm-pr-merge.shinherits the same refusal because it records throughfm-pr-check.shfirst. Opening or pushing a PR against a read-only upstream remains unaffected - only arming it as a landing path is refused.bin/fm-fleet-snapshot.sh,bin/fm-fleet-view.sh,bin/fm-bearings-snapshot.sh, andbin/fm-inactive-reconcile.shnow read and propagate the recordedpr_landingverdict (confirmed,unchecked, orunverifiedwhen absent or scraped from a status log) alongside every reported PR URL, so none of these zero-network reporting paths can present an unverified pull request as awaiting a merge decision.docs/verification/pr-landing-target.mdwith forge evidence for the new guard, updateAGENTS.md,docs/architecture.md,docs/scripts.md,docs/gitlab-merge-watch.md, anddocs/documentation-audiences.jsonaccordingly, and add/extend tests covering the refusal, the unreachable-forge behavior, and the reporting paths (tests/fm-pr-check-security.test.sh,tests/fm-pr-merge.test.sh,tests/fm-fleet-snapshot-view.test.sh,tests/fm-inactive-reconcile.test.sh).Risk Assessment
✅ Low: The core guard (fm_pr_landing_resolve/fm_pr_landing_github) is well-scoped, refuses on every non-mergeable/unreachable outcome before any side effect, is verified against the live GitHub API in docs/verification/pr-landing-target.md, is applied at the single choke point (fm-pr-check.sh) that fm-pr-merge.sh already routes through, and all four reporting paths (fleet-snapshot, fleet-view, bearings-snapshot, inactive-reconcile) read the persisted pr_landing= verdict rather than re-deriving it; the metadata-ordering trick is independently confirmed against fm_pr_metadata_identity_parse's actual parsing logic. Tests are behavioral (exercise real script entrypoints and assert observable stdout/stderr/metadata state), cover both directions of the guard, unreachable-forge variants, and the GitLab unchecked passthrough. The one identified issue is a cosmetic text-only edge case with no security or correctness impact on the arming decision itself.
Testing
Ran the new and changed test coverage for the landing-target guard directly: the isolated new test_landing_target_guard case and the full fm-pr-merge, fm-fleet-snapshot-view, and fm-inactive-reconcile suites all pass, and a manual live gh-axi call against the real GitHub API reproduces the exact push-permission contract the guard depends on, false for the read-only upstream and true for the fork, matching the author's own recorded verification in docs/verification/pr-landing-target.md. The full fm-pr-check-security.test.sh file (3550 lines, includes many slow timing-sensitive concurrency and watcher cases predating this change) did not finish in the time available but showed zero failures in the portion it completed; the specific new test it contains was already verified in isolation with a full pass, so this is a scope and runtime limitation rather than a signal of a defect.
Evidence: Isolated test_landing_target_guard run
Evidence: Live gh-axi permission check reproducing the guard's contract
Evidence: fm-pr-merge.test.sh full run, 25 of 25 pass
Evidence: fm-fleet-snapshot-view.test.sh full run, 16 of 16 pass
Evidence: fm-inactive-reconcile.test.sh full run, 15 of 15 pass
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-pr-landing-lib.sh:139- fm_pr_landing_fork_hint matches the origin URL against the glob github.com[:/] to detect a GitHub remote. This matches as a substring anywhere in the URL, not just as the host, so a remote like https://notgithub.com/x/y (or any host that merely contains the literal substring "github.com") is misparsed into a slug and could produce a nonsensical fork-hint suggestion in the refusal message.✅ **Test** - passed
✅ No issues found.
bash tests/fm-pr-check-security.test.sh test_landing_target_guard (isolated run) - all 6 sub-cases pass: refused and names fork, confirmed and armed, verdict persisted before pr= and fails closed on forgery, unreachable forge (call failure, timeout, garbage reply, absent CLI) all refuse, no-origin refusal still names the fork placeholder, GitLab stays unchecked and armed and never calls the GitHub permission endpointbash tests/fm-pr-merge.test.sh full file, 25 tests, all pass, including new test_unmergeable_repository_refuses_before_mergebash tests/fm-fleet-snapshot-view.test.sh full file, 16 tests, all pass, including new test_pr_landing_verdict_is_reported (confirmed PR renders bare, unverified or scraped PRs render with the landing-unverified marker)bash tests/fm-inactive-reconcile.test.sh full file, 15 tests, all pass, including new test_reported_pr_carries_its_landing_verdict (verdict travels with the recorded pr=, never inherited by a scraped URL, survives the secondmate parent-report hop)Manual live-forge check: gh-axi api /repos/kunchenguid/firstmate --jq .permissions.push returns false; gh-axi api /repos/x45dev/firstmate --jq .permissions.push returns true - reproduces the exact contract the guard and docs/verification/pr-landing-target.md rely onbash tests/fm-pr-check-security.test.sh full 3550-line file, started in background, progressed cleanly through the tests it reached with zero failures before the phase deadline but did not finish within the available window due to the file's size and timing-heavy concurrency cases unrelated to this change✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.