Skip to content

Commit de0a01f

Browse files
committed
fix(doctor): parse Codex config section headers with inline comments
1 parent ef5321e commit de0a01f

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

dist/bin/cc-safety-net.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5317,7 +5317,7 @@ function _parseCodexConfig(content) {
53175317
const trimmed = line.trim();
53185318
if (trimmed === "" || trimmed.startsWith("#"))
53195319
return activeSection;
5320-
const sectionMatch = /^\[([^\]]+)]$/.exec(trimmed);
5320+
const sectionMatch = /^\[([^\]]+)]\s*(?:#.*)?$/.exec(trimmed);
53215321
if (sectionMatch)
53225322
return sectionMatch[1];
53235323
if (activeSection === "features") {

src/bin/doctor/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function _parseCodexConfig(content: string): CodexConfig {
412412
const trimmed = line.trim();
413413
if (trimmed === '' || trimmed.startsWith('#')) return activeSection;
414414

415-
const sectionMatch = /^\[([^\]]+)]$/.exec(trimmed);
415+
const sectionMatch = /^\[([^\]]+)]\s*(?:#.*)?$/.exec(trimmed);
416416
if (sectionMatch) return sectionMatch[1];
417417

418418
if (activeSection === 'features') {

tests/bin/doctor/hooks.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,36 @@ describe('detectAllHooks', () => {
12771277
}
12781278
});
12791279

1280+
test('Codex: parses config section headers with inline comments', () => {
1281+
const tmpBase = join(tmpdir(), `doctor-codex-${Date.now()}`);
1282+
const homeDir = join(tmpBase, 'home');
1283+
const projectDir = join(tmpBase, 'project');
1284+
const codexHome = join(homeDir, '.codex');
1285+
mkdirSync(projectDir, { recursive: true });
1286+
mkdirSync(codexHome, { recursive: true });
1287+
_createCodexPluginVersion(codexHome);
1288+
writeFileSync(
1289+
join(codexHome, 'config.toml'),
1290+
`[features] # required for plugin hooks
1291+
plugin_hooks = true
1292+
1293+
[plugins."safety-net@cc-marketplace"] # installed from marketplace
1294+
enabled = true
1295+
`,
1296+
);
1297+
1298+
try {
1299+
const hooks = detectAllHooks(projectDir, { homeDir });
1300+
const codex = hooks.find((hook) => hook.platform === 'codex');
1301+
1302+
expect(codex?.status).toBe('configured');
1303+
expect(codex?.method).toBe('plugin cache');
1304+
expect(codex?.errors).toBeUndefined();
1305+
} finally {
1306+
rmSync(tmpBase, { recursive: true, force: true });
1307+
}
1308+
});
1309+
12801310
test('Codex: uses CODEX_HOME when set', () => {
12811311
const tmpBase = join(tmpdir(), `doctor-codex-${Date.now()}`);
12821312
const homeDir = join(tmpBase, 'home');

0 commit comments

Comments
 (0)