


























@@ -1,5 +1,5 @@
11import { describe, expect, it, vi } from "vitest";
2-import { buildCopilotIdeHeaders } from "./copilot-dynamic-headers.js";
2+import { COPILOT_INTEGRATION_ID, buildCopilotIdeHeaders } from "./copilot-dynamic-headers.js";
33import {
44deriveCopilotApiBaseUrlFromToken,
55resolveCopilotApiToken,
@@ -47,7 +47,7 @@ describe("resolveCopilotApiToken", () => {
4747expect(result.expiresAt).toBe(12_345_678_901_000);
4848});
494950-it("sends IDE headers when exchanging the GitHub token", async () => {
50+it("sends IDE and integration headers when exchanging the GitHub token", async () => {
5151const fetchImpl = vi.fn(async () => ({
5252ok: true,
5353json: async () => ({
@@ -71,7 +71,40 @@ describe("resolveCopilotApiToken", () => {
7171expect(init.headers).toEqual({
7272Accept: "application/json",
7373Authorization: "Bearer github-token",
74+"Copilot-Integration-Id": COPILOT_INTEGRATION_ID,
7475 ...buildCopilotIdeHeaders({ includeApiVersion: true }),
7576});
7677});
78+79+it("refreshes legacy cached tokens without the vscode-chat integration identity", async () => {
80+const fetchImpl = vi.fn(async () => ({
81+ok: true,
82+json: async () => ({
83+token: "fresh-copilot-token",
84+expires_at: Math.floor(Date.now() / 1000) + 3600,
85+}),
86+}));
87+const saveJsonFileImpl = vi.fn();
88+89+const result = await resolveCopilotApiToken({
90+githubToken: "github-token",
91+cachePath: "/tmp/github-copilot-token-test.json",
92+loadJsonFileImpl: () => ({
93+token: "legacy-copilot-token",
94+expiresAt: Date.now() + 60 * 60 * 1000,
95+updatedAt: Date.now(),
96+}),
97+ saveJsonFileImpl,
98+fetchImpl: fetchImpl as unknown as typeof fetch,
99+});
100+101+expect(result.token).toBe("fresh-copilot-token");
102+expect(fetchImpl).toHaveBeenCalledTimes(1);
103+expect(saveJsonFileImpl).toHaveBeenCalledWith("/tmp/github-copilot-token-test.json", {
104+token: "fresh-copilot-token",
105+expiresAt: expect.any(Number),
106+updatedAt: expect.any(Number),
107+integrationId: COPILOT_INTEGRATION_ID,
108+});
109+});
77110});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。