/amplihack:smart-testfrom amplihack
Selects tests to run based on code changes using import analysis. Provides tiered testing (fast <1 min, impacted <5 min, full suite) and tracks test reliability to optimize feedback loops and CI time.
Ships in amplihack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Optimizes test execution by intelligently selecting which tests to run based on code changes. Instead of running the full test suite every time, this skill:
I automatically load when you mention:
Tier 1: Fast Tests (< 1 minute)
pytest -m "not slow and not integration" [selected_tests]Tier 2: Impacted Tests (< 5 minutes)
pytest [selected_tests]Tier 3: Full Suite
pytestThe skill builds a dependency graph by analyzing Python imports:
source_file.py
|
+-- Imported by: module_a.py, module_b.py
| |
| +-- Tested by: test_module_a.py, test_module_b.py
|
+-- Tested by: test_source_file.py (direct test)
Direct Tests: Files matching pattern test_{module}.py or {module}_test.py
Indirect Tests: Tests that import modules which import the changed file
Tests are scored on reliability (0.0 to 1.0):
Reliability is tracked in ~/.amplihack/.claude/data/test-mapping/reliability.yaml
User: What tests should I run for my changes?
Claude (using smart-test):
1. Analyzes git diff or staged changes
2. Maps changed files to test dependencies
3. Returns tiered test commands
Example Output:
------------------------------------------
Smart Test Analysis
------------------------------------------
Changed Files:
- crates/amplihack-cli/src/core/processor.rs
- crates/amplihack-cli/src/utils/helpers.rs
Tier 1 (Fast - 45s estimated):
cargo test -p amplihack-cli processor helpers -- --test-threads=1
Tier 2 (Impacted - 3m estimated):
cargo test -p amplihack-cli processor helpers pipeline -- --test-threads=1
Tier 3 (Full - 12m estimated):
pytest
Recommendation: Start with Tier 1 for quick feedback.
User: Build the test mapping for this project
Claude:
1. Scans all Python files
2. Builds import dependency graph
3. Maps source files to test files
4. Saves to .claude/data/test-mapping/code_to_tests.yaml
User: Show flaky tests
Claude:
1. Reads reliability.yaml
2. Lists tests with reliability < 0.8
3. Suggests investigation or quarantine
# For staged changes
git diff --cached --name-only --diff-filter=ACMR
# For all uncommitted changes
git diff --name-only --diff-filter=ACMR
# For PR changes (vs main)
git diff main...HEAD --name-only --diff-filter=ACMR
Filter to only Python source files (exclude tests themselves for mapping).
For each Python file, extract imports:
# Patterns to detect:
import module
from module import item
from package.module import item
from . import relative
from ..parent import item
Build bidirectional mapping:
For each changed file, find tests via:
test_{filename}.py or {filename}_test.pyFor Tier 1 only, exclude tests with reliability < 0.8.
Output pytest commands with appropriate markers:
# Tier 1
pytest -m "not slow and not integration" tests/a.py tests/b.py
# Tier 2
pytest tests/a.py tests/b.py tests/c.py
# Tier 3
pytest
# .claude/data/test-mapping/code_to_tests.yaml
version: 1
last_updated: "2025-11-25T10:00:00Z"
mappings:
crates/amplihack-cli/src/core/processor.rs:
direct_tests:
- crates/amplihack-cli/tests/processor_test.rs
indirect_tests:
- crates/amplihack-cli/tests/pipeline_integration.rs
transitive_tests:
- tests/e2e/full_workflow_test.rs
crates/amplihack-cli/src/utils/helpers.rs:
direct_tests:
- crates/amplihack-cli/tests/helpers_test.rs
indirect_tests:
- crates/amplihack-cli/tests/processor_test.rs # processor imports helpers
# .claude/data/test-mapping/reliability.yaml
version: 1
last_updated: "2025-11-25T10:00:00Z"
tests:
crates/amplihack-cli/tests/processor_test.rs::test_basic:
passes: 98
failures: 2
reliability: 0.98
last_failure: "2025-11-20"
crates/amplihack-cli/tests/api_integration.rs::test_timeout:
passes: 45
failures: 15
reliability: 0.75
last_failure: "2025-11-24"
flaky_reason: "Network dependent"
This skill integrates with the default-workflow skill/recipe:
Step 12: Run Tests and Pre-commit Hooks
Step 13: Mandatory Local Testing
CI Pipeline
Works with existing pytest markers from pyproject.toml:
slow - Excluded from Tier 1integration - Excluded from Tier 1e2e - Excluded from Tier 1 and 2neo4j - Requires special environmentrequires_docker - Requires Docker daemon| Scenario | Tier | Time Budget | Command Pattern |
|---|---|---|---|
| Pre-commit | 1 | < 1 min | pytest -m "not slow" [affected] |
| Pre-push | 2 | < 5 min | pytest [affected + transitive] |
| Draft PR | 2 | < 5 min | pytest [affected + transitive] |
| Ready PR | 3 | Full | pytest |
| CI main | 3 | Full | pytest |
[Developer makes small change]
Claude: Run affected tests (Tier 1)
[45 seconds later]
Claude: 3/3 tests passed. Ready for commit.
[Developer about to push]
Claude: Run impacted tests (Tier 2)
[3 minutes later]
Claude: 12/12 tests passed including integrations.
User: Tests keep failing randomly
Claude: Checking reliability data...
Found 2 flaky tests (< 0.8 reliability):
- test_api_timeout (0.75) - Network dependent
- test_concurrent_write (0.68) - Race condition
Recommend: Quarantine these tests or fix root cause.
Do NOT use smart-test when:
pytest.ini, conftest.py, or fixtures affect all testsRule of thumb: When in doubt, run the full suite. Smart-test optimizes iteration speed, not correctness.
Issue: "No tests found for changed file"
Cause: File is new or not yet mapped
Fix: Rebuild the mapping cache
User: "Rebuild test mapping cache"
Issue: "Import analysis failed"
Cause: Syntax error in Python file or circular imports
Fix: 1. Check file for syntax errors: python -m py_compile file.py
2. Resolve circular imports
3. Rebuild mapping cache
Issue: "Reliability data missing"
Cause: No test runs have been recorded yet
Fix: Run full test suite once, then:
User: "Update test reliability with these results"
Issue: "Tier 1 tests taking too long"
Cause: Too many tests marked as "fast" or slow tests not marked
Fix: 1. Add @pytest.mark.slow to tests > 1 second
2. Add @pytest.mark.integration to integration tests
3. Review test granularity
Issue: "Cache is stale / wrong tests selected"
Cause: Module structure changed since last cache build
Fix: Delete cache and rebuild:
rm -rf .claude/data/test-mapping/*.yaml
User: "Rebuild test mapping cache"
# Verify test mapping is valid
python -c "import yaml; yaml.safe_load(open('.claude/data/test-mapping/code_to_tests.yaml'))"
# Check reliability data
python -c "import yaml; print(yaml.safe_load(open('.claude/data/test-mapping/reliability.yaml')))"
# Force full suite (bypass smart-test)
pytest --ignore-glob='**/test_slow_*'
# Find tests with no source mapping (orphaned tests)
find tests -name "test_*.py" -exec basename {} \; | sort > /tmp/tests.txt
The mapping cache should be rebuilt when:
Trigger manually: "Rebuild test mapping cache"
Note: Start with Tier 1 for rapid feedback. If tests pass, you likely caught any regressions. Only escalate to higher tiers when approaching commit/push milestones.
Stop a background job you started by the PID you recorded with $!, or by a process group you created for the job with set -m or setsid, using kill -- -PGID. Never use pkill -f, pgrep -f with kill or xargs kill, or killall <name>: a pattern matches every process whose command line contains the same words, including the recipe runner and other agents. Time-box test runs with the test runner's own options (for example nextest slow-timeout with terminate-after, or vitest --testTimeout) instead of killing the run afterwards.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
test-selection, impact-analysis, tiered-testing, ci-optimization, pytest
30 skills in this plugin
/agentic-workflow-firstStart new work as a deterministic workflow of agentic steps, prompts, and tools instead of code. Use when designing a feature, deciding how to build something, choosing code vs recipe, or asking "how should I structure this"./amplihack-expertComprehensive knowledge of amplihack framework architecture, patterns, and usage/code-atlasBuilds comprehensive, living code-atlases as multi-layer architecture documents derived from
code-first truth. Defaults to both Graphviz DOT and Mermaid. User can override to single format.
Language-agnostic (Go, TypeScript, Python, .NET, Rust, Java). Files issues with
'code-atlas-bughunt' label. Treats atlas-building as a multi-agent bug-hunting journey:
graph-form reasoning exposes structural bugs, route/DTO mismatches, orphaned env vars,
dead code paths, and stale documentation that linear review misses. Three-pass bug hunt
with per-journey PASS/FAIL/NEEDS_ATTENTION verdicts.
Use when: creating architecture documentation, investigating unfamiliar codebases,
hunting structural bugs, setting up CI/CD diagram refresh, or publishing to GitHub Pages/mkdocs.
/code-philosophyMulti-pass code philosophy audit skill. Performs three distinct passes
over target code to verify adherence to the project's PHILOSOPHY.md
principles. Produces a structured report with findings and delegates
fixes to dev-orchestrator. This is an advisory audit-only skill — it
does not modify code directly.
/crusty-old-engineerCurmudgeonly engineering advisor that provides grounded skepticism, evidence-linked judgment,
and constructive progress on architectural decisions, legacy refactors, tooling choices, and
broad "how should I start?" questions. Sounds like a senior systems engineer who has reviewed
too many designs to be impressed, but still cares about correctness.
Use when: architectural decisions, legacy replacements, new tooling evaluation, broad planning questions.
/default-workflowDevelopment workflow for features, bugs, refactoring. Normally executed as a
sub-recipe by dev-orchestrator/smart-orchestrator. Supports direct invocation
via recipe runner for standalone use.
npx claudepluginhub rysweet/amplihack-rs --plugin amplihackOther plugins' skills for the same job