Repository navigation
fix(bin): require per-PR captain approval before merging - #65
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughChangesThe merge command now supports Captain-approved merge flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: 🟡 Moderate · up to The merge guard can select approval policy from task metadata while targeting a repository supplied separately in the pull request URL; if those identities do not match, a protected pull request could be merged without the required captain approval. Duplicate project entries could also select a less restrictive policy. This should be fixed or explicitly accepted before merging. Sequence Diagram(s)sequenceDiagram
participant fm-pr-merge.sh
participant fm-project-mode.sh
participant fm-pr-check.sh
participant gh-axi
fm-pr-merge.sh->>fm-project-mode.sh: Query registered captain-merge policy
fm-project-mode.sh-->>fm-pr-merge.sh: Return registry line or policy status
fm-pr-merge.sh->>fm-pr-merge.sh: Validate captain approval URL
fm-pr-merge.sh->>fm-pr-check.sh: Record PR metadata
fm-pr-merge.sh->>gh-axi: Invoke pr merge
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
Refs #1 Refs #42 Refs #60 Refs #65 Refs #73 Refs #74 Refs #107 Refs #109 Refs #117 ## What I walked In a throwaway `.scratch-c4-walk/home` and local Git repository: ``` $ FM_HOME=.scratch-c4-walk/home bin/fm-merge-local.sh walk-clean merged fm/walk-clean into local main (aa84759 -> 1b9c678) in /Users/evanagee/.treehouse/firstmate-df5ff1/9/firstmate/.scratch-c4-walk/project $ git -C .scratch-c4-walk/project log -1 --format=%s main clean local landing ``` ``` $ FM_HOME=.scratch-c4-walk/home FM_GH_BIN=.scratch-c4-walk/fake-gh bin/fm-flow.sh walk status matched rulesets: main-protection=1 (rules: pull_request,required_status_checks) review=2 (rules: pull_request) registry posture: [no-mistakes-prod-only +yolo] main-protection ruleset 1 enforcement: active main-protection ruleset gates: pull_request + required_status_checks present review ruleset 2 enforcement: active stored previous posture: <none> verdict: full ``` ``` $ FM_HOME=.scratch-c4-walk/home bin/fm-merge-local.sh walk-outage fm/walk-outage error: task walk-outage is mode=no-mistakes; a PR-bound task lands locally only while GitHub is unreachable (state/.github-down present) merge its PR with bin/fm-pr-merge.sh after approval exit=1 ``` The flow status used a local fake that returned read-only ruleset data. No GitHub request, PR, or push was made. ## Port record The root already had guarded `fm-pr-merge.sh` and `fm-merge-local.sh`, canonical v2 PR poll registration and repair, GitLab merge verification, task control locks, leases, captain holds, and persisted merge authority. During the final rebase, the root also gained the outage landing skill unchanged. I kept those root implementations. The port adds auto-arm, reviewer chase, review-thread gating, issue claims and post-merge closing, GitHub outage landing and return sync, and the project flow switch around them. I dropped the fork's obsolete `captain-merge` token, `fm-pr-check-migrate.sh`, and C3 delivery timing, backfill, and token ledger changes. The root's captain-hold authority and repairable poll publication cover those seams.
Intent
Make bin/fm-pr-merge.sh refuse to merge a pull request for a project whose registered delivery posture includes captain-merge unless the caller supplies explicit approval for that exact pull request.
Resolve the project from project= in state/.meta, map the recorded project path to its registry name, and read data/projects.md only through bin/fm-project-mode.sh. Extend that parser instead of adding a second parser. Registry bracket lists are free-form. Match the captain-merge token exactly, including when a parenthetical follows it.
Refuse before any review-thread query or merge call. The stderr refusal must name the project, full matching registry line, and canonical pull request URL.
Add --captain-approved . It bypasses only the captain-merge refusal when its value exactly matches the canonical URL produced by bin/fm-pr-lib.sh. Any mismatch refuses. Log a successful bypass on stderr. Never infer approval from an environment variable, config file, or default.
A missing registry or a project absent from the registry must not trigger this guard. A registered project without the exact token must merge normally.
Update the script header and --help. Add one line in AGENTS.md section 7 stating that captain-merge requires --captain-approved and firstmate may pass it only under a current explicit captain instruction naming that pull request.
Extend tests/fm-pr-merge.test.sh through the executable. Cover no-flag refusal, mismatched approval refusal, matching approval with stderr log, a project without the token, and a project absent from the registry. Do not assert on source bytes.
bin/fm-lint.sh and bin/fm-doc-audience-check.sh must pass.
The pull request body must include this real scratch-registry proof from 2026-08-29:
command_exit=1
error: captain approval required; refusing to merge captain-merge project "pto"
error: registry: - pto [no-mistakes, factory-enabled, captain-merge (HARD: firstmate never merges without per-PR approval), evidence-required] - scratch registry proof
error: PR: https://github.com/EvanAgee/faapto/pull/163
error: pass --captain-approved https://github.com/EvanAgee/faapto/pull/163 only after a current explicit captain instruction naming this PR
What Changed
Require an exact
--captain-approved <pr-url>match before merging a registeredcaptain-mergeproject. The guard runs before review-thread queries and logs either the refusal details or a successful bypass.Scratch-registry proof from 2026-08-29:
Extend
fm-project-mode.shto find the exactcaptain-mergetoken in free-form registry annotations and return the full matching registry line. Missing registries and unregistered projects remain unguarded.Add executable coverage for approval refusal and bypass paths, registry parsing, project identity validation, and unguarded projects. Update the operator contract and script documentation with the new approval requirement.
Risk Assessment
✅ Low: The merge guard is well-bounded, preserves the required refusal ordering, and closes the previously identified bypass paths.
Testing
Inspected the target change, verified help output, ran the focused executable-level merge tests, and reproduced the requested scratch-registry refusal through the real CLI. All checks passed. This is a CLI-only change, so visual evidence was not applicable; the reviewer-visible command transcript is attached.
Evidence: Captain merge refusal transcript
Source: Captain merge refusal transcript
command_exit=1 error: captain approval required; refusing to merge captain-merge project "pto" error: registry: - pto [no-mistakes, factory-enabled, captain-merge (HARD: firstmate never merges without per-PR approval), evidence-required] - scratch registry proof error: PR: https://github.com/EvanAgee/faapto/pull/163 error: pass --captain-approved https://github.com/EvanAgee/faapto/pull/163 only after a current explicit captain instruction naming this PR stdout_bytes=0Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 4 issues found → auto-fixed (2) ✅
bin/fm-project-mode.sh:72- The intent says registry bracket lists are free-form and captain-merge must match exactly. This regex requires whitespace before the token and whitespace or(after it, so[no-mistakes,captain-merge,evidence-required]is missed and the merge proceeds without approval. Accept punctuation-delimited tokens while still rejectingcaptain-merge-later, and cover the comma-adjacent form through the executable.bin/fm-pr-merge.sh:105- The intent requires a refusal to name the project, full matching registry line, and canonical PR URL. A mismatched--captain-approvedvalue exits here before project lookup and prints only the canonical URL. For a protected project, defer this refusal until registry resolution so it emits the required details, while retaining a generic mismatch refusal for unguarded projects.bin/fm-pr-merge.sh:194- Every nonzero parser result is treated as no matching policy. If an existing registry is unreadable orawkfails, the script clears the result and continues to the review query and merge. Preserve the parser status, ignore only the documented missing-registry, absent-project, and absent-token result, and refuse on operational errors.bin/fm-project-mode.sh:69- The intent guards only a registered delivery posture containing the token, but this path scans the first bracket pair anywhere on the project line. A valid legacy entry such as- app - note [captain-merge]is falsely guarded even though its posture has no token. Require the posture annotation at the registry format's third field before scanning its brackets.🔧 Fix: Fix captain merge guard parsing and diagnostics
3 issues (2 errors, 1 warning) still open:
bin/fm-pr-merge.sh:184- The required behavior says, “Resolve the project from project= in state/<task-id>.meta.” This read hides failures and treats a missing, empty, or ambiguous project value as unprotected. A partial metadata write can therefore skip policy lookup and reach the review query and merge without approval. Require exactly one readable, nonempty project value before continuing.bin/fm-pr-merge.sh:94- The requirement says, “Any mismatch refuses.” Each repeated --captain-approved flag overwrites the previous value, so a wrong URL followed by the canonical URL permits the merge. Refuse duplicate approval flags or validate every supplied value.bin/fm-project-mode.sh:35- The new --captain-merge mode returns a full registry line, but the header still promises only two output words and its consumer list omits fm-pr-merge.sh. Update both statements to satisfy CONTRIBUTING.md’s accurate-header rule.🔧 Fix: Fix captain approval and project identity validation
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-pr-merge.test.sh./bin/fm-pr-merge.sh --helpRanbin/fm-pr-merge.sh task-proof https://github.com/EvanAgee/faapto/pull/163against the required scratch registry and confirmed exit 1, the complete refusal message, canonical URL, and zero stdout.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation