* fix(#2773): emit correct Codex 0.124.0+ two-level nested hooks schema Codex 0.124.0's stable spec requires: [[hooks.SessionStart]] ← event entry (optional matcher) [[hooks.SessionStart.hooks]] ← handler sub-table type = "command" command = "node ..." Previous GSD versions wrote the flat [[hooks]] + event = "SessionStart" form (#2637) or a single-block [[hooks.SessionStart]] without the nested .hooks sub-table (#2760). Both are rejected by Codex 0.124.0+ at launch. Changes: bin/install.js - Hook block emission now always writes the two-level nested AoT form. - migrateCodexHooksMapFormat extended to also migrate flat [[hooks]] array-of-tables entries (event = "..." key → [[hooks.<EVENT>]] form). Flat [[hooks]] and [[hooks.<EVENT>]] are mutually exclusive TOML types; any pre-existing flat entries must be promoted before GSD appends its own namespaced hooks. - Migrated flat AoT blocks are inserted BEFORE the GSD marker so they stay in the "user" portion of the file and survive stripGsdFromCodexConfig. - stripCodexGsd* regexes cover all four historical block shapes. - validateCodexConfigSchema no longer rejects flat [[hooks]] at the root level (removing the false-positive that blocked install when users had their own AfterCommand hooks). The validator still enforces the nested [[hooks.<EVENT>.hooks]] shape for entries that have a .hooks sub-table. tests/ - bug-2760-codex-install-defensive.test.cjs: 29/29 passing. Added 5 new regression cases for fresh install, upgrade from each legacy shape, idempotent reinstall, and user hook preservation. - codex-config.test.cjs: 106/106 passing. All migration tests updated to assert [[hooks.<TYPE>.hooks]] sub-table (command now in handler level, not event-entry level). New tests: flat [[hooks]] migration (SessionStart, AfterCommand), install+uninstall preserves non-GSD AfterCommand hook. Closes #2773 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: address CodeRabbit review + CI regression in bug-2698-crlf-install CI regression (#2698 tests): Strip GSD-managed hook blocks BEFORE running migrateCodexHooksMapFormat. The previous order let migration convert the stale [[hooks]] + event = "SessionStart" + gsd-update-check.js block to [[hooks.SessionStart]] form before Shape 1 strip regex could match it; Shape 1 only matches the flat [[hooks]] form, so the stale block survived reinstall. Swapping to strip-then-migrate ensures only user-authored hooks reach the migration step. Shape 3/4 regexes also extended to match both gsd-check-update.js and the legacy gsd-update-check.js filename so no variant slips through. CodeRabbit actionable (major): migrateCodexHooksMapFormat now accepts single-quoted TOML event values (event = 'SessionStart') in the flat [[hooks]] filter and event-name extractor. TOML spec allows single-quoted literal strings; double-quote-only regexes silently skipped them, leaving the block unmigrated and triggering the hard-fail validator. CodeRabbit nitpicks: tests/codex-config.test.cjs: replace indexOf('[[hooks.AfterCommand]]') ordering check with parseTomlToObject structural assertions (no-source-grep rule). tests/bug-2760-codex-install-defensive.test.cjs: replace three content.match(/…/g).length raw-text counts with parseTomlToObject structural assertions for single-handler and single-event-entry invariants. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: address CodeRabbit review #2 — extractFlatHookEventName helper + type assertions - bin/install.js: consolidate TOML_QUOTED_STRING + TOML_EVENT_CAPTURE into a single extractFlatHookEventName() helper that rejects empty-string event values (event = "" or event = ''); previously two independent regexes had to be kept in sync and neither guarded against a blank event name producing a [[hooks.]] header - tests/bug-2760-codex-install-defensive.test.cjs: add comments explaining why the e.command fallback is retained in both allSessionStartCommands and afterToolCommands collectors — migration only upgrades [hooks.TYPE] map-format sections, not existing [[hooks.TYPE]] namespaced AoT entries authored with command at event-entry level; removing the fallback causes false failures for preserved user entries - tests/codex-config.test.cjs: add type = "command" assertions to all migration tests that verify .command but were missing .type checks; buildNestedBlock injects type = "command" when the source body has no explicit type key, so every migrated handler must carry it per the Codex 0.124.0+ schema 138 tests pass, 0 fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: CR round 3 + proactive audit — TOML quoting, stale AoT migration, strict validator Three real issues from CodeRabbit round 3, plus the collateral improvements they enable: bin/install.js — tomlBareKey() helper (#2773 CR6a) buildNestedBlock interpolated the raw event name into [[hooks.${type}]] and [[hooks.${type}.hooks]] headers without TOML escaping. An event name containing spaces or punctuation (e.g. "Before Tool") would produce invalid TOML that parseTomlToObject would subsequently reject. Added tomlBareKey() — wraps the key in double-quoted TOML strings when it contains non-bare-key characters ([A-Za-z0-9_-]). bin/install.js — staleNamespacedAotSections migration path (#2773 CR6b) migrateCodexHooksMapFormat handled [hooks.TYPE] (map-format) and flat [[hooks]] with event = "..." but ignored [[hooks.TYPE]] AoT entries that carried handler fields (command, type, timeout, statusMessage) at event-entry level without a nested [[hooks.TYPE.hooks]] sub-table. This is the pre-#2773 single-block shape that Codex 0.124.0+ rejects. Added staleNamespacedAotSections as the third migration category: detected by STALE_HANDLER_FIELD_PATTERN + absence of a [[hooks.TYPE.hooks]] sub-table in the same file; promoted to the two-level nested form by buildNestedBlock. Matcher-only entries (no handler fields) are intentionally skipped. bin/install.js — validator now rejects event-level handler fields (#2773 CR6c) With migration covering the stale AoT shape, validateCodexConfigSchema can be strict: entries that have handler fields at event-entry level but no .hooks sub-array return ok: false instead of silently passing. Matcher-only entries (no handler fields and no .hooks) remain valid as event filters. tests/codex-config.test.cjs — four new migration tests + missing type assertion Four tests cover the new stale AoT migration path: single-entry promotion, already-nested entry is left untouched (no double-wrap), multiple event types, and matcher-only entry is skipped. Added the missing type = "command" assertion to the CRLF migration test (the one miss from CR round 2). tests/bug-2760-codex-install-defensive.test.cjs — strict .hooks-only collectors With stale AoT entries now migrated, the entry.command fallbacks in allSessionStartCommands and afterToolCommands are dead code. Replaced with strict entry.hooks-only collection guarded by an every(Array.isArray(e.hooks)) pre-assertion, so any future regression that leaves handler fields at event level produces an explicit test failure rather than silently collecting them. 142 tests pass, 0 fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: CR round 4 — segment-safe quoted-key detection + structural test assertions bin/install.js — getTomlTableSections now exposes segments (#2773 CR7a) The staleNamespacedAotSections filter used section.path.split('.').length > 2 to skip [[hooks.TYPE.hooks]] sub-table entries. That check misclassifies quoted event names containing dots: [[hooks."before.tool"]] has path hooks.before.tool (3 dot-parts) but only 2 true parsed segments, so it was incorrectly excluded from migration. Fixed by adding segments to the getTomlTableSections return shape (already available on record.tableHeader.segments) and replacing the split-based check with section.segments.length !== 2, which uses the true parsed key count regardless of dots inside quoted names. tests/codex-config.test.cjs — replace raw-equality assertions (#2773 CR7b) The two new no-op migration tests (already-nested and matcher-only) used assert.strictEqual(result, content) — raw string equality that conflicts with the repo no-source-grep testing standard. Replaced with structural assertions using parseTomlToObject: the already-nested test verifies the handler stays under .hooks[0] and no double-wrap occurs; the matcher-only test verifies the matcher key is preserved and no .hooks sub-array is added. 142 tests pass, 0 fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: CR round 5 — parseHooksBody key parser, empty-handler guard, segment-safe legacyMap filter, stronger test assertions - parseHooksBody: replace /^([\w.]+)\s*=/ regex with parseTomlKey() so hyphenated keys (status-message) and quoted keys are not silently dropped - buildNestedBlock: guard against handlerEntries.length === 0 — do not synthesise [[hooks.TYPE.hooks]] with type="command" but no command for matcher-only or otherwise handler-empty stale sections - legacyMapSections filter: use section.segments.length === 2 (same fix applied to staleNamespacedAotSections in round 4) to prevent [hooks.X.Y] 3-segment tables from being misclassified as event entries - tests: add regression test for [[hooks."before.tool"]] quoted-dot event names; strengthen command path assertion to exact absolute path comparison Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,12 +90,59 @@ describe('#2760 defect 3 — Hooks AoT preservation across install/uninstall/rei
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('preserves both pre-existing [[hooks.SessionStart]] entries and adds GSD entry in namespaced form', () => {
|
||||
test('fresh install emits the two-level nested AoT schema (#2773)', () => {
|
||||
// Codex 0.124.0+ requires [[hooks.SessionStart]] + [[hooks.SessionStart.hooks]]
|
||||
// with type = "command". Neither the flat [[hooks]] + event field form nor
|
||||
// the single-block [[hooks.SessionStart]] form without .hooks is accepted.
|
||||
writeCodexConfig(codexHome, '');
|
||||
runCodexInstall(codexHome);
|
||||
const content = readCodexConfig(codexHome);
|
||||
const parsed = parseTomlToObject(content);
|
||||
|
||||
// hooks must be an object (namespaced), NOT a flat array.
|
||||
assert.ok(
|
||||
parsed.hooks && !Array.isArray(parsed.hooks) && typeof parsed.hooks === 'object',
|
||||
'hooks must be a namespaced object, not a flat array: got ' + JSON.stringify(parsed.hooks)
|
||||
);
|
||||
// hooks.SessionStart must be an array-of-tables.
|
||||
assert.ok(
|
||||
Array.isArray(parsed.hooks.SessionStart),
|
||||
'hooks.SessionStart must be array-of-tables: got ' + typeof parsed.hooks.SessionStart
|
||||
);
|
||||
// Each event entry must have a .hooks sub-array.
|
||||
const eventEntry = parsed.hooks.SessionStart[0];
|
||||
assert.ok(
|
||||
eventEntry && Array.isArray(eventEntry.hooks),
|
||||
'hooks.SessionStart[0].hooks must be an array of handlers: got ' + JSON.stringify(eventEntry)
|
||||
);
|
||||
// The handler must have type = "command" and reference gsd-check-update.js.
|
||||
const handler = eventEntry.hooks[0];
|
||||
assert.strictEqual(handler.type, 'command', 'handler type must be "command"');
|
||||
assert.ok(
|
||||
typeof handler.command === 'string' && /gsd-check-update\.js/.test(handler.command),
|
||||
'handler command must reference gsd-check-update.js: got ' + handler.command
|
||||
);
|
||||
// No flat [[hooks]] entries must exist alongside the namespaced form.
|
||||
assert.ok(
|
||||
!Array.isArray(parsed.hooks),
|
||||
'flat [[hooks]] AoT must not coexist with namespaced [[hooks.SessionStart]]'
|
||||
);
|
||||
});
|
||||
|
||||
test('preserves user [[hooks.SessionStart]] entries and adds GSD nested handler', () => {
|
||||
// Users may have their own [[hooks.SessionStart]] entries using the new schema.
|
||||
// GSD must append its own two-level block without disturbing theirs.
|
||||
const userConfig = [
|
||||
'[[hooks.SessionStart]]',
|
||||
'',
|
||||
'[[hooks.SessionStart.hooks]]',
|
||||
'type = "command"',
|
||||
'command = "echo first user hook"',
|
||||
'',
|
||||
'[[hooks.SessionStart]]',
|
||||
'',
|
||||
'[[hooks.SessionStart.hooks]]',
|
||||
'type = "command"',
|
||||
'command = "echo second user hook"',
|
||||
'',
|
||||
].join('\n');
|
||||
@@ -105,59 +152,111 @@ describe('#2760 defect 3 — Hooks AoT preservation across install/uninstall/rei
|
||||
const afterInstall = readCodexConfig(codexHome);
|
||||
const parsed = parseTomlToObject(afterInstall);
|
||||
|
||||
// hooks.SessionStart must be an array-of-tables (namespaced AoT form).
|
||||
assert.ok(
|
||||
parsed.hooks && Array.isArray(parsed.hooks.SessionStart),
|
||||
'hooks.SessionStart must be an array-of-tables, got: '
|
||||
+ (parsed.hooks ? typeof parsed.hooks.SessionStart : 'no hooks table')
|
||||
'hooks.SessionStart must remain an array-of-tables after install'
|
||||
);
|
||||
|
||||
const commands = parsed.hooks.SessionStart.map((entry) => entry.command);
|
||||
|
||||
// Both pre-existing user hook entries survive in the parsed structure.
|
||||
assert.ok(
|
||||
commands.includes('echo first user hook'),
|
||||
'first user [[hooks.SessionStart]] entry preserved in parsed structure: ' + JSON.stringify(commands)
|
||||
);
|
||||
assert.ok(
|
||||
commands.includes('echo second user hook'),
|
||||
'second user [[hooks.SessionStart]] entry preserved in parsed structure: ' + JSON.stringify(commands)
|
||||
// Collect all handler commands across all event entries.
|
||||
const allCommands = parsed.hooks.SessionStart.flatMap((entry) =>
|
||||
Array.isArray(entry.hooks) ? entry.hooks.map((h) => h.command) : []
|
||||
);
|
||||
|
||||
// GSD's managed entry is emitted in the same namespaced AoT shape so it
|
||||
// does not collide with the user's preferred form.
|
||||
assert.ok(
|
||||
commands.some((cmd) => typeof cmd === 'string' && /gsd-check-update\.js/.test(cmd)),
|
||||
'GSD entry must appear in hooks.SessionStart array (not top-level [[hooks]]): '
|
||||
+ JSON.stringify(commands)
|
||||
allCommands.includes('echo first user hook'),
|
||||
'first user hook preserved: ' + JSON.stringify(allCommands)
|
||||
);
|
||||
|
||||
// Top-level [[hooks]] AoT must not coexist when namespaced form is in use —
|
||||
// mixing forms is what produces the round-trip break this fix prevents.
|
||||
assert.ok(
|
||||
!Array.isArray(parsed.hooks) || parsed.hooks.length === 0,
|
||||
'no top-level [[hooks]] AoT entries when namespaced form is in use'
|
||||
allCommands.includes('echo second user hook'),
|
||||
'second user hook preserved: ' + JSON.stringify(allCommands)
|
||||
);
|
||||
assert.ok(
|
||||
allCommands.some((cmd) => typeof cmd === 'string' && /gsd-check-update\.js/.test(cmd)),
|
||||
'GSD handler must appear in hooks.SessionStart[].hooks: ' + JSON.stringify(allCommands)
|
||||
);
|
||||
assert.ok(!Array.isArray(parsed.hooks), 'no flat [[hooks]] entries');
|
||||
});
|
||||
|
||||
test('selects top-level [[hooks]] form when user has no namespaced hooks (status-quo behavior)', () => {
|
||||
writeCodexConfig(codexHome, '');
|
||||
test('reinstall replaces flat [[hooks]] + event form with nested schema', () => {
|
||||
// Upgrade path: user has a config written by GSD 1.38.x (flat [[hooks]] form).
|
||||
const legacyConfig = [
|
||||
'[features]',
|
||||
'codex_hooks = true',
|
||||
'',
|
||||
'# GSD Hooks',
|
||||
'[[hooks]]',
|
||||
'event = "SessionStart"',
|
||||
'command = "node /old/path/to/gsd-check-update.js"',
|
||||
'',
|
||||
].join('\n');
|
||||
writeCodexConfig(codexHome, legacyConfig);
|
||||
|
||||
runCodexInstall(codexHome);
|
||||
const content = readCodexConfig(codexHome);
|
||||
const parsed = parseTomlToObject(content);
|
||||
|
||||
// Top-level hooks must be an array-of-tables; the GSD entry must be one
|
||||
// of those tables and carry event = "SessionStart".
|
||||
assert.ok(
|
||||
Array.isArray(parsed.hooks),
|
||||
'fresh install must produce top-level [[hooks]] AoT, got: ' + typeof parsed.hooks
|
||||
// Old flat form must be gone.
|
||||
assert.ok(!Array.isArray(parsed.hooks), 'flat [[hooks]] must be stripped on upgrade');
|
||||
// New nested form must be present.
|
||||
assert.ok(Array.isArray(parsed.hooks && parsed.hooks.SessionStart), 'new [[hooks.SessionStart]] must be present');
|
||||
const handler = parsed.hooks.SessionStart[0].hooks[0];
|
||||
assert.strictEqual(handler.type, 'command');
|
||||
assert.ok(/gsd-check-update\.js/.test(handler.command));
|
||||
// Only one GSD hook entry must exist (no duplication).
|
||||
const sessionStart = parsed.hooks?.SessionStart ?? [];
|
||||
const gsdHandlers = sessionStart.flatMap((entry) =>
|
||||
Array.isArray(entry.hooks) ? entry.hooks : []
|
||||
).filter((h) => typeof h?.command === 'string' && /gsd-check-update\.js/.test(h.command));
|
||||
assert.strictEqual(gsdHandlers.length, 1, 'exactly one managed handler after upgrade');
|
||||
});
|
||||
|
||||
test('reinstall replaces single-block [[hooks.SessionStart]] (no .hooks sub-table) with nested schema', () => {
|
||||
// Upgrade path: user has a config written by the PR #2802 shape —
|
||||
// [[hooks.SessionStart]] without a nested [[hooks.SessionStart.hooks]] sub-table.
|
||||
const prBranchConfig = [
|
||||
'[features]',
|
||||
'codex_hooks = true',
|
||||
'',
|
||||
'# GSD Hooks',
|
||||
'[[hooks.SessionStart]]',
|
||||
'command = "node /old/path/to/gsd-check-update.js"',
|
||||
'',
|
||||
].join('\n');
|
||||
writeCodexConfig(codexHome, prBranchConfig);
|
||||
|
||||
runCodexInstall(codexHome);
|
||||
const content = readCodexConfig(codexHome);
|
||||
const parsed = parseTomlToObject(content);
|
||||
|
||||
assert.ok(Array.isArray(parsed.hooks && parsed.hooks.SessionStart), '[[hooks.SessionStart]] must be present');
|
||||
const eventEntry = parsed.hooks.SessionStart[0];
|
||||
assert.ok(Array.isArray(eventEntry.hooks), '[[hooks.SessionStart.hooks]] sub-table must be present');
|
||||
const handler = eventEntry.hooks[0];
|
||||
assert.strictEqual(handler.type, 'command');
|
||||
assert.ok(/gsd-check-update\.js/.test(handler.command));
|
||||
const handlers = (parsed.hooks?.SessionStart ?? []).flatMap((entry) =>
|
||||
Array.isArray(entry.hooks) ? entry.hooks : []
|
||||
);
|
||||
assert.ok(
|
||||
parsed.hooks.some((h) => h && h.event === 'SessionStart'),
|
||||
'top-level [[hooks]] AoT must contain an entry with event = "SessionStart": '
|
||||
+ JSON.stringify(parsed.hooks)
|
||||
assert.strictEqual(
|
||||
handlers.filter((h) => typeof h?.command === 'string' && /gsd-check-update\.js/.test(h.command)).length,
|
||||
1,
|
||||
'exactly one managed handler after upgrade from PR-#2802-shape'
|
||||
);
|
||||
});
|
||||
|
||||
test('reinstall is idempotent: correct nested schema is stripped and re-emitted cleanly', () => {
|
||||
writeCodexConfig(codexHome, '');
|
||||
runCodexInstall(codexHome);
|
||||
runCodexInstall(codexHome); // second install
|
||||
const content = readCodexConfig(codexHome);
|
||||
|
||||
const parsed = parseTomlToObject(content);
|
||||
const sessionStart = parsed.hooks?.SessionStart ?? [];
|
||||
assert.strictEqual(sessionStart.length, 1, 'exactly one SessionStart event entry after double install');
|
||||
assert.ok(Array.isArray(sessionStart[0].hooks), 'SessionStart event has nested handlers array');
|
||||
assert.strictEqual(sessionStart[0].hooks.length, 1, 'exactly one handler in SessionStart after double install');
|
||||
assert.ok(/gsd-check-update\.js/.test(sessionStart[0].hooks[0].command), 'managed handler command preserved');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#2760 fix 2 — Strip purges invalid legacy [agents] / [[agents]] regardless of marker', () => {
|
||||
@@ -572,15 +671,25 @@ describe('#2760 CR4 finding 2 — Legacy flat [[hooks]] block migrates to namesp
|
||||
+ (parsed.hooks ? typeof parsed.hooks.SessionStart : 'no hooks table')
|
||||
);
|
||||
|
||||
const namespacedCommands = parsed.hooks.SessionStart.map((entry) => entry.command);
|
||||
// Migration now handles stale [[hooks.SessionStart]] entries with handler
|
||||
// fields at event-entry level (pre-#2773 shape), promoting them to the
|
||||
// two-level nested form. Every entry must carry a .hooks sub-array after
|
||||
// migration, so collect from nested handlers only.
|
||||
assert.ok(
|
||||
namespacedCommands.includes('echo user hook'),
|
||||
'user [[hooks.SessionStart]] entry preserved: ' + JSON.stringify(namespacedCommands)
|
||||
parsed.hooks.SessionStart.every((entry) => Array.isArray(entry.hooks)),
|
||||
'every hooks.SessionStart entry must use nested [[hooks.SessionStart.hooks]] handlers after migration'
|
||||
);
|
||||
const allSessionStartCommands = parsed.hooks.SessionStart.flatMap((entry) =>
|
||||
entry.hooks.map((h) => h.command).filter(Boolean)
|
||||
);
|
||||
assert.ok(
|
||||
namespacedCommands.some((cmd) => typeof cmd === 'string' && /gsd-check-update\.js/.test(cmd)),
|
||||
allSessionStartCommands.includes('echo user hook'),
|
||||
'user [[hooks.SessionStart]] entry preserved: ' + JSON.stringify(allSessionStartCommands)
|
||||
);
|
||||
assert.ok(
|
||||
allSessionStartCommands.some((cmd) => typeof cmd === 'string' && /gsd-check-update\.js/.test(cmd)),
|
||||
'GSD entry must appear in hooks.SessionStart array (namespaced AoT form): '
|
||||
+ JSON.stringify(namespacedCommands)
|
||||
+ JSON.stringify(allSessionStartCommands)
|
||||
);
|
||||
|
||||
// The legacy top-level [[hooks]] AoT must NOT coexist with the namespaced
|
||||
@@ -592,7 +701,7 @@ describe('#2760 CR4 finding 2 — Legacy flat [[hooks]] block migrates to namesp
|
||||
);
|
||||
|
||||
// No duplicate gsd-check-update entries — exactly one managed entry.
|
||||
const gsdEntries = namespacedCommands.filter(
|
||||
const gsdEntries = allSessionStartCommands.filter(
|
||||
(cmd) => typeof cmd === 'string' && /gsd-check-update\.js/.test(cmd)
|
||||
);
|
||||
assert.equal(gsdEntries.length, 1,
|
||||
@@ -936,18 +1045,35 @@ describe('#2760 CR5 finding 3 — migration emits namespaced AoT (no flat/namesp
|
||||
parsed.hooks && Array.isArray(parsed.hooks.AfterTool),
|
||||
'pre-existing [[hooks.AfterTool]] must remain a namespaced AoT array'
|
||||
);
|
||||
// AfterTool was in [[hooks.AfterTool]] with command at event-entry level
|
||||
// (pre-#2773 stale namespaced AoT shape). Migration now promotes these to
|
||||
// the two-level nested form, so every entry must have a .hooks sub-array.
|
||||
assert.ok(
|
||||
parsed.hooks.AfterTool.some((entry) => entry.command === 'x'),
|
||||
'user AfterTool entry must be preserved: ' + JSON.stringify(parsed.hooks.AfterTool)
|
||||
parsed.hooks.AfterTool.every((e) => Array.isArray(e.hooks)),
|
||||
'every AfterTool entry must use nested [[hooks.AfterTool.hooks]] handlers after migration'
|
||||
);
|
||||
const afterToolCommands = parsed.hooks.AfterTool.flatMap((e) =>
|
||||
e.hooks.map((h) => h.command).filter(Boolean)
|
||||
);
|
||||
assert.ok(
|
||||
afterToolCommands.includes('x'),
|
||||
'user AfterTool entry must be preserved: ' + JSON.stringify(afterToolCommands)
|
||||
);
|
||||
|
||||
// The migrated SessionStart entry is now namespaced AoT, not flat
|
||||
// [[hooks]] with event="SessionStart".
|
||||
// The migrated SessionStart entry is now namespaced AoT with nested .hooks sub-table.
|
||||
assert.ok(
|
||||
parsed.hooks && Array.isArray(parsed.hooks.SessionStart),
|
||||
'migrated SessionStart must be namespaced AoT (not flat [[hooks]])'
|
||||
);
|
||||
const ssCommands = parsed.hooks.SessionStart.map((e) => e.command);
|
||||
// After migration, [hooks.SessionStart] map-format is promoted to nested AoT.
|
||||
// Command lives in [[hooks.SessionStart.hooks]][0].command (nested schema).
|
||||
assert.ok(
|
||||
parsed.hooks.SessionStart.every((e) => Array.isArray(e.hooks)),
|
||||
'every SessionStart entry must use nested [[hooks.SessionStart.hooks]] handlers after migration'
|
||||
);
|
||||
const ssCommands = parsed.hooks.SessionStart.flatMap((e) =>
|
||||
e.hooks.map((h) => h.command).filter(Boolean)
|
||||
);
|
||||
assert.ok(
|
||||
ssCommands.includes('y'),
|
||||
'user SessionStart command "y" must be preserved in namespaced array: ' +
|
||||
|
||||
@@ -578,7 +578,9 @@ describe('stripGsdFromCodexConfig', () => {
|
||||
// ─── migrateCodexHooksMapFormat ─────────────────────────────────────────────────
|
||||
|
||||
describe('migrateCodexHooksMapFormat', () => {
|
||||
test('returns content unchanged when no legacy [hooks] map sections present', () => {
|
||||
test('migrates flat [[hooks]] with event key to namespaced [[hooks.<EVENT>]] form', () => {
|
||||
// Flat [[hooks]] + event = "..." is TOML-incompatible with [[hooks.SessionStart]],
|
||||
// so migrateCodexHooksMapFormat now converts it to the nested namespaced form.
|
||||
const content = [
|
||||
'[features]',
|
||||
'codex_hooks = true',
|
||||
@@ -588,7 +590,21 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
'command = "node /home/.codex/hooks/gsd-check-update.js"',
|
||||
'',
|
||||
].join('\n');
|
||||
assert.strictEqual(migrateCodexHooksMapFormat(content), content);
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.SessionStart),
|
||||
'flat [[hooks]] event=SessionStart must be promoted to [[hooks.SessionStart]] AoT');
|
||||
assert.strictEqual(parsed.hooks.SessionStart.length, 1);
|
||||
assert.ok(Array.isArray(parsed.hooks.SessionStart[0].hooks),
|
||||
'must emit [[hooks.SessionStart.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].command,
|
||||
'node /home/.codex/hooks/gsd-check-update.js');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].type, 'command',
|
||||
'migrated handler must carry type = "command" per Codex 0.124.0+ schema');
|
||||
assert.equal(parsed.hooks.SessionStart[0].event, undefined,
|
||||
'event key consumed as namespace — must not appear in emitted block');
|
||||
assert.ok(!Array.isArray(parsed.hooks), 'hooks must be a table, not a flat array');
|
||||
assert.equal(parsed.features && parsed.features.codex_hooks, true);
|
||||
});
|
||||
|
||||
test('returns content unchanged for empty string', () => {
|
||||
@@ -612,7 +628,10 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.shell),
|
||||
'hooks.shell must be an array of tables, got: ' + (parsed.hooks ? typeof parsed.hooks.shell : 'no hooks table'));
|
||||
assert.strictEqual(parsed.hooks.shell.length, 1);
|
||||
assert.strictEqual(parsed.hooks.shell[0].command, 'node /home/.codex/hooks/gsd-check-update.js');
|
||||
// #2773: command now lives in [[hooks.shell.hooks]] sub-table, not at event-entry level
|
||||
assert.ok(Array.isArray(parsed.hooks.shell[0].hooks), 'must emit [[hooks.shell.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].command, 'node /home/.codex/hooks/gsd-check-update.js');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].type, 'command');
|
||||
// No flat top-level [[hooks]] AoT and no synthetic event field.
|
||||
assert.ok(!Array.isArray(parsed.hooks),
|
||||
'no top-level [[hooks]] AoT — namespace IS the event in CR5 form');
|
||||
@@ -633,8 +652,12 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.exec));
|
||||
assert.strictEqual(parsed.hooks.exec.length, 1);
|
||||
assert.strictEqual(parsed.hooks.exec[0].command, 'echo hello');
|
||||
assert.strictEqual(parsed.hooks.exec[0].extra_key, 'preserved');
|
||||
// #2773: command and extra keys now live in [[hooks.exec.hooks]] sub-table
|
||||
assert.ok(Array.isArray(parsed.hooks.exec[0].hooks), 'must emit [[hooks.exec.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.exec[0].hooks[0].command, 'echo hello');
|
||||
assert.strictEqual(parsed.hooks.exec[0].hooks[0].type, 'command',
|
||||
'migrated handler must carry type = "command" per Codex 0.124.0+ schema');
|
||||
assert.strictEqual(parsed.hooks.exec[0].hooks[0].extra_key, 'preserved');
|
||||
assert.equal(parsed.hooks.exec[0].event, undefined);
|
||||
});
|
||||
|
||||
@@ -653,18 +676,37 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.exec));
|
||||
assert.strictEqual(parsed.hooks.shell.length, 1);
|
||||
assert.strictEqual(parsed.hooks.exec.length, 1);
|
||||
assert.strictEqual(parsed.hooks.shell[0].command, 'node /home/.codex/hooks/gsd-check-update.js');
|
||||
assert.strictEqual(parsed.hooks.exec[0].command, 'echo done');
|
||||
// #2773: commands now live in the [[hooks.<TYPE>.hooks]] sub-table
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].command, 'node /home/.codex/hooks/gsd-check-update.js');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].type, 'command',
|
||||
'migrated shell handler must carry type = "command"');
|
||||
assert.strictEqual(parsed.hooks.exec[0].hooks[0].command, 'echo done');
|
||||
assert.strictEqual(parsed.hooks.exec[0].hooks[0].type, 'command',
|
||||
'migrated exec handler must carry type = "command"');
|
||||
});
|
||||
|
||||
test('leaves user-authored [[hooks]] array entries untouched when no legacy [hooks] map present', () => {
|
||||
test('migrates flat [[hooks]] with event=AfterCommand to [[hooks.AfterCommand]] namespaced form', () => {
|
||||
// Flat [[hooks]] + event = "..." is incompatible with [[hooks.<EVENT>]] AoT in the same
|
||||
// file — TOML cannot have hooks be both an array and a table. Migration promotes it.
|
||||
const content = [
|
||||
'[[hooks]]',
|
||||
'event = "AfterCommand"',
|
||||
'command = "echo custom"',
|
||||
'',
|
||||
].join('\n');
|
||||
assert.strictEqual(migrateCodexHooksMapFormat(content), content);
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.AfterCommand),
|
||||
'flat [[hooks]] event=AfterCommand must become [[hooks.AfterCommand]] AoT');
|
||||
assert.strictEqual(parsed.hooks.AfterCommand.length, 1);
|
||||
assert.ok(Array.isArray(parsed.hooks.AfterCommand[0].hooks),
|
||||
'must emit [[hooks.AfterCommand.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.AfterCommand[0].hooks[0].command, 'echo custom');
|
||||
assert.strictEqual(parsed.hooks.AfterCommand[0].hooks[0].type, 'command',
|
||||
'migrated AfterCommand handler must carry type = "command" per Codex 0.124.0+ schema');
|
||||
assert.equal(parsed.hooks.AfterCommand[0].event, undefined,
|
||||
'event key consumed as namespace — must not appear in emitted block');
|
||||
assert.ok(!Array.isArray(parsed.hooks), 'hooks must be a table, not a flat array');
|
||||
});
|
||||
|
||||
test('end-to-end: install on config with old [hooks] map format produces namespaced AoT (#2637, #2760 CR5)', () => {
|
||||
@@ -686,8 +728,12 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.shell),
|
||||
'hooks.shell must be array-of-tables in namespaced form');
|
||||
assert.strictEqual(parsed.hooks.shell.length, 1);
|
||||
assert.strictEqual(parsed.hooks.shell[0].command,
|
||||
// #2773: command lives in [[hooks.shell.hooks]] sub-table
|
||||
assert.ok(Array.isArray(parsed.hooks.shell[0].hooks), 'must emit [[hooks.shell.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].command,
|
||||
'node /home/.codex/hooks/gsd-check-update.js');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].type, 'command',
|
||||
'migrated shell handler must carry type = "command" per Codex 0.124.0+ schema');
|
||||
assert.equal(parsed.features && parsed.features.codex_hooks, true);
|
||||
});
|
||||
|
||||
@@ -710,6 +756,132 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
assert.ok(result.includes('[model]'), 'preserves [model]');
|
||||
});
|
||||
|
||||
test('upgrades stale [[hooks.SessionStart]] with event-level command to nested schema (#2773 CR6)', () => {
|
||||
// Pre-#2773 single-block format: handler fields live directly under
|
||||
// [[hooks.SessionStart]] rather than under [[hooks.SessionStart.hooks]].
|
||||
// Codex 0.124.0+ rejects this shape. Migration must promote it.
|
||||
const content = [
|
||||
'[features]',
|
||||
'codex_hooks = true',
|
||||
'',
|
||||
'[[hooks.SessionStart]]',
|
||||
'command = "echo stale-user-hook"',
|
||||
'',
|
||||
].join('\n');
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.SessionStart),
|
||||
'stale [[hooks.SessionStart]] must remain a namespaced AoT');
|
||||
assert.strictEqual(parsed.hooks.SessionStart.length, 1);
|
||||
assert.ok(Array.isArray(parsed.hooks.SessionStart[0].hooks),
|
||||
'must emit [[hooks.SessionStart.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].command, 'echo stale-user-hook');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].type, 'command',
|
||||
'must inject type = "command" when source body has no explicit type');
|
||||
assert.equal(parsed.hooks.SessionStart[0].command, undefined,
|
||||
'command must not remain at event-entry level after promotion');
|
||||
assert.equal(parsed.features && parsed.features.codex_hooks, true);
|
||||
});
|
||||
|
||||
test('leaves [[hooks.SessionStart]] + [[hooks.SessionStart.hooks]] untouched (already nested)', () => {
|
||||
// Properly-nested schema: handler lives under [[hooks.SessionStart.hooks]].
|
||||
// Migration must NOT create a double-wrapped [[hooks.SessionStart.hooks.hooks]] shape.
|
||||
const content = [
|
||||
'[[hooks.SessionStart]]',
|
||||
'',
|
||||
'[[hooks.SessionStart.hooks]]',
|
||||
'type = "command"',
|
||||
'command = "echo already-nested"',
|
||||
'',
|
||||
].join('\n');
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(Array.isArray(parsed.hooks?.SessionStart),
|
||||
'SessionStart must remain a namespaced AoT after no-op migration');
|
||||
assert.strictEqual(parsed.hooks.SessionStart.length, 1,
|
||||
'must not duplicate the event entry');
|
||||
assert.ok(Array.isArray(parsed.hooks.SessionStart[0].hooks),
|
||||
'nested [[hooks.SessionStart.hooks]] sub-table must still be present');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks.length, 1,
|
||||
'must not create a double-wrapped [[hooks.SessionStart.hooks.hooks]]');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].type, 'command');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].command, 'echo already-nested');
|
||||
assert.equal(parsed.hooks.SessionStart[0].command, undefined,
|
||||
'command must not appear at event-entry level');
|
||||
});
|
||||
|
||||
test('promotes multiple stale [[hooks.TYPE]] entries from different event types', () => {
|
||||
const content = [
|
||||
'[[hooks.SessionStart]]',
|
||||
'command = "echo session"',
|
||||
'',
|
||||
'[[hooks.AfterCommand]]',
|
||||
'command = "echo after-cmd"',
|
||||
'',
|
||||
].join('\n');
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.SessionStart));
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.AfterCommand));
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].command, 'echo session');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].type, 'command');
|
||||
assert.strictEqual(parsed.hooks.AfterCommand[0].hooks[0].command, 'echo after-cmd');
|
||||
assert.strictEqual(parsed.hooks.AfterCommand[0].hooks[0].type, 'command');
|
||||
assert.equal(parsed.hooks.SessionStart[0].command, undefined);
|
||||
assert.equal(parsed.hooks.AfterCommand[0].command, undefined);
|
||||
});
|
||||
|
||||
test('matcher-only [[hooks.SessionStart]] (no handler fields) is left untouched', () => {
|
||||
// A [[hooks.SessionStart]] entry with only a `matcher` key is a valid
|
||||
// event filter — no handler fields → not a stale single-block entry.
|
||||
const content = [
|
||||
'[[hooks.SessionStart]]',
|
||||
'matcher = "some-tool"',
|
||||
'',
|
||||
].join('\n');
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(Array.isArray(parsed.hooks?.SessionStart),
|
||||
'matcher-only SessionStart must remain a namespaced AoT');
|
||||
assert.strictEqual(parsed.hooks.SessionStart.length, 1);
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].matcher, 'some-tool',
|
||||
'matcher key must be preserved');
|
||||
assert.equal(parsed.hooks.SessionStart[0].hooks, undefined,
|
||||
'matcher-only entry must not gain a .hooks sub-array');
|
||||
assert.equal(parsed.hooks.SessionStart[0].command, undefined,
|
||||
'no spurious command key must appear');
|
||||
});
|
||||
|
||||
test('quoted event name with dot ([[hooks."before.tool"]]) is treated as single 2-segment namespace', () => {
|
||||
// Regression for the split('.') bug: "before.tool" contains a dot, but the
|
||||
// key is quoted so it is ONE segment — [[hooks."before.tool"]] has exactly
|
||||
// two path segments and must be classified the same as [[hooks.SessionStart]].
|
||||
// It should NOT be treated as a 3-level path (hooks / before / tool).
|
||||
const content = [
|
||||
'[[hooks."before.tool"]]',
|
||||
'command = "echo hi"',
|
||||
'',
|
||||
].join('\n');
|
||||
const result = migrateCodexHooksMapFormat(content);
|
||||
const parsed = parseTomlToObject(result);
|
||||
// The key in the parsed object is the unquoted event name "before.tool".
|
||||
assert.ok(
|
||||
parsed.hooks && Array.isArray(parsed.hooks['before.tool']),
|
||||
'[[hooks."before.tool"]] must be a namespaced AoT — not split on the inner dot'
|
||||
);
|
||||
assert.ok(
|
||||
Array.isArray(parsed.hooks['before.tool'][0].hooks),
|
||||
'must emit [[hooks."before.tool".hooks]] sub-table'
|
||||
);
|
||||
assert.strictEqual(
|
||||
parsed.hooks['before.tool'][0].hooks[0].command,
|
||||
'echo hi',
|
||||
'command must be preserved in the nested handler sub-table'
|
||||
);
|
||||
// Ensure no spurious "before" or "tool" top-level hook keys appeared.
|
||||
assert.equal(parsed.hooks?.before, undefined, 'must not split quoted key on dot');
|
||||
});
|
||||
|
||||
test('CRLF line endings are preserved through migration (#2760 CR5: namespaced AoT)', () => {
|
||||
const content = [
|
||||
'[features]',
|
||||
@@ -725,8 +897,12 @@ describe('migrateCodexHooksMapFormat', () => {
|
||||
// Round-trip parse confirms the structural shape independent of EOL.
|
||||
const parsed = parseTomlToObject(result);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.shell));
|
||||
assert.strictEqual(parsed.hooks.shell[0].command,
|
||||
// #2773: command lives in [[hooks.shell.hooks]] sub-table
|
||||
assert.ok(Array.isArray(parsed.hooks.shell[0].hooks), 'must emit [[hooks.shell.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].command,
|
||||
'node /home/.codex/hooks/gsd-check-update.js');
|
||||
assert.strictEqual(parsed.hooks.shell[0].hooks[0].type, 'command',
|
||||
'migrated shell handler must carry type = "command" per Codex 0.124.0+ schema');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -750,7 +926,7 @@ describe('Codex hooks emit: migration produces namespaced AoT so managed-emit co
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('migration of legacy [hooks.SessionStart] produces namespaced AoT', () => {
|
||||
test('migration of legacy [hooks.SessionStart] produces two-level nested AoT (#2773)', () => {
|
||||
const legacyContent = [
|
||||
'[features]',
|
||||
'codex_hooks = true',
|
||||
@@ -761,16 +937,27 @@ describe('Codex hooks emit: migration produces namespaced AoT so managed-emit co
|
||||
].join('\n');
|
||||
const migrated = migrateCodexHooksMapFormat(legacyContent);
|
||||
const parsed = parseTomlToObject(migrated);
|
||||
// Outer event entry
|
||||
assert.ok(
|
||||
parsed.hooks && Array.isArray(parsed.hooks.SessionStart),
|
||||
'migration must emit [[hooks.SessionStart]] namespaced AoT'
|
||||
);
|
||||
assert.equal(parsed.hooks.SessionStart[0].event, undefined,
|
||||
'migration must NOT emit a synthetic event field — namespace IS the event');
|
||||
assert.equal(
|
||||
Array.isArray(parsed.hooks),
|
||||
false,
|
||||
'migration must NOT emit a flat top-level [[hooks]] AoT'
|
||||
assert.equal(Array.isArray(parsed.hooks), false,
|
||||
'migration must NOT emit a flat top-level [[hooks]] AoT');
|
||||
// Inner handler sub-table
|
||||
assert.ok(
|
||||
Array.isArray(parsed.hooks.SessionStart[0].hooks),
|
||||
'migration must emit [[hooks.SessionStart.hooks]] sub-table'
|
||||
);
|
||||
const handler = parsed.hooks.SessionStart[0].hooks[0];
|
||||
assert.strictEqual(handler.type, 'command',
|
||||
'migration must inject type = "command" in handler sub-table');
|
||||
assert.strictEqual(
|
||||
handler.command,
|
||||
'node /home/.codex/hooks/gsd-check-update.js',
|
||||
'migration must preserve original command value in handler sub-table'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1237,7 +1424,17 @@ describe('Codex install hook configuration (e2e)', () => {
|
||||
|
||||
const content = readCodexConfig(codexHome);
|
||||
assert.ok(content.includes('[features]\ncodex_hooks = true\n'), 'writes codex_hooks feature');
|
||||
assert.ok(content.includes('# GSD Hooks\n[[hooks]]\nevent = "SessionStart"\n'), 'writes GSD SessionStart hook block');
|
||||
// Codex 0.124.0+ nested schema: [[hooks.SessionStart]] + [[hooks.SessionStart.hooks]]
|
||||
const parsed = parseTomlToObject(content);
|
||||
assert.ok(parsed.hooks && Array.isArray(parsed.hooks.SessionStart), 'writes [[hooks.SessionStart]] AoT');
|
||||
assert.ok(Array.isArray(parsed.hooks.SessionStart[0].hooks), 'writes [[hooks.SessionStart.hooks]] sub-table');
|
||||
assert.strictEqual(parsed.hooks.SessionStart[0].hooks[0].type, 'command', 'handler type is "command"');
|
||||
assert.strictEqual(
|
||||
parsed.hooks.SessionStart[0].hooks[0].command,
|
||||
'node ' + path.join(codexHome, 'hooks', 'gsd-check-update.js').replace(/\\/g, '/'),
|
||||
'handler command must be the exact absolute path to gsd-check-update.js'
|
||||
);
|
||||
assert.ok(!Array.isArray(parsed.hooks), 'no flat [[hooks]] AoT emitted');
|
||||
assert.strictEqual(countMatches(content, /^codex_hooks = true$/gm), 1, 'writes one codex_hooks key');
|
||||
assert.strictEqual(countMatches(content, /gsd-check-update\.js/g), 1, 'writes one GSD update hook');
|
||||
assertNoDraftRootKeys(content);
|
||||
@@ -1667,7 +1864,14 @@ describe('Codex install hook configuration (e2e)', () => {
|
||||
assert.ok(content.includes('notes = \'\'\'\n[model]\ncodex_hooks = false\n\'\'\''), 'preserves multiline string content');
|
||||
assert.strictEqual(countMatches(content, /^codex_hooks = false$/gm), 1, 'does not rewrite codex_hooks text inside multiline string');
|
||||
assert.ok(content.indexOf('codex_hooks = true') > content.indexOf('other_feature = true'), 'does not stop the features section at multiline string content');
|
||||
assert.ok(content.indexOf('codex_hooks = true') < content.indexOf('[[hooks]]'), 'inserts the real codex_hooks key before the next table');
|
||||
// Parse structurally — verify codex_hooks and migrated AfterCommand hook via parsed object
|
||||
const parsed = parseTomlToObject(content);
|
||||
assert.equal(parsed.features?.codex_hooks, true, 'writes a real codex_hooks boolean key');
|
||||
assert.ok(Array.isArray(parsed.hooks?.AfterCommand), 'AfterCommand flat [[hooks]] migrated to namespaced AoT');
|
||||
const afterCmds = parsed.hooks.AfterCommand.flatMap((entry) =>
|
||||
Array.isArray(entry.hooks) ? entry.hooks.map((h) => h.command).filter(Boolean) : []
|
||||
);
|
||||
assert.ok(afterCmds.includes('echo custom-after-command'), 'preserves AfterCommand user hook command');
|
||||
assertNoDraftRootKeys(content);
|
||||
});
|
||||
|
||||
@@ -1846,7 +2050,10 @@ describe('Codex install hook configuration (e2e)', () => {
|
||||
// [features] is inserted after top-level lines, before [model] — not prepended
|
||||
assert.ok(content.includes('# first line wins\n\n[features]\ncodex_hooks = true\n'), 'inserts features after top-level lines using first newline style');
|
||||
assert.ok(content.includes(`# GSD Agent Configuration — managed by get-shit-done installer\n`), 'writes the managed agent block using the first newline style');
|
||||
assert.ok(content.includes('# GSD Hooks\n[[hooks]]\nevent = "SessionStart"\n'), 'writes the GSD hook block using the first newline style');
|
||||
// Structural check: nested schema must be present regardless of mixed EOL
|
||||
const parsedMixed = parseTomlToObject(content);
|
||||
assert.ok(parsedMixed.hooks && Array.isArray(parsedMixed.hooks.SessionStart), 'writes [[hooks.SessionStart]] AoT with first-newline style');
|
||||
assert.ok(Array.isArray(parsedMixed.hooks.SessionStart[0].hooks), 'writes [[hooks.SessionStart.hooks]] sub-table');
|
||||
assert.ok(content.includes('[model]\r\nname = "o3"'), 'preserves the existing CRLF model lines');
|
||||
assert.strictEqual(countMatches(content, /^codex_hooks = true$/gm), 1, 'remains idempotent on repeated installs');
|
||||
assert.strictEqual(countMatches(content, /gsd-check-update\.js/g), 1, 'does not duplicate the GSD hook block');
|
||||
|
||||
Reference in New Issue
Block a user