Skip to content

fix(menubar): follow the credential's GitHub host for Copilot quota - #1291

Closed
ozymandiashh wants to merge 2 commits into
getagentseal:mainfrom
ozymandiashh:feat/1286-copilot-ghe
Closed

ozymandiashh wants to merge 2 commits into
getagentseal:mainfrom
ozymandiashh:feat/1286-copilot-ghe

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Summary

  • Copilot live quota now follows the GitHub host its credential came from: api.github.com for github.com
    (and for any rung that carries no host — an app-name apps.json key, COPILOT_GITHUB_TOKEN / GH_TOKEN /
    GITHUB_TOKEN, gh auth token, a pasted token), and https://api.<tenant>.ghe.com/copilot_internal/user
    for a GitHub Enterprise Cloud data-residency host. Both readers hardcoded api.github.com and dropped the
    host, so a *.ghe.com enterprise could only ever report "Temporarily unavailable". Fixes [Feature Request] Support Copilot Enterprise on custom *.ghe.com hosts #1286.
  • The token and the host always come from the same credential entry (hosts.json is keyed by host, newer
    apps.json files by <host>:<app id>). With several hosts signed in github.com wins, otherwise the
    first .ghe.com tenant in sorted order; with exactly one, that host is used. A host neither rule can
    address — a self-hosted GitHub Enterprise Server install — fails with a message naming that host rather
    than sending the credential to dotcom, and unreachable-host and HTTP failures name the host that was tried
    (the CLI prints it instead of the bare "Temporarily unavailable").
  • macOS Settings says which host answered in the Copilot connection row; docs/providers/copilot.md gains a
    GHE-hosts section. Tokens are still never logged and sanitizeForUI is unchanged. The issue's second ask,
    a configurable 1.10 data-residency credit multiplier for estimated credits, is not part of this PR.

Testing

  • I have tested this locally against real data (not just unit tests) — dotcom path only; no *.ghe.com
    enterprise account was available, so the tenant path is covered by unit tests and by compiling the new
    host-policy type standalone against the expected values.
  • npm test passes
  • npm run build succeeds
  • cd mac && swift build succeeds. swift test cannot run on this machine (Command Line Tools only, no
    swift-testing module — the test target fails to compile in files this PR does not touch), so the new
    XCTest cases rely on CI.

Both Copilot quota readers hardcoded
https://api.github.com/copilot_internal/user and dropped the host their
credential was read from, so an enterprise on a GitHub Enterprise Cloud
data-residency host (<tenant>.ghe.com) could only ever report
"Temporarily unavailable": its token is not a dotcom token, and dotcom is
not an endpoint it may be sent to.

A discovered credential now carries its host. hosts.json is keyed by
GitHub host and newer apps.json files key by "<host>:<app id>", so the
token and the host always come from the same entry; the rungs that carry
no host of their own (an app-name apps.json key, COPILOT_GITHUB_TOKEN /
GH_TOKEN / GITHUB_TOKEN, gh auth token, a pasted token) mean dotcom. The
endpoint follows the host: api.github.com for github.com, and
api.<tenant>.ghe.com for an Enterprise Cloud host. With several hosts
signed in github.com wins, otherwise the first .ghe.com tenant in sorted
order, which keeps the pick stable across reads; with exactly one, that
host is used.

A host neither rule can address, such as a self-hosted GitHub Enterprise
Server install, fails with a message naming that host instead of falling
back to dotcom, and network and HTTP failures name the host that was
tried. macOS Settings now says which host answered in the Copilot
connection row. Tokens are still never logged and sanitizeForUI is
unchanged.

Closes getagentseal#1286
The fake credential reader keyed its files by splitting the path on "/",
but the adapter builds the path with path.join, which uses a backslash on
Windows: every lookup missed there, so the credential read as absent and
the six adapter-level cases saw no request and a "disconnected" quota.
path.basename is separator-correct on both platforms. Test-only; the
reader itself is unchanged and the existing Windows path test still
covers the real directories.
@iamtoruk

Copy link
Copy Markdown
Member

Landed as #1305 (ef86348) with your commits and authorship intact, rebased onto current main, plus one hardening commit: the normalized host is character-validated before URL construction, since a hosts.json key such as evil.com?.ghe.com passes the suffix check but builds a URL whose host is api.evil.com. Verified on this machine for github.com (same URL as main, HTTP 200, expected keys); the ghe.com path is covered by tests only, no enterprise account here. #1306 tracks the rungs that still carry no host. Thank you.

@iamtoruk iamtoruk closed this Sep 12, 2026
ozymandiashh added a commit to ozymandiashh/codeburn that referenced this pull request Sep 12, 2026
…IX paths

Two CI failures on getagentseal#1327, both ours.

macOS `swift test`: five tests in CodexQuotaSummaryTests assert Codex's
`footerLines` exactly, and got three lines instead of one. Appending
the forecast there was the wrong call, not a stale expectation.
`QuotaSummary.footerLines` is the adapter's normalized output, consumed
verbatim by the Capacity Dock, the hover card and those tests; an
estimate derived from a public record is not something the account
reported, and stacking it in there puts words in the adapter's mouth and
couples every consumer to a feature none of them asked for. getagentseal#1322 adds
Codex lines to the same array, so the collision was going to get worse.

`QuotaSummary` gains `forecastLines`, defaulted empty, so every other
adapter's construction site and every other provider's summary are
untouched. The hover card draws it under its own divider, below the
provider's own facts. The five existing tests are unchanged and now
cannot be affected: the Codex `footerLines` array is built from the
credit rows alone.

Windows `test-platforms`: the dataset-parity test compared
`datasetPaths()` against paths written with '/'. The separator is '\'
there, so two identical path lists compared unequal - getagentseal#1291's lesson
again. The expected side is now built with `join`, the invariant is
pinned as tail segments rather than as a spelling, and a case with a
Windows path exercises the splitter on both separators. The
byte-identical check also normalizes line endings and compares the
parsed documents, because a Windows checkout can hand back CRLF for a
file the refresh script wrote with '\n'.
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.

[Feature Request] Support Copilot Enterprise on custom *.ghe.com hosts

2 participants