Agent skill
test-and-fix
Run unit tests and automatically fix code failures, regression bugs, or test mismatches. Use when tests are failing, after implementing new features, or to repair "broken" tests.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/test-and-fix
SKILL.md
Test and Fix Loop
Purpose
An autonomous loop for the agent to identify, analyze, and fix failing unit tests using Vitest.
Loop Logic
- Identify: Run
pnpm testto identify failing tests. - Analyze: Examine the test output to determine:
- The failing test file and line number.
- The expected vs actual values.
- Refer to ../common-references/troubleshooting.md for common test failure patterns.
- Fix: Apply the minimum necessary change to either the source code (if it's a bug) or the test code (if the test is outdated).
- Verify: Re-run
pnpm test.- If passed: Move to the next failing test or finish if all are resolved.
- If failed: Analyze the new failure (or the same one if the fix was insufficient) and repeat the loop.
Termination Criteria
- All tests pass (as reported by
pnpm test). - Reached max iteration limit (default: 5).
- The error persists after multiple distinct fix attempts, indicating a need for human intervention or a broader architectural change.
Examples
Scenario: Fixing a logic error
pnpm testfails inpackages/common/src/math.test.tsbecauseadd(2, 2)returned5.- Agent analyzes
packages/common/src/math.tsand finds a typoa + b + 1. - Agent fixes the typo to
a + b. pnpm testpasses.
Scenario: Updating a test after a deliberate change
pnpm testfails because a UI component's text changed from "Submit" to "Confirm".- Agent confirms the change was intentional.
pnpm testpasses.
Resources
- pnpm Commands for Node.js: Common commands for testing and managing dependencies.
- Testing Best Practices: Project-specific testing guidelines.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?