CAP-008: Testing & Simulation

Structured Data

Capability Metadata

FieldValue
IDCAP-008
Versionv1.2
DomainQuality & Testing
StatusDocumented
RelatedCAP-007, CAP-025, CAP-016
Sourcesrc/testing/skill-simulator.ts
Toggleenable_testing (integration.json)

Configuration Reference

Toggle: enable_testing in integration.json

{
  "enable_testing": true,
  "test_suite_path": ".claude/tests/",
  "calibration_threshold": 0.80,
  "simulation_history_days": 30
}

Run simulation: skill-creator test --simulate

Run full suite: skill-creator test --suite all

Technical Specifications

Class: SkillSimulator

interface TestCase {
  id: string;               // Unique test identifier
  description: string;      // Human-readable intent
  context: string;          // Input context string
  expected_skills: string[]; // Skills expected to activate
  expected_absent: string[]; // Skills expected NOT to fire
}

interface SimulationResult {
  test_id: string;
  passed: boolean;
  activated: string[];      // Skills that actually fired
  precision: number;        // TP / (TP + FP)
  recall: number;           // TP / (TP + FN)
  f1: number;               // Harmonic mean of P/R
}

class SkillSimulator {
  runTestCase(tc: TestCase): SimulationResult;
  runSuite(path: string): SimulationResult[];
  calibrate(target_f1: number): void;
}

Metrics: precision, recall, F1, MCC (Matthews Correlation Coefficient)

Overview

Testing & Simulation treats the skill system like production software — you write test cases that define expected activation behavior, run simulations against historical session data, and calibrate thresholds until precision and recall meet target levels. This prevents regressions when skills are modified, added, or removed.

Each test case specifies a context string (the text Claude is processing), which skills are expected to activate, and which skills must remain silent. The simulator replays the activation algorithm against this context and compares the result to expectations, producing precision and recall metrics. A passing test means the right skills fire for the right reasons.

Calibration takes this further: given a target F1 score, the simulator sweeps the activation threshold to find the setting that maximizes performance across the full test suite. This removes the guesswork from threshold tuning and gives you a principled, evidence-based configuration for your skill library.

History

Testing & Simulation was introduced in v1.2, shortly after Quality Validation (CAP-007) established the conflict detection foundation. The motivation was regression prevention: as skills evolved over multiple sessions, there was no systematic way to verify that a skill modification hadn't broken previously-working activation behavior. Unit testing for skills was the obvious solution.

In v1.9, the Testing & Simulation subsystem evolved into the Evaluator-Optimizer (CAP-025), which added A/B testing between skill variants and automated threshold optimization. CAP-008 remained as the foundational simulation engine; CAP-025 extended it with comparative evaluation and learning feedback loops. In v1.13, the Pipeline List Coprocessor (CAP-016) integrated with the test suite to run validation as part of the skill promotion pipeline.

Key Concepts

For Students & Teachers

Imagine writing unit tests for your own study habits. You write a test that says: "When I'm studying calculus, I should reach for my calculus notes — not my history textbook." Testing & Simulation does this for skills: you define what should activate in what context, then verify that the system actually behaves that way.

Precision and recall are two complementary measures of accuracy. Precision asks "of the skills that fired, how many were correct?" Recall asks "of the skills that should have fired, how many actually did?" A high-precision, low-recall system is picky but reliable; a high-recall, low-precision system fires too many skills but never misses a relevant one. Calibration finds the threshold that balances both — measured by F1 score, the harmonic mean of precision and recall.

Usage Examples

Example 1: Run the simulation suite

# Run all test cases in .claude/tests/
skill-creator test --simulate

# Output example:
# Running 12 test cases against 23 skills...
# PASS  test-001: commit-context activates commit-style.md
# PASS  test-002: python-context skips git-conventions.md
# FAIL  test-003: typescript-context — expected lint-ts.md, got lint-js.md
# ...
# Results: 11/12 passed | Precision: 0.92 | Recall: 0.88 | F1: 0.90

Example 2: Read test output details

// SimulationResult from a failing test
{
  "test_id": "test-003",
  "passed": false,
  "activated": ["lint-js.md"],        // What actually fired
  "expected_skills": ["lint-ts.md"],  // What should have fired
  "precision": 0.0,                   // lint-js.md was wrong
  "recall": 0.0,                      // lint-ts.md never fired
  "f1": 0.0
}

// Fix: update lint-ts.md trigger conditions to include TypeScript contexts

Example 3: Write a test case in YAML

# .claude/tests/test-001.yaml
id: test-001
description: "Commit context should activate commit style skill"
context: "I need to write a git commit message for this refactor"
expected_skills:
  - commit-style.md
expected_absent:
  - python-style.md
  - lint-ts.md
Detailed Reference: Test Case Format

Full YAML Schema for Test Cases

# Complete test case schema (.claude/tests/*.yaml)
id: string                    # Required. Unique identifier (e.g., "test-001")
description: string           # Required. Human-readable test intent
context: string               # Required. Input text for activation simulation
expected_skills:              # Required. Skills that MUST activate
  - skill-name.md             # Filename relative to .claude/commands/
expected_absent:              # Optional. Skills that MUST NOT activate
  - other-skill.md
tags:                         # Optional. Labels for filtering test runs
  - regression
  - commit
  - typescript
weight: 1.0                   # Optional. Weight in F1 calculation (default: 1.0)
min_activation_score: 0.75    # Optional. Minimum score for expected skills

Simulation Flags

# Full simulation command options
skill-creator test [options]

Options:
  --simulate          Run activation simulation (default mode)
  --suite <path>      Path to test suite directory (default: .claude/tests/)
  --filter <tag>      Run only tests with matching tag
  --verbose           Show full SimulationResult for each test
  --threshold <n>     Override activation threshold (0.0–1.0)
  --calibrate         Auto-tune threshold to maximize F1
  --export <file>     Write results to JSON file for CI integration

Output Format

// Full SimulationResult structure (--verbose output)
{
  "suite_summary": {
    "total": 12,
    "passed": 11,
    "failed": 1,
    "precision": 0.92,
    "recall": 0.88,
    "f1": 0.90,
    "mcc": 0.85,
    "threshold_used": 0.72
  },
  "results": [
    {
      "test_id": "test-001",
      "passed": true,
      "activated": ["commit-style.md"],
      "precision": 1.0,
      "recall": 1.0,
      "f1": 1.0
    }
    // ... one entry per test case
  ]
}
Advanced: Calibration & Threshold Tuning

The Precision/Recall Tradeoff

Every activation threshold creates a tradeoff. A low threshold (e.g., 0.3) means skills activate easily — high recall, but many false positives lower precision. A high threshold (e.g., 0.9) means skills are selective — high precision, but relevant skills may fail to fire, lowering recall.

The F1 score is the harmonic mean of precision and recall. Unlike the arithmetic mean, F1 punishes extreme imbalances — a system with 100% precision and 0% recall gets an F1 of 0, not 50%. This makes F1 the right optimization target for skill activation.

Threshold Calibration Procedure

# Step 1: Run calibration sweep
skill-creator test --calibrate --target-f1 0.90

# The simulator sweeps thresholds from 0.3 to 0.95 in 0.05 increments
# For each threshold, it runs the full test suite and records F1
# Output: threshold recommendation + F1 curve

# Step 2: Review recommendation
# Calibration result:
# Optimal threshold: 0.72 (F1: 0.91 at this setting)
# Current threshold: 0.65 (F1: 0.87)
# Recommended change: +0.07 to threshold

# Step 3: Apply to integration.json
{
  "activation_threshold": 0.72
}

F1 and MCC Metrics

F1 Score: 2 * (P * R) / (P + R) — The standard metric for binary classification quality. Best for imbalanced datasets where negative examples (skills that should not fire) vastly outnumber positive examples.

MCC (Matthews Correlation Coefficient): Takes all four quadrants of the confusion matrix into account (TP, TN, FP, FN). More reliable than F1 when the class distribution is highly skewed. Range: −1 (inverse prediction) to +1 (perfect prediction).

Integration with CAP-025 (Evaluator-Optimizer)

In v1.9, the Evaluator-Optimizer (CAP-025) extended this calibration process with A/B testing: instead of tuning a single skill variant, CAP-025 can run two skill versions head-to-head on the same test suite and select the higher-performing variant automatically. CAP-008 provides the simulation infrastructure; CAP-025 adds the comparative evaluation and automatic promotion logic.

Related Capabilities