# 🧪 Crafted Skills - Testing Guide

**Complete testing checklist for Crafted Skills**

This guide helps you verify that Skills work correctly in your Crafted project.

---

## 📋 Pre-Test Checklist

Before testing, ensure:

- [x] Crafted project created (`crafted clone`)
- [x] MCP servers installed (`crafted install-mcp-all`)
- [x] Skills installed (`crafted install-skills`)
- [x] Claude Code configured (`.mcp.json` exists)
- [x] Project dependencies installed (`pnpm install`)

Verify installation:

```bash
# Check skills directory
ls -la .claude/skills/

# Should show:
# README.md
# TUTORIAL.md
# QUICKSTART.md
# levels/
# workflows/
# agents/
# utils/

# Check .craftedrc.json
cat .craftedrc.json

# Should show:
# {
#   "level": "balanced",  # or rapid/crafted
#   "platform": "web"     # or web-mobile
# }
```

---

## 🎯 Test Suite

### Test 1: Auto-Detection

**Objective**: Verify Skills auto-detect project level

**Steps**:
1. Open Claude Code in VS Code
2. Type: `"What level is this project?"`

**Expected Result**:
```
Claude should respond with:
"This is a BALANCED-level project (detected from .craftedrc.json)."

And explain what that means:
- 3-layer architecture
- Max 50 lines per function
- 70% test coverage
- etc.
```

**Pass Criteria**: ✅ Correct level detected

---

### Test 2: Level Skills

**Objective**: Verify level skills can be activated

#### Test 2.1: Rapid Skill

**Prompt**: `/rapid`

**Expected Result**:
```
Rapid Mode activated

Context: 1-2 developers, 3-6 months, 0-100 users
Rules:
  • Functions: < 100 lines
  • Coverage: None required
  • Architecture: Flat (logic in routers)

Philosophy: "Ship fast, iterate, learn"
```

**Pass Criteria**: ✅ Shows Rapid rules

#### Test 2.2: Balanced Skill

**Prompt**: `/balanced`

**Expected Result**:
```
Balanced Mode activated

Context: 3-10 developers, 1-3 years, 100-10K users
Rules:
  • Functions: < 50 lines
  • Parameters: Max 3
  • Coverage: 70% minimum
  • Architecture: 3-layer (Router → Service → Repository)

Philosophy: "Quality where it matters"
```

**Pass Criteria**: ✅ Shows Balanced rules

#### Test 2.3: Crafted Skill

**Prompt**: `/crafted`

**Expected Result**:
```
Crafted Mode activated

Context: 10-200+ developers, 5-10+ years, 10K-1M+ users
Rules:
  • Functions: < 20 lines
  • Parameters: Max 2
  • Coverage: Domain 100%, Use-cases 100%, Infrastructure 80%
  • Architecture: Hexagonal (Domain → Application → Infrastructure)

Philosophy: "Build it right, sustainable for 10+ years"
```

**Pass Criteria**: ✅ Shows Crafted rules

---

### Test 3: Workflow Skills

#### Test 3.1: Feature Workflow

**Prompt**: `"I want to add a simple user profile feature with name and bio"`

**Expected Behavior**:
1. Auto-detects level
2. Activates /feature workflow
3. Goes through phases:
   - Architecture (design)
   - Implementation (code)
   - Testing (tests)
   - Review (validation)

**Expected Result** (for Balanced level):
```
🔍 Auto-detect: balanced level

🏗️  Architect: Design 3-layer architecture
   Router: userRouter.getProfile(), userRouter.updateProfile()
   Service: userService with business logic
   Repository: userRepository for data access

👨‍💻 Developer: Implement
   Files created:
   ✅ packages/api/routers/user.ts (18 lines)
   ✅ packages/services/user.service.ts (42 lines)
   ✅ packages/database/repositories/user.repository.ts (25 lines)

🧪 Tester: Write tests
   ✅ Unit tests (service)
   ✅ Integration tests
   Coverage: 78%

👀 Reviewer: Validate
   ✅ Code quality OK
   ✅ Architecture OK
   ✅ Coverage OK

Feature ready! 🎉
```

**Pass Criteria**:
- ✅ Auto-detects level
- ✅ Creates appropriate architecture (3-layer for Balanced)
- ✅ Generates code following level rules
- ✅ Writes tests with appropriate coverage
- ✅ Validates everything

**Files to Check**:
```bash
# Should exist:
ls packages/api/routers/user.ts
ls packages/services/user.service.ts
ls packages/database/repositories/user.repository.ts
ls packages/services/user.service.test.ts

# Code should be clean:
# - Router < 20 lines
# - Service < 50 lines
# - No inline comments
# - Self-documenting
```

#### Test 3.2: Bugfix Workflow

**Setup**: First, introduce a "bug" to fix

**Prompt**: `"Bug: When I try to update user profile with empty name, it saves anyway. It should reject empty names."`

**Expected Behavior**:
1. Reproduce (writes failing test)
2. Diagnose (finds issue)
3. Fix (updates validation)
4. Test (regression test)
5. Validate (no side effects)

**Expected Result**:
```
🔍 Step 1: Reproduce
Writing failing test...

it('should reject empty name', async () => {
  await expect(
    userService.updateProfile(userId, { name: '' })
  ).rejects.toThrow('Name cannot be empty');
});

❌ Test fails (bug confirmed)

🔬 Step 2: Diagnose
Found issue in userService.updateProfile()
Missing validation for empty name

🔧 Step 3: Fix
Adding validation:

if (!data.name || data.name.trim() === '') {
  throw new ValidationError('Name cannot be empty');
}

🧪 Step 4: Test
✅ Regression test passes
✅ All tests pass

✅ Step 5: Validate
No side effects detected

Bug fixed! 🎉
```

**Pass Criteria**:
- ✅ Writes failing test first
- ✅ Finds root cause
- ✅ Fixes issue
- ✅ Adds regression test
- ✅ Validates no side effects

#### Test 3.3: Refactor Workflow

**Setup**: Have some code that needs refactoring

**Prompt**: `"This userService file is getting long, can you refactor it?"`

**Expected Behavior**:
1. Analyze (finds issues)
2. Plan (refactoring strategy)
3. Refactor (applies changes)
4. Test (ensures behavior unchanged)
5. Validate (metrics improved)

**Expected Result**:
```
🔍 Step 1: Analyze

File: packages/services/user.service.ts
Current: 120 lines
Issues:
  ❌ Too long (max 50 lines per function for Balanced)
  ❌ Mixed concerns

📋 Step 2: Plan

Strategy:
  1. Extract profile logic to user-profile.service.ts
  2. Extract auth logic to user-auth.service.ts
  3. Keep core user logic in user.service.ts

🔨 Step 3: Refactor
✅ Created user-profile.service.ts (35 lines)
✅ Created user-auth.service.ts (28 lines)
✅ Updated user.service.ts (40 lines)

🧪 Step 4: Test
✅ All tests pass (behavior unchanged)

✅ Step 5: Validate
Before: 120 lines in one file
After: 3 files (35, 28, 40 lines)

Refactoring complete! 🎉
```

**Pass Criteria**:
- ✅ Identifies issues
- ✅ Creates refactoring plan
- ✅ Applies refactoring
- ✅ Tests pass
- ✅ Metrics improved

#### Test 3.4: Security Workflow

**Prompt**: `"Can you review the security of the user authentication?"`

**Expected Behavior**:
1. Scan (automated checks)
2. Analyze (OWASP Top 10)
3. Harden (fix issues)
4. Test (security tests)
5. Document (ADR/docs)

**Expected Result**:
```
🔍 Step 1: Scan
✅ No hardcoded secrets
⚠️  3 dependencies with vulnerabilities (will update)

🛡️  Step 2: OWASP Top 10 Analysis

Issues found:
  ⚠️  Missing rate limiting on login
  ⚠️  Weak password requirements (min 8 chars)
  ⚠️  No audit logging

🔧 Step 3: Harden
✅ Added rate limiting (5 attempts/minute)
✅ Strengthened password (min 12 chars + complexity)
✅ Added audit logging

🧪 Step 4: Security Tests
✅ Should rate limit after 5 attempts
✅ Should reject weak passwords
✅ Should log security events

📝 Step 5: Document
✅ Created ADR-050: Authentication Security Hardening
✅ Updated SECURITY.md

Security review complete! 🛡️
```

**Pass Criteria**:
- ✅ Runs automated scans
- ✅ Identifies security issues
- ✅ Implements fixes
- ✅ Adds security tests
- ✅ Documents decisions

---

### Test 4: Agent Skills

#### Test 4.1: Architect Mode

**Prompt**: `/architect "Design a notification system that supports email, SMS, and push notifications"`

**Expected Result**:
```
🏗️  Architect Mode Activated

Detected level: balanced

Designing notification system with 3-layer architecture:

Router Layer:
  - notificationRouter.send()
  - notificationRouter.list()
  - notificationRouter.markAsRead()

Service Layer:
  - notificationService (orchestration)
  - Strategy pattern for different channels:
    • EmailNotificationStrategy (Resend)
    • SmsNotificationStrategy (Twilio)
    • PushNotificationStrategy (Expo)

Repository Layer:
  - notificationRepository (history)

Creating ADR-051: Multi-Channel Notification System
  Decision: Strategy pattern for extensibility
  Alternatives: Factory pattern (rejected - less flexible)
```

**Pass Criteria**:
- ✅ Provides architecture design only
- ✅ Follows level-appropriate patterns
- ✅ Creates ADR
- ✅ Doesn't implement (just designs)

#### Test 4.2: Developer Mode

**Prompt**: `/developer "Implement the email notification strategy"`

**Expected Result**:
```
👨‍💻 Developer Mode Activated

Implementing EmailNotificationStrategy...

Files created:
  ✅ packages/services/notifications/EmailNotificationStrategy.ts

Code follows Balanced rules:
  ✅ < 50 lines per function
  ✅ Max 3 parameters
  ✅ No inline comments
  ✅ Self-documenting

Validating...
  ✅ No violations

Implementation complete!
```

**Pass Criteria**:
- ✅ Implements code only
- ✅ Follows level rules
- ✅ Validates quality
- ✅ Doesn't write tests (that's Tester's job)

#### Test 4.3: Tester Mode

**Prompt**: `/tester "Add tests for the email notification strategy"`

**Expected Result**:
```
🧪 Tester Mode Activated

Writing tests for EmailNotificationStrategy...

Tests:
  ✅ Should send email with valid data
  ✅ Should reject invalid email
  ✅ Should handle Resend errors
  ✅ Should retry on failure

Running tests...
  ✅ 4 tests passing

Coverage:
  ✅ EmailNotificationStrategy: 100%
  ✅ Overall: 76% (required: 70%)

Tests complete!
```

**Pass Criteria**:
- ✅ Writes comprehensive tests
- ✅ Tests happy path + edge cases
- ✅ Ensures coverage requirements
- ✅ Doesn't implement code (that's Developer's job)

#### Test 4.4: Reviewer Mode

**Prompt**: `/reviewer "Review the notification system implementation"`

**Expected Result**:
```
👀 Reviewer Mode Activated

Reviewing notification system...

✅ Code Quality:
  ✅ Self-documenting code
  ✅ No inline comments
  ✅ Proper error handling

✅ Architecture:
  ✅ 3-layer separation
  ✅ Strategy pattern correctly implemented
  ✅ No circular dependencies

✅ Testing:
  ✅ Coverage: 78% (required: 70%)
  ✅ All tests pass

✅ Security:
  ✅ Input validation present
  ✅ No hardcoded secrets

Implementation approved! ✅
```

**Pass Criteria**:
- ✅ Reviews code quality
- ✅ Checks architecture
- ✅ Validates tests
- ✅ Checks security
- ✅ Provides approval or requests changes

---

### Test 5: Utility Skills

#### Test 5.1: Validate

**Prompt**: `/validate`

**Expected Result**:
```
✅ Code validates for BALANCED level

Checks:
  ✅ Function length: All < 50 lines
  ✅ Parameters: All ≤ 3 params
  ✅ Type safety: All functions typed
  ⚠️  Duplication: 2 places (acceptable for Balanced)

No blocking issues!
```

**Pass Criteria**: ✅ Shows validation results

#### Test 5.2: Guard

**Prompt**: `/guard`

**Expected Result**:
```
✅ Architecture boundaries OK for BALANCED level

Checks:
  ✅ 3-layer separation
  ✅ No circular dependencies
  ✅ Services don't import routers
  ✅ Repositories don't import services

Architecture is clean!
```

**Pass Criteria**: ✅ Shows architecture check results

#### Test 5.3: Coverage

**Prompt**: `/coverage`

**Expected Result**:
```
✅ Test coverage OK for BALANCED level

Coverage: 76% (required: 70%)

Breakdown:
  ✅ Services: 84%
  ✅ Repositories: 72%
  ✅ Routers: 68%

All requirements met!
```

**Pass Criteria**: ✅ Shows coverage results

---

## 🔄 Test Different Levels

### Test with Rapid Level

**Setup**: Change `.craftedrc.json` to `"level": "rapid"`

**Test**: `"Add a simple todo feature"`

**Expected**:
- Flat architecture (logic in router)
- Functions can be up to 100 lines
- No test coverage requirement
- Duplication acceptable

### Test with Crafted Level

**Setup**: Change `.craftedrc.json` to `"level": "crafted"`

**Test**: `"Add a product entity with price validation"`

**Expected**:
- Hexagonal architecture
- Domain entities (pure business logic)
- Use-cases for orchestration
- Spec-First TDD (tests written FIRST)
- 100% domain coverage
- Max 20 lines per function

---

## 📊 Results Summary

After running all tests, you should have:

### ✅ Pass Criteria

- [ ] Auto-detection works
- [ ] All level skills activate correctly
- [ ] All workflow skills complete end-to-end
- [ ] All agent skills work independently
- [ ] All utility skills provide validation
- [ ] Skills adapt to different levels
- [ ] MCP tools are called correctly (check logs)
- [ ] Generated code follows level rules
- [ ] Tests are comprehensive
- [ ] Architecture is validated

### 📝 Test Report Template

```markdown
# Crafted Skills Test Report

**Date**: YYYY-MM-DD
**Project**: [Project Name]
**Level**: [Rapid/Balanced/Crafted]
**Platform**: [Web/Web+Mobile]

## Test Results

### Level Skills
- [ ] /rapid - PASS/FAIL
- [ ] /balanced - PASS/FAIL
- [ ] /crafted - PASS/FAIL

### Workflow Skills
- [ ] /feature - PASS/FAIL
- [ ] /bugfix - PASS/FAIL
- [ ] /refactor - PASS/FAIL
- [ ] /security - PASS/FAIL

### Agent Skills
- [ ] /architect - PASS/FAIL
- [ ] /developer - PASS/FAIL
- [ ] /tester - PASS/FAIL
- [ ] /reviewer - PASS/FAIL

### Utility Skills
- [ ] /validate - PASS/FAIL
- [ ] /guard - PASS/FAIL
- [ ] /coverage - PASS/FAIL

## Issues Found

[List any issues or unexpected behaviors]

## Overall Status

✅ PASS / ❌ FAIL

## Notes

[Any additional observations]
```

---

## 🐛 Common Issues & Solutions

### Issue: Skills not activating

**Symptoms**: Skills don't respond to slash commands

**Solutions**:
1. Verify installation: `ls .claude/skills/`
2. Check `.mcp.json` is configured
3. Reload VS Code window
4. Check Claude Code logs

### Issue: Wrong level detected

**Symptoms**: Skills apply wrong rules (e.g., expects Crafted but applies Rapid)

**Solutions**:
1. Check `.craftedrc.json`: `cat .craftedrc.json`
2. Ensure `level` field is correct
3. Restart Claude Code

### Issue: MCP tools not found

**Symptoms**: Error messages about missing MCP tools

**Solutions**:
1. Install MCP servers: `crafted install-mcp-all`
2. Check `.mcp.json` configuration
3. Verify Context Manager is built: `ls .ai/context/dist/`

---

## 📊 Performance Benchmarks

Expected performance for workflow skills:

| Workflow | Expected Time | Notes |
|----------|---------------|-------|
| /feature (simple) | 30-60s | Basic CRUD feature |
| /feature (complex) | 2-3 min | Multi-layer with tests |
| /bugfix | 30-90s | Depends on complexity |
| /refactor | 1-2 min | Depends on scope |
| /security | 2-3 min | Full review |

Utility skills should be instant (< 5s).

---

## ✅ Sign Off

After completing all tests and resolving issues:

```
Crafted Skills Testing Complete ✅

All skills working as expected:
  ✅ Auto-detection
  ✅ Level adaptation
  ✅ Workflow orchestration
  ✅ Agent specialization
  ✅ Utility validation

Ready for production use! 🚀
```

---

**Questions or issues?**
- GitHub: https://github.com/crafted-saas/issues
- Discord: https://discord.gg/crafted-saas
