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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
B
Blog
腾讯CDC
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
L
LangChain Blog
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS 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): decouple device code discovery · openclaw/openc...
obviyus · 2026-05-19 · via Recent Commits to openclaw:main

@@ -1,3 +1,6 @@

1+

import type { ProviderAuthContext } from "openclaw/plugin-sdk/plugin-entry";

2+

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

3+

import { createRuntimeEnv, createTestWizardPrompter } from "openclaw/plugin-sdk/testing";

14

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

25

import {

36

buildXaiOAuthAuthorizationCodeTokenBody,

@@ -97,34 +100,29 @@ describe("xAI OAuth", () => {

9710098101

it("validates discovered endpoints before using them", async () => {

99102

vi.stubEnv("OPENCLAW_VERSION", "2026.3.22");

100-

const fetchImpl = vi.fn(async () =>

103+

const fetchImpl = vi.fn<typeof fetch>(async () =>

101104

jsonResponse({

102105

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

103-

device_authorization_endpoint: "https://auth.x.ai/oauth2/device/code",

104106

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

105107

}),

106-

) as unknown as typeof fetch;

108+

);

107109108110

await expect(fetchXaiOAuthDiscovery({ fetchImpl })).resolves.toEqual({

109111

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

110-

deviceAuthorizationEndpoint: "https://auth.x.ai/oauth2/device/code",

111112

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

112113

});

113114114-

const discoveryInit = (fetchImpl as unknown as ReturnType<typeof vi.fn>).mock.calls.at(

115-

0,

116-

)?.[1] as RequestInit | undefined;

115+

const discoveryInit = fetchImpl.mock.calls.at(0)?.[1];

117116

const discoveryHeaders = new Headers(discoveryInit?.headers ?? {});

118117

expect(discoveryHeaders.get("user-agent")).toBe("openclaw/2026.3.22");

119118

vi.unstubAllEnvs();

120119121-

const poisonedFetch = vi.fn(async () =>

120+

const poisonedFetch = vi.fn<typeof fetch>(async () =>

122121

jsonResponse({

123122

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

124-

device_authorization_endpoint: "https://auth.x.ai/oauth2/device/code",

125123

token_endpoint: "https://evil.test/oauth2/token",

126124

}),

127-

) as unknown as typeof fetch;

125+

);

128126129127

await expect(fetchXaiOAuthDiscovery({ fetchImpl: poisonedFetch })).rejects.toThrow(

130128

"untrusted token endpoint",

@@ -133,10 +131,10 @@ describe("xAI OAuth", () => {

133131134132

it("refreshes with the cached token endpoint and preserves refresh fallback", async () => {

135133

vi.stubEnv("OPENCLAW_VERSION", "2026.3.22");

136-

const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {

134+

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

137135

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

138136

expect(typeof init?.body).toBe("string");

139-

const body = init?.body as string;

137+

const body = requireStringBody(init);

140138

expect(body).toContain("grant_type=refresh_token");

141139

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

142140

expect(body).toContain("refresh_token=refresh-1");

@@ -146,19 +144,17 @@ describe("xAI OAuth", () => {

146144

access_token: "access-2",

147145

expires_in: 120,

148146

});

149-

}) as unknown as typeof fetch;

147+

});

150148151-

const refreshed = await refreshXaiOAuthCredential(

152-

{

153-

type: "oauth",

154-

provider: "xai",

155-

access: "access-1",

156-

refresh: "refresh-1",

157-

expires: 100,

158-

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

159-

} as unknown as Parameters<typeof refreshXaiOAuthCredential>[0],

160-

{ fetchImpl, now: () => 1_000 },

161-

);

149+

const credential = {

150+

type: "oauth",

151+

provider: "xai",

152+

access: "access-1",

153+

refresh: "refresh-1",

154+

expires: 100,

155+

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

156+

} satisfies OAuthCredential & { tokenEndpoint: string };

157+

const refreshed = await refreshXaiOAuthCredential(credential, { fetchImpl, now: () => 1_000 });

162158163159

expect(fetchImpl).toHaveBeenCalledWith("https://auth.x.ai/oauth2/token", expect.any(Object));

164160

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

@@ -205,28 +201,30 @@ describe("xAI OAuth", () => {

205201

}),

206202

);

207203

vi.stubGlobal("fetch", fetchImpl);

208-

const ctx = {

204+

const note = vi.fn(async () => {});

205+

const openUrl = vi.fn(async () => {});

206+

const runtime = createRuntimeEnv();

207+

const ctx: ProviderAuthContext = {

209208

config: {},

210209

isRemote: true,

211-

openUrl: vi.fn(async () => {}),

212-

prompter: {

210+

openUrl,

211+

prompter: createTestWizardPrompter({

213212

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

214-

note: vi.fn(async () => {}),

215-

},

216-

runtime: {

217-

log: vi.fn(),

213+

note,

214+

}),

215+

runtime,

216+

oauth: {

217+

createVpsAwareHandlers: () => {

218+

throw new Error("unexpected VPS OAuth handler request");

219+

},

218220

},

219-

oauth: {},

220221

};

221222222-

const result = await loginXaiDeviceCode(ctx as never);

223+

const result = await loginXaiDeviceCode(ctx);

223224224-

expect(ctx.openUrl).not.toHaveBeenCalled();

225-

expect(ctx.prompter.note).toHaveBeenCalledWith(

226-

expect.stringContaining("ABCD-1234"),

227-

"xAI device code",

228-

);

229-

const remoteLog = ctx.runtime.log.mock.calls[0]?.[0];

225+

expect(openUrl).not.toHaveBeenCalled();

226+

expect(note).toHaveBeenCalledWith(expect.stringContaining("ABCD-1234"), "xAI device code");

227+

const remoteLog = runtime.log.mock.calls[0]?.[0];

230228

expect(remoteLog).toContain("https://accounts.x.ai/oauth2/device");

231229

expect(remoteLog).not.toContain("ABCD-1234");

232230

const deviceRequest = fetchImpl.mock.calls[1]?.[1];

@@ -243,8 +241,7 @@ describe("xAI OAuth", () => {

243241

);

244242

expect(tokenBody).toContain("device_code=device-code-1");

245243246-

const credential = result.profiles[0]?.credential as Record<string, unknown> | undefined;

247-

expect(credential).toMatchObject({

244+

expect(result.profiles[0]?.credential).toMatchObject({

248245

type: "oauth",

249246

provider: "xai",

250247

refresh: "refresh-1",

@@ -255,8 +252,8 @@ describe("xAI OAuth", () => {

255252

issuer: "https://auth.x.ai",

256253

authFlow: "device-code",

257254

accountId: "acct-1",

255+

access: expect.any(String),

258256

});

259-

expect(credential?.access).toEqual(expect.any(String));

260257

expect(progress.update).toHaveBeenCalledWith("Waiting for xAI device authorization...");

261258

expect(progress.stop).toHaveBeenCalledWith("xAI device code complete");

262259

});