fix(core): read the enterprise domain from the resolved Copilot credential

This commit is contained in:
exe.dev user
2026-11-05 21:16:44 +00:00
Unverified
parent 9db1956a4d
commit 5c69b22b0a
2 changed files with 23 additions and 20 deletions
@@ -104,15 +104,14 @@ const oauth = (app: App.Info) =>
Effect.flatMap((token) => {
if (token.access_token) {
const access = token.access_token
return request(userURL(domain), {
headers: {
Accept: "application/json",
Authorization: `Bearer ${access}`,
"User-Agent": App.useragent(app),
"X-GitHub-Api-Version": userApiVersion,
},
return request(userURL(enterprise ? domain : undefined), {
headers: {
Accept: "application/json",
Authorization: `Bearer ${access}`,
"User-Agent": App.useragent(app),
"X-GitHub-Api-Version": userApiVersion,
},
).pipe(
}).pipe(
Effect.map((user) => Option.getOrUndefined(decodeUser(user))),
// Only an explicit entitlement answer blocks login; a failed
// or malformed lookup must not turn a GitHub hiccup into a denial.
@@ -189,7 +188,13 @@ export const GithubCopilotPlugin = define({
current?.type === "oauth"
? HttpClient.filterStatusOk(http)
.execute(
HttpClientRequest.get(userURL(enterpriseDomain(credential.metadata))).pipe(
HttpClientRequest.get(
userURL(
typeof current.metadata?.enterpriseUrl === "string"
? current.metadata.enterpriseUrl
: undefined,
),
).pipe(
HttpClientRequest.setHeaders({
Accept: "application/json",
Authorization: `Bearer ${current.refresh}`,
@@ -394,12 +399,8 @@ function oauthURLs(domain: string) {
}
}
function userURL(domain: string) {
return `${domain === "github.com" ? "https://api.github.com" : `https://api.${domain}`}/copilot_internal/user`
}
function enterpriseDomain(metadata?: Readonly<Record<string, unknown>>) {
return typeof metadata?.enterpriseUrl === "string" ? normalizeDomain(metadata.enterpriseUrl) : "github.com"
function userURL(enterprise?: string) {
return `${enterprise ? `https://api.${normalizeDomain(enterprise)}` : "https://api.github.com"}/copilot_internal/user`
}
function baseURL(enterprise?: string) {
@@ -147,7 +147,6 @@ describe("GithubCopilotPlugin", () => {
const before = folds.count
yield* TestClock.adjust("10 minutes")
// Each refresh reads the endpoint before the model list.
yield* advance(() => models().length === 2)
yield* drain
expect(folds.count).toBe(before)
@@ -410,9 +409,11 @@ describe("GithubCopilotPlugin", () => {
const credentials = yield* Credential.Service
const providers = yield* Provider.Service
const hooks = yield* PluginHooks.Service
const requests: string[] = []
const http = HttpClient.make((request) =>
Effect.succeed(
HttpClientResponse.fromWeb(
Effect.sync(() => {
requests.push(request.url)
return HttpClientResponse.fromWeb(
request,
Response.json({
data: [
@@ -429,8 +430,8 @@ describe("GithubCopilotPlugin", () => {
},
],
}),
),
),
)
}),
)
const sent: string[] = []
const outbound = Object.assign(
@@ -457,6 +458,7 @@ describe("GithubCopilotPlugin", () => {
Effect.provideService(HttpClient.HttpClient, http),
Effect.provideService(FetchHttpClient.Fetch, outbound),
)
yield* advance(() => requests.some((url) => url.endsWith("/models")))
yield* drain
const event = yield* hooks.trigger("session", "title", {