-
Notifications
You must be signed in to change notification settings - Fork 0
517 lines (433 loc) · 16.7 KB
/
ci.yml
File metadata and controls
517 lines (433 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
validate:
name: Validate Plugin Structure
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Validate plugin.json
run: |
echo "Validating .claude-plugin/plugin.json..."
python3 -c "import json; json.load(open('.claude-plugin/plugin.json'))"
echo "Valid JSON"
- name: Validate marketplace.json
run: |
echo "Validating .claude-plugin/marketplace.json..."
python3 -c "
import json
with open('.claude-plugin/marketplace.json') as f:
m = json.load(f)
# Check required fields
assert 'name' in m, 'Missing name field'
assert 'owner' in m, 'Missing owner field'
assert 'plugins' in m, 'Missing plugins field'
assert len(m['plugins']) > 0, 'No plugins defined'
for p in m['plugins']:
assert 'name' in p, 'Plugin missing name'
assert 'source' in p, 'Plugin missing source'
print('All required fields present')
"
echo "Valid marketplace.json"
- name: Validate hooks.json
run: |
echo "Validating hooks/hooks.json..."
python3 -c "import json; json.load(open('hooks/hooks.json'))"
echo "Valid JSON"
- name: Validate plugin configuration
run: |
echo "Running comprehensive plugin configuration validation..."
uv run tests/test_plugin_config.py
- name: Lint bash scripts
run: |
echo "Checking bash script syntax..."
for script in scripts/*.sh; do
echo " Checking $script..."
bash -n "$script"
done
echo "All scripts have valid syntax"
test-scripts:
name: Test Plugin Scripts
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Create test project
run: |
mkdir -p test-project
cd test-project
# Python test file
cat > main.py << 'EOF'
"""Test Python module for CI."""
class TestClass:
"""A test class with documentation."""
def method_one(self, value: int) -> str:
"""Convert value to string."""
return str(value)
def helper_function(x: int, y: int) -> int:
"""Add two numbers together."""
return x + y
EOF
# C++ test file
cat > lib.cpp << 'EOF'
/// A simple C++ class for testing
class Calculator {
public:
/// Add two integers
int add(int a, int b) {
return a + b;
}
};
/// Multiply two numbers
int multiply(int x, int y) {
return x * y;
}
EOF
# Rust test file
cat > utils.rs << 'EOF'
/// A point in 2D space
struct Point {
x: f64,
y: f64,
}
impl Point {
/// Create a new point
fn new(x: f64, y: f64) -> Self {
Point { x, y }
}
}
/// Calculate distance between two points
fn distance(p1: &Point, p2: &Point) -> f64 {
((p2.x - p1.x).powi(2) + (p2.y - p1.y).powi(2)).sqrt()
}
EOF
- name: Run scan.py
run: |
cd test-project
uv run ../scripts/scan.py .
echo "--- Manifest content ---"
cat .claude/project-manifest.json
- name: Run map.py
run: |
cd test-project
uv run ../scripts/map.py . 2>&1 | head -100
echo "--- Repo map generated ---"
- name: Verify manifest output
run: |
cd test-project
if [ ! -f ".claude/project-manifest.json" ]; then
echo "ERROR: project-manifest.json not created"
exit 1
fi
# Check it's valid JSON
python3 -c "import json; json.load(open('.claude/project-manifest.json'))"
echo "Manifest is valid JSON"
- name: Verify repo-map output
run: |
cd test-project
if [ ! -f ".claude/repo-map.md" ]; then
echo "ERROR: repo-map.md not created"
exit 1
fi
# Verify Python symbols were extracted
if ! grep -q "TestClass" .claude/repo-map.md; then
echo "ERROR: Python class not found in repo map"
exit 1
fi
if ! grep -q "helper_function" .claude/repo-map.md; then
echo "ERROR: Python function not found in repo map"
exit 1
fi
# Verify C++ symbols were extracted
if ! grep -q "Calculator" .claude/repo-map.md; then
echo "ERROR: C++ class not found in repo map"
exit 1
fi
if ! grep -q "multiply" .claude/repo-map.md; then
echo "ERROR: C++ function not found in repo map"
exit 1
fi
# Verify Rust symbols were extracted
if ! grep -q "Point" .claude/repo-map.md; then
echo "ERROR: Rust struct not found in repo map"
exit 1
fi
if ! grep -q "distance" .claude/repo-map.md; then
echo "ERROR: Rust function not found in repo map"
exit 1
fi
echo "All expected symbols found in repo map"
- name: Verify cache created
run: |
cd test-project
if [ ! -f ".claude/repo-map-cache.json" ]; then
echo "ERROR: repo-map-cache.json not created"
exit 1
fi
python3 -c "import json; json.load(open('.claude/repo-map-cache.json'))"
echo "Cache file is valid JSON"
- name: Verify SQLite database created
run: |
cd test-project
if [ ! -f ".claude/repo-map.db" ]; then
echo "ERROR: repo-map.db not created"
exit 1
fi
# Verify database structure and content
python3 << 'EOF'
import sqlite3
conn = sqlite3.connect('.claude/repo-map.db')
# Check table exists
tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()
assert ('symbols',) in tables, "symbols table not found"
# Check indexes exist
indexes = conn.execute("SELECT name FROM sqlite_master WHERE type='index'").fetchall()
index_names = [i[0] for i in indexes]
assert 'idx_name' in index_names, "idx_name index not found"
assert 'idx_file' in index_names, "idx_file index not found"
assert 'idx_kind' in index_names, "idx_kind index not found"
# Check symbols were inserted
count = conn.execute("SELECT COUNT(*) FROM symbols").fetchone()[0]
assert count > 0, f"No symbols in database, expected > 0"
# Check specific symbols exist
symbols = conn.execute("SELECT name FROM symbols").fetchall()
symbol_names = [s[0] for s in symbols]
assert 'TestClass' in symbol_names, "TestClass not in database"
assert 'helper_function' in symbol_names, "helper_function not in database"
assert 'Calculator' in symbol_names, "Calculator not in database"
assert 'Point' in symbol_names, "Point not in database"
# Check end_line_number column exists and has values
cursor = conn.execute("SELECT name, line_number, end_line_number FROM symbols WHERE name = 'helper_function'")
row = cursor.fetchone()
assert row is not None, "helper_function not found"
assert row[2] is not None, "end_line_number should not be None for helper_function"
assert row[2] > row[1], f"end_line_number ({row[2]}) should be > line_number ({row[1]})"
print(f"end_line_number verified: helper_function spans lines {row[1]}-{row[2]}")
print(f"SQLite database valid with {count} symbols")
conn.close()
EOF
- name: Test MCP server syntax
run: |
python3 -m py_compile servers/repo-map-server.py
echo "MCP server syntax valid"
- name: Test MCP server imports
run: |
cd test-project
# Test that the server can import and initialize
# Use --project .. to find pyproject.toml with MCP dependency
uv run --project .. python3 << 'EOF'
import sys
sys.path.insert(0, '..')
# Just test imports work - full MCP test needs async
import sqlite3
import fnmatch
import json
from pathlib import Path
# Verify we can import mcp (installed by uv)
from mcp.server import Server
from mcp.types import Tool, TextContent
print("All MCP server imports successful")
EOF
- name: Test MCP server query functions
run: |
cd test-project
PROJECT_ROOT="$(pwd)"
export PROJECT_ROOT
# Use --project .. to find pyproject.toml with MCP dependency
uv run --project .. python3 << 'EOF'
import os
import sqlite3
from pathlib import Path
import fnmatch
PROJECT_ROOT = Path(os.environ.get("PROJECT_ROOT", os.getcwd()))
DB_PATH = PROJECT_ROOT / ".claude" / "repo-map.db"
def get_db():
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
return conn
def row_to_dict(row):
return {key: row[key] for key in row.keys()}
# Test search_symbols logic
conn = get_db()
pattern = "helper_*"
sql_pattern = pattern.replace("*", "%").replace("?", "_")
cursor = conn.execute("SELECT * FROM symbols WHERE name LIKE ?", [sql_pattern])
rows = cursor.fetchall()
results = [row_to_dict(row) for row in rows if fnmatch.fnmatch(row["name"], pattern)]
assert len(results) == 1, f"Expected 1 result for 'helper_*', got {len(results)}"
assert results[0]["name"] == "helper_function"
print(f"search_symbols test passed: found {results[0]['name']}")
# Test get_file_symbols logic
cursor = conn.execute("SELECT * FROM symbols WHERE file_path = ? ORDER BY line_number", ["main.py"])
results = [row_to_dict(row) for row in cursor.fetchall()]
assert len(results) >= 2, f"Expected >= 2 symbols in main.py, got {len(results)}"
print(f"get_file_symbols test passed: found {len(results)} symbols in main.py")
# Test kind filter
cursor = conn.execute("SELECT * FROM symbols WHERE kind = ?", ["class"])
classes = cursor.fetchall()
assert len(classes) >= 3, f"Expected >= 3 classes, got {len(classes)}"
print(f"Kind filter test passed: found {len(classes)} classes")
conn.close()
print("All MCP query function tests passed!")
EOF
- name: Test get_symbol_content function
run: |
cd test-project
PROJECT_ROOT="$(pwd)"
export PROJECT_ROOT
# Use --project .. to find pyproject.toml with MCP dependency
uv run --project .. python3 << 'EOF'
import os
import sqlite3
from pathlib import Path
PROJECT_ROOT = Path(os.environ.get("PROJECT_ROOT", os.getcwd()))
DB_PATH = PROJECT_ROOT / ".claude" / "repo-map.db"
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
# Test get_symbol_content logic
cursor = conn.execute(
"SELECT * FROM symbols WHERE name = ?",
["helper_function"]
)
row = cursor.fetchone()
assert row is not None, "helper_function not found"
file_path = PROJECT_ROOT / row["file_path"]
assert file_path.exists(), f"File not found: {row['file_path']}"
lines = file_path.read_text(encoding="utf-8").splitlines()
start_line = row["line_number"]
end_line = row["end_line_number"]
assert end_line is not None, "end_line_number should not be None"
content_lines = lines[start_line - 1:end_line]
content = "\n".join(content_lines)
assert "def helper_function" in content, "Content should include function definition"
assert "return x + y" in content, "Content should include function body"
print(f"get_symbol_content test passed!")
print(f"Retrieved {len(content_lines)} lines for helper_function")
conn.close()
EOF
- name: Test incremental update
run: |
cd test-project
# Add a new file
cat > extra.py << 'EOF'
def new_function():
"""A newly added function."""
pass
EOF
# Re-run repo map
uv run ../scripts/map.py . 2>&1 | tail -10
# Verify new function was picked up in markdown
if ! grep -q "new_function" .claude/repo-map.md; then
echo "ERROR: New function not found in repo-map.md after incremental update"
exit 1
fi
# Verify new function was picked up in SQLite
python3 << 'EOF'
import sqlite3
conn = sqlite3.connect('.claude/repo-map.db')
result = conn.execute("SELECT name FROM symbols WHERE name = 'new_function'").fetchone()
assert result is not None, "new_function not found in SQLite database"
print("new_function found in SQLite database")
conn.close()
EOF
echo "Incremental update works correctly for both markdown and SQLite"
test-update-context:
name: Test Update Context & Git Hooks
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Run update-context tests
run: uv run tests/test_update_context.py
test-session-start:
name: Test Session Start Hook
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Create test project
run: |
mkdir -p test-project
cat > test-project/app.py << 'EOF'
"""Simple test application."""
def main():
"""Entry point."""
print("Hello, World!")
EOF
- name: Run session-start.sh
run: |
cd test-project
export CLAUDE_PLUGIN_ROOT="${GITHUB_WORKSPACE}"
bash ../scripts/session-start.sh
echo "Session start hook completed"
- name: Verify session start output
run: |
cd test-project
# Give background process a moment
sleep 2
if [ ! -f ".claude/project-manifest.json" ]; then
echo "ERROR: Manifest not created by session start"
exit 1
fi
echo "Session start hook works correctly"
test-plugin-install:
name: Test Plugin Installation
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Claude Code CLI
run: npm install -g @anthropic-ai/claude-code
- name: Verify Claude Code installed
run: claude --version
- name: Add marketplace from local checkout
run: |
echo "Adding local directory as marketplace..."
claude plugin marketplace add ./
echo "Marketplace added successfully"
- name: Install plugin
run: |
echo "Installing context-daddy plugin..."
claude plugin install context-daddy
echo "Plugin installed successfully"
- name: Test plugin loads with --plugin-dir
run: |
echo "Testing plugin loads correctly..."
# Just verify the CLI accepts the --plugin-dir flag without error
claude --plugin-dir ./ --version
echo "Plugin loads without errors"