From 44e65428e0ccf1c24008bc521bdd3ad14f9a98ed Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Thu, 14 May 2026 13:46:34 -0400 Subject: [PATCH] test(codex): harden hooks.json sessionStart test helper --- tests/codex-config.test.cjs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/codex-config.test.cjs b/tests/codex-config.test.cjs index 5be0a224f..a704507e0 100644 --- a/tests/codex-config.test.cjs +++ b/tests/codex-config.test.cjs @@ -91,11 +91,12 @@ function readHooksSessionStartCommands(codexHome) { ? parsed.hooks : parsed; const sessionStart = Array.isArray(table.SessionStart) ? table.SessionStart : []; - return sessionStart.flatMap((entry) => - (Array.isArray(entry?.hooks) ? entry.hooks : []) - .map((hook) => hook && hook.command) - .filter((cmd) => typeof cmd === 'string') - ); + return sessionStart.flatMap((entry) => [ + ...(typeof entry?.command === 'string' ? [entry.command] : []), + ...(Array.isArray(entry?.hooks) + ? entry.hooks.map((hook) => hook && hook.command).filter((cmd) => typeof cmd === 'string') + : []), + ]); } function countMatches(content, pattern) { @@ -1432,7 +1433,11 @@ describe('Codex install hook configuration (e2e)', () => { runCodexInstall(codexHome); const configContent = readCodexConfig(codexHome); - assert.ok(!configContent.includes('gsd-check-update.js'), 'config.toml does not carry managed SessionStart hooks'); + const parsedConfig = parseTomlToObject(configContent); + assert.ok( + !parsedConfig.hooks || !Array.isArray(parsedConfig.hooks.SessionStart), + 'config.toml does not carry managed SessionStart hooks' + ); const hooksJsonCommands = readHooksSessionStartCommands(codexHome); assert.equal( hooksJsonCommands.some((cmd) => cmd.includes('gsd-check-update.js')),