본문으로 건너뛰기
cccskills
무료GitHub에 공개

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(4)

  • SKILL.md5.8 KB
  • references/coverage_tools.md7.0 KB
  • references/debloating_strategy.md5.6 KB
  • scripts/analyze_coverage.py8.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Test-Guided Debloating

Remove unnecessary code from a repository while preserving exactly the behavior exercised by a given test suite.

Workflow

1. Understand Requirements

Inputs needed:

  • Target repository path
  • Test command to run the test suite
  • Programming language/framework

Clarify scope:

  • Which tests define required behavior (all tests, specific test files, integration tests only)?
  • Should test files themselves be preserved (yes, never modify tests)?
  • Are there any files that must be kept regardless of coverage (configuration, documentation)?

2. Run Coverage Analysis

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:

  • Coverage report generated successfully
  • All tests pass
  • Coverage data includes all source files

3. Analyze Coverage Data

Use scripts/analyze_coverage.py to identify removal candidates:

python scripts/analyze_coverage.py coverage.json --output analysis.json

The script identifies:

  • Uncovered files (0% coverage) - safest to remove
  • Partially covered files - require manual review
  • Uncovered lines - potential dead code within files

Manual review checklist:

  • Are uncovered files truly unused (check imports)?
  • Do uncovered functions have side effects?
  • Are there dynamic imports or reflection?
  • Is this a library with public API requirements?

4. Incremental Removal

Remove code incrementally, validating after each step. See debloating_strategy.md for detailed strategy.

Removal order (safest to riskiest):

  1. Unused imports

    # Remove unused import statements
    # Run tests after removal
    
  2. Uncovered files (0% coverage, not imported)

    # Remove file
    rm path/to/unused_file.py
    # Run tests
    pytest
    
  3. Uncovered functions/methods

    # Remove function definition
    # Run tests
    
  4. Dead branches

    # Before: if condition that's always true
    if always_true_condition:
        do_something()
    else:
        never_executed()  # Remove this branch
    
    # After:
    do_something()
    
  5. Unused classes

    # 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

5. Validate Preservation of Behavior

Final validation:

  • All tests pass
  • Build succeeds without errors
  • No import/module errors
  • No runtime errors during test execution
  • Test coverage of remaining code unchanged
  • No modifications to test files

Run tests multiple times to catch flaky tests or timing issues.

6. Document Changes

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

Key Principles

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).

Common Pitfalls

Avoid removing:

  • Code with side effects (module-level initialization, decorators, metaclasses)
  • Code used via reflection or dynamic imports
  • Public API methods (if building a library)
  • Configuration files
  • Error handling needed in production (even if untested)

Watch for:

  • Dynamic behavior (eval, exec, importlib, reflection)
  • Transitive dependencies (code called by covered code)
  • Module-level code execution
  • Static initializers
  • Decorator/annotation side effects

Helper Script

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:

  • List of uncovered files (safe to remove)
  • Partially covered files (review needed)
  • Uncovered line ranges
  • Safety ratings for removal candidates

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2572026년 8월 21일 업데이트

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2572026년 8월 21일 업데이트

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2572026년 8월 21일 업데이트

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2572026년 8월 21일 업데이트

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2572026년 8월 21일 업데이트

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2572026년 8월 21일 업데이트

ArabelaTso의 스킬 모두 보기

이 스킬의 문제 신고