Skip to content

feat(bin): support pull requests on any GitHub host - #6868

Open
mielientiev wants to merge 7 commits into
kunchenguid:mainfrom
mielientiev:fm/github-host-support
Open

mielientiev wants to merge 7 commits into
kunchenguid:mainfrom
mielientiev:fm/github-host-support

Conversation

@mielientiev

@mielientiev mielientiev commented Oct 8, 2026 •

Copy link
Copy Markdown

Intent

Make firstmate's PR tooling work for pull requests on any GitHub host, not only github.com. The tooling accepted only https://github.com/<owner>/<repo>/pull/<n> URLs, so merge polling, merge, cleanup and backlog closing failed for pull requests on a self-hosted GitHub Enterprise Server host such as ghe.example.com.

Requirements and decisions: the URL parser accepts https://<host>/<owner>/<repo>/pull/<n> for any valid lowercase DNS host and keeps the host in the recorded identity, so the same owner/repo/number on two hosts never shares a record; github.com stays valid and GitLab and Gerrit URL shapes on github.com stay refused. Every gh and gh-axi call that addresses a pull request or repository by owner/repo is made against the pull request's own host by setting GH_HOST for that one command; github.com is left untouched so its behavior is unchanged. The default host is github.com and is overridable with one environment variable, FM_GITHUB_HOST (documented in docs/configuration.md); GH_HOST is honored only as gh's own selection and FM_GITHUB_HOST wins. The backlog tool only links github.com or Forgejo pull request URLs, so a pull request on another host is recorded on the closed backlog item as a note carrying its URL, the same way Gerrit changes already are. Out of scope: GitLab and Gerrit behavior, any other refactor. Tests use only neutral example hosts (ghe.example.com, git.example.org). A second commit makes fm-test-run's coverage guard compare sorted lists with the C collation; it failed under a UTF-8 locale independent of this change. Look-alike hosts such as github.com.example.org are now valid distinct hosts, so the security test that listed them as invalid was updated deliberately.

Standard to hold the change to: .agents/skills/firstmate-coding-guidelines/SKILL.md. Check the diff against it: one owner per contract with cross-references instead of restatements, knowledge placed at the right tier (script header comments own mechanics, docs/configuration.md owns the setting), one sentence per line in tracked Markdown, plain dash, shellcheck-clean bin scripts, tests colocated in tests/ that exercise behavior through executables and never assert source bytes, and no unrelated refactors or hardening beyond the stated scope. This is a re-validation of an already open pull request; keep the existing branch history and the existing pull request.

What Changed

  • Pull request URLs are parsed as https://<host>/<owner>/<repo>/pull/<n> for any valid lowercase DNS host, the host stays part of the recorded identity, github.com behavior is unchanged, and GitLab and Gerrit URL shapes on github.com stay refused.
  • Every gh and gh-axi call that addresses a pull request or repository now runs against that pull request's own host through new fm_gh_at and fm_github_default_host helpers; FM_GITHUB_HOST overrides the github.com default for a pull request known only by number, documented in docs/configuration.md.
  • Backlog close and retention record a pull request on another GitHub host as a PR <url> note like an existing Gerrit change; tests/fm-github-host.test.sh plus host cases in the PR, teardown, and security suites cover the behavior, and bin/fm-test-run.sh compares coverage-guard lists with the C collation.

Risk Assessment

⚠️ Medium: The change is well-bounded and heavily tested with all earlier review decisions applied, but the intent's universal 'every gh and gh-axi call' wording leaves two sibling consumers host-blind, and that scope decision should be settled before merge.

Testing

Ran the targeted behavior suites for the changed PR tooling with bash: tests/fm-github-host.test.sh, tests/fm-pr-state.test.sh, tests/fm-pr-reviewers.test.sh, tests/fm-pr-merge.test.sh, tests/fm-teardown.test.sh, and tests/fm-pr-check-security.test.sh; all exited 0 and the new host-aware cases passed. Independently drove the real product end to end in a throwaway home with a disposable forge stub: armed a PR on ghe.example.com, ran the armed poll, fm-pr-state, fm-pr-reviewers, and fm-pr-merge (verified merged), and repeated the same for github.com; every gh call carried GH_HOST=ghe.example.com for the other host and no GH_HOST for github.com, and doctored or malformed poll sidecars produced no output and no gh call. Teardown's recorded-URL, FM_GITHUB_HOST bare-number/branch, Gerrit-host, and backlog-note behaviors were driven by the teardown suite against the real script. The fm-test-run coverage-guard locale fix was exercised live with bash bin/fm-test-run.sh --check-coverage under en_US.UTF-8, reporting FM_TEST_COVERAGE ok. This is CLI tooling with no GUI surface, so evidence is CLI transcripts, recorded state, per-call GH_HOST logs, and test output rather than screenshots. The only substitute is the external forge CLI (no self-hosted GitHub instance is reachable from this machine); the product scripts themselves are real.

  • Live validation: ✅ go - 14 of 14 scenarios driven live against the product
Scenario Result Live Evidence
Arming a pull request on ghe.example.com records pr= with that host and reads the draft state and head through gh with GH_HOST set to that host ✅ pass live live-host-scenario.txt S1: armed: state/task-ghe.check.sh, pr=https://ghe.example.com/o/r/pull/7, sidecar host ghe.example.com, and both gh calls logged HOST=ghe.example.com
Re-arming a task after a pending retirement receipt for a pull request on another host reads the new pull request at its own host ✅ pass live targeted-test-fm-pr-check-security.log: ok - re-arming after a retirement receipt for another host reads the new pull request at its own host
The armed merge poll reports merged for a pull request on ghe.example.com and issues its gh read with GH_HOST=ghe.example.com ✅ pass live live-host-scenario.txt S2: poll stdout merged, gh log HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/7 --json state -q .state
A doctored poll sidecar whose host differs from its URL, a leading-hyphen host label, or an over-long label never reaches gh and never reports merged ✅ pass live live-host-scenario.txt S6/S7: doctored host, leading-hyphen label, and 64-character label each produced empty stdout and zero gh calls; targeted-test-fm-github-host.log covers the same at the poll ent…
fm-pr-state reports on a pull request on ghe.example.com with every gh call addressed at that host ✅ pass live live-host-scenario.txt S3: rc=0, both pr view and pr checks logged HOST=ghe.example.com; targeted-test-fm-pr-state.log `ok - a pull request on another GitHub host is read at that host and github…
fm-pr-reviewers resolves reviewer candidates for a pull request on ghe.example.com with every gh call addressed at that host ✅ pass live live-host-scenario.txt S4: output alice 1 recent commit, all three gh calls logged HOST=ghe.example.com; targeted-test-fm-pr-reviewers.log `ok - a pull request on another GitHub host is read at th…
fm-pr-merge merges a pull request on ghe.example.com: every merge-path gh call carries GH_HOST=ghe.example.com and pr= keeps the host ✅ pass live live-host-scenario.txt S8: verified: ... is merged, meta pr=https://ghe.example.com/o/r/pull/9, and all six calls (head read, mergeable read, branch rules, commit rules, pr merge, outcome graphq…
Pull requests on github.com behave as before: no GH_HOST is set for any gh call across arm, poll, state, reviewers, and merge ✅ pass live live-host-scenario.txt S5 and S9: every logged call for https://github.com/o/r/pull/8 and pull/10 has HOST=unset, including pr merge 10 --repo o/r --match-head-commit ... --squash; the state, revi…
Teardown reads a recorded pull request at its own host, and a Gerrit change's host is never selected for gh ✅ pass live targeted-test-fm-teardown.log: ok - teardown reads a recorded pull request at its own host and ok - teardown never selects a non-GitHub forge&#39;s host for gh
With no recorded URL, teardown's bare-number and branch lookups reach gh at FM_GITHUB_HOST (or github.com when unset), and an unusual ambient GH_HOST (uppercase, port) no longer breaks them ✅ pass live targeted-test-fm-teardown.log: ok - teardown&#39;s branch and bare-number lookups reach gh at FM_GITHUB_HOST, and github.com otherwise and `ok - an exported GH_HOST never breaks the teardown lookups, an…
Closing a backlog item for landed work whose pull request lives on another GitHub host records the URL as a note and the item reaches done ✅ pass live targeted-test-fm-teardown.log: ok - teardown closes a landed task on another GitHub host with its pull request URL as a note (row state done, body PR https://ghe.example.com/example/repo/pull/7)
An invalid FM_GITHUB_HOST is refused instead of being passed to gh ✅ pass live targeted-test-fm-github-host.log: ok - the default host is github.com and overridable with FM_GITHUB_HOST (invalid bad host/x refused)
URL parsing accepts any valid lowercase DNS host and keeps it in the identity, github.com stays unchanged, look-alike hosts are distinct hosts, and GitLab/Gerrit shapes on github.com stay refused ✅ pass live targeted-test-fm-github-host.log parser cases; targeted-test-fm-pr-check-security.log ok - raw-byte parser accepts canonical URLs and rejects the complete adversarial matrix (look-alike hosts now di…
The fm-test-run coverage guard runs clean under a UTF-8 locale (the C-collation fix) ✅ pass live coverage-guard-utf8-locale.txt: FM_TEST_COVERAGE ok total=251 ... with rc=0 under en_US.UTF-8
Evidence: Independent live drive transcript (arm, poll, state, reviewers, merge, adversarial sidecar cases)

Source: Independent live drive transcript (arm, poll, state, reviewers, merge, adversarial sidecar cases)

=================== S1: arm a PR on a self-hosted host ===================
armed: state/task-ghe.check.sh
--- recorded pr= and pr_head= ---
pr=https://ghe.example.com/o/r/pull/7
pr_head=9a7bdc484a820d73b5ef09d88b5840b691f434cf
--- armed poll sidecar (provider,url,host,path,number) ---
github
https://ghe.example.com/o/r/pull/7
ghe.example.com
o/r
7
--- gh calls during arm ---
HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/7 --json isDraft
HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/7 --json headRefOid -q .headRefOid
=================== S2: armed poll watches the self-hosted host ===================
poll stdout: merged
gh calls during poll:
HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/7 --json state -q .state
=================== S3: fm-pr-state reads the PR at its host ===================
fm-pr-state rc=0 (no blockers printed)
gh calls during state read:
HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/7 --json state,mergedAt,isDraft,headRefOid,author,mergeable,reviewDecision --jq 
  "state=\(.state | ascii_downcase)",
  "merged_at=\(.mergedAt // "")",
  "draft=\(.isDraft)",
  "head=\(.headRefOid)",
  "author=\(.author.login)",
  "mergeability=\(if .mergeable == null or .mergeable == "UNKNOWN" then "unknown" else (.mergeable | ascii_downcase) end)",
  "review_decision=\(.reviewDecision // "")"
HOST=ghe.example.com ARGS=pr checks https://ghe.example.com/o/r/pull/7 --required --json name,state,bucket --jq 
  .[]
  | select(.bucket != "pass" and .bucket != "skipping")
  | "REQUIRED CHECK: \(.name) (\(.state))"
=================== S4: fm-pr-reviewers reads the PR at its host ===================
alice	1 recent commit
gh calls during reviewer lookup:
HOST=ghe.example.com ARGS=api /repos/o/r/pulls/7 --jq "author=\(.user.login)", "base=\(.base.sha)"
HOST=ghe.example.com ARGS=api /repos/o/r/pulls/7/files?per_page=100 --paginate --jq .[].filename
HOST=ghe.example.com ARGS=api --method GET /repos/o/r/commits -f sha=9a7bdc484a820d73b5ef09d88b5840b691f434cf -f path=src/a.sh -F per_page=100 --jq .[] | select(.author.type != "Bot") | [.sha, (.author.login // "")] | @tsv
=================== S5: github.com control is untouched ===================
poll stdout: merged
gh calls across arm+poll+state for github.com (every HOST must be unset):
HOST=unset ARGS=pr view https://github.com/o/r/pull/8 --json isDraft
HOST=unset ARGS=pr view https://github.com/o/r/pull/8 --json headRefOid -q .headRefOid
HOST=unset ARGS=pr view https://github.com/o/r/pull/8 --json state -q .state
HOST=unset ARGS=pr view https://github.com/o/r/pull/8 --json state,mergedAt,isDraft,headRefOid,author,mergeable,reviewDecision --jq 
  "state=\(.state | ascii_downcase)",
  "merged_at=\(.mergedAt // "")",
  "draft=\(.isDraft)",
  "head=\(.headRefOid)",
  "author=\(.author.login)",
  "mergeability=\(if .mergeable == null or .mergeable == "UNKNOWN" then "unknown" else (.mergeable | ascii_downcase) end)",
  "review_decision=\(.reviewDecision // "")"
HOST=unset ARGS=pr checks https://github.com/o/r/pull/8 --required --json name,state,bucket --jq 
  .[]
  | select(.bucket != "pass" and .bucket != "skipping")
  | "REQUIRED CHECK: \(.name) (\(.state))"
=================== S6: adversarial - a doctored sidecar host is never polled ===================
doctored sidecar (host differs from URL):
github
https://ghe.example.com/o/r/pull/7
git.example.org
o/r
7
poll stdout: []
gh calls during doctored poll (must be none):
gh log line count: 0
=================== S7: adversarial - malformed host labels are never polled ===================
leading-hyphen: stdout=[] gh-log-lines=0
64-char label: stdout=[] gh-log-lines=0
=================== S8: fm-pr-merge merges a PR on the self-hosted host ===================
armed: state/task-merge.check.sh
verified: https://ghe.example.com/o/r/pull/9 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 9a7bdc484a820d73b5ef09d88b5840b691f434cf
verified: https://ghe.example.com/o/r/pull/9 is merged (state=MERGED, merged=true, isInMergeQueue=false)
fm-pr-merge rc=0
recorded identity in meta:
pr=https://ghe.example.com/o/r/pull/9
pr_head=9a7bdc484a820d73b5ef09d88b5840b691f434cf
gh calls during merge:
HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/9 --json headRefOid -q .headRefOid
HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/9 --json state,isDraft,mergeable,mergeStateStatus,headRefOid,baseRefName,statusCheckRollup
HOST=ghe.example.com ARGS=api repos/o/r/branches/main
HOST=ghe.example.com ARGS=api --paginate repos/o/r/rules/branches/main
HOST=ghe.example.com ARGS=pr merge 9 --repo o/r --match-head-commit 9a7bdc484a820d73b5ef09d88b5840b691f434cf --squash
HOST=ghe.example.com ARGS=api graphql -f query=query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){state merged isInMergeQueue baseRefName}}} -F owner=o -F repo=r -F number=9 --jq .data.repository.pullRequest | "state=" + (.state // ""), "merged=" + (.merged | tostring), "queued=" + (.isInMergeQueue | tostring), "base=" + (.baseRefName // "")
distinct hosts seen by every gh call: ghe.example.com 
=================== S9: fm-pr-merge leaves github.com untouched ===================
verified: https://github.com/o/r/pull/10 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 9a7bdc484a820d73b5ef09d88b5840b691f434cf
fm-pr-merge rc=0
distinct hosts seen by every gh call: unset 
merge line: HOST=unset ARGS=pr merge 10 --repo o/r --match-head-commit 9a7bdc484a820d73b5ef09d88b5840b691f434cf --squash
Evidence: Fixture script that built the disposable home, worktree, and logging gh stub

Source: Fixture script that built the disposable home, worktree, and logging gh stub

#!/usr/bin/env bash
# Independent live drive of firstmate's PR tooling against a disposable
# self-hosted GitHub host fixture. The real product scripts run; only the
# external forge CLI (gh) is a stub that records the host each command saw.
set -u
REPO=${REPO:-/home/coder/.no-mistakes/worktrees/a51cecb24137/01M4E01THEKA92YHWE931E4XJ0}
DIR=${DIR:-/tmp/fm-live-host-scenario/work}
rm -rf "$DIR"; mkdir -p "$DIR/home/state" "$DIR/home/data" "$DIR/home/config" "$DIR/fakebin" "$DIR/root/bin" "$DIR/wt"

git -C "$DIR/wt" -c init.defaultBranch=main init -q
git -C "$DIR/wt" config user.email [email protected]
git -C "$DIR/wt" config user.name t
git -C "$DIR/wt" commit -q --allow-empty -m init
git -C "$DIR/wt" branch -M feat-x
HEAD_SHA=$(git -C "$DIR/wt" rev-parse HEAD)
git -C "$DIR/wt" update-ref refs/remotes/origin/main "$HEAD_SHA"

cat > "$DIR/root/bin/fm-guard.sh" <<'SH'
#!/usr/bin/env bash
exit 0
SH
chmod +x "$DIR/root/bin/fm-guard.sh"

cat > "$DIR/fakebin/gh" <<SH
#!/usr/bin/env bash
printf 'HOST=%s ARGS=%s\n' "\${GH_HOST-unset}" "\$*" >> "$DIR/gh.log"
case " \$* " in
  *" repos/o/r/branches/main "*) printf '{"name":"main","protected":false}\n'; exit 0 ;;
  *" repos/o/r/rules/branches/main "*) printf '[]\n'; exit 0 ;;
esac
case "\${1:-} \${2:-}" in
  "pr view")
    case " \$* " in
      *" --json isDraft "*) printf '{"isDraft":false}\n'; exit 0 ;;
      *" --json headRefOid "*) printf '%s\n' "$HEAD_SHA"; exit 0 ;;
      *" --json state -q .state "*) printf 'MERGED\n'; exit 0 ;;
      *" --json state,mergedAt,isDraft,headRefOid,author,mergeable,reviewDecision "*)
        printf 'state=open\nmerged_at=\ndraft=false\nhead=%s\nauthor=author\nmergeability=mergeable\nreview_decision=APPROVED\n' "$HEAD_SHA"; exit 0 ;;
      *statusCheckRollup*)
        printf '{"state":"OPEN","isDraft":false,"mergeable":"MERGEABLE","mergeStateStatus":"CLEAN","headRefOid":"%s","baseRefName":"main","statusCheckRollup":[{"__typename":"CheckRun","name":"ci","status":"COMPLETED","conclusion":"SUCCESS"}]}\n' "$HEAD_SHA"; exit 0 ;;
    esac
    ;;
  "pr checks")
    exit 0
    ;;
  "pr merge")
    printf 'merged:\n  number: 9\n  status: ok\n'; exit 0
    ;;
  "api graphql")
    printf 'state=MERGED\nmerged=true\nqueued=false\nbase=main\n'; exit 0
    ;;
  "api /repos/o/r/pulls/7"*|"api /repos/o/r/pulls/8"*)
    case " \$* " in
      *"/files"*) printf 'src/a.sh\n'; exit 0 ;;
    esac
    printf 'author=author\nbase=%s\n' "$HEAD_SHA"; exit 0
    ;;
  "api --method")
    printf '%s\talice\n' "$HEAD_SHA"; exit 0
    ;;
esac
exit 0
SH
chmod +x "$DIR/fakebin/gh"
: > "$DIR/gh.log"

write_meta() {  # <id>
  local id=$1
  cat > "$DIR/home/state/$id.meta" <<META
window=firstmate:fm-$id
endpoint_task_id=$id
worktree=$DIR/wt
project=$DIR/project
kind=ship
mode=no-mistakes
META
  chmod 0600 "$DIR/home/state/$id.meta"
}

run_product() {  # <command...>
  PATH="$DIR/fakebin:/usr/bin:/bin" FM_ROOT_OVERRIDE="$DIR/root" FM_HOME="$DIR/home" "$@"
}

echo "=================== S1: arm a PR on a self-hosted host ==================="
write_meta task-ghe
run_product bash "$REPO/bin/fm-pr-check.sh" task-ghe https://ghe.example.com/o/r/pull/7
echo "--- recorded pr= and pr_head= ---"
grep -E '^(pr|pr_head)=' "$DIR/home/state/task-ghe.meta"
echo "--- armed poll sidecar (provider,url,host,path,number) ---"
cat "$DIR/home/state/task-ghe.pr-poll"
echo "--- gh calls during arm ---"
cat "$DIR/gh.log"
: > "$DIR/gh.log"

echo "=================== S2: armed poll watches the self-hosted host ==================="
poll_out=$(run_product bash "$DIR/home/state/task-ghe.check.sh")
printf 'poll stdout: %s\n' "$poll_out"
printf 'gh calls during poll:\n'; cat "$DIR/gh.log"
: > "$DIR/gh.log"

echo "=================== S3: fm-pr-state reads the PR at its host ==================="
run_product bash "$REPO/bin/fm-pr-state.sh" https://ghe.example.com/o/r/pull/7; rc=$?
printf 'fm-pr-state rc=%s (no blockers printed)\n' "$rc"
printf 'gh calls during state read:\n'; cat "$DIR/gh.log"
: > "$DIR/gh.log"

echo "=================== S4: fm-pr-reviewers reads the PR at its host ==================="
run_product bash "$REPO/bin/fm-pr-reviewers.sh" https://ghe.example.com/o/r/pull/7
printf 'gh calls during reviewer lookup:\n'; cat "$DIR/gh.log"
: > "$DIR/gh.log"

echo "=================== S5: github.com control is untouched ==================="
write_meta task-com
run_product bash "$REPO/bin/fm-pr-check.sh" task-com https://github.com/o/r/pull/8 >/dev/null
poll_out=$(run_product bash "$DIR/home/state/task-com.check.sh")
run_product bash "$REPO/bin/fm-pr-state.sh" https://github.com/o/r/pull/8 >/dev/null
printf 'poll stdout: %s\n' "$poll_out"
printf 'gh calls across arm+poll+state for github.com (every HOST must be unset):\n'; cat "$DIR/gh.log"
: > "$DIR/gh.log"

echo "=================== S6: adversarial - a doctored sidecar host is never polled ==================="
sed -i '3s/^ghe\.example\.com$/git.example.org/' "$DIR/home/state/task-ghe.pr-poll"
printf 'doctored sidecar (host differs from URL):\n'; cat "$DIR/home/state/task-ghe.pr-poll"
poll_out=$(run_product bash "$DIR/home/state/task-ghe.check.sh")
printf 'poll stdout: [%s]\n' "$poll_out"
printf 'gh calls during doctored poll (must be none):\n'; cat "$DIR/gh.log"
printf 'gh log line count: %s\n' "$(wc -l < "$DIR/gh.log")"

echo "=================== S7: adversarial - malformed host labels are never polled ==================="
printf '%s\n' github "-ghe.example.com/o/r/pull/7" -ghe.example.com o/r 7 > "$DIR/home/state/task-ghe.pr-poll"
poll_out=$(run_product bash "$DIR/home/state/task-ghe.check.sh")
printf 'leading-hyphen: stdout=[%s] gh-log-lines=%s\n' "$poll_out" "$(wc -l < "$DIR/gh.log")"
longlabel=$(printf 'a%.0s' {1..64})
printf '%s\n' github "https://$longlabel.example.com/o/r/pull/7" "$longlabel.example.com" o/r 7 > "$DIR/home/state/task-ghe.pr-poll"
poll_out=$(run_product bash "$DIR/home/state/task-ghe.check.sh")
printf '64-char label: stdout=[%s] gh-log-lines=%s\n' "$poll_out" "$(wc -l < "$DIR/gh.log")"

: > "$DIR/gh.log"
echo "=================== S8: fm-pr-merge merges a PR on the self-hosted host ==================="
write_meta task-merge
run_product bash "$REPO/bin/fm-pr-merge.sh" task-merge https://ghe.example.com/o/r/pull/9; rc=$?
printf 'fm-pr-merge rc=%s\n' "$rc"
printf 'recorded identity in meta:\n'; grep -E '^(pr|pr_head)=' "$DIR/home/state/task-merge.meta"
printf 'gh calls during merge:\n'; cat "$DIR/gh.log"
printf 'distinct hosts seen by every gh call: %s\n' "$(sed -n 's/^HOST=\([^ ]*\).*/\1/p' "$DIR/gh.log" | sort -u | tr '\n' ' ')"

: > "$DIR/gh.log"
echo "=================== S9: fm-pr-merge leaves github.com untouched ==================="
write_meta task-merge-com
run_product bash "$REPO/bin/fm-pr-merge.sh" task-merge-com https://github.com/o/r/pull/10 >/dev/null; rc=$?
printf 'fm-pr-merge rc=%s\n' "$rc"
printf 'distinct hosts seen by every gh call: %s\n' "$(sed -n 's/^HOST=\([^ ]*\).*/\1/p' "$DIR/gh.log" | sort -u | tr '\n' ' ')"
printf 'merge line: %s\n' "$(grep 'ARGS=pr merge' "$DIR/gh.log" || true)"
Evidence: Live validation summary (scenarios and observed results)

Source: Live validation summary (scenarios and observed results)

# Live validation: PR tooling on any GitHub host

Change under test: `fm/github-host-support` (worktree, target commit 09d0de9).
Product: firstmate shell tooling (`bin/fm-pr-*.sh`, `bin/fm-teardown.sh`, `bin/fm-backlog-transition-lib.sh`).
There is no GUI surface; the end-user surface is the CLI and the files it records, so the evidence is CLI transcripts plus the recorded state.

## 1. Independent end-to-end drive against a disposable fixture

Script: a disposable fixture was built under `/tmp/fm-live-host-scenario/work`:
a throwaway home (`home/state`, `home/data`, `home/config`), a throwaway git worktree, and a fake `gh` on `PATH` that emulates a self-hosted forge and logs `HOST=<GH_HOST> ARGS=<command>` for every call.
The product scripts themselves are the real ones from the worktree; only the external forge CLI is the fixture.
Transcript: `live-host-scenario.txt`.

| Step | What an end user does | Observed result |
| --- | --- | --- |
| S1 | Arm a PR on `ghe.example.com` (`bin/fm-pr-check.sh task-ghe https://ghe.example.com/o/r/pull/7`) | `armed: state/task-ghe.check.sh`; meta holds `pr=https://ghe.example.com/o/r/pull/7` and the forge head; sidecar holds `github / https://ghe.example.com/o/r/pull/7 / ghe.example.com / o/r / 7`; both gh reads ran with `HOST=ghe.example.com` |
| S2 | Run the armed poll sidecar | prints `merged`; the gh read ran with `HOST=ghe.example.com` |
| S3 | `bin/fm-pr-state.sh https://ghe.example.com/o/r/pull/7` | rc=0, no blockers; both gh calls (`pr view`, `pr checks`) ran with `HOST=ghe.example.com` |
| S4 | `bin/fm-pr-reviewers.sh https://ghe.example.com/o/r/pull/7` | prints `alice 1 recent commit`; all three gh calls ran with `HOST=ghe.example.com` |
| S5 | Same arm + poll + state for `https://github.com/o/r/pull/8` | every call ran with `HOST=unset` (github.com untouched) |
| S6 | Doctor the sidecar so its host (`git.example.org`) differs from its URL (`ghe.example.com`), then run it | no output, zero gh calls |
| S7 | Doctor the sidecar to a leading-hyphen host label and to a 64-character host label | both: no output, zero gh calls |
| S8 | `bin/fm-pr-merge.sh task-merge https://ghe.example.com/o/r/pull/9` | `verified: ... is merged`; meta holds the host URL and head; all six gh calls (head read, mergeable read, branch rules, commit-rules list, `pr merge`, outcome graphql) ran with `HOST=ghe.example.com` |
| S9 | `bin/fm-pr-merge.sh task-merge-com https://github.com/o/r/pull/10` | `verified: ... is merged`; every call ran with `HOST=unset`, including `pr merge 10 --repo o/r --match-head-commit ... --squash` |

## 2. Repository tests that drive the real scripts end to end

Each of these executes the real product scripts with a disposable fixture `gh`/`gh-axi` that records `GH_HOST` per call. All exited 0.

* `bash tests/fm-github-host.test.sh` - parser identity, default-host rule, ambient `GH_HOST` ignored by the default rule, `fm_gh_at` per-command selection, bounded record read, poll host selection and sidecar refusal.
* `bash tests/fm-pr-state.test.sh` - state read at the PR's host and github.com untouched.
* `bash tests/fm-pr-reviewers.test.sh` - reviewer lookup at the PR's host.
* `bash tests/fm-pr-merge.test.sh` - every merge-path gh call at the PR's host; github.com leaves the environment untouched.
* `bash tests/fm-teardown.test.sh` - recorded URL read at its own host, Gerrit host never selected, bare-number/branch lookups at `FM_GITHUB_HOST`, unusual ambient `GH_HOST` tolerated, landed task on another host closed with the URL as a backlog note.
* `bash tests/fm-pr-check-security.test.sh` - re-arming after a retirement receipt for another host reads the new PR at its own host.

## 3. Not exercised

No real self-hosted GitHub Enterprise instance is reachable from this machine, so the forge CLI is a disposable stub in every run; the product scripts, their host selection, and their recorded state are real.
Evidence: targeted-test-fm-github-host.log

Source: targeted-test-fm-github-host.log

ok - the parser accepts a pull request URL on any valid GitHub host and keeps the host
ok - the parser refuses malformed pull request URLs on every host
ok - GitLab and Gerrit shapes keep their providers and github.com stays refused for them
ok - the default host is github.com and overridable with FM_GITHUB_HOST
ok - the default host never reads an exported GH_HOST, whatever its form
ok - the host is selected for the one command and github.com is left untouched
ok - the pull request record is read at the given host
ok - the merge poll reads a pull request at its own host and refuses an inconsistent record
Evidence: targeted-test-fm-pr-state.log

Source: targeted-test-fm-pr-state.log

ok - a passing required check and a skipped one leave nothing to report
ok - a terminal pull request reports that state and nothing else
ok - draft state blocks readiness
ok - stale changes-requested verdicts explain a blocking review decision
ok - approved PR ignores stale changes-requested history
ok - current changes-requested review blocks readiness
ok - a CHANGES_REQUESTED decision is always reported
ok - the author's own review is never listed as a blocker
ok - a pending approval is not reported as a blocker
ok - required failure blocks readiness
ok - given gh's sentence, an unreported required check is unconfirmed, other check lookup failures refuse
ok - given gh's sentence, a head with no reported checks is unverified rather than ready
ok - help states what empty output means and what is out of scope
ok - unknown and conflicting mergeability block readiness
ok - argument and lookup refusals exit nonzero
ok - a pull request on another GitHub host is read at that host and github.com is untouched
Evidence: targeted-test-fm-pr-reviewers.log

Source: targeted-test-fm-pr-reviewers.log

ok - reviewer candidates use API-resolved logins and unique commits
ok - author-only evidence produces no candidate and says why
ok - argument and lookup refusals exit nonzero
ok - a pull request on another GitHub host is read at that host and github.com is untouched
Evidence: targeted-test-fm-pr-merge.log

Source: targeted-test-fm-pr-merge.log

ok - fm-pr-merge reports exact queue retry flags after a zero-exit false success
ok - fm-pr-merge omits merge-queue retry guidance for a closed GitHub PR
ok - fm-pr-merge aggregates agreeing merge-queue rules
ok - fm-pr-merge reports ambiguity for conflicting merge-queue rules
ok - fm-pr-merge records pr= and pr_head= for a verified GitHub merge
ok - fm-pr-merge records pr= before the forge call can land the merge
ok - fm-pr-merge propagates a real merge failure without silently succeeding
ok - fm-pr-merge refuses a GitHub merge call that leaves the PR open and unqueued
ok - fm-pr-merge retries a bounded number of times when mergeable is UNKNOWN and merges once it resolves
ok - fm-pr-merge reports mergeability still pending after its bounded UNKNOWN retry is spent
ok - fm-pr-merge refuses on the UNKNOWN re-check when a check turned red between reads
ok - fm-pr-merge refuses a genuine mergeable conflict immediately, without retrying
ok - fm-pr-merge keeps PR bookkeeping when it cannot read a successful merge call's outcome
ok - fm-pr-merge refuses with the forge's own output quoted apart from its verdict
ok - fm-pr-merge quotes the forge output when it cannot read the outcome either
ok - fm-pr-merge does not echo back queue flags the caller already used
ok - fm-pr-merge still names retry flags when the caller used a different method
ok - fm-pr-merge names the queue requirement even when its method is unrecognised
ok - fm-pr-merge distinguishes unreadable branch rules from a base with no merge queue
ok - fm-pr-merge reads a plan-gated 403 on branch rules as no merge queue, not unreadable
ok - fm-pr-merge says nothing about a merge queue when the base branch has no queue rule
ok - fm-pr-merge accepts only a proved merge from the gh-axi fallback
ok - fm-pr-merge explains an armed auto-merge that landed nothing on a queue-less base
ok - fm-pr-merge never reports auto-merge as armed when the merge command failed
ok - fm-pr-merge claims no acceptance for a failed merge command carrying queue flags
ok - fm-pr-merge falls back to the gh-axi view when gh's read fails
ok - fm-pr-merge names a landed state hiding behind a failed GitHub merge command
ok - fm-pr-merge refuses a GitHub merge when gh is missing, before recording
ok - fm-pr-merge refuses a GitHub merge when gh is missing rather than merging blind
ok - fm-pr-merge verifies a genuinely merged GitHub pull request
ok - fm-pr-merge refuses to claim a merge when poll recording fails
ok - fm-pr-merge accepts and accurately reports a GitHub merge-queue entry
ok - fm-pr-merge explains how to retry with the required GitHub merge queue method
ok - fm-pr-merge refuses branch deletion unless --attended-override is passed
ok - fm-pr-merge refuses before merging when task meta is missing
ok - fm-pr-merge refuses malformed PR URLs before calling gh-axi
ok - fm-pr-merge refuses unsafe PR URL segments before recording state
ok - fm-pr-merge refuses repo override args before recording state
ok - fm-pr-merge refuses a bundled short-option repo override and refuses -d unless attended
ok - fm-pr-merge does not add default --squash when the caller passes an explicit merge method
ok - fm-pr-merge respects --method=<value> as an explicit merge method
ok - fm-pr-merge parses a GitHub PR URL into gh-axi number and --repo arguments
ok - fm-pr-merge addresses every gh call at the pull request's own host and leaves github.com untouched
ok - fm-pr-merge refuses a caller --sha on GitHub because the head comes from the live read
ok - fm-pr-merge merges a GitLab merge request through glab instead of refusing it
ok - fm-pr-merge takes the GitLab instance from the URL rather than assuming one
ok - fm-pr-merge imposes no merge method on GitLab, leaving the project's own one
ok - fm-pr-merge refuses GitLab source-branch deletion unless --attended-override is passed
ok - fm-pr-merge propagates a real glab merge failure without silently succeeding
ok - fm-pr-merge refuses on each GitLab pre-merge condition independently
ok - fm-pr-merge reports every failing GitLab condition, not only the first
ok - fm-pr-merge reports a stale recorded head and verifies the live one
ok - fm-pr-merge refuses an unreadable GitLab merge request state rather than merging blind
ok - fm-pr-merge refuses a GitLab head commit it cannot validate
ok - fm-pr-merge refuses before recording anything when glab or jq is absent
ok - fm-pr-merge refuses a GitLab head override before recording state
ok - a merge a secondmate home performs itself is reported upward exactly once
ok - a locally routed secondmate home reports the landed PR into its parent's own channel
ok - a landed GitLab merge request is reported upward on the same channel
ok - a queued GitLab merge stays silent and leaves confirmation to the armed poll
ok - a refused or failed merge reports no outcome
ok - a GitLab merge refused before the forge call reports no outcome
ok - a merge a main home performs itself leaves one durable wake naming the PR
ok - a queued GitHub merge stays silent and leaves confirmation to the armed poll
ok - distinct merged PRs for one task retain distinct captain-facing wakes
ok - an uncommitted marker retry preserves at least one durable outcome
ok - a secondmate home that cannot report upward says so instead of merging in silence
ok - fm-pr-merge proceeds when the home carries no backlog at all
ok - fm-pr-merge refuses when the backlog exists but cannot be read
ok - fm-pr-merge refuses when its configured backend cannot be read
ok - fm-pr-merge refuses when its user backend configuration cannot be read
ok - fm-pr-merge refuses when its user backend configuration directory cannot be traversed
ok - fm-pr-merge proceeds once when its user configuration directory and backlog are genuinely absent
ok - fm-pr-merge honors a backend override over an unreadable user configuration
ok - fm-pr-merge refuses red GitHub checks and waives only a named --allow-red check
ok - fm-pr-merge refuses a draft pull request and one with no boolean draft state
ok - fm-pr-merge merges when a failed check run was replaced by a passing re-run
ok - fm-pr-merge never lets a check run supersede a legacy status context
ok - fm-pr-merge still refuses when a check's current run failed after an earlier pass
ok - fm-pr-merge uses start order when the old success finishes last
ok - fm-pr-merge supersedes an old cancellation that finishes last
ok - fm-pr-merge keeps a check red while its re-run is still in flight
ok - fm-pr-merge never lets one check's pass clear another check's failure
ok - fm-pr-merge clears a failure only on a proven later pass of the same check
ok - fm-pr-merge keeps --allow-red scoped to its named check beside a superseded failure
ok - fm-pr-merge rechecks away presence before an attended red merge
ok - fm-pr-merge keeps a quiet-mode home's merges attended, the named red-check waiver included
ok - fm-pr-merge accepts exactly one separately named red-check waiver
ok - while the away-posture record exists any green merge lands under away authority, yolo or not, and attended merges stay untagged
ok - under the away-posture record the branch merges a green task, is refused on a red check with or without --allow-red, and is refused at the partition while attended
ok - a branch merge refuses under the lock when the away record is archived during preflight
ok - away posture permits immediate merges but refuses every asynchronous path
ok - away merge proceeds on a plan-gated 403 because that repository cannot have a merge queue
ok - the away record does not bypass red checks, and a recorded pr= must match the URL
ok - an unreadable away-posture record refuses the merge instead of skipping the record
ok - no away-record archive or replacement lands between the authority read and the merge
ok - a record made unreadable before the merge's own authority read refuses the merge
ok - a merge that cannot lock the away record refuses instead of merging unlocked
ok - fm-pr-merge refuses --allow-red on GitLab
ok - fm-pr-merge refuses when a required check from branch protection or a ruleset never reported
ok - fm-pr-merge merges when every required check reported and is green
ok - fm-pr-merge reports a red check and an unreported required check together with every other failure
ok - fm-pr-merge refuses when the required checks cannot be read, and tells a plan without rules apart
ok - fm-pr-merge --allow-missing waives only its named unreported check
ok - fm-pr-merge --allow-missing is single use, attended-only, and GitHub-only like --allow-red
ok - fm-pr-merge enforces required producer identity and named waivers
ok - fm-pr-merge matches an app-bound required commit status by name
ok - fm-pr-merge reports known missing checks and all independent read errors
Evidence: targeted-test-fm-pr-check-security.log

Source: targeted-test-fm-pr-check-security.log

ok - raw-byte parser accepts canonical URLs and rejects the complete adversarial matrix
ok - GitLab merge requests are followed on any instance and never wake falsely
ok - the Gerrit watch wakes only on an explicit merged status and never on submittability
ok - Gerrit arming records no patch set revision and the merge path refuses to submit
ok - Gerrit arming accepts a published HEAD only by the change's current patch set tree
ok - a no-mistakes Gerrit ready report requires the pipeline's fixes recovered into the published copy
ok - validated merged polls notify once and retire before the next watcher cycle
ok - a repeat identical merged poll for an already-notified task is absorbed, never queued as a main-blocking row
ok - a failed upward merge report keeps its poll armed for repair and retry
ok - staged self-merge and poll interleavings are never silent
ok - queued merges retain their away authority after captain return
ok - poll distinguishes attended authorization from external landing
ok - accepted merge authority refuses rebound task metadata
ok - accepted merge authority persists under the lifecycle lock
ok - teardown cannot race merged-poll authority consumption
ok - poll retirement preserves a replacement authority record
ok - a merge detected by the poll is reported upward from a secondmate home exactly once
ok - a different merged PR for the same task gets its own first notification
ok - a merged poll on a persistent secondmate retires silently: no outcome, marker, or wake, and every lifecycle artifact preserved
ok - queue, receipt, and every fixed-path removal crash point recover without loss or repeated execution
ok - open/red, closed-unmerged, malformed, and forge errors remain armed until an exact merged transition
ok - replacement, nonterminal, tampered, and custom results receive no deletion authority
ok - queue failure and untrusted receipts preserve canonical poll evidence
ok - GitHub and GitLab exact merged results share one retirement path
ok - PR and teardown entrypoints reject invalid arguments before every side effect
ok - arming refuses a draft pull request, naming it, and arms a ready or unreadable one
ok - re-arming after a retirement receipt for another host reads the new pull request at its own host
ok - fm-pr-check refuses to record a PR or arm a merge watch on a secondmate record
ok - fm-pr-check refuses to register a PR whose named head is only in the worker copy
ok - fm-pr-check refuses a direct-PR registration while a later commit is only in the copy
ok - valid direct and merge flows record exact metadata and reject multiline head metadata
ok - rejected metacharacter bytes remain inert at generation and watcher time
ok - static poll is silent except for one merged line and remains watcher-bounded
ok - interrupted atomic preparation cleans private temporaries and publishes nothing
ok - concurrent watchers observe only complete private poll publications
ok - poll publication paths refuse symlinks and directories
ok - live poll and custom-check artifacts require private single-link files
ok - a poll armed before a volume renumber is re-recorded under the control lock and keeps detecting merges
ok - a renumbered registration is never re-recorded around a tampered artifact: swapped-check altered-check swapped-sidecar altered-sidecar altered-template-hash wrong-mode hardlinked-check split-device foreign-device, or a pending retirement
ok - direct re-arm publication waits without replacing an armed poll
ok - device re-record publication waits without rewriting its registration
ok - post-rename poll validation faults revoke both names and allow a clean retry
ok - bootstrap does not rewrite unauthenticated checks or emit retired migration diagnostics
ok - watcher signals promptly stop custom checks and clean private state
ok - returned custom check descendants are drained on installed and fallback timeout paths
ok - teardown removes safe poll artifacts and refuses directory-shaped check files without traversal
Evidence: Coverage guard under a UTF-8 locale (the C-collation fix)

Source: Coverage guard under a UTF-8 locale (the C-collation fix)

FM_TEST_COVERAGE ok total=251 parallel=24 parallel_max_ms=665545 parallel_imbalance_ms=2 parallel_unhinted=0 serial=211 serial_shards=9 serial_unhinted=9 serial_max_ms=1074843 serial_budget_ms=1200000 herdr=16

FM_TEST_COVERAGE ok total=251 parallel=24 parallel_max_ms=665545 parallel_imbalance_ms=2 parallel_unhinted=0 serial=211 serial_shards=9 serial_unhinted=9 serial_max_ms=1074843 serial_budget_ms=1200000 herdr=16
- Outcome: 🔧 1 issue found → no changes applied ✅ across 2 runs (41m38s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ℹ️ bin/fm-pr-poll.sh:58 - The github branch's host revalidation is weaker than the rule its own comment claims. The comment at 56-57 says the host is 'validated as the lowercase DNS name the parser accepts', but the inline check at 58-61 only enforces length 1-253, the lowercase [a-z0-9.-] character class, and no leading/trailing/double dot; it omits the per-label length (at most 63) and leading/trailing-hyphen rules that fm_pr_forge_host_valid applies (bin/fm-pr-lib.sh:127-142). A sidecar carrying a host such as -ghe.example.com or ghe-.example.com passes this check and reaches the gh call at 78 with that malformed GH_HOST, although the parser can never produce it. The exact-URL equality at line 72 keeps the poll from reaching any host the record does not name, and a failed lookup stays silent, so no false merged result is possible; the defect is that the check and its comment diverge. Smallest honest fix: point the comment at fm_pr_forge_host_valid instead of claiming the parser's rule, or apply the same per-label rules inline.
  • ⚠️ bin/fm-pr-lib.sh:166 - Intent-scope question against the required constraint 'Every gh and gh-axi call that addresses a pull request or repository by owner/repo is made against the pull request's own host by setting GH_HOST for that one command'. The constraint is implemented for the PR lifecycle scripts, but two sibling consumers of the same recorded pr= URL bypass fm_gh_at and still hardcode github.com: bin/fm-bearings-snapshot.sh:255 repo_slug matches only github.com[:/] URLs, so the gh pr list --repo call at bin/fm-bearings-snapshot.sh:301 (through the gh_bounded wrapper at 263) never runs for a PR or clone on another host and the PR is silently omitted from 'bearings include PRs'; bin/fm-contributions.sh:249 observe() refuses anything that is not https://github.com/*, so the gh api repos/.../pulls/... reads at bin/fm-contributions.sh:254-272 never run and the observer prints 'contributions: observation unavailable for <url>'. Reachable sequence: arm a task with https://ghe.example.com/o/r/pull/7 (now accepted by the change), and both the armed contributions observer and a /bearings PR run skip it. No wrong value is produced, and the enumerated failing flows (merge polling, merge, cleanup, backlog closing) are fully host-aware, so this is a scope decision: the narrowest remedy is to route these callers through fm_gh_at with the PR's host, or to state in docs/configuration.md:2340 that these surfaces remain github.com-only. That remedy extends the change beyond the flows the intent enumerates, which is why it needs your call rather than an automatic fix.

🔧 Fix applied.
1 warning still open:

  • ⚠️ bin/fm-pr-lib.sh:166 - Intent-scope question against the required constraint 'Every gh and gh-axi call that addresses a pull request or repository by owner/repo is made against the pull request's own host by setting GH_HOST for that one command'. The constraint is implemented for the PR lifecycle scripts, but two sibling consumers of the same recorded pr= URL bypass fm_gh_at and still hardcode github.com: bin/fm-bearings-snapshot.sh:255 repo_slug matches only github.com[:/] URLs, so the gh pr list --repo call at bin/fm-bearings-snapshot.sh:301 (through the gh_bounded wrapper at 263) never runs for a PR or clone on another host and the PR is silently omitted from 'bearings include PRs'; bin/fm-contributions.sh:249 observe() refuses anything that is not https://github.com/*, so the gh api repos/.../pulls/... reads at bin/fm-contributions.sh:254-272 never run and the observer prints 'contributions: observation unavailable for <url>'. Reachable sequence: arm a task with https://ghe.example.com/o/r/pull/7 (now accepted by the change), and both the armed contributions observer and a /bearings PR run skip it. No wrong value is produced, and the enumerated failing flows (merge polling, merge, cleanup, backlog closing) are fully host-aware, so this is a scope decision: the narrowest remedy is to route these callers through fm_gh_at with the PR's host, or to state in docs/configuration.md:2340 that these surfaces remain github.com-only. That remedy extends the change beyond the flows the intent enumerates, which is why it needs your call rather than an automatic fix.
🔧 **Test** - 1 issue found → no changes applied ✅
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 2m43s ago (214 observed); agent reported: pi exited: exit status 143: [marketplace] 3 configured default marketplace catalog(s) are not initialized. Non-TUI sessions keep startup network-free; run /marketplace add <source> explicitly before install or discovery.. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.

🔧 No changes applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 14 of 14 scenarios driven live against the product
Scenario Result Live Evidence
Arming a pull request on ghe.example.com records pr= with that host and reads the draft state and head through gh with GH_HOST set to that host ✅ pass live live-host-scenario.txt S1: armed: state/task-ghe.check.sh, pr=https://ghe.example.com/o/r/pull/7, sidecar host ghe.example.com, and both gh calls logged HOST=ghe.example.com
Re-arming a task after a pending retirement receipt for a pull request on another host reads the new pull request at its own host ✅ pass live targeted-test-fm-pr-check-security.log: ok - re-arming after a retirement receipt for another host reads the new pull request at its own host
The armed merge poll reports merged for a pull request on ghe.example.com and issues its gh read with GH_HOST=ghe.example.com ✅ pass live live-host-scenario.txt S2: poll stdout merged, gh log HOST=ghe.example.com ARGS=pr view https://ghe.example.com/o/r/pull/7 --json state -q .state
A doctored poll sidecar whose host differs from its URL, a leading-hyphen host label, or an over-long label never reaches gh and never reports merged ✅ pass live live-host-scenario.txt S6/S7: doctored host, leading-hyphen label, and 64-character label each produced empty stdout and zero gh calls; targeted-test-fm-github-host.log covers the same at the poll ent…
fm-pr-state reports on a pull request on ghe.example.com with every gh call addressed at that host ✅ pass live live-host-scenario.txt S3: rc=0, both pr view and pr checks logged HOST=ghe.example.com; targeted-test-fm-pr-state.log `ok - a pull request on another GitHub host is read at that host and github…
fm-pr-reviewers resolves reviewer candidates for a pull request on ghe.example.com with every gh call addressed at that host ✅ pass live live-host-scenario.txt S4: output alice 1 recent commit, all three gh calls logged HOST=ghe.example.com; targeted-test-fm-pr-reviewers.log `ok - a pull request on another GitHub host is read at th…
fm-pr-merge merges a pull request on ghe.example.com: every merge-path gh call carries GH_HOST=ghe.example.com and pr= keeps the host ✅ pass live live-host-scenario.txt S8: verified: ... is merged, meta pr=https://ghe.example.com/o/r/pull/9, and all six calls (head read, mergeable read, branch rules, commit rules, pr merge, outcome graphq…
Pull requests on github.com behave as before: no GH_HOST is set for any gh call across arm, poll, state, reviewers, and merge ✅ pass live live-host-scenario.txt S5 and S9: every logged call for https://github.com/o/r/pull/8 and pull/10 has HOST=unset, including pr merge 10 --repo o/r --match-head-commit ... --squash; the state, revi…
Teardown reads a recorded pull request at its own host, and a Gerrit change's host is never selected for gh ✅ pass live targeted-test-fm-teardown.log: ok - teardown reads a recorded pull request at its own host and ok - teardown never selects a non-GitHub forge&#39;s host for gh
With no recorded URL, teardown's bare-number and branch lookups reach gh at FM_GITHUB_HOST (or github.com when unset), and an unusual ambient GH_HOST (uppercase, port) no longer breaks them ✅ pass live targeted-test-fm-teardown.log: ok - teardown&#39;s branch and bare-number lookups reach gh at FM_GITHUB_HOST, and github.com otherwise and `ok - an exported GH_HOST never breaks the teardown lookups, an…
Closing a backlog item for landed work whose pull request lives on another GitHub host records the URL as a note and the item reaches done ✅ pass live targeted-test-fm-teardown.log: ok - teardown closes a landed task on another GitHub host with its pull request URL as a note (row state done, body PR https://ghe.example.com/example/repo/pull/7)
An invalid FM_GITHUB_HOST is refused instead of being passed to gh ✅ pass live targeted-test-fm-github-host.log: ok - the default host is github.com and overridable with FM_GITHUB_HOST (invalid bad host/x refused)
URL parsing accepts any valid lowercase DNS host and keeps it in the identity, github.com stays unchanged, look-alike hosts are distinct hosts, and GitLab/Gerrit shapes on github.com stay refused ✅ pass live targeted-test-fm-github-host.log parser cases; targeted-test-fm-pr-check-security.log ok - raw-byte parser accepts canonical URLs and rejects the complete adversarial matrix (look-alike hosts now di…
The fm-test-run coverage guard runs clean under a UTF-8 locale (the C-collation fix) ✅ pass live coverage-guard-utf8-locale.txt: FM_TEST_COVERAGE ok total=251 ... with rc=0 under en_US.UTF-8
  • bash tests/fm-github-host.test.sh
  • bash tests/fm-pr-state.test.sh
  • bash tests/fm-pr-reviewers.test.sh
  • bash tests/fm-pr-merge.test.sh
  • bash tests/fm-teardown.test.sh
  • bash tests/fm-pr-check-security.test.sh
  • bash /tmp/fm-live-host-scenario/run.sh (disposable live drive: real bin/fm-pr-check.sh, armed state/*.check.sh poll, bin/fm-pr-state.sh, bin/fm-pr-reviewers.sh, bin/fm-pr-merge.sh for ghe.example.com and github.com, plus doctored-sidecar adversarial cases)
  • bash bin/fm-test-run.sh --check-coverage under en_US.UTF-8
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

A pull request URL on a GitHub host other than github.com was rejected by
the PR tooling, so merge polling, merge, cleanup and backlog closing failed
for it.

The parser now accepts https://<host>/<owner>/<repo>/pull/<n> for any valid
host and keeps the host in the recorded identity. Every gh and gh-axi call
that addresses a pull request or repository is made against that host, and
github.com is addressed exactly as before. FM_GITHUB_HOST (falling back to
GH_HOST, then github.com) names the host to assume where none is given by a
URL. The backlog tool links only github.com pull requests, so a pull request
on another host is recorded on the closed item as a note.
The coverage guard sorts with LC_ALL=C but compared with comm under the
ambient locale, which reports the lists as unsorted in a UTF-8 locale.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks, @mielientiev. I read the thread and the diff of head 6d08542d against main b062eb94 (20 files, +667/-79). The attestation matches 6d08542d.

What it does: fm_pr_url_parse now accepts https://<any-valid-lowercase-host>/<owner>/<repo>/pull/<n> as a GitHub PR and keeps the host in the identity. A new fm_gh_at sets GH_HOST for that one command on every PR read, merge, poll, reviewer and teardown call; github.com stays untouched. FM_GITHUB_HOST sets the default host for PRs known only by number. A PR on another host is recorded on the backlog item as a PR <url> note. A separate commit makes the fm-test-run.sh coverage guard compare with LC_ALL=C.

Security review before approving fork CI: there are no workflow, secret or CI-config edits. I approved CI 37805839108 and no-mistakes 37808412328. Security FYI: this widens the host set the merge, poll and teardown parser treats as GitHub from exactly github.com to any DNS host with a /pull/ path. The fm-pr-check-security adversarial matrix changes so that look-alike hosts are now distinct hosts rather than refused. gh will only send credentials to hosts it's logged into. Still, this changes a security-contract parser on the merge path, so Kun needs to see it explicitly.

Contract-class: new-default. On main, every non-github.com /pull/ URL is refused. After this, it's accepted and acted on, with no setting to turn on. FM_GITHUB_HOST only changes the bare-number default. It won't auto-merge.

VISION.md, rule by rule

  • One captain, one interface: aligns. GHE PRs stop failing silently.
  • Authority is explicit and never inferred: cannot tell. Merge authority is unchanged, but which URLs count as mergeable GitHub PRs widens by default.
  • Scripts own the mechanics, agents own the judgment: aligns. Host validation is deterministic.
  • A restart is a non-event: aligns. The host is part of the durable identity, so two hosts never share a record.
  • Delegation with a spine: aligns.
  • The fleet outlives any vendor: aligns. It drops a github.com-only assumption.
  • Scope: mostly aligns. The LC_ALL=C coverage-guard fix is unrelated, and it's better as its own small PR. Your own review also leaves fm-bearings-snapshot.sh and fm-contributions.sh github.com-only, which is fine if it's stated.

Heads-up: #6866 changes the same parser, merge, teardown and backlog-transition code for GitLab, so whichever lands second will need a rebase.

Next step: fork CI is now running. Nothing is needed from you unless it goes red. When it's green, it goes to Kun.

@mielientiev

Copy link
Copy Markdown
Author

Hey @kunchenguid
Anything I can do to speed up merging this PR?

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for checking in, @mielientiev, and sorry for the wait. Nothing more is needed from you right now. Here's where it stands on head 6d08542d (unchanged since my last look, and the attestation still matches).

CI: every check is green except "Behavior portable serial 2". That shard didn't fail a test. It ran all of its cases ok and was cancelled at the job's 30-minute limit, a slow-shard timeout we've seen on other PRs. I've re-run that failed job on the same run (37805839108, now attempt 3). Body compliance and "PR must be raised via no-mistakes" already passed.

Contract-class: new-default (unchanged). On main, every non-github.com /pull/ URL is refused. With this PR it's accepted and acted on across poll, merge and teardown, with no setting to turn on. So it doesn't auto-merge. Kun decides.

Security FYI (unchanged): this widens the host set the merge, poll and teardown parser treats as GitHub, from exactly github.com to any valid DNS host. Kun will see that explicitly when he decides.

VISION.md: my rule-by-rule verdict from the previous comment stands. Authority is the one "cannot tell", because of the default-on host widening. Scope is "mostly aligns", because of the unrelated LC_ALL=C coverage-guard commit.

Next step: waiting on the re-run of the serial 2 shard. Once it's green, this goes to Kun for a merge-or-leave decision. That part is on him, not you. One heads-up: #6866 (GitLab) edits the same parser and merge code, so whichever lands second will need a rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants