AgentSkillsCN

test-pruning-advisor

当被要求“审查待删除的测试”、“查找冗余测试”、“清理测试”、“识别低价值测试”,或希望根据项目测试指南确定哪些测试应考虑移除时使用。

SKILL.md
--- frontmatter
name: test-pruning-advisor
description: Use when asked to "review tests for deletion", "find redundant tests", "cleanup tests", "identify low-value tests", or wants to identify tests that should be considered for removal based on project testing guidelines.

Test Pruning Advisor

Skill for identifying tests that should be considered for removal based on the project's testing guidelines.

Purpose

Analyze test files to identify redundant, low-value, or obsolete tests that may be candidates for deletion. This skill follows the project's testing philosophy which prioritizes golden file tests over function-level unit tests.

Deletion Consideration Criteria

Based on project testing guidelines (CLAUDE.md):

  1. Golden file test replaceable unit tests: Function-level unit tests for code analysis, schema generation, or code generation logic that could be covered by testdata golden file tests
  2. Trivial tests: Tests for simple getters/setters, direct value passthrough, or obvious behavior that provides minimal value
  3. Implementation-coupled tests: Tests that are tightly coupled to internal implementation details and would break with reasonable refactoring
  4. Orphaned tests: Tests for code or features that no longer exist in the codebase

Workflow

Step 1: Select Review Target

When the review target is not explicitly specified, use AskUserQuestion to present the following options:

  1. Branch/PR changes: Review only test files added/modified in current branch vs main
  2. All tests: Review all *.test.ts files in the codebase
  3. Specific pattern: Review tests matching a specific path or pattern

Getting Test Files by Target

bash
# Branch/PR changes - test files added or modified
git diff main --name-only -- '**/*.test.ts' | grep -v testdata

# All test files (excluding testdata golden tests which are reviewed by golden-test-reviewer)
find packages -name "*.test.ts" -not -path "*/testdata/*" -not -path "*/__generated__/*"

# Specific pattern
find packages -name "*.test.ts" -path "*/<pattern>/*" -not -path "*/testdata/*"

Step 2: Categorize Test Files

Group test files by their purpose:

CategoryPath PatternNotes
Type extractionpackages/cli/src/type-extractor/*.test.tsMay overlap with golden tests
Resolver extractionpackages/cli/src/resolver-extractor/*.test.tsMay overlap with golden tests
Schema generationpackages/cli/src/schema-generator/*.test.tsMay overlap with golden tests
Auto-type generationpackages/cli/src/auto-type-generator/*.test.tsMay overlap with golden tests
Shared utilitiespackages/cli/src/shared/*.test.tsUtility functions
Config loadingpackages/cli/src/config-loader/*.test.tsConfiguration handling
Runtimepackages/runtime/src/*.test.tsRuntime utilities
Golden testspackages/cli/src/gen-orchestrator/golden.test.tsMain golden test runner

Step 3: Launch Subagents for Analysis

For each test file (or batch of related files), launch a subagent using the Task tool with subagent_type: "general-purpose".

IMPORTANT: Launch all subagents in a single response with multiple Task tool calls to enable parallel execution.

Subagent Prompt

Read the prompt template from references/subagent-prompt.md and use it for each subagent.

Replace placeholders:

  • {test-file-path} - path to the test file
  • {category} - category from the table above
  • {related-source-files} - source files that the tests cover

Step 4: Aggregate Results and Generate Report

After all subagents complete:

  1. Parse JSON results from each subagent
  2. Generate summary table showing all test files:
markdown
## Review Summary

| Test File | Category | Tests | Deletable | Reason |
|-----------|----------|-------|-----------|--------|
| type-extractor/scanner.test.ts | Type extraction | 15 | 3 | Golden test overlap |
| shared/utils.test.ts | Utilities | 8 | 0 | - |
  1. List deletion candidates by reason:
markdown
## Deletion Candidates

### Golden File Test Replaceable (High Confidence)
- **file.test.ts**: `describe("feature X")` - Covered by testdata/feature-x-basic/
  - Specific tests: `it("should handle...")`, `it("should convert...")`

### Trivial Tests (Medium Confidence)
- **file.test.ts**: `it("should return input")` - Tests obvious passthrough behavior

### Implementation-Coupled (Review Recommended)
- **file.test.ts**: `it("internal state...")` - Depends on internal implementation detail

### Orphaned Tests (High Confidence)
- **file.test.ts**: `describe("OldFeature")` - OldFeature no longer exists
  1. Provide confidence levels:

    • High: Clear candidates for deletion
    • Medium: Likely candidates but verify before deleting
    • Low: Potentially removable but keep for now
  2. Summary statistics:

markdown
## Summary

- Total test files analyzed: X
- Total test cases: Y
- Deletion candidates: Z
  - High confidence: A
  - Medium confidence: B
  - Low confidence: C
- Estimated test reduction: Z/Y (XX%)

Evaluation Confidence Levels

  • High Confidence: Tests that clearly meet deletion criteria with no ambiguity
  • Medium Confidence: Tests that likely meet criteria but should be verified
  • Low Confidence: Tests that might be deletable but have some value

Important Notes

  • This skill does NOT evaluate golden file test cases in testdata/ - use golden-test-reviewer for that
  • Focus on identifying tests that provide little value relative to maintenance cost
  • Consider the project's "prefer golden file tests over unit tests" guideline
  • Always provide reasoning for each deletion recommendation

Additional Resources

Reference Files

  • references/subagent-prompt.md - Prompt template for subagent analysis
  • references/evaluation-criteria.md - Detailed evaluation criteria with examples