# Test Procedures

## Pre-Test Cleanup

Clean up any leftover artifacts from previous test runs (ignore errors):

**In `--dev` mode:**
```bash
node scripts/test-mcp-dev.js call execute '{"command":"store:delete","args":{"store":"bk-test-store"}}' 2>/dev/null || true
node scripts/test-mcp-dev.js call execute '{"command":"store:delete","args":{"store":"bk-test-folder"}}' 2>/dev/null || true
node scripts/test-mcp-dev.js call execute '{"command":"store:delete","args":{"store":"bk-crawl-test"}}' 2>/dev/null || true
rm -rf .bluera/bluera-knowledge/test-content
```

**In production mode:**
1. Call MCP `execute` with `{ command: "store:delete", args: { store: "bk-test-store" } }` - ignore errors
2. Call MCP `execute` with `{ command: "store:delete", args: { store: "bk-test-folder" } }` - ignore errors
3. Call MCP `execute` with `{ command: "store:delete", args: { store: "bk-crawl-test" } }` - ignore errors
4. Run: `rm -rf .bluera/bluera-knowledge/test-content`

## Test Content Setup

```bash
mkdir -p .bluera/bluera-knowledge/test-content
cat > .bluera/bluera-knowledge/test-content/test-file.md << 'EOF'
# BK Plugin Test File

This file contains unique test content for validating the Bluera Knowledge plugin.

## Test Function

The `validateBKPlugin` function performs comprehensive testing of all plugin features.
It checks MCP connectivity, store operations, search functionality, and cleanup.

Keywords: bluera-knowledge-test, plugin-validation, mcp-test
EOF
```

---

# PRODUCTION MODE (default)

Use this section if `--dev` flag is NOT present.

## Part 1: MCP Execute Commands

1. **help**: Call `execute` with `{ command: "help" }` — PASS if contains "Available commands"
2. **commands**: Call `execute` with `{ command: "commands" }` — PASS if contains all 15 commands
3. **stores**: Call `execute` with `{ command: "stores" }` — PASS if no error
4. **store:create**: `{ "command": "store:create", "args": { "name": "bk-test-store", "type": "file", "source": ".bluera/bluera-knowledge/test-content" } }` — PASS if success
5. **store:info**: `{ "command": "store:info", "args": { "store": "bk-test-store" } }` — PASS if contains name/type
6. **store:index**: `{ "command": "store:index", "args": { "store": "bk-test-store" } }` — PASS if indexing starts
7. **jobs**: `{ command: "jobs" }` — PASS if returns jobs array
8. **job:status**: `{ "command": "job:status", "args": { "jobId": "<from-step-6>" } }` — PASS if returns status. SKIP if synchronous.
9. **stores:health**: `{ command: "stores:health" }` — PASS if no error
10. **stores:check-models**: `{ command: "stores:check-models" }` — PASS if no error
11. **stores:sync**: `{ "command": "stores:sync", "args": { "dryRun": true } }` — PASS if returns sync result
12. **stores:pull**: `{ "command": "stores:pull", "args": { "store": "bk-test-store" } }` — PASS if error about non-repo store

## Part 2: MCP Search Tools

13. **search**: `{ "query": "validateBKPlugin", "stores": ["bk-test-store"] }` — PASS if non-empty results
14. **get_full_context**: Use resultId from step 13 — PASS if contains content

## Part 3: Slash Commands

15. `/stores` — PASS if bk-test-store listed
16. `/search "bluera-knowledge-test"` — PASS if results shown
17. `/suggest` — PASS if no error
18. `/check-status` — PASS if shows status
19. `/skill-activation` — PASS if shows config
20. `/index bk-test-store` — PASS if indexing starts
21. `/add-folder .bluera/bluera-knowledge/test-content --name bk-test-folder` — PASS if store created
22. `/health` — PASS if health report shown
23. `/sync --dry-run` — PASS if sync preview shown

## Part 4: Web Crawl Testing

24. **Create web store**: `bluera-knowledge crawl https://httpbin.org/html bk-crawl-test --max-pages 1` — PASS if crawl completes. SKIP if CLI unavailable.
25. **Verify store**: Check bk-crawl-test in stores list
26. **job:cancel**: Cancel crawl job if still running
27. **Delete crawl store**: Delete bk-crawl-test

## Part 5: Hook Tests

28. **Hook Registration**: `jq -e '(.hooks.PostToolUse | length) > 0 and (.hooks.UserPromptSubmit | length) > 0 and (.hooks.SessionStart | length) > 0' "$CLAUDE_PLUGIN_ROOT/hooks/hooks.json"` — PASS if true
29. **PostToolUse - Library**: `echo '{"tool_name": "Read", "tool_input": {"file_path": "/project/node_modules/express/index.js"}}' | python3 "$CLAUDE_PLUGIN_ROOT/hooks/posttooluse-bk-reminder.py"` — PASS if contains "BLUERA-KNOWLEDGE REMINDER"
30. **PostToolUse - Non-Library**: Same with `/project/src/index.ts` — PASS if empty output

## Part 6: Cleanup

31. **Delete test store**: Delete bk-test-store — PASS if deleted
32. **Delete test folder store**: Delete bk-test-folder — PASS if deleted or doesn't exist
33. **Remove test content**: `rm -rf .bluera/bluera-knowledge/test-content`
34. **Verify store cleanup**: Confirm bk-test-store and bk-test-folder not in list
35. **Verify no artifacts**: `test ! -d .bluera/bluera-knowledge/test-content && echo "clean"`

---

# DEVELOPMENT MODE (`--dev`)

Uses `scripts/test-mcp-dev.js`. Same tests as production but:
- All MCP calls via: `node scripts/test-mcp-dev.js call execute '<json>'`
- Tests 15-23 (slash commands) are SKIPPED — require Claude's skill router
- Set `CLAUDE_PLUGIN_ROOT` to current directory for hook tests

**Result: X/29 tests passed (9 skipped)**
