Skip to content

Commit 7743a82

Browse files
refactor: enhance skill logging in hook-cursor-prompt-dispatch.sh and update test environment variables
- Updated the skill logging guard in `hook-cursor-prompt-dispatch.sh` to allow overriding the repository root for testing purposes. - Modified test cases in `hook-dispatchers.test.ts` to use the new `TOOL_USAGE_REPO_ROOT` environment variable instead of `GIT_DIR`, improving test isolation and flexibility.
1 parent 5126c91 commit 7743a82

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

scripts/tooling/hook-cursor-prompt-dispatch.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ _skill_name=$(printf '%s' "$_payload" \
1919

2020
[ -z "${_skill_name:-}" ] && exit 0
2121

22-
# Only log skills shipped in this repo
23-
_repo_root=$(git rev-parse --show-toplevel 2>/dev/null)
22+
# Only log skills shipped in this repo.
23+
# TOOL_USAGE_REPO_ROOT can be overridden in tests to avoid a real git lookup.
24+
_repo_root="${TOOL_USAGE_REPO_ROOT:-$(git rev-parse --show-toplevel 2>/dev/null)}"
2425
_is_known_skill=0
2526
for _dir in \
2627
"${_repo_root}/.claude/skills" \

scripts/tooling/hook-dispatchers.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,9 @@ describe('Cursor slash command prompt payload', () => {
303303
runDispatcher(CURSOR_PROMPT_DISPATCHER, {
304304
stdin: slashCommandPayload,
305305
env: {
306-
CI: '', // opt-in to collection
307-
HOME: tmpDir, // resolve SKILL.md via the stub created in beforeEach
308-
GIT_DIR: '/dev/null', // prevent git rev-parse from resolving the real repo root
309-
TOOL_USAGE_COLLECTION_LOG_PATH: logFile, // write to the per-test temp file
306+
CI: '', // opt-in to collection
307+
TOOL_USAGE_REPO_ROOT: tmpDir, // resolve SKILL.md via the stub created in beforeEach
308+
TOOL_USAGE_COLLECTION_LOG_PATH: logFile, // write to the per-test temp file
310309
},
311310
});
312311

@@ -328,10 +327,9 @@ describe('Cursor slash command prompt payload', () => {
328327
const result = runDispatcher(CURSOR_PROMPT_DISPATCHER, {
329328
stdin: JSON.stringify({ prompt: '/totally-fake-skill', session_id: 's' }),
330329
env: {
331-
CI: '', // opt-in to collection
332-
HOME: tmpDir, // resolve SKILL.md via the stub created in beforeEach
333-
GIT_DIR: '/dev/null', // prevent git rev-parse from resolving the real repo root
334-
TOOL_USAGE_COLLECTION_LOG_PATH: logFile, // write to the per-test temp file
330+
CI: '', // opt-in to collection
331+
TOOL_USAGE_REPO_ROOT: tmpDir, // resolve SKILL.md via the stub created in beforeEach
332+
TOOL_USAGE_COLLECTION_LOG_PATH: logFile, // write to the per-test temp file
335333
},
336334
});
337335
expect(result.stdout.trim()).toBe('{"permission":"allow"}');
@@ -366,10 +364,9 @@ describe('Cursor slash command prompt payload', () => {
366364
runDispatcher(CURSOR_PROMPT_DISPATCHER, {
367365
stdin: slashCommandPayload,
368366
env: {
369-
CI: '', // opt-in to collection
370-
HOME: tmpDir, // resolve SKILL.md via the stub created in beforeEach
371-
GIT_DIR: '/dev/null', // prevent git rev-parse from resolving the real repo root
372-
TOOL_USAGE_COLLECTION_LOG_PATH: logFile, // write to the per-test temp file
367+
CI: '', // opt-in to collection
368+
TOOL_USAGE_REPO_ROOT: tmpDir, // resolve SKILL.md via the stub created in beforeEach
369+
TOOL_USAGE_COLLECTION_LOG_PATH: logFile, // write to the per-test temp file
373370
},
374371
});
375372

0 commit comments

Comments
 (0)