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

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
美团技术团队
D
Docker
WordPress大学
WordPress大学
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
Y
Y Combinator Blog
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
S
SegmentFault 最新的问题
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans

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(openai): reuse Codex OAuth for OpenAI images · opencl...
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -1,8 +1,5 @@

11

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

2-

import {

3-

buildOpenAICodexImageGenerationProvider,

4-

buildOpenAIImageGenerationProvider,

5-

} from "./image-generation-provider.js";

2+

import { buildOpenAIImageGenerationProvider } from "./image-generation-provider.js";

6374

const {

85

resolveApiKeyForProviderMock,

@@ -11,7 +8,13 @@ const {

118

assertOkOrThrowHttpErrorMock,

129

resolveProviderHttpRequestConfigMock,

1310

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

14-

resolveApiKeyForProviderMock: vi.fn(async () => ({ apiKey: "openai-key" })),

11+

resolveApiKeyForProviderMock: vi.fn(

12+

async (_params?: {

13+

provider?: string;

14+

}): Promise<{ apiKey?: string; source?: string; mode?: string }> => ({

15+

apiKey: "openai-key",

16+

}),

17+

),

1518

postJsonRequestMock: vi.fn(),

1619

postMultipartRequestMock: vi.fn(),

1720

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

@@ -76,9 +79,19 @@ function mockCodexImageStream(params: { imageData?: string; revisedPrompt?: stri

7679

}));

7780

}

788182+

function mockCodexAuthOnly() {

83+

resolveApiKeyForProviderMock.mockImplementation(async (params?: { provider?: string }) => {

84+

if (params?.provider === "openai-codex") {

85+

return { apiKey: "codex-key", source: "profile:openai-codex:default", mode: "oauth" };

86+

}

87+

return {};

88+

});

89+

}

90+7991

describe("openai image generation provider", () => {

8092

afterEach(() => {

81-

resolveApiKeyForProviderMock.mockClear();

93+

resolveApiKeyForProviderMock.mockReset();

94+

resolveApiKeyForProviderMock.mockResolvedValue({ apiKey: "openai-key" });

8295

postJsonRequestMock.mockReset();

8396

postMultipartRequestMock.mockReset();

8497

assertOkOrThrowHttpErrorMock.mockClear();

@@ -281,13 +294,14 @@ describe("openai image generation provider", () => {

281294

expect(result.images).toHaveLength(1);

282295

});

283296284-

it("registers Codex OAuth image generation through Responses streaming", async () => {

297+

it("falls back to Codex OAuth image generation through Responses streaming", async () => {

298+

mockCodexAuthOnly();

285299

mockCodexImageStream({ imageData: "codex-image", revisedPrompt: "revised codex prompt" });

286300287-

const provider = buildOpenAICodexImageGenerationProvider();

301+

const provider = buildOpenAIImageGenerationProvider();

288302

const authStore = { version: 1, profiles: {} };

289303

const result = await provider.generateImage({

290-

provider: "openai-codex",

304+

provider: "openai",

291305

model: "gpt-image-2",

292306

prompt: "Draw a Codex lighthouse",

293307

cfg: {},

@@ -296,6 +310,12 @@ describe("openai image generation provider", () => {

296310

size: "1024x1536",

297311

});

298312313+

expect(resolveApiKeyForProviderMock).toHaveBeenCalledWith(

314+

expect.objectContaining({

315+

provider: "openai",

316+

store: authStore,

317+

}),

318+

);

299319

expect(resolveApiKeyForProviderMock).toHaveBeenCalledWith(

300320

expect.objectContaining({

301321

provider: "openai-codex",

@@ -306,7 +326,7 @@ describe("openai image generation provider", () => {

306326

expect.objectContaining({

307327

defaultBaseUrl: "https://chatgpt.com/backend-api/codex",

308328

defaultHeaders: expect.objectContaining({

309-

Authorization: "Bearer openai-key",

329+

Authorization: "Bearer codex-key",

310330

Accept: "text/event-stream",

311331

}),

312332

provider: "openai-codex",

@@ -353,11 +373,12 @@ describe("openai image generation provider", () => {

353373

});

354374355375

it("sends Codex reference images as Responses input images", async () => {

376+

mockCodexAuthOnly();

356377

mockCodexImageStream();

357378358-

const provider = buildOpenAICodexImageGenerationProvider();

379+

const provider = buildOpenAIImageGenerationProvider();

359380

await provider.generateImage({

360-

provider: "openai-codex",

381+

provider: "openai",

361382

model: "gpt-image-2",

362383

prompt: "Use the reference image",

363384

cfg: {},

@@ -384,11 +405,12 @@ describe("openai image generation provider", () => {

384405

});

385406386407

it("satisfies Codex count by issuing one Responses request per image", async () => {

408+

mockCodexAuthOnly();

387409

mockCodexImageStream({ imageData: "codex-image" });

388410389-

const provider = buildOpenAICodexImageGenerationProvider();

411+

const provider = buildOpenAIImageGenerationProvider();

390412

const result = await provider.generateImage({

391-

provider: "openai-codex",

413+

provider: "openai",

392414

model: "gpt-image-2",

393415

prompt: "Draw two Codex icons",

394416

cfg: {},