Skip to content

fix(bin): support configured GitHub Enterprise PR hosts - #7489

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
tin-hong:fm/fm-ghe-pr-urls
Oct 24, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
tin-hong:fm/fm-ghe-pr-urls

Conversation

@tin-hong

@tin-hong tin-hong commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix GitHub issue #5936 (GitHub Enterprise PR URLs such as https://leadsonline.ghe.com///pull/ are rejected, so a task PR on a GitHub Enterprise host cannot be registered, monitored for merge, merged through the merge script, or linked when its backlog item closes) and open the upstream pull request for it.

Context: the issue's maintainer triage (#5936 (comment)) labeled it ready-for-pr as a restore-class fix and asked that host allowance derive from registered project origins or configured GitHub hosts rather than accepting any host, and that the host be carried through bin/fm-pr-merge.sh.

Fixes #5936

What Changed

  • Accept GitHub Enterprise PR URLs for hosts explicitly listed in config/github-hosts, while rejecting unlisted hosts.
  • Carry the parsed host through PR registration, merge monitoring, merging, reviewer checks, and merge-outcome reads via GH_HOST.
  • Document host configuration and add regression coverage for configuration precedence, Enterprise PR flows, unlisted-host rejection, and github.com compatibility.

Known follow-ups

  • Backlog-close PR linking for an Enterprise URL needs the companion tasks-axi change in fix: accept GitHub Enterprise pull request URLs tasks-axi#77 . tasks-axi validates the --pr link itself and rejects a singular /pull/ route outside github.com, so nothing here vendors, patches, or works around it. Until that change lands, a merged Enterprise PR keeps the existing retained pending-close record: teardown records what it owes before any destructive step, the rejected link leaves that record and the backlog row untouched, and the same record closes normally once the link is accepted. Verified against the installed tasks-axi with a real pending-close record.
  • Replacing the static merge-poll template invalidates polls armed before the update, because a registration binds the exact check bytes it published. That predates this change and applies to every earlier template change too; refreshing those registrations through the existing publication helpers, while preserving their tamper checks, is follow-up work rather than part of accepting Enterprise URLs.

Risk Assessment

Medium: the code change is confined to GitHub host acceptance and host routing, and github.com behavior is unchanged. The two residual risks are both documented above rather than fixed here: backlog-close linking for an Enterprise URL waits on the companion tasks-axi change, and polls armed before this update are invalidated by the static-template change exactly as any earlier template change invalidated them.

Testing

Live read-only registration, merged polling, notification persistence, and merge-preflight refusal passed against Enterprise PR 505. CLI transcripts and persisted-state evidence were captured; fixtures were removed. No actual merge, broad suite, lint, or static analysis was run.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Register Enterprise PR 505 and persist its real head SHA and complete merge-monitoring identity ✅ pass live ghe-registration.txt; ghe-registration-state.txt
Observe merged Enterprise PR 505 and persist its merge notification ✅ pass live ghe-merged-poll.txt; ghe-merged-notification.txt; ghe-merged-notification-state.txt
Read Enterprise merge preflight state and refuse an already-merged PR before calling merge ✅ pass live ghe-merge-refusal.txt
Evidence: Live registration and forge reads

Source: Live registration and forge reads

Command: bash -x bin/fm-pr-check.sh scratch-ghe-505 https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505
Exit: 0
STDOUT:
armed: state/scratch-ghe-505.check.sh

STDERR:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  repair missing watcher supervision with a foreground checkpoint: bin/fm-watch-checkpoint.sh --seconds 180.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Executed forge commands and host export (bash execution trace):
+ GH_HOST=leadsonline.ghe.com
++ gh pr view https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 --json isDraft
++ gh pr view https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 --json headRefOid -q .headRefOid
Evidence: Persisted Enterprise identity and real head SHA

Source: Persisted Enterprise identity and real head SHA

scratch-ghe-505.meta:
worktree=~/.no-mistakes/worktrees/e8951d61b05b/01M57VPA183NS321E80CVYR61Z/.test-ghe-readonly/home/wt
project=~/.no-mistakes/worktrees/e8951d61b05b/01M57VPA183NS321E80CVYR61Z/.test-ghe-readonly/home/wt
kind=ship
mode=no-mistakes
pr=https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505
pr_head=64604370df0ddb1379b87ccfb71ba82a85dd7e2c


scratch-ghe-505.pr-poll:
github
https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505
leadsonline.ghe.com
LeadsOnline/nighthawk-tf
505


scratch-ghe-505.pr-poll-registration:
fm-pr-poll-registration-v2
scratch-ghe-505
github
https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505
leadsonline.ghe.com
LeadsOnline/nighthawk-tf
505
ecf6f3e16f243dcf677a025dbb7b39bfa1f2d8d0e24ad97abc11cd958146d307
820527122387591c2b17c5888aff4d461ffbd0814542b6e4645abb4f6b40fc61
2096:3712869
2096:3712893
Evidence: Live poll prints merged

Source: Live poll prints merged

Command: bash -x ~/.no-mistakes/worktrees/e8951d61b05b/01M57VPA183NS321E80CVYR61Z/.test-ghe-readonly/home/state/scratch-ghe-505.check.sh
Exit: 0
STDOUT:
merged

STDERR:
+ case "$number" in
+ case "$number" in
+ case "$provider" in
+ '[' 19 -ge 1 ']'
+ '[' 19 -le 253 ']'
+ case "$host" in
+ owner=LeadsOnline
+ repo=nighthawk-tf
+ '[' 11 -ge 1 ']'
+ '[' 11 -le 39 ']'
+ case "$owner" in
+ '[' 12 -ge 1 ']'
+ '[' 12 -le 100 ']'
+ case "$repo" in
+ '[' https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 = https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 ']'
++ GH_HOST=leadsonline.ghe.com
++ gh pr view https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 --json state -q .state
+ state=MERGED
+ '[' MERGED = MERGED ']'
+ printf '%s\n' merged
+ exit 0

Executed forge commands and host export (bash execution trace):
Evidence: Notification publication returns zero

Source: Notification publication returns zero

Command: bash -c . bin/fm-pr-lib.sh; . bin/fm-wake-lib.sh; . bin/fm-parent-channel-lib.sh; . bin/fm-merge-outcome-lib.sh; fm_merge_outcome_report "$FM_HOME" "$FM_STATE_OVERRIDE" scratch-ghe-505 https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 poll
Exit: 0
STDOUT:

STDERR:
Evidence: Durable wake and Enterprise notification marker

Source: Durable wake and Enterprise notification marker

.wake-queue:
1792341825	1	check	merged-scratch-ghe-505-https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505	check: merge landed: scratch-ghe-505 https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505

merge-notified:
fm-pr-poll-merge-notified-v1
github
leadsonline.ghe.com
LeadsOnline/nighthawk-tf
505
Evidence: Live merge refusal and host-specific preflight reads

Source: Live merge refusal and host-specific preflight reads

Command: bash -x bin/fm-pr-merge.sh scratch-ghe-505 https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505
Exit: 1
STDOUT:
armed: state/scratch-ghe-505.check.sh

STDERR:
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
error: refusing to merge https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505
  - state is "MERGED", not open
  - mergeable is "UNKNOWN", not MERGEABLE

Executed forge commands and host export (bash execution trace):
+ GH_HOST=leadsonline.ghe.com
++ gh pr view https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 --json state,isDraft,mergeable,mergeStateStatus,headRefOid,baseRefName,statusCheckRollup
++ gh api repos/LeadsOnline/nighthawk-tf/branches/master
++ gh api --paginate repos/LeadsOnline/nighthawk-tf/rules/branches/master
- Outcome: ⚠️ 1 info across 2 runs (6m54s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 issues (1 error, 1 warning)
  • 🚨 bin/fm-pr-lib.sh:271 - The intent requires Enterprise PRs to be “linked when its backlog item closes”, but the new FM_PR_HOST=$host acceptance leaves that failure unresolved. For a merged Enterprise PR, teardown passes --pr <enterprise-url> through fm_backlog_done unchanged; supported tasks-axi 0.2.6 rejects its singular /pull/ route outside github.com. Normal closure, retained artifacts, and pending-close replay remain affected (bin/fm-backlog-transition-lib.sh:533, :552, :1221). Complete the shared backlog adaptation or require a dependency that supports these links.
  • ⚠️ bin/fm-pr-lib.sh:222 - With FM_HOME and FM_CONFIG_OVERRIDE unset, this resolves to /config/github-hosts, ignoring the documented default home. Both standalone consumers, bin/fm-pr-state.sh:64 and bin/fm-pr-reviewers.sh:51, initialize neither variable before parsing, so they reject Enterprise hosts configured under the repository's config directory. Apply the normal home fallback before reading the allowlist.
  • ⚠️ bin/fm-pr-poll.sh:61 - Updating this static template invalidates every previously armed merge poll, including other providers. Their saved check files contain the old bytes, while bin/fm-pr-lib.sh:761 requires equality with the current template. The watcher then rejects those registrations at bin/fm-watch.sh:2987 instead of checking merges; the update path does not refresh them. Republish existing authenticated registrations through the existing publication helpers when updating the template, preserving tamper checks.

🔧 Fix applied.
2 issues (1 error, 1 warning) still open:

  • 🚨 bin/fm-pr-lib.sh:271 - The intent requires Enterprise PRs to be “linked when its backlog item closes”, but the new FM_PR_HOST=$host acceptance leaves that failure unresolved. For a merged Enterprise PR, teardown passes --pr <enterprise-url> through fm_backlog_done unchanged; supported tasks-axi 0.2.6 rejects its singular /pull/ route outside github.com. Normal closure, retained artifacts, and pending-close replay remain affected (bin/fm-backlog-transition-lib.sh:533, :552, :1221). Complete the shared backlog adaptation or require a dependency that supports these links.
  • ⚠️ bin/fm-pr-poll.sh:61 - Updating this static template invalidates every previously armed merge poll, including other providers. Their saved check files contain the old bytes, while bin/fm-pr-lib.sh:761 requires equality with the current template. The watcher then rejects those registrations at bin/fm-watch.sh:2987 instead of checking merges; the update path does not refresh them. Republish existing authenticated registrations through the existing publication helpers when updating the template, preserving tamper checks.
⚠️ **Test** - 1 info
  • ⚠️ End-to-end Enterprise registration, merge detection, and merging remain unproven. Real CLI requests reached the Enterprise API but received HTTP 401. Provide an authorized disposable Enterprise repository, PR, and scoped credential to complete live validation; simulated forge tests cannot establish those outcomes.
  • ⚠️ live validation verdict: inconclusive (4 of 7 scenarios were driven live against the product); untested: Register an authorized Enterprise PR and persist its identity and merge monitoring, Observe an actually merged Enterprise PR and emit its merged notification, Merge a disposable Enterprise PR through the merge script on its recorded host
  • Live validation: ⚠️ inconclusive - 4 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Register or merge an unlisted, lookalike, or malformed Enterprise URL; reject it without changing task state ✅ pass live live-cli-transcript.log
Submit a github.com URL without a host list; accept its URL and proceed to task validation ✅ pass live live-cli-transcript.log
Run standalone PR-state and reviewer commands without home overrides; honor the code-root allowlist and reach the Enterprise API ✅ pass live live-cli-transcript.log
Monitor an Enterprise PR without authentication; emit no false merged notification ✅ pass live live-cli-transcript.log
Register an authorized Enterprise PR and persist its identity and merge monitoring ⏸️ untested no The simulated registration test passed, but real Enterprise requests returned HTTP 401. No authorized disposable repository, PR, or credential was available within the permitted isolated setup. Supply…
Observe an actually merged Enterprise PR and emit its merged notification ⏸️ untested no The simulated merged-state test passed. Real lookup lacked Enterprise authentication, so no actual merged PR could be observed. Supply a readable disposable Enterprise PR and scoped credential.
Merge a disposable Enterprise PR through the merge script on its recorded host ⏸️ untested no The simulated merge test verified host routing. A real merge requires an authorized disposable Enterprise repository, mergeable PR, and write credential, none available to the isolated setup. Producti…
  • bash tests/.gate-ghe-selected.sh: parser matrix, Enterprise config resolution, Enterprise registration/poll/merge routing, invalid-entrypoint side effects, recording/merge derivation, and static poll behavior
  • bash tests/fm-pr-state.test.sh
  • bash tests/fm-pr-reviewers.test.sh
  • python3 .test-ghe-gate/live-checks.py: actual entrypoints and real gh with isolated home/config; reproduction driver retained in the evidence directory
  • Removed temporary validation drivers and fixtures; git status --short was clean

🔧 No changes applied.
1 info still open:

  • ℹ️ The three authorized scenarios were driven live read-only against Enterprise PR 505. An actual Enterprise merge remains untested because it requires writing to a real PR and was explicitly forbidden.
  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Register Enterprise PR 505 and persist its real head SHA and complete merge-monitoring identity ✅ pass live ghe-registration.txt; ghe-registration-state.txt
Observe merged Enterprise PR 505 and persist its merge notification ✅ pass live ghe-merged-poll.txt; ghe-merged-notification.txt; ghe-merged-notification-state.txt
Read Enterprise merge preflight state and refuse an already-merged PR before calling merge ✅ pass live ghe-merge-refusal.txt
  • bash -x bin/fm-pr-check.sh scratch-ghe-505 https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505 with isolated FM_HOME and a one-host allowlist
  • Executed the generated scratch-ghe-505.check.sh with real gh; asserted stdout was exactly merged\n.
  • Sourced the specified libraries and called fm_merge_outcome_report; verified return zero, durable wake, and Enterprise identity marker.
  • FM_PR_GITHUB_MERGEABLE_RETRY_DELAY=0 bash -x bin/fm-pr-merge.sh scratch-ghe-505 https://leadsonline.ghe.com/LeadsOnline/nighthawk-tf/pull/505; verified live state MERGED, mergeability UNKNOWN, Enterprise preflight commands, and no gh pr merge invocation.
  • Inspected persisted registration records, removed the disposable driver and home, and confirmed git status --short was empty.
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → no changes applied ✅
  • ⚠️ linter found issues (exit code 1)

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

✅ **Push** - passed

✅ No issues found.

fm_pr_url_parse accepted a GitHub pull request URL only on github.com and
hard-set the recorded host, so a task PR on GitHub Enterprise (Cloud *.ghe.com
or Enterprise Server) could not be registered, watched for merge, merged, or
read back after a merge.

A GitHub URL now carries its host like the GitLab, Gerrit, and Forgejo
identities already do, with GitHub's owner and repository rules unchanged.
github.com needs no configuration and behaves exactly as before. Any other host
is accepted only when this home names it in config/github-hosts, because a URL
shape cannot tell a real GitHub host from a look-alike such as github.com.evil;
only an exact line match authorizes, so comments and malformed lines allow
nothing.

The parsed host is then carried to every forge call on those paths as GH_HOST,
which gh and gh-axi both honor: registration, the static merge poll, the merge
command and its pre-merge reads, the merge-outcome read, the teardown read, and
the crew-state PR state read. github.com exports nothing and keeps its ambient
behavior.

Backlog PR links still need the companion tasks-axi change, because that
package validates the URL itself.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (OSS triage): thank you @tin-hong, this is careful work, and the read-only live run against a real Enterprise PR is exactly the kind of evidence that helps.

Checked head cb9d09b1 against main 45dd50a5 (0 behind, merges cleanly). The body says Fixes #5936, and the diff does what that issue's triage asked: an Enterprise host is accepted only when this home lists it in config/github-hosts (exact-line match; absent, unreadable or symlinked file allows nothing), and the parsed host is carried through GH_HOST on check, poll, merge, reviewers, state and crew-state reads. github.com needs no config and exports no host.

Contract-class (my own read): opt-in. With no config/github-hosts the parser accepts exactly what it accepted before (github.com only), so nothing new happens unless the captain writes that file.

VISION.md: One captain aligns (no captain-facing surface). Authority aligns (the captain names the host; look-alikes refused). Scripts/agents aligns (pure script mechanics). Restart aligns (host is part of the durable PR identity). Delegation aligns (merge preflight and refusals unchanged, now on the right host). Vendor aligns (uses gh's own GH_HOST). Scope aligns.

Two notes, neither blocking: the backlog-close link for an Enterprise URL still waits on kunchenguid/tasks-axi#77 (documented in the body), and the changed static poll template means polls armed before an update get rejected, which you documented as the same thing every earlier template change did. Also heads-up that #6910 edits the same GitHub URL regex, so whichever lands second may need a small rebase.

I approved the first-time fork workflow runs on this head. Waiting on CI (including the no-mistakes check), so nothing is needed from you right now.

… ShellCheck comment lines in tests/fm-pr-check-security.test.sh. Canonical lint, the complete behavioral suite, and git diff --check pass. Full CI partition rerun remains with the outer executor
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @tin-hong. The new head 4c60c28a fixes the Lint 2 failure from the last CI run (39146806853) on cb9d09b1. I checked the patch between the two heads: it only adds three scoped ShellCheck comments in tests/fm-pr-check-security.test.sh and changes no behavior. Nothing touches .github/workflows or anything secret-bearing, and the attestation binds this head.

I approved this head's fork runs: CI 39156796558 and Require no-mistakes 39156796602.

Contract-class: opt-in (unchanged). Without config/github-hosts, only github.com is accepted, the same as before. VISION: every rule aligns (unchanged). Fixes #5936 is still in the body.

Status: waiting on CI. You don't need to do anything unless it comes back red. If it's green, including no-mistakes, and the PR is still mergeable, this takes the auto-merge path.

@kunchenguid
kunchenguid merged commit d96bff0 into kunchenguid:main Oct 24, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @tin-hong — really appreciate you taking the time on this.

Context: head 4c60c28a had all 19 checks green and the no-mistakes attestation bound to it (live go 3/3). Since CI ran, main moved about 60 commits, so I trial-merged onto current main and re-ran tests/fm-pr-check-security.test.sh (49 ok, 0 failed) before landing. Contract-class: opt-in. Without config/github-hosts, only github.com is accepted, exactly as before. VISION.md: every rule aligns. Hosts come only from the captain's own declaration, refusals stay strict for undeclared look-alikes, and the github.com path is unchanged. One thing stays open: backlog-close linking for Enterprise URLs still needs kunchenguid/tasks-axi#77, as the body notes. Landed as d96bff0. Fixes #5936.

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.

GitHub Enterprise (ghe.com / GHES) PR URLs are rejected: no PR registration, merge polling, or backlog PR link

2 participants