Skip to content

Commit 647c00d

Browse files
author
jzli
committed
fix(codex): recognize trailing comments on provider table headers
TOML v1.0 permits a comment after a table header, so [model_providers.opencodex] # comment is a valid root header form. The exact string compare missed it, skipping provider cleanup on inject and restore and letting hasOpencodexRouting miss the table. Match the root header by regex with optional whitespace + trailing comment; the sub-table prefix check already tolerates trailing comments by construction. Regression tests for commented root and sub-table headers.
1 parent 76906a3 commit 647c00d

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎src/codex/inject.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,11 @@ export async function injectCodexConfig(
11041104
* `[model_providers.opencodex_backup]`-style tables out of scope.
11051105
*/
11061106
function isOcxProviderHeaderLine(trimmedLine: string): boolean {
1107+
// Root form matched by regex, not equality: TOML v1.0 allows a trailing comment
1108+
// (`[model_providers.opencodex] # comment`), and an exact compare would miss that form.
1109+
// The sub-table prefix check already tolerates trailing comments by construction.
11071110
return (
1108-
trimmedLine === "[model_providers.opencodex]" ||
1111+
/^\[model_providers\.opencodex\]\s*(?:#.*)?$/.test(trimmedLine) ||
11091112
trimmedLine.startsWith("[model_providers.opencodex.")
11101113
);
11111114
}

‎tests/codex-inject.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,36 @@ describe("Design B openai_base_url injection", () => {
431431
expect(stripped).toContain("[model_providers.opencodex_backup]");
432432
expect(stripped).toContain('name = "user backup"');
433433
});
434+
435+
test("a trailing comment on the root provider header is still recognized (TOML allows `[table] # comment`)", () => {
436+
const commented = [
437+
'model = "gpt-5.5"',
438+
"",
439+
"[model_providers.opencodex] # managed provider",
440+
'name = "OpenCodex Proxy"',
441+
'base_url = "http://127.0.0.1:10100/v1"',
442+
"",
443+
].join("\n");
444+
const stripped = stripOpencodexConfig(commented);
445+
446+
expect(stripped).not.toContain("model_providers.opencodex");
447+
expect(stripped).not.toContain("OpenCodex Proxy");
448+
expect(stripped).toContain('model = "gpt-5.5"');
449+
});
450+
451+
test("a trailing comment on the sub-table header is still recognized", () => {
452+
const commented = [
453+
'model = "gpt-5.5"',
454+
"",
455+
"[model_providers.opencodex.env_http_headers] # managed sub-table",
456+
'"x-opencodex-api-key" = "OPENCODEX_API_AUTH_TOKEN"',
457+
"",
458+
].join("\n");
459+
const stripped = stripOpencodexConfig(commented);
460+
461+
expect(stripped).not.toContain("opencodex");
462+
expect(stripped).toContain('model = "gpt-5.5"');
463+
});
434464
});
435465

436466
describe("EOL boundary helpers (Windows CRLF configs)", () => {

0 commit comments

Comments
 (0)