fix(providers): classify copilot native endpoints (#59644)

* fix(providers): classify copilot native endpoints

* fix(changelog): add copilot endpoint note

* fix(providers): handle copilot proxy hints
This commit is contained in:
Vincent Koc
2026-04-02 20:51:46 +09:00
committed by GitHub
parent 71d49012fc
commit 5abd5d889f
5 changed files with 88 additions and 4 deletions

View File

@@ -1,7 +1,31 @@
import { describe, expect, it, vi } from "vitest";
import { resolveCopilotApiToken } from "./github-copilot-token.js";
import {
deriveCopilotApiBaseUrlFromToken,
resolveCopilotApiToken,
} from "./github-copilot-token.js";
describe("resolveCopilotApiToken", () => {
it("derives native Copilot base URLs from Copilot proxy hints", () => {
expect(
deriveCopilotApiBaseUrlFromToken(
"copilot-token;proxy-ep=https://proxy.individual.githubcopilot.com;",
),
).toBe("https://api.individual.githubcopilot.com");
expect(deriveCopilotApiBaseUrlFromToken("copilot-token;proxy-ep=proxy.example.com;")).toBe(
"https://api.example.com",
);
expect(deriveCopilotApiBaseUrlFromToken("copilot-token;proxy-ep=proxy.example.com:8443;")).toBe(
"https://api.example.com",
);
});
it("rejects malformed or non-http proxy hints", () => {
expect(
deriveCopilotApiBaseUrlFromToken("copilot-token;proxy-ep=javascript:alert(1);"),
).toBeNull();
expect(deriveCopilotApiBaseUrlFromToken("copilot-token;proxy-ep=://bad;")).toBeNull();
});
it("treats 11-digit expires_at values as seconds epochs", async () => {
const fetchImpl = vi.fn(async () => ({
ok: true,