Skip to content

Commit 3466ba0

Browse files
committed
test(install): cover SubagentStart hook registration
Verify the Claude SubagentStart reminder: install writes a SubagentStart entry with a match-all matcher pointing at cbm-subagent-reminder, a second upsert is idempotent (no duplicate entry), and removal leaves no SubagentStart key behind. Signed-off-by: Shane McCarron <shane.mccarron@corvexconnect.com>
1 parent 64af0b8 commit 3466ba0

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎tests/test_cli.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,42 @@ TEST(cli_gemini_session_hook_parity) {
17501750
PASS();
17511751
}
17521752

1753+
/* Claude SubagentStart reminder: subagents spawned via the Agent tool do not
1754+
* fire SessionStart, so this hook is their code-discovery channel. Verify the
1755+
* install shape, idempotent re-install, and clean removal. */
1756+
TEST(cli_claude_subagent_hook) {
1757+
char tmpdir[256];
1758+
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-subhook-XXXXXX");
1759+
if (!cbm_mkdtemp(tmpdir))
1760+
FAIL("cbm_mkdtemp failed");
1761+
1762+
char cfg[512];
1763+
snprintf(cfg, sizeof(cfg), "%s/settings.json", tmpdir);
1764+
1765+
ASSERT_EQ(cbm_upsert_claude_subagent_hooks(cfg), 0);
1766+
const char *d = read_test_file(cfg);
1767+
ASSERT_NOT_NULL(d);
1768+
ASSERT(strstr(d, "SubagentStart") != NULL);
1769+
ASSERT(strstr(d, "\"*\"") != NULL); /* match-all matcher */
1770+
ASSERT(strstr(d, "cbm-subagent-reminder") != NULL); /* points at the hook script */
1771+
1772+
/* Idempotent: a second upsert must not duplicate our entry. */
1773+
ASSERT_EQ(cbm_upsert_claude_subagent_hooks(cfg), 0);
1774+
d = read_test_file(cfg);
1775+
ASSERT_NOT_NULL(d);
1776+
int count = 0;
1777+
for (const char *p = d; (p = strstr(p, "cbm-subagent-reminder")) != NULL; p++)
1778+
count++;
1779+
ASSERT_EQ(count, 1);
1780+
1781+
ASSERT_EQ(cbm_remove_claude_subagent_hooks(cfg), 0);
1782+
d = read_test_file(cfg);
1783+
ASSERT_NULL(strstr(d, "SubagentStart"));
1784+
1785+
test_rmdir_r(tmpdir);
1786+
PASS();
1787+
}
1788+
17531789
TEST(cli_detect_agents_finds_gemini) {
17541790
char tmpdir[256];
17551791
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-detect-XXXXXX");
@@ -2831,6 +2867,7 @@ SUITE(cli) {
28312867
RUN_TEST(cli_install_plan_receipt_no_mutation_issue388);
28322868
RUN_TEST(cli_codex_session_hook_issue330);
28332869
RUN_TEST(cli_gemini_session_hook_parity);
2870+
RUN_TEST(cli_claude_subagent_hook);
28342871
RUN_TEST(cli_detect_agents_finds_gemini);
28352872
RUN_TEST(cli_detect_agents_finds_zed);
28362873
RUN_TEST(cli_detect_agents_finds_antigravity);

0 commit comments

Comments
 (0)