arabelatso/test-guided-debloating
Removes unnecessary code from a repository while preserving exactly the behavior exercised by a given test suite. Use this skill when you need to debloat, slim down, or remove unused code from a codebase based on test coverage. The skill analyzes which code elements (files, classes, functions, methods, branches, imports) are exercised by tests, identifies unreachable or unused code, and safely removes it while ensuring all tests continue to pass. Triggers when users ask to remove unused code, debloat based on tests, eliminate dead code guided by test coverage, or slim down a repository to only test-required functionality.
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill test-guided-debloating
Remove unnecessary code from a repository while preserving exactly the behavior exercised by a given test suite.
Inputs needed:
Clarify scope:
Generate test coverage data to identify exercised code. See coverage_tools.md for language-specific commands.
Python example:
pytest --cov=. --cov-report=json --cov-report=html
JavaScript example:
npm test -- --coverage --coverageReporters=json --coverageReporters=html
Java example:
mvn clean test jacoco:report
Verify:
Use scripts/analyze_coverage.py to identify removal candidates:
python scripts/analyze_coverage.py coverage.json --output analysis.json
The script identifies:
Manual review checklist:
Remove code incrementally, validating after each step. See debloating_strategy.md for detailed strategy.
Removal order (safest to riskiest):
# Remove unused import statements
# Run tests after removal
# Remove file
rm path/to/unused_file.py
# Run tests
pytest
# Remove function definition
# Run tests
# Before: if condition that's always true
if always_true_condition:
do_something()
else:
never_executed() # Remove this branch
# After:
do_something()
# Remove class definition if never instantiated
# Run tests
After each removal:
# Run full test suite
<test_command>
# Verify all tests pass
# Check for import errors
# Verify build succeeds
Final validation:
Run tests multiple times to catch flaky tests or timing issues.
Generate removal report:
DEBLOATING SUMMARY
==================
Removed Elements:
- 15 unused files
- 42 unused functions
- 8 unused classes
- 156 unused imports
- 23 dead branches
Total lines removed: 3,847
Tests passing: 156/156
Preservation Justification:
All test-defined behavior is preserved because:
1. All test-covered code remains intact
2. All transitive dependencies of test-covered code remain
3. No side effects required by tests were removed
4. Build succeeds and all 156 tests pass
Test-Defined Behavior: The test suite is the single source of truth for required functionality.
Conservative Removal: When in doubt, keep the code. Only remove code you're confident is unused.
Incremental Validation: Remove code in small batches and run tests after each change.
Never Modify Tests: Test files define the required behavior and must not be changed.
Preserve Side Effects: Be cautious with code that has side effects (logging, initialization, registration).
Avoid removing:
Watch for:
The analyze_coverage.py script automates coverage analysis:
# Analyze Python coverage
python scripts/analyze_coverage.py coverage.json
# Analyze JavaScript coverage
python scripts/analyze_coverage.py coverage-final.json --format javascript
# Save detailed analysis
python scripts/analyze_coverage.py coverage.json --output analysis.json
Output includes:
Take arabelatso/test-guided-debloating from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.