Skip to content

Latest commit

 

History

History
117 lines (96 loc) · 6.9 KB

preflight.md

File metadata and controls

117 lines (96 loc) · 6.9 KB

preflight.sh — guide

Revision: 1 Last modified: 2026-12-04T00:00:00Z

Library: scripts/pr/lib/preflight.sh (sourced by scripts/pr/lib/steps.sh; never executed on its own). Engine guide: docs/scripts/pr_deliver.md. Manual: docs/manuals/pr_delivery_engine_manual.md.

Overview

This is the check the operator's absolute constraint depends on: the flow may be used only if a pull request can genuinely be created, reviewed AND merged — a hanging pull request is worse than no pull request at all. Preflight runs BEFORE anything is created, reads only, and answers READY only when every check passes. Each failing check maps to one CLOSED refusal code, so a refusal is machine-actionable rather than an anecdote.

It is also the S0 step of preflight, and create runs it itself and refuses to continue without READY. There is no flag that skips it.

Prerequisites

  • A validated declaration (lib/config.sh has run) — preflight re-asserts mode, it does not re-parse.
  • A git working tree; git; the provider's tooling (gh, or curl + jq for the REST providers).
  • A credential the provider accepts for this repository, with push rights. Preflight tries every candidate variable and the CLI keyring, and records WHICH one answered — never a value.

Usage examples

$ bash scripts/pr/pr_deliver.sh preflight --task CON-641
CHECK P1 declaration PASS mode=pr
CHECK P2 decision PASS OPD-… 2026-11-16
CHECK P3 provider PASS github github.com
CHECK P4 tooling PASS gh
CHECK P5 credential PASS identity=… via=keyring-oauth
CHECK P6 base PASS main@4f2c1a9…
CHECK P7 merge_method PASS merge-commit
CHECK P8 protection PASS no required approvals (the recorded review comment is the gate, see the docs)
CHECK P9 drift PASS no pull request for task/CON-641-… yet
CHECK P10 tree PASS branch=main dirty=0
CHECK P11 mergeability SKIP no_pull_request_yet
CHECK P12 enforcement NOTE direct_push_guard=off: nothing mechanically stops a direct push to main
RESULT: READY

From a shell function or a gate:

out="$(bash scripts/pr/pr_deliver.sh preflight --task "$T" 2>&1)"; rc=$?
case "$rc" in
  0) : ;;                                    # READY
  3) printf '%s\n' "$out" | sed -n 's/^REASON: //p' ;;   # a closed refusal code
  5) echo "instrument could not answer — never a pass" ;;
esac

The checks

Check What it proves Blocking refusals
P1 declaration mode=pr (a mode=direct project gets SKIP mode_direct and READY) —
P2 decision a recorded decision id and date, not a placeholder no_recorded_decision, config_invalid_value:decision_date
P3 provider pr_remote resolves to exactly ONE host with a row in config/forge/hosts.tsv provider_ambiguous, unknown_forge, provider_unimplemented
P4 tooling gh (github) or curl+jq (gitlab/gitea) is installed and answers pr_tool_absent, pr_tool_broken
P5 credential some credential is ACCEPTED for this repository with push/admin credentials_refused, credentials_absent, credentials_no_merge_right
P6 base branch refs/heads/<base> exists on pr_remote base_absent, unreachable_upstream (exit 5)
P7 merge method the platform offers the declared landing form merge_method_not_allowed
P8 protection the effective rules cannot demand what the flow cannot obtain approvals_unobtainable, status_checks_unrunnable
P9 drift no second open pull request for the task, no merged-but-still-present branch duplicate_pr, stale_branch
P10 tree a real repository, not detached, no merge/rebase/cherry-pick in progress tree_not_quiescent, tree_detached
P11 mergeability the platform's mergeability machinery answers (only when a pull request exists) mergeability_unavailable
P12 enforcement honesty direct_push_guard is recorded, and the engine does not claim to have installed it never blocks (a NOTE)

Edge cases

  • Verdicts other than PASS are not failures. NOTE is informational. SKIP <reason> means the check does not apply yet — P9 and P11 skip without a task id, P11 also skips when no pull request exists. A SKIP is never a pass and is never counted as one.
  • CANNOT-DETERMINE blocks (exit 5): if git ls-remote cannot answer, the engine says so instead of assuming the base branch is there. Offline is a stated state, not a pass.
  • ff-only is refused by design. No measured provider offers it, and a squash or rebase would lose the reviewed head — the landing form the whole review chain depends on.
  • P8 separates two rule kinds. A pull_request rule carries the required approval count; a required_status_checks rule carries the contexts. Reading only the first kind reported "no required approvals" on a branch that required checks and would have opened a pull request into a check that can never run. required_checks_assume_run=on is the operator's recorded assumption that the checks do run.
  • P5 is a probe, not a guess. The measured hazard: the ambient GITHUB_TOKEN is a fine-grained PAT the owning organisation answers 403 to, while the keyring credential of the same account works. A probe that stopped at the first candidate would declare a perfectly able host impossible.
  • The rules read prefers /rules/branches/<base> and falls back to the classic protection endpoint, because the classic endpoint answers 404 "Branch not protected" for a branch protected by a ruleset — a false pass preflight must not inherit.

Internal behaviour

  • pr_pf ID NAME VERDICT DETAIL prints one CHECK … line and accumulates it in PR_PF_LINES.
  • pr_pf_fail ID CODE [DETAIL] records the check id in PR_PF_FAILED and sets the closed reason through pr_reason, so the reason the caller prints is the one the failing check chose.
  • pr_preflight_run [--for create|merge] returns 0 READY, 3 REFUSED or 5 CANNOT-DETERMINE, and sets PR_PF_VERDICT / PR_PF_FAILED for the caller. merge adds one extra P10 rule: the working tree must be clean.
  • pr_cmd_preflight prints RESULT: READY on success and RESULT: REFUSED + REASON: otherwise.
  • merge runs preflight for information only (> /dev/null || true): the seven explicit merge conditions in lib/steps.sh decide, so a stale P11 cannot block a legitimate resume.

Related scripts

  • provider.md — P3/P4/P5 delegate to pr_provider_resolve, pr_cred_probe and prv_*.
  • steps.md — create gates on this file; merge runs it informationally.
  • config.md — the declaration P1/P2 read.
  • pr_deliver.md — the full refusal-code inventory.

Last verified

2026-12-04 — read against scripts/pr/lib/preflight.sh (353 lines). The check table above is derived from the code's own branches; the twenty-five preflight assertions in tests/pr/test_pr_preflight.sh (including PF10/PF17 golden-FALSE cases) are the executable form of it.