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

推荐订阅源

J
Java Code Geeks
Martin Fowler
Martin Fowler
B
Blog RSS Feed
D
DataBreaches.Net
L
LangChain Blog
月光博客
月光博客
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
美团技术团队
Jina AI
Jina AI
博客园 - 司徒正美
雷峰网
雷峰网
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
小众软件
小众软件
罗磊的独立博客
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta

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(agents): inject resolved OAuth bearer into boundary-a...
openperf · 2026-04-29 · via Recent Commits to openclaw:main

@@ -1,11 +1,32 @@

1+

import type { StreamFn } from "@mariozechner/pi-agent-core";

12

import { streamSimple } from "@mariozechner/pi-ai";

23

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

4+

import * as providerTransportStream from "../provider-transport-stream.js";

35

import {

46

describeEmbeddedAgentStreamStrategy,

57

resolveEmbeddedAgentApiKey,

68

resolveEmbeddedAgentStreamFn,

79

} from "./stream-resolution.js";

81011+

// Wrap createBoundaryAwareStreamFnForModel with a spy that delegates to the

12+

// real implementation by default so existing routing tests still observe a

13+

// real transport stream; per-test overrideBoundaryAwareStreamFnOnce() injects

14+

// a probe stream when a regression test needs to inspect the wrapped

15+

// transport's options.

16+

vi.mock("../provider-transport-stream.js", async (importOriginal) => {

17+

const actual = await importOriginal<typeof providerTransportStream>();

18+

return {

19+

...actual,

20+

createBoundaryAwareStreamFnForModel: vi.fn(actual.createBoundaryAwareStreamFnForModel),

21+

};

22+

});

23+24+

const overrideBoundaryAwareStreamFnOnce = (streamFn: StreamFn): void => {

25+

vi.mocked(providerTransportStream.createBoundaryAwareStreamFnForModel).mockReturnValueOnce(

26+

streamFn,

27+

);

28+

};

29+930

describe("describeEmbeddedAgentStreamStrategy", () => {

1031

it("describes provider-owned stream paths explicitly", () => {

1132

expect(

@@ -203,4 +224,138 @@ describe("resolveEmbeddedAgentStreamFn", () => {

203224

signal: explicitSignal,

204225

});

205226

});

227+228+

it("injects the resolved run api key into the boundary-aware Codex Responses fallback", async () => {

229+

const innerStreamFn = vi.fn(async (_model, _context, options) => options);

230+

overrideBoundaryAwareStreamFnOnce(innerStreamFn as never);

231+

const streamFn = resolveEmbeddedAgentStreamFn({

232+

currentStreamFn: undefined,

233+

shouldUseWebSocketTransport: false,

234+

sessionId: "session-1",

235+

model: {

236+

api: "openai-codex-responses",

237+

provider: "openai-codex",

238+

id: "gpt-5.5",

239+

} as never,

240+

resolvedApiKey: "oauth-bearer-token",

241+

});

242+243+

await expect(

244+

streamFn({ provider: "openai-codex", id: "gpt-5.5" } as never, {} as never, {}),

245+

).resolves.toMatchObject({ apiKey: "oauth-bearer-token" });

246+

expect(innerStreamFn).toHaveBeenCalledTimes(1);

247+

});

248+249+

it("falls back to authStorage when no resolved api key is available for boundary-aware fallback", async () => {

250+

const innerStreamFn = vi.fn(async (_model, _context, options) => options);

251+

const authStorage = {

252+

getApiKey: vi.fn(async () => "stored-bearer-token"),

253+

};

254+

overrideBoundaryAwareStreamFnOnce(innerStreamFn as never);

255+

const streamFn = resolveEmbeddedAgentStreamFn({

256+

currentStreamFn: undefined,

257+

shouldUseWebSocketTransport: false,

258+

sessionId: "session-1",

259+

model: {

260+

api: "openai-codex-responses",

261+

provider: "openai-codex",

262+

id: "gpt-5.5",

263+

} as never,

264+

authStorage,

265+

});

266+267+

await expect(

268+

streamFn({ provider: "openai-codex", id: "gpt-5.5" } as never, {} as never, {}),

269+

).resolves.toMatchObject({ apiKey: "stored-bearer-token" });

270+

expect(authStorage.getApiKey).toHaveBeenCalledWith("openai-codex");

271+

});

272+273+

it("forwards the run abort signal into the boundary-aware fallback when callers omit one", async () => {

274+

const innerStreamFn = vi.fn(async (_model, _context, options) => options);

275+

const runSignal = new AbortController().signal;

276+

overrideBoundaryAwareStreamFnOnce(innerStreamFn as never);

277+

const streamFn = resolveEmbeddedAgentStreamFn({

278+

currentStreamFn: undefined,

279+

shouldUseWebSocketTransport: false,

280+

sessionId: "session-1",

281+

signal: runSignal,

282+

model: {

283+

api: "openai-codex-responses",

284+

provider: "openai-codex",

285+

id: "gpt-5.5",

286+

} as never,

287+

resolvedApiKey: "oauth-bearer-token",

288+

});

289+290+

await expect(

291+

streamFn({ provider: "openai-codex", id: "gpt-5.5" } as never, {} as never, {}),

292+

).resolves.toMatchObject({ signal: runSignal, apiKey: "oauth-bearer-token" });

293+

});

294+295+

it("does not overwrite an explicit signal on the boundary-aware fallback path", async () => {

296+

const innerStreamFn = vi.fn(async (_model, _context, options) => options);

297+

const runSignal = new AbortController().signal;

298+

const explicitSignal = new AbortController().signal;

299+

overrideBoundaryAwareStreamFnOnce(innerStreamFn as never);

300+

const streamFn = resolveEmbeddedAgentStreamFn({

301+

currentStreamFn: undefined,

302+

shouldUseWebSocketTransport: false,

303+

sessionId: "session-1",

304+

signal: runSignal,

305+

model: {

306+

api: "openai-codex-responses",

307+

provider: "openai-codex",

308+

id: "gpt-5.5",

309+

} as never,

310+

resolvedApiKey: "oauth-bearer-token",

311+

});

312+313+

await expect(

314+

streamFn({ provider: "openai-codex", id: "gpt-5.5" } as never, {} as never, {

315+

signal: explicitSignal,

316+

}),

317+

).resolves.toMatchObject({ signal: explicitSignal });

318+

});

319+320+

it("forwards the run signal on the sync boundary-aware fallback path without auth credentials", async () => {

321+

const innerStreamFn = vi.fn(async (_model, _context, options) => options);

322+

const runSignal = new AbortController().signal;

323+

overrideBoundaryAwareStreamFnOnce(innerStreamFn as never);

324+

const streamFn = resolveEmbeddedAgentStreamFn({

325+

currentStreamFn: undefined,

326+

shouldUseWebSocketTransport: false,

327+

sessionId: "session-1",

328+

signal: runSignal,

329+

model: {

330+

api: "openai-codex-responses",

331+

provider: "openai-codex",

332+

id: "gpt-5.5",

333+

} as never,

334+

});

335+336+

await expect(

337+

streamFn({ provider: "openai-codex", id: "gpt-5.5" } as never, {} as never, {}),

338+

).resolves.toMatchObject({ signal: runSignal });

339+

});

340+341+

it("does not strip cache boundary markers on the boundary-aware fallback path", async () => {

342+

const innerStreamFn = vi.fn(async (_model, context, _options) => context);

343+

overrideBoundaryAwareStreamFnOnce(innerStreamFn as never);

344+

const streamFn = resolveEmbeddedAgentStreamFn({

345+

currentStreamFn: undefined,

346+

shouldUseWebSocketTransport: false,

347+

sessionId: "session-1",

348+

model: {

349+

api: "openai-codex-responses",

350+

provider: "openai-codex",

351+

id: "gpt-5.5",

352+

} as never,

353+

resolvedApiKey: "oauth-bearer-token",

354+

});

355+356+

const systemPrompt = "intro<<openclaw-cache-boundary>>tail";

357+

await expect(

358+

streamFn({ provider: "openai-codex", id: "gpt-5.5" } as never, { systemPrompt } as never, {}),

359+

).resolves.toMatchObject({ systemPrompt });

360+

});

206361

});