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

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
D
DataBreaches.Net
宝玉的分享
宝玉的分享
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
腾讯CDC
博客园_首页
The Cloudflare Blog
S
SegmentFault 最新的问题
C
Check Point Blog
美团技术团队
爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale

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
test: guard proxy fetch mock calls · openclaw/openclaw@fc...
steipete · 2026-05-12 · via Recent Commits to openclaw:main

@@ -92,6 +92,32 @@ function requireProxyFetch(

9292

return fetchFn;

9393

}

949495+

function requireUndiciFetchCall(index = 0): unknown[] {

96+

const call = undiciFetch.mock.calls[index];

97+

if (!call) {

98+

throw new Error(`expected undici fetch call at index ${index}`);

99+

}

100+

return call;

101+

}

102+103+

function requireUndiciFetchInit(index = 0): Record<string, unknown> {

104+

const init = requireUndiciFetchCall(index)[1];

105+

if (!init || typeof init !== "object" || Array.isArray(init)) {

106+

throw new Error(`expected undici fetch init at index ${index}`);

107+

}

108+

return init as Record<string, unknown>;

109+

}

110+111+

function requireHeadersInit(value: unknown, label: string): HeadersInit {

112+

if (value === undefined || value instanceof Headers || Array.isArray(value)) {

113+

return value as HeadersInit;

114+

}

115+

if (value && typeof value === "object") {

116+

return value as HeadersInit;

117+

}

118+

throw new Error(`expected ${label} headers`);

119+

}

120+95121

function clearProxyEnv(): void {

96122

for (const key of PROXY_ENV_KEYS) {

97123

delete process.env[key];

@@ -128,9 +154,10 @@ describe("makeProxyFetch", () => {

128154129155

expect(proxyAgentSpy).toHaveBeenCalledWith(proxyUrl);

130156

expect(undiciFetch).toHaveBeenCalledOnce();

131-

const [input, init] = undiciFetch.mock.calls[0] ?? [];

157+

const [input] = requireUndiciFetchCall();

158+

const init = requireUndiciFetchInit();

132159

expect(input).toBe("https://api.example.com/v1/audio");

133-

expect(init?.dispatcher).toBe(getLastAgent());

160+

expect(init.dispatcher).toBe(getLastAgent());

134161

});

135162136163

it("reuses the same ProxyAgent across calls", async () => {

@@ -139,9 +166,9 @@ describe("makeProxyFetch", () => {

139166

const proxyFetch = makeProxyFetch("http://proxy.test:8080");

140167141168

await proxyFetch("https://api.example.com/one");

142-

const firstDispatcher = undiciFetch.mock.calls[0]?.[1]?.dispatcher;

169+

const firstDispatcher = requireUndiciFetchInit().dispatcher;

143170

await proxyFetch("https://api.example.com/two");

144-

const secondDispatcher = undiciFetch.mock.calls[1]?.[1]?.dispatcher;

171+

const secondDispatcher = requireUndiciFetchInit(1).dispatcher;

145172146173

expect(proxyAgentSpy).toHaveBeenCalledOnce();

147174

expect(secondDispatcher).toBe(firstDispatcher);

@@ -164,13 +191,13 @@ describe("makeProxyFetch", () => {

164191

body: form,

165192

});

166193167-

const passedInit = undiciFetch.mock.calls[0]?.[1];

168-

expect(passedInit?.body).toBeInstanceOf(MockUndiciFormData);

169-

const passedBody = passedInit?.body as InstanceType<typeof MockUndiciFormData>;

194+

const passedInit = requireUndiciFetchInit();

195+

expect(passedInit.body).toBeInstanceOf(MockUndiciFormData);

196+

const passedBody = passedInit.body as InstanceType<typeof MockUndiciFormData>;

170197

expect(passedBody.get("model")).toBe("whisper-1");

171198

expect(passedBody.get("file")).toBeInstanceOf(Blob);

172199

expect(passedBody.entriesList.find(([key]) => key === "file")?.[2]).toBe("voice.ogg");

173-

const sentHeaders = new Headers(passedInit?.headers);

200+

const sentHeaders = new Headers(requireHeadersInit(passedInit.headers, "FormData proxy"));

174201

expect(sentHeaders.has("content-length")).toBe(false);

175202

expect(sentHeaders.has("content-type")).toBe(false);

176203

});

@@ -186,7 +213,7 @@ describe("makeProxyFetch", () => {

186213

body,

187214

});

188215189-

expect(undiciFetch.mock.calls[0]?.[1]?.body).toBe(body);

216+

expect(requireUndiciFetchInit().body).toBe(body);

190217

});

191218192219

it("drops symbol metadata from plain header dictionaries before undici fetch", async () => {

@@ -207,10 +234,12 @@ describe("makeProxyFetch", () => {

207234

body: "{}",

208235

});

209236210-

const passedHeaders = undiciFetch.mock.calls[0]?.[1]?.headers;

237+

const passedHeaders = requireUndiciFetchInit().headers;

211238

expect(passedHeaders).not.toBe(headers);

212239

expect(Object.getOwnPropertySymbols(passedHeaders as object)).toStrictEqual([]);

213-

expect(new Headers(passedHeaders).get("content-type")).toBe("application/json");

240+

expect(

241+

new Headers(requireHeadersInit(passedHeaders, "plain dictionary proxy")).get("content-type"),

242+

).toBe("application/json");

214243

expect(Object.getOwnPropertySymbols(headers)).toHaveLength(1);

215244

});

216245

@@ -226,7 +255,7 @@ describe("makeProxyFetch", () => {

226255

body: form as unknown as BodyInit,

227256

});

228257229-

expect(undiciFetch.mock.calls[0]?.[1]?.body).toBe(form);

258+

expect(requireUndiciFetchInit().body).toBe(form);

230259

});

231260232261

it("converts FormData-like bodies from another implementation", async () => {

@@ -245,9 +274,9 @@ describe("makeProxyFetch", () => {

245274

body: formLike as unknown as BodyInit,

246275

});

247276248-

const passedInit = undiciFetch.mock.calls[0]?.[1];

249-

expect(passedInit?.body).toBeInstanceOf(MockUndiciFormData);

250-

expect(passedInit?.body.get("model")).toBe("whisper-1");

277+

const passedBody = requireUndiciFetchInit().body;

278+

expect(passedBody).toBeInstanceOf(MockUndiciFormData);

279+

expect((passedBody as InstanceType<typeof MockUndiciFormData>).get("model")).toBe("whisper-1");

251280

});

252281

});

253282

@@ -302,9 +331,10 @@ describe("resolveProxyFetchFromEnv", () => {

302331303332

await fetchFn("https://api.example.com");

304333

expect(undiciFetch).toHaveBeenCalledOnce();

305-

const [input, init] = undiciFetch.mock.calls[0] ?? [];

334+

const [input] = requireUndiciFetchCall();

335+

const init = requireUndiciFetchInit();

306336

expect(input).toBe("https://api.example.com");

307-

expect(init?.dispatcher).toBe(EnvHttpProxyAgent.lastCreated);

337+

expect(init.dispatcher).toBe(EnvHttpProxyAgent.lastCreated);

308338

});

309339310340

it("converts global FormData bodies when using proxy env fetch", async () => {

@@ -326,10 +356,12 @@ describe("resolveProxyFetchFromEnv", () => {

326356

body: form,

327357

});

328358329-

const passedInit = undiciFetch.mock.calls[0]?.[1];

330-

expect(passedInit?.body).toBeInstanceOf(MockUndiciFormData);

331-

expect(passedInit?.body.get("model")).toBe("test-model");

332-

expect(passedInit?.body.get("file")).toBeInstanceOf(Blob);

359+

const passedBody = requireUndiciFetchInit().body;

360+

expect(passedBody).toBeInstanceOf(MockUndiciFormData);

361+

expect((passedBody as InstanceType<typeof MockUndiciFormData>).get("model")).toBe("test-model");

362+

expect((passedBody as InstanceType<typeof MockUndiciFormData>).get("file")).toBeInstanceOf(

363+

Blob,

364+

);

333365

});

334366335367

it("returns proxy fetch when HTTP_PROXY is set", () => {