Skip to content

Commit 39c74bd

Browse files
committed
test: converge hook tests and smoke on the exec-form registration
The rebase onto main brought the Bash-enabled PreToolUse matcher (Grep|Glob|Bash), which the exec-form tests still counted as Grep|Glob. The Windows lifecycle test seeded the .cmd shell spelling as the converged identity; the shell-free registration converges every owned shell spelling onto one exec-form entry per matcher instead. The test now asserts that, plus their removal on uninstall, and hands cbm_install_agent_configs the '/'-spelled binary path cbm_cmd_install registers (cbm_mkdtemp returns a native '\' temp root on Windows, which uninstall never derives). Smoke 8aq proved Claude's gate registration by grepping the shim name out of settings.json; the exec form carries no shim name, so it now checks the binary-plus-'hook-augment' PreToolUse hook. 9d's shim-name marker would otherwise pass vacuously after uninstall; the 'hook-augment' argument is an owned marker there too. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 7d20ff9 commit 39c74bd

2 files changed

Lines changed: 46 additions & 10 deletions

File tree

‎scripts/smoke-test.sh‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,19 @@ ok = ok and owned_total == 2
25502550
sys.exit(0 if ok else 1)
25512551
" 2>/dev/null ||
25522552
! grep -q 'SessionStart' "$FAKE_HOME/.claude/settings.json" 2>/dev/null ||
2553-
! grep -q 'cbm-code-discovery-gate' "$FAKE_HOME/.claude/settings.json" 2>/dev/null; then
2553+
! cat "$FAKE_HOME/.claude/settings.json" 2>/dev/null | SELF_PATH="$SELF_PATH" python3 -c "
2554+
# Claude's gate is registered shell-free (#1733): the binary itself as the
2555+
# command with 'hook-augment' as its argument, so no shim name can be grepped.
2556+
import json, os, sys
2557+
d = json.load(sys.stdin)
2558+
self_path = os.environ['SELF_PATH']
2559+
hooks = [h for entry in d.get('hooks', {}).get('PreToolUse', []) for h in entry.get('hooks', [])]
2560+
ok = any(h.get('args') == ['hook-augment'] and
2561+
(h.get('command') == self_path or
2562+
os.path.basename(str(h.get('command', ''))) == os.path.basename(self_path))
2563+
for h in hooks)
2564+
sys.exit(0 if ok else 1)
2565+
" 2>/dev/null; then
25542566
echo "FAIL 8aq: Devin hooks are not deduplicated against Claude SessionStart"
25552567
exit 1
25562568
else
@@ -2755,9 +2767,14 @@ if cat "$FAKE_HOME/.claude/settings.json" 2>/dev/null | python3 -c "
27552767
import json, sys
27562768
d = json.load(sys.stdin)
27572769
hooks = d.get('hooks', {})
2770+
# Shim names cover legacy shell registrations; the exec form (#1733) carries
2771+
# no shim name, so its 'hook-augment' argument is the owned marker there.
27582772
found = any('cbm-code-discovery-gate' in str(h) or
27592773
'cbm-session-reminder' in str(h) or
2760-
'cbm-subagent-reminder' in str(h)
2774+
'cbm-subagent-reminder' in str(h) or
2775+
any('hook-augment' in str(x.get('args', [])) or
2776+
'hook-augment' in str(x.get('command', ''))
2777+
for x in h.get('hooks', []))
27612778
for entries in hooks.values() for h in entries)
27622779
sys.exit(1 if found else 0)
27632780
" 2>/dev/null; then

‎tests/test_cli.c‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10046,7 +10046,7 @@ TEST(cli_claude_hook_commands_use_exec_form_with_custom_config_dir) {
1004610046
yyjson_doc *document = settings ? yyjson_read(settings, strlen(settings), 0) : NULL;
1004710047
yyjson_val *root = document ? yyjson_doc_get_root(document) : NULL;
1004810048
static const char *const matchers[] = {"startup", "resume", "clear", "compact"};
10049-
size_t owned = test_count_exec_hook(root, "PreToolUse", "Grep|Glob", binary, "hook-augment") +
10049+
size_t owned = test_count_exec_hook(root, "PreToolUse", "Grep|Glob|Bash", binary, "hook-augment") +
1005010050
test_count_exec_hook(root, "PostToolUse", "Read", binary, "hook-augment") +
1005110051
test_count_exec_hook(root, "SubagentStart", "*", binary, "hook-augment");
1005210052
for (size_t i = 0U; i < sizeof(matchers) / sizeof(matchers[0]); i++) {
@@ -10914,7 +10914,7 @@ TEST(cli_upgrade_migrates_released_claude_hook_scripts) {
1091410914
yyjson_val *settings_root = settings_doc ? yyjson_doc_get_root(settings_doc) : NULL;
1091510915
static const char *const matchers[] = {"startup", "resume", "clear", "compact"};
1091610916
size_t registered =
10917-
test_count_exec_hook(settings_root, "PreToolUse", "Grep|Glob", binary, "hook-augment") +
10917+
test_count_exec_hook(settings_root, "PreToolUse", "Grep|Glob|Bash", binary, "hook-augment") +
1091810918
test_count_exec_hook(settings_root, "PostToolUse", "Read", binary, "hook-augment") +
1091910919
test_count_exec_hook(settings_root, "SubagentStart", "*", binary, "hook-augment");
1092010920
for (size_t i = 0U; i < sizeof(matchers) / sizeof(matchers[0]); i++) {
@@ -12124,8 +12124,13 @@ TEST(cli_windows_claude_lifecycle_migrates_only_exact_owned_legacy_state) {
1212412124
snprintf(settings_path, sizeof(settings_path), "%s/settings.json", config_dir);
1212512125
snprintf(appdata, sizeof(appdata), "%s/AppData/Roaming", tmpdir);
1212612126
snprintf(binary_path, sizeof(binary_path), "%s/.local/bin/codebase-memory-mcp.exe", tmpdir);
12127+
/* cbm_mkdtemp hands back a native '\\' temp root; the product normalizes
12128+
* the install directory before any registration (cbm_cmd_install), so the
12129+
* exact-owned exec command is the '/'-spelled path uninstall derives. */
12130+
cbm_normalize_path_sep(binary_path);
1212712131
test_mkdirp(hooks_dir);
1212812132

12133+
static const char *const matchers[] = {"startup", "resume", "clear", "compact"};
1212912134
const char *const script_names[] = {
1213012135
"cbm-code-discovery-gate",
1213112136
"cbm-session-reminder",
@@ -12199,13 +12204,21 @@ TEST(cli_windows_claude_lifecycle_migrates_only_exact_owned_legacy_state) {
1219912204
yyjson_doc *installed_doc =
1220012205
installed_settings ? yyjson_read(installed_settings, strlen(installed_settings), 0) : NULL;
1220112206
yyjson_val *installed_root = installed_doc ? yyjson_doc_get_root(installed_doc) : NULL;
12207+
/* Every owned shell spelling (current .cmd, previous, released) converges
12208+
* on one exec-form registration per matcher; foreign hooks are untouched. */
12209+
size_t installed_exec =
12210+
test_count_exec_hook(installed_root, "SubagentStart", "*", binary_path, "hook-augment");
12211+
for (size_t i = 0U; i < sizeof(matchers) / sizeof(matchers[0]); i++) {
12212+
installed_exec += test_count_exec_hook(installed_root, "SessionStart", matchers[i],
12213+
binary_path, "hook-augment");
12214+
}
1220212215
bool commands_migrated =
12203-
install_rc == 0 &&
12204-
test_count_hook_command(installed_root, "SessionStart", session_current) == 4U &&
12216+
install_rc == 0 && installed_exec == 5U &&
12217+
test_count_hook_command(installed_root, "SessionStart", session_current) == 0U &&
1220512218
test_count_hook_command(installed_root, "SessionStart", session_previous) == 0U &&
1220612219
test_count_hook_command(installed_root, "SessionStart", session_released) == 0U &&
1220712220
test_count_hook_command(installed_root, "SessionStart", foreign_command) == 1U &&
12208-
test_count_hook_command(installed_root, "SubagentStart", subagent_current) == 1U &&
12221+
test_count_hook_command(installed_root, "SubagentStart", subagent_current) == 0U &&
1220912222
test_count_hook_command(installed_root, "SubagentStart", subagent_previous) == 0U &&
1221012223
test_count_hook_command(installed_root, "SubagentStart", subagent_released) == 0U &&
1221112224
test_count_hook_command(installed_root, "SubagentStart", foreign_command) == 1U;
@@ -12229,8 +12242,14 @@ TEST(cli_windows_claude_lifecycle_migrates_only_exact_owned_legacy_state) {
1222912242
uninstalled_settings ? yyjson_read(uninstalled_settings, strlen(uninstalled_settings), 0)
1223012243
: NULL;
1223112244
yyjson_val *uninstalled_root = uninstalled_doc ? yyjson_doc_get_root(uninstalled_doc) : NULL;
12245+
size_t uninstalled_exec =
12246+
test_count_exec_hook(uninstalled_root, "SubagentStart", "*", binary_path, "hook-augment");
12247+
for (size_t i = 0U; i < sizeof(matchers) / sizeof(matchers[0]); i++) {
12248+
uninstalled_exec += test_count_exec_hook(uninstalled_root, "SessionStart", matchers[i],
12249+
binary_path, "hook-augment");
12250+
}
1223212251
bool commands_clean =
12233-
uninstall_rc == 0 &&
12252+
uninstall_rc == 0 && uninstalled_exec == 0U &&
1223412253
test_count_hook_command(uninstalled_root, "SessionStart", session_current) == 0U &&
1223512254
test_count_hook_command(uninstalled_root, "SessionStart", session_previous) == 0U &&
1223612255
test_count_hook_command(uninstalled_root, "SessionStart", session_released) == 0U &&
@@ -12453,7 +12472,7 @@ TEST(cli_claude_hooks_use_exec_form_across_shells_issue1733) {
1245312472
yyjson_doc *doc = settings ? yyjson_read(settings, strlen(settings), 0) : NULL;
1245412473
yyjson_val *root = doc ? yyjson_doc_get_root(doc) : NULL;
1245512474
size_t owned =
12456-
test_count_exec_hook(root, "PreToolUse", "Grep|Glob", binary_path, "hook-augment") +
12475+
test_count_exec_hook(root, "PreToolUse", "Grep|Glob|Bash", binary_path, "hook-augment") +
1245712476
test_count_exec_hook(root, "PostToolUse", "Read", binary_path, "hook-augment") +
1245812477
test_count_exec_hook(root, "SubagentStart", "*", binary_path, "hook-augment");
1245912478
for (size_t i = 0U; i < sizeof(matchers) / sizeof(matchers[0]); i++) {
@@ -12516,7 +12535,7 @@ TEST(cli_claude_exec_hooks_custom_dir_uninstall_issue1733) {
1251612535
yyjson_val *installed_root = installed_doc ? yyjson_doc_get_root(installed_doc) : NULL;
1251712536
const char *const matchers[] = {"startup", "resume", "clear", "compact"};
1251812537
size_t before_owned =
12519-
test_count_exec_hook(installed_root, "PreToolUse", "Grep|Glob", binary_path,
12538+
test_count_exec_hook(installed_root, "PreToolUse", "Grep|Glob|Bash", binary_path,
1252012539
"hook-augment") +
1252112540
test_count_exec_hook(installed_root, "PostToolUse", "Read", binary_path,
1252212541
"hook-augment") +

0 commit comments

Comments
 (0)