fix(3566): narrow scope; update codex-config tests for canonical hooks key

Two follow-up adjustments after running the full suite:

1. Reverted the rewriteTomlKeyLines() change. The original
   `match.keyRaw || key` fallback respects user ownership of pre-existing
   legacy lines (#2760 defensive principle). My fix now applies the
   canonical-vs-legacy split at the INSERTION points only: fresh installs
   write `hooks = true`, but a pre-existing user-authored
   `codex_hooks = true` is preserved verbatim. Codex's own runtime
   legacy_key alias handles backward-compat at the Codex layer.

2. Updated 12 test cases in tests/codex-config.test.cjs that pinned the
   old fresh-write key. These assertions now expect canonical `hooks` for
   fresh-write scenarios; tests covering legacy-line preservation already
   pass against the narrowed fix without further edits.

Also updated bug-3566 regression-test cases for the legacy-preservation
path — they now verify that user-owned `codex_hooks` survives an install.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-05-15 14:22:32 -04:00
parent 55b3f45ad0
commit 1746f89ac7
4 changed files with 42 additions and 49 deletions

View File

@@ -4444,14 +4444,14 @@ function rewriteTomlKeyLines(content, matches, key) {
const blockEol = blockEnd > 0 && content[blockEnd - 1] === '\n'
? (blockEnd > 1 && content[blockEnd - 2] === '\r' ? '\r\n' : '\n')
: '';
// Always rewrite to the caller-supplied canonical `key`, ignoring
// `match.keyRaw`. The previous `match.keyRaw || key` fallback
// silently preserved legacy aliases (issue #3566): callers asking
// to rewrite a section line to `hooks` would get back the original
// `codex_hooks` line unchanged because the parsed record carried
// `keyRaw: "codex_hooks"`. The caller's intent — emit the canonical
// key — must win.
rewritten += normalizeCodexHooksLine(match.text, key) + blockEol;
// Preserve the existing key when one is present on the line
// (`match.keyRaw`). This respects user ownership: a user-authored
// `codex_hooks = true` line stays as `codex_hooks = true` even
// though `hooks` is the canonical key in current Codex (#3566).
// Codex's own `legacy_key` alias mechanism in codex-rs handles the
// backward compat at the runtime layer. Migration to canonical is
// a fresh-insert-only operation in ensureCodexHooksFeature.
rewritten += normalizeCodexHooksLine(match.text, match.keyRaw || key) + blockEol;
cursor = blockEnd;
return;
}