



























@@ -23,7 +23,7 @@ describe("loginOpenAICodexDeviceCode", () => {
2323vi.stubEnv("OPENCLAW_VERSION", "2026.3.22");
2424try {
2525const fetchMock = vi
26-.fn()
26+.fn<typeof fetch>()
2727.mockResolvedValueOnce(
2828createJsonResponse({
2929device_auth_id: "device-auth-123",
@@ -74,45 +74,35 @@ describe("loginOpenAICodexDeviceCode", () => {
7474await vi.advanceTimersByTimeAsync(1);
7575const credentials = await credentialsPromise;
767677-expect(fetchMock).toHaveBeenNthCalledWith(
78-1,
79-"https://auth.openai.com/api/accounts/deviceauth/usercode",
80-expect.objectContaining({
81-method: "POST",
82-headers: {
83-"Content-Type": "application/json",
84-originator: "openclaw",
85-version: "2026.3.22",
86-"User-Agent": "openclaw/2026.3.22",
87-},
88-}),
89-);
90-expect(fetchMock).toHaveBeenNthCalledWith(
91-2,
92-"https://auth.openai.com/api/accounts/deviceauth/token",
93-expect.objectContaining({
94-method: "POST",
95-headers: {
96-"Content-Type": "application/json",
97-originator: "openclaw",
98-version: "2026.3.22",
99-"User-Agent": "openclaw/2026.3.22",
100-},
101-}),
102-);
103-expect(fetchMock).toHaveBeenNthCalledWith(
104-4,
105-"https://auth.openai.com/oauth/token",
106-expect.objectContaining({
107-method: "POST",
108-headers: {
109-"Content-Type": "application/x-www-form-urlencoded",
110-originator: "openclaw",
111-version: "2026.3.22",
112-"User-Agent": "openclaw/2026.3.22",
113-},
114-}),
115-);
77+const userCodeRequest = fetchMock.mock.calls[0];
78+expect(userCodeRequest?.[0]).toBe("https://auth.openai.com/api/accounts/deviceauth/usercode");
79+expect(userCodeRequest?.[1]?.method).toBe("POST");
80+expect(userCodeRequest?.[1]?.headers).toEqual({
81+"Content-Type": "application/json",
82+originator: "openclaw",
83+version: "2026.3.22",
84+"User-Agent": "openclaw/2026.3.22",
85+});
86+87+const deviceTokenRequest = fetchMock.mock.calls[1];
88+expect(deviceTokenRequest?.[0]).toBe("https://auth.openai.com/api/accounts/deviceauth/token");
89+expect(deviceTokenRequest?.[1]?.method).toBe("POST");
90+expect(deviceTokenRequest?.[1]?.headers).toEqual({
91+"Content-Type": "application/json",
92+originator: "openclaw",
93+version: "2026.3.22",
94+"User-Agent": "openclaw/2026.3.22",
95+});
96+97+const oauthTokenRequest = fetchMock.mock.calls[3];
98+expect(oauthTokenRequest?.[0]).toBe("https://auth.openai.com/oauth/token");
99+expect(oauthTokenRequest?.[1]?.method).toBe("POST");
100+expect(oauthTokenRequest?.[1]?.headers).toEqual({
101+"Content-Type": "application/x-www-form-urlencoded",
102+originator: "openclaw",
103+version: "2026.3.22",
104+"User-Agent": "openclaw/2026.3.22",
105+});
116106expect(onVerification).toHaveBeenCalledWith({
117107verificationUrl: "https://auth.openai.com/codex/device",
118108userCode: "CODE-12345",
@@ -121,10 +111,9 @@ describe("loginOpenAICodexDeviceCode", () => {
121111expect(onProgress).toHaveBeenNthCalledWith(1, "Requesting device code…");
122112expect(onProgress).toHaveBeenNthCalledWith(2, "Waiting for device authorization…");
123113expect(onProgress).toHaveBeenNthCalledWith(3, "Exchanging device code…");
124-expect(credentials).toMatchObject({
125-access: expect.any(String),
126-refresh: "refresh-token-123",
127-});
114+expect(typeof credentials.access).toBe("string");
115+expect(credentials.access.length).toBeGreaterThan(0);
116+expect(credentials.refresh).toBe("refresh-token-123");
128117expect(credentials).not.toHaveProperty("accountId");
129118expect(credentials.expires).toBeGreaterThan(Date.now());
130119} finally {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。