fix(install): keep foreign Claude hooks in mixed groups

Remove only setup-owned hook entries from a hook group and keep foreign
entries with their group options, such as matcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian lechnerandClaude Opus 5.5 committed 2026-10-01 10:23:23 +02:00
1 parent 857720bcfd
commit e2394ca1d1
2 files changed
+24 -6

No files matched your search

+13
View File
@@ -45,6 +45,19 @@ class InstallOptionsTests(unittest.TestCase):
self.assertEqual(result['mcp_servers'], {'demo': {'command': 'demo', 'env': {'TOKEN_NAME': 'x'}}})
self.assertEqual(result['model_providers'], {'custom': {'name': 'Custom', 'base_url': 'https://example.invalid'}})
def test_merge_json_removes_only_owned_hooks_from_mixed_group(self):
owned = {'type': 'command', 'command': 'bash "/old/hooks/flashbang.sh"', 'timeout': 8}
foreign = {'type': 'command', 'command': 'notify-done', 'timeout': 3}
current = {'hooks': {'Stop': [{'matcher': 'custom', 'hooks': [owned, foreign]}],
'PreCompact': [{'hooks': [{'type': 'command', 'command': 'bash "/old/record-compact.sh"'}]}]}}
managed_stop = {'hooks': [{'type': 'command', 'command': 'bash "/new/hooks/flashbang.sh"', 'timeout': 8}]}
managed = {'hooks': {'Stop': [managed_stop], 'PreCompact': []}}
hooks = OPTIONS.merge_json(current, managed)['hooks']
self.assertEqual(hooks['Stop'], [managed_stop, {'matcher': 'custom', 'hooks': [foreign]}])
self.assertNotIn('PreCompact', hooks)
def test_merge_cli_accepts_bom_input_and_preserves_non_ascii(self):
with tempfile.TemporaryDirectory() as directory:
current = Path(directory) / 'config.toml'