Get the FREE Ultimate OpenClaw Setup Guide →

test-and-fix

Scanned
npx machina-cli add skill yu-iskw/coding-agent-fabric/test-and-fix --openclaw
Files (1)
SKILL.md
2.0 KB

Test and Fix Loop

Purpose

An autonomous loop for the agent to identify, analyze, and fix failing unit tests using Vitest.

Loop Logic

  1. Identify: Run pnpm test to identify failing tests.
  2. Analyze: Examine the test output to determine:
  3. 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).
  4. 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

  1. pnpm test fails in packages/common/src/math.test.ts because add(2, 2) returned 5.
  2. Agent analyzes packages/common/src/math.ts and finds a typo a + b + 1.
  3. Agent fixes the typo to a + b.
  4. pnpm test passes.

Scenario: Updating a test after a deliberate change

  1. pnpm test fails because a UI component's text changed from "Submit" to "Confirm".
  2. Agent confirms the change was intentional.
  3. pnpm test passes.

Resources

Source

git clone https://github.com/yu-iskw/coding-agent-fabric/blob/main/.claude/skills/test-and-fix/SKILL.mdView on GitHub

Overview

The Test and Fix Loop runs unit tests with pnpm, analyzes failures, and applies the minimal necessary fixes to either source code or tests. It uses Vitest to detect failures and repeats the cycle until all tests pass or a max iteration is reached. This approach helps repair broken tests after changes and prevent regressions.

How This Skill Works

It follows Identify, Analyze, Fix, Verify: run pnpm test to identify failures, examine the output to locate the failing file and line, apply a minimal fix to the source or the test, then re-run pnpm test. The loop repeats until success or the default max iterations (5).

When to Use It

  • When pnpm test reports failing tests, to quickly locate and fix issues.
  • After adding new features, to ensure no regressions were introduced.
  • To repair tests that no longer reflect expected behavior (test mismatches).
  • When tests reveal a logic error, to fix the root cause with minimal changes.
  • Before releasing, to iterate fixes until all tests pass or human intervention is required.

Quick Start

  1. Step 1: Run pnpm test to identify failing tests.
  2. Step 2: Inspect the failure output to locate the file and cause.
  3. Step 3: Implement the minimal fix in source or test, then re-run pnpm test.

Best Practices

  • Run pnpm test to identify failures and note the failing file and line.
  • Analyze the failure output and refer to troubleshooting patterns.
  • Apply the minimum necessary change to either source code or tests.
  • Re-run pnpm test to verify progress and decide next steps.
  • Limit iterations to a max of 5 unless human intervention is required.

Example Use Cases

  • Fix a logic error where add(2, 2) returned 5 by correcting a typo in math.ts.
  • Update a test after UI text change from 'Submit' to 'Confirm' to reflect new behavior.
  • Address a test mismatch caused by an API rename by updating the test or code.
  • Resolve a regression after a feature refactor by adjusting mocks or expectations.
  • Repair a failing test in another package by correcting a mock setup.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers