* Validate that Codex openai-proxy base_url matches the configured OpenAI endpoint from /reflect. * @param {{ * codexConfigPath: string, * reflectPath: string, * readFileSync?: (path: import("node:fs").PathOrFileDescriptor, options?: import("node:fs").ObjectEncodingOptions & { flag?: strin
(options)
| 310 | * @returns {{ ok: boolean, reason?: string }} |
| 311 | */ |
| 312 | function validateCodexOpenAIBaseURLFromReflect(options) { |
| 313 | const readFileSync = (options && options.readFileSync) || fs.readFileSync; |
| 314 | const codexConfigPath = options && options.codexConfigPath; |
| 315 | const reflectPath = options && options.reflectPath; |
| 316 | if (!codexConfigPath || !reflectPath) return { ok: true }; |
| 317 | |
| 318 | let tomlContent; |
| 319 | let reflectContent; |
| 320 | try { |
| 321 | tomlContent = readFileSync(codexConfigPath, "utf8"); |
| 322 | reflectContent = readFileSync(reflectPath, "utf8"); |
| 323 | } catch { |
| 324 | return { ok: true }; |
| 325 | } |
| 326 | |
| 327 | const baseURL = extractOpenAIProxyBaseURLFromToml(tomlContent); |
| 328 | if (!baseURL) return { ok: true }; |
| 329 | const baseURLPort = extractPortFromURL(baseURL); |
| 330 | if (baseURLPort == null) return { ok: true }; |
| 331 | |
| 332 | let reflectData; |
| 333 | try { |
| 334 | reflectData = JSON.parse(reflectContent); |
| 335 | } catch { |
| 336 | return { ok: true }; |
| 337 | } |
| 338 | const openAIPort = getConfiguredOpenAIPortFromReflect(reflectData); |
| 339 | if (openAIPort == null) return { ok: true }; |
| 340 | if (openAIPort !== baseURLPort) { |
| 341 | return { |
| 342 | ok: false, |
| 343 | reason: `Codex openai-proxy base_url port mismatch: config.toml uses ${baseURLPort}, but /reflect reports OpenAI on port ${openAIPort}`, |
| 344 | }; |
| 345 | } |
| 346 | return { ok: true }; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Main entry point: run codex with retry logic for transient API failures. |
no test coverage detected