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

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
博客园_首页
量子位
T
Tailwind CSS Blog
博客园 - Franky
G
Google Developers Blog
D
DataBreaches.Net
Vercel News
Vercel News
B
Blog
Recent Announcements
Recent Announcements
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
爱范儿
爱范儿
博客园 - 【当耐特】
The Cloudflare Blog
H
Help Net Security
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
C
Check Point Blog
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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(feishu): normalize app registration poll timers · ope...
steipete · 2026-05-30 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -0,0 +1,61 @@

1+

import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";

2+

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

3+

import { beginAppRegistration, pollAppRegistration } from "./app-registration.js";

4+
5+

const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({

6+

fetchWithSsrFGuardMock: vi.fn(),

7+

}));

8+
9+

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

10+

fetchWithSsrFGuard: fetchWithSsrFGuardMock,

11+

}));

12+
13+

function mockFeishuJson(payload: unknown) {

14+

fetchWithSsrFGuardMock.mockResolvedValueOnce({

15+

response: new Response(JSON.stringify(payload), { status: 200 }),

16+

release: async () => {},

17+

});

18+

}

19+
20+

describe("Feishu app registration", () => {

21+

afterEach(() => {

22+

vi.useRealTimers();

23+

vi.restoreAllMocks();

24+

fetchWithSsrFGuardMock.mockReset();

25+

});

26+
27+

it("defaults unsafe begin polling lifetimes from provider responses", async () => {

28+

mockFeishuJson({

29+

device_code: "device-code",

30+

verification_uri_complete: "https://accounts.feishu.cn/verify?x=1",

31+

user_code: "user-code",

32+

interval: Number.POSITIVE_INFINITY,

33+

expire_in: Number.POSITIVE_INFINITY,

34+

});

35+
36+

await expect(beginAppRegistration()).resolves.toMatchObject({

37+

deviceCode: "device-code",

38+

userCode: "user-code",

39+

interval: 5,

40+

expireIn: 600,

41+

});

42+

});

43+
44+

it("clamps unsafe poll sleeps from provider intervals", async () => {

45+

vi.useFakeTimers();

46+

const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");

47+

fetchWithSsrFGuardMock.mockRejectedValueOnce(new Error("transient"));

48+
49+

const poll = pollAppRegistration({

50+

deviceCode: "device-code",

51+

interval: 10_000_000,

52+

expireIn: 10_000_000,

53+

});

54+

await vi.advanceTimersByTimeAsync(0);

55+
56+

expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);

57+
58+

await vi.advanceTimersByTimeAsync(MAX_TIMER_TIMEOUT_MS);

59+

await expect(poll).resolves.toEqual({ status: "timeout" });

60+

});

61+

});

Original file line numberDiff line numberDiff line change

@@ -1,3 +1,4 @@

1+

import { finiteSecondsToTimerSafeMilliseconds } from "openclaw/plugin-sdk/number-runtime";

12

/**

23

* Feishu app registration via OAuth device-code flow.

34

*

@@ -19,6 +20,8 @@ const LARK_ACCOUNTS_URL = "https://accounts.larksuite.com";

1920

const REGISTRATION_PATH = "/oauth/v1/app/registration";

2021
2122

const REQUEST_TIMEOUT_MS = 10_000;

23+

const DEFAULT_REGISTRATION_POLL_INTERVAL_SECONDS = 5;

24+

const DEFAULT_REGISTRATION_EXPIRE_SECONDS = 600;

2225
2326

// ---------------------------------------------------------------------------

2427

// Types

@@ -151,8 +154,14 @@ export async function beginAppRegistration(domain: FeishuDomain = "feishu"): Pro

151154

deviceCode: res.device_code,

152155

qrUrl: qrUrl.toString(),

153156

userCode: res.user_code,

154-

interval: res.interval || 5,

155-

expireIn: res.expire_in || 600,

157+

interval:

158+

finiteSecondsToTimerSafeMilliseconds(res.interval) === undefined

159+

? DEFAULT_REGISTRATION_POLL_INTERVAL_SECONDS

160+

: res.interval,

161+

expireIn:

162+

finiteSecondsToTimerSafeMilliseconds(res.expire_in) === undefined

163+

? DEFAULT_REGISTRATION_EXPIRE_SECONDS

164+

: res.expire_in,

156165

};

157166

}

158167

@@ -175,7 +184,11 @@ export async function pollAppRegistration(params: {

175184

let domain: FeishuDomain = initialDomain;

176185

let domainSwitched = false;

177186
178-

const deadline = Date.now() + expireIn * 1000;

187+

const expireInMs =

188+

finiteSecondsToTimerSafeMilliseconds(expireIn) ??

189+

finiteSecondsToTimerSafeMilliseconds(DEFAULT_REGISTRATION_EXPIRE_SECONDS) ??

190+

REQUEST_TIMEOUT_MS;

191+

const deadline = Date.now() + expireInMs;

179192
180193

while (Date.now() < deadline) {

181194

if (abortSignal?.aborted) {

@@ -193,7 +206,7 @@ export async function pollAppRegistration(params: {

193206

});

194207

} catch {

195208

// Transient network error — keep polling.

196-

await sleep(currentInterval * 1000);

209+

await sleepRegistrationPollInterval(currentInterval);

197210

continue;

198211

}

199212

@@ -239,7 +252,7 @@ export async function pollAppRegistration(params: {

239252

}

240253

}

241254
242-

await sleep(currentInterval * 1000);

255+

await sleepRegistrationPollInterval(currentInterval);

243256

}

244257
245258

return { status: "timeout" };

@@ -329,3 +342,11 @@ export async function getAppOwnerOpenId(params: {

329342

function sleep(ms: number): Promise<void> {

330343

return new Promise((resolve) => setTimeout(resolve, ms));

331344

}

345+
346+

function sleepRegistrationPollInterval(intervalSeconds: number): Promise<void> {

347+

const intervalMs =

348+

finiteSecondsToTimerSafeMilliseconds(intervalSeconds) ??

349+

finiteSecondsToTimerSafeMilliseconds(DEFAULT_REGISTRATION_POLL_INTERVAL_SECONDS) ??

350+

REQUEST_TIMEOUT_MS;

351+

return sleep(intervalMs);

352+

}