惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
D
Docker
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
J
Java Code Geeks
Jina AI
Jina AI
博客园 - 【当耐特】
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(xai): keep OAuth URL clickable (#84927) · openclaw/op...
rubencu · 2026-05-21 · via Recent Commits to openclaw:main

@@ -4,17 +4,27 @@ import {

44

createTestWizardPrompter,

55

} from "openclaw/plugin-sdk/plugin-test-runtime";

66

import type { OAuthCredential } from "openclaw/plugin-sdk/provider-auth";

7-

import { afterEach, describe, expect, it, vi } from "vitest";

7+

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

8+9+

const waitForLocalOAuthCallbackMock = vi.hoisted(() => vi.fn());

10+11+

vi.mock("openclaw/plugin-sdk/provider-auth-runtime", () => ({

12+

waitForLocalOAuthCallback: waitForLocalOAuthCallbackMock,

13+

}));

14+815

import {

916

buildXaiOAuthAuthorizationCodeTokenBody,

1017

buildXaiOAuthAuthorizeUrl,

1118

fetchXaiOAuthDiscovery,

1219

isTrustedXaiOAuthEndpoint,

1320

loginXaiDeviceCode,

21+

loginXaiOAuth,

1422

refreshXaiOAuthCredential,

1523

XAI_OAUTH_CALLBACK_CORS_ORIGIN_ALLOWLIST,

24+

XAI_OAUTH_CALLBACK_HOST,

1625

XAI_OAUTH_CALLBACK_PORT,

1726

XAI_OAUTH_CLIENT_ID,

27+

XAI_OAUTH_DISCOVERY_URL,

1828

XAI_OAUTH_REDIRECT_URI,

1929

XAI_OAUTH_SCOPE,

2030

} from "./xai-oauth.js";

@@ -40,7 +50,42 @@ function requireStringBody(init: RequestInit | undefined): string {

4050

return init.body;

4151

}

425253+

function requestUrl(input: RequestInfo | URL): string {

54+

if (typeof input === "string") {

55+

return input;

56+

}

57+

if (input instanceof URL) {

58+

return input.href;

59+

}

60+

return input.url;

61+

}

62+63+

function stubSuccessfulXaiOAuthNetwork(): void {

64+

const fetchImpl = vi.fn<typeof fetch>(async (url, init) => {

65+

if (requestUrl(url) === XAI_OAUTH_DISCOVERY_URL) {

66+

return jsonResponse({

67+

authorization_endpoint: "https://auth.x.ai/oauth2/authorize",

68+

token_endpoint: "https://auth.x.ai/oauth2/token",

69+

});

70+

}

71+72+

expect(requestUrl(url)).toBe("https://auth.x.ai/oauth2/token");

73+

expect(init?.method).toBe("POST");

74+

expect(requireStringBody(init)).toContain("code=AUTHCODE");

75+

return jsonResponse({

76+

access_token: "access-token",

77+

refresh_token: "refresh-token",

78+

expires_in: 3600,

79+

});

80+

});

81+

vi.stubGlobal("fetch", fetchImpl);

82+

}

83+4384

describe("xAI OAuth", () => {

85+

beforeEach(() => {

86+

waitForLocalOAuthCallbackMock.mockReset();

87+

});

88+4489

afterEach(() => {

4590

vi.unstubAllGlobals();

4691

vi.unstubAllEnvs();

@@ -163,7 +208,85 @@ describe("xAI OAuth", () => {

163208

expect(refreshed.access).toBe("access-2");

164209

expect(refreshed.refresh).toBe("refresh-1");

165210

expect(refreshed.expires).toBe(121_000);

166-

vi.unstubAllEnvs();

211+

});

212+213+

it("prints the authorize URL through plain prompter output so terminal link detection keeps it whole", async () => {

214+

waitForLocalOAuthCallbackMock.mockResolvedValue({ code: "AUTHCODE", state: "state-1" });

215+

stubSuccessfulXaiOAuthNetwork();

216+217+

const progress = { update: vi.fn(), stop: vi.fn() };

218+

const note = vi.fn<(message: string, title?: string) => Promise<void>>(async () => undefined);

219+

const plain = vi.fn<(message: string) => Promise<void>>(async () => undefined);

220+

const openUrl = vi.fn<(url: string) => Promise<void>>(async () => undefined);

221+

const runtimeLog = vi.fn<(message: string) => void>();

222+

const ctx = {

223+

config: {},

224+

isRemote: true,

225+

openUrl,

226+

prompter: {

227+

note,

228+

plain,

229+

progress: vi.fn(() => progress),

230+

},

231+

runtime: {

232+

log: runtimeLog,

233+

error: vi.fn(),

234+

exit: vi.fn(),

235+

},

236+

oauth: { createVpsAwareHandlers: vi.fn() },

237+

} as unknown as ProviderAuthContext;

238+239+

await loginXaiOAuth(ctx);

240+241+

expect(openUrl).not.toHaveBeenCalled();

242+

const noteMessage = note.mock.calls[0]?.[0] ?? "";

243+

expect(noteMessage).toContain("Open this xAI OAuth URL in your browser:");

244+

expect(noteMessage).toContain(

245+

`ssh -N -L ${XAI_OAUTH_CALLBACK_PORT}:${XAI_OAUTH_CALLBACK_HOST}:${XAI_OAUTH_CALLBACK_PORT} <host>`,

246+

);

247+

expect(noteMessage).not.toContain("https://auth.x.ai/oauth2/authorize");

248+249+

const plainOutput = plain.mock.calls[0]?.[0] ?? "";

250+

expect(plainOutput.trim()).toMatch(/^https:\/\/auth\.x\.ai\/oauth2\/authorize\?/);

251+

expect(plainOutput).toContain(`client_id=${encodeURIComponent(XAI_OAUTH_CLIENT_ID)}`);

252+

expect(plainOutput).toContain("code_challenge=");

253+

expect(runtimeLog).not.toHaveBeenCalled();

254+

expect(progress.stop).toHaveBeenCalledWith("xAI OAuth complete");

255+

});

256+257+

it("keeps the authorize URL visible for prompters without plain output", async () => {

258+

waitForLocalOAuthCallbackMock.mockResolvedValue({ code: "AUTHCODE", state: "state-1" });

259+

stubSuccessfulXaiOAuthNetwork();

260+261+

const progress = { update: vi.fn(), stop: vi.fn() };

262+

const note = vi.fn<(message: string, title?: string) => Promise<void>>(async () => undefined);

263+

const openUrl = vi.fn<(url: string) => Promise<void>>(async () => undefined);

264+

const runtimeLog = vi.fn<(message: string) => void>();

265+

const ctx = {

266+

config: {},

267+

isRemote: false,

268+

openUrl,

269+

prompter: {

270+

note,

271+

progress: vi.fn(() => progress),

272+

},

273+

runtime: {

274+

log: runtimeLog,

275+

error: vi.fn(),

276+

exit: vi.fn(),

277+

},

278+

oauth: { createVpsAwareHandlers: vi.fn() },

279+

} as unknown as ProviderAuthContext;

280+281+

await loginXaiOAuth(ctx);

282+283+

const authorizeUrl = openUrl.mock.calls[0]?.[0] ?? "";

284+

const noteMessage = note.mock.calls[0]?.[0] ?? "";

285+

expect(authorizeUrl).toContain("https://auth.x.ai/oauth2/authorize?");

286+

expect(noteMessage).toContain("Open this xAI OAuth URL in your browser:");

287+

expect(noteMessage).not.toContain(authorizeUrl);

288+

expect(runtimeLog.mock.calls[0]?.[0] ?? "").toContain(authorizeUrl);

289+

expect(progress.stop).toHaveBeenCalledWith("xAI OAuth complete");

167290

});

168291169292

it("logs in with xAI device code without a localhost callback", async () => {