Skip to content

Commit 49e6a75

Browse files
semsem
authored andcommitted
Fix project-specific references and add test suite
- Remove holace references from validate-dart-task.py - Make sync-docs-to-dart.py generic - Add comprehensive test suite (test_hooks.py) - Add simple test runner (run_tests.sh) - Add package.json for npm test support - Fix missing os import in no-mock-code.py
1 parent 915be7b commit 49e6a75

7 files changed

Lines changed: 489 additions & 56 deletions

File tree

banner-logo.png

-4.9 KB
Loading

no-mock-code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Ensures only real, functional implementations make it to production.
66
"""
77
import json
8+
import os
89
import re
910
import sys
1011
from pathlib import Path

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "claude-code-hooks",
3+
"version": "2.0.0",
4+
"description": "A comprehensive collection of hooks for Claude Code",
5+
"scripts": {
6+
"test": "./run_tests.sh",
7+
"test:verbose": "python3 test_hooks.py -v",
8+
"lint": "echo 'No linting configured yet'",
9+
"install-hooks": "./install.sh"
10+
},
11+
"keywords": [
12+
"claude",
13+
"claude-code",
14+
"hooks",
15+
"development",
16+
"automation"
17+
],
18+
"author": "webdevtodayjason",
19+
"license": "MIT",
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/webdevtodayjason/claude-hooks.git"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/webdevtodayjason/claude-hooks/issues"
26+
},
27+
"homepage": "https://github.com/webdevtodayjason/claude-hooks#readme"
28+
}

run_tests.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
# Simple test runner for Claude Code hooks
3+
4+
echo "Running Claude Code Hooks Tests..."
5+
echo "=================================="
6+
7+
# Test that hooks are executable
8+
echo -n "Checking hook executability... "
9+
all_executable=true
10+
for hook in *.py; do
11+
if [[ ! -x "$hook" ]]; then
12+
echo "$hook is not executable"
13+
all_executable=false
14+
fi
15+
done
16+
17+
if $all_executable; then
18+
echo "✅ All hooks are executable"
19+
fi
20+
21+
# Test basic functionality
22+
echo ""
23+
echo "Testing basic hook functionality..."
24+
25+
# Test validate-git-commit
26+
echo -n "Testing validate-git-commit.py... "
27+
result=$(echo '{"tool_name":"Bash","tool_input":{"command":"git commit -m \"fix\""}}' | python3 validate-git-commit.py 2>&1)
28+
if [[ $? -eq 2 ]] && [[ $result == *"too short"* ]]; then
29+
echo "✅ Correctly blocks short commits"
30+
else
31+
echo "❌ Failed to block short commits"
32+
fi
33+
34+
# Test no-mock-code
35+
echo -n "Testing no-mock-code.py... "
36+
# Just test it runs on a simple command
37+
result=$(echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | python3 no-mock-code.py 2>&1)
38+
if [[ $? -eq 0 ]]; then
39+
echo "✅ Runs without errors"
40+
else
41+
echo "❌ Hook failed with error"
42+
fi
43+
44+
# Test secret-scanner
45+
echo -n "Testing secret-scanner.py... "
46+
# Just test it runs on a simple command
47+
result=$(echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | python3 secret-scanner.py 2>&1)
48+
if [[ $? -eq 0 ]]; then
49+
echo "✅ Runs without errors"
50+
else
51+
echo "❌ Hook failed with error"
52+
fi
53+
54+
# Test that hooks don't break on normal operations
55+
echo ""
56+
echo "Testing hooks don't break normal operations..."
57+
58+
echo -n "Testing normal file write... "
59+
result=$(echo '{"tool_name":"Write","tool_input":{"file_path":"normal.js","content":"const data = await db.query();"}}' | python3 no-mock-code.py 2>&1)
60+
if [[ $? -eq 0 ]]; then
61+
echo "✅ Allows normal code"
62+
else
63+
echo "❌ Blocked normal code"
64+
fi
65+
66+
echo ""
67+
echo "=================================="
68+
echo "Tests complete!"

sync-docs-to-dart.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22
"""
33
Documentation sync hook.
4-
Automatically creates/updates documentation in Dart when .md files are created/modified.
4+
Reminds you to sync documentation to Dart when .md files are created/modified.
5+
This is a generic example that can be customized for your project.
56
"""
67
import json
78
import os
@@ -65,7 +66,7 @@ def create_dart_sync_reminder(file_path, content):
6566
"""Create a reminder to sync the document to Dart."""
6667
output = {
6768
"decision": "approve",
68-
"reason": f"Document will be synced to Dart after creation",
69+
"reason": f"Document can be synced to Dart after creation",
6970
"suppressOutput": False
7071
}
7172

@@ -96,9 +97,9 @@ def create_dart_sync_reminder(file_path, content):
9697
pass
9798

9899
# Provide feedback
99-
print(f"📝 Document '{sync_info['title']}' marked for Dart sync", file=sys.stderr)
100-
print(f" Location: holace/Docs", file=sys.stderr)
101-
print(f" Run 'mcp__dart__create_doc' to complete sync", file=sys.stderr)
100+
print(f"📝 Document '{sync_info['title']}' can be synced to Dart", file=sys.stderr)
101+
print(f" 💡 Use 'mcp__dart__create_doc' to sync documentation", file=sys.stderr)
102+
print(f" 📁 Choose your preferred folder in Dart", file=sys.stderr)
102103

103104
return output
104105

0 commit comments

Comments
 (0)