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

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
量子位
雷峰网
雷峰网
宝玉的分享
宝玉的分享
V
Visual Studio Blog
博客园_首页
小众软件
小众软件
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
S
SegmentFault 最新的问题
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学

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(codex): auto-clear api key for subscription auth · op...
pashpashpash · 2026-04-28 · via Recent Commits to openclaw:main

@@ -8,6 +8,7 @@ import {

88

bridgeCodexAppServerStartOptions,

99

refreshCodexAppServerAuthTokens,

1010

} from "./auth-bridge.js";

11+

import type { CodexAppServerStartOptions } from "./config.js";

11121213

const oauthMocks = vi.hoisted(() => ({

1314

refreshOpenAICodexToken: vi.fn(),

@@ -96,25 +97,54 @@ afterEach(() => {

9697

providerRuntimeMocks.refreshProviderOAuthCredentialWithPlugin.mockClear();

9798

});

9899100+

function createStartOptions(

101+

overrides: Partial<CodexAppServerStartOptions> = {},

102+

): CodexAppServerStartOptions {

103+

return {

104+

transport: "stdio",

105+

command: "codex",

106+

args: ["app-server"],

107+

headers: { authorization: "Bearer dev-token" },

108+

...overrides,

109+

};

110+

}

111+112+

async function writeCodexCliAuthFile(codexHome: string): Promise<void> {

113+

await fs.mkdir(codexHome, { recursive: true });

114+

await fs.writeFile(

115+

path.join(codexHome, "auth.json"),

116+

JSON.stringify({

117+

tokens: {

118+

access_token: "cli-access-token",

119+

refresh_token: "cli-refresh-token",

120+

account_id: "cli-account-123",

121+

},

122+

}),

123+

);

124+

}

125+99126

describe("bridgeCodexAppServerStartOptions", () => {

100-

it("leaves Codex app-server start options unchanged", async () => {

127+

it("clears an inherited OpenAI API key when local Codex CLI OAuth is available", async () => {

101128

const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));

102-

const startOptions = {

103-

transport: "stdio" as const,

104-

command: "codex",

105-

args: ["app-server"],

106-

headers: { authorization: "Bearer dev-token" },

129+

const codexHome = path.join(agentDir, "codex-home");

130+

const startOptions = createStartOptions({

107131

env: { CODEX_HOME: "/tmp/source-codex-home", EXISTING: "1" },

108132

clearEnv: ["FOO"],

109-

};

133+

});

134+

vi.stubEnv("CODEX_HOME", codexHome);

110135

try {

136+

await writeCodexCliAuthFile(codexHome);

137+111138

await expect(

112139

bridgeCodexAppServerStartOptions({

113140

startOptions,

114141

agentDir,

115-

authProfileId: "openai-codex:default",

116142

}),

117-

).resolves.toBe(startOptions);

143+

).resolves.toEqual({

144+

...startOptions,

145+

clearEnv: ["FOO", "OPENAI_API_KEY"],

146+

});

147+

expect(startOptions.clearEnv).toEqual(["FOO"]);

118148

await expect(fs.access(path.join(agentDir, "harness-auth"))).rejects.toMatchObject({

119149

code: "ENOENT",

120150

});

@@ -123,6 +153,126 @@ describe("bridgeCodexAppServerStartOptions", () => {

123153

}

124154

});

125155156+

it("clears an inherited OpenAI API key for an explicit Codex OAuth profile", async () => {

157+

const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));

158+

const startOptions = createStartOptions({ clearEnv: ["FOO"] });

159+

try {

160+

upsertAuthProfile({

161+

agentDir,

162+

profileId: "openai-codex:work",

163+

credential: {

164+

type: "oauth",

165+

provider: "openai-codex",

166+

access: "access-token",

167+

refresh: "refresh-token",

168+

expires: Date.now() + 24 * 60 * 60_000,

169+

accountId: "account-123",

170+

},

171+

});

172+173+

await expect(

174+

bridgeCodexAppServerStartOptions({

175+

startOptions,

176+

agentDir,

177+

authProfileId: "openai-codex:work",

178+

}),

179+

).resolves.toEqual({

180+

...startOptions,

181+

clearEnv: ["FOO", "OPENAI_API_KEY"],

182+

});

183+

} finally {

184+

await fs.rm(agentDir, { recursive: true, force: true });

185+

}

186+

});

187+188+

it("clears an inherited OpenAI API key for an explicit Codex token profile", async () => {

189+

const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));

190+

const startOptions = createStartOptions({ clearEnv: ["FOO"] });

191+

try {

192+

upsertAuthProfile({

193+

agentDir,

194+

profileId: "openai-codex:work",

195+

credential: {

196+

type: "token",

197+

provider: "openai-codex",

198+

token: "access-token",

199+

},

200+

});

201+202+

await expect(

203+

bridgeCodexAppServerStartOptions({

204+

startOptions,

205+

agentDir,

206+

authProfileId: "openai-codex:work",

207+

}),

208+

).resolves.toEqual({

209+

...startOptions,

210+

clearEnv: ["FOO", "OPENAI_API_KEY"],

211+

});

212+

} finally {

213+

await fs.rm(agentDir, { recursive: true, force: true });

214+

}

215+

});

216+217+

it("keeps an inherited OpenAI API key for an explicit Codex api-key profile", async () => {

218+

const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));

219+

const startOptions = createStartOptions({ clearEnv: ["FOO"] });

220+

try {

221+

upsertAuthProfile({

222+

agentDir,

223+

profileId: "openai-codex:work",

224+

credential: {

225+

type: "api_key",

226+

provider: "openai-codex",

227+

key: "explicit-api-key",

228+

},

229+

});

230+231+

await expect(

232+

bridgeCodexAppServerStartOptions({

233+

startOptions,

234+

agentDir,

235+

authProfileId: "openai-codex:work",

236+

}),

237+

).resolves.toBe(startOptions);

238+

} finally {

239+

await fs.rm(agentDir, { recursive: true, force: true });

240+

}

241+

});

242+243+

it("does not clear process environment for websocket app-server connections", async () => {

244+

const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));

245+

const startOptions = createStartOptions({

246+

transport: "websocket",

247+

url: "ws://127.0.0.1:1455",

248+

clearEnv: ["FOO"],

249+

});

250+

try {

251+

upsertAuthProfile({

252+

agentDir,

253+

profileId: "openai-codex:work",

254+

credential: {

255+

type: "oauth",

256+

provider: "openai-codex",

257+

access: "access-token",

258+

refresh: "refresh-token",

259+

expires: Date.now() + 24 * 60 * 60_000,

260+

accountId: "account-123",

261+

},

262+

});

263+264+

await expect(

265+

bridgeCodexAppServerStartOptions({

266+

startOptions,

267+

agentDir,

268+

authProfileId: "openai-codex:work",

269+

}),

270+

).resolves.toBe(startOptions);

271+

} finally {

272+

await fs.rm(agentDir, { recursive: true, force: true });

273+

}

274+

});

275+126276

it("applies an OpenAI Codex OAuth profile through app-server login", async () => {

127277

const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));

128278

const request = vi.fn(async () => ({ type: "chatgptAuthTokens" }));