Fix Tests
Run tests iteratively, fixing failures until all pass.
Claude CodeGeneric
# Fix Tests
Run tests iteratively, fixing failures until all pass.
## Usage
`/fix-tests`
## Behavior
1. Run the test suite
2. If all tests pass, report success and stop
3. If tests fail:
- Analyze the failure output
- Identify the root cause (test bug or implementation bug)
- Fix the issue
- Return to step 1
4. Maximum 5 retry attempts to prevent infinite loops
5. If stuck on same failure 3 times, ask for help
## Test Commands
### Unit Tests (Default)
```bash
npm test
E2E Tests (After Unit Pass)
If unit tests pass and E2E validation is needed:
npm run e2e:smoke
For full E2E suite:
npm run e2e:all
Playwright Setup
If E2E tests fail due to missing browsers:
npx playwright install --with-deps chromium
Analysis Approach
- Parse failure output - Extract test name, assertion message, stack trace
- Locate the test - Find test file (
.test.tsor.spec.ts) - Understand the assertion - What behavior is being verified?
- Find code under test - Navigate to the implementation
- Determine root cause:
- Is the test wrong? (outdated expectation, incorrect mock)
- Is the implementation wrong? (bug, missing case)
- Apply minimal fix - Change only what's necessary
E2E Test Considerations
E2E tests can be flaky. Before deep investigation:
- Retry once - Transient failures happen
- Check browser state - May need
npx playwright install - Check extension state - May need fresh Extension Development Host
- Check test isolation - Ensure tests don't depend on each other
What To Fix
| Scenario | Action |
|---|---|
| Implementation bug | Fix the source code |
| Test has wrong expectation | Fix the test assertion |
| Mock is incomplete | Update mock to match real behavior |
| Test is flaky | Add proper waits/retries or stabilize |
What NOT To Do
- Don't skip or delete failing tests
- Don't add
.skip()without discussion - Don't weaken assertions to make tests pass
- Don't fix unrelated code while fixing tests
Output
Fix Tests
=========
[1/5] Running unit tests...
[✗] 1 test failed
Analyzing failure:
1. PluginRegistration.parseOutput.should_extract_assembly_name
- Expected: "MyPlugin.dll", Actual: undefined
- Root cause: Regex doesn't handle paths with spaces
- Fix: Update regex pattern in parseOutput()
Applying fix...
[2/5] Running unit tests...
[✓] All 23 unit tests passed
[3/5] Running E2E smoke tests...
[✓] All 5 E2E tests passed
Done.
When to Use
- After making changes that might break tests
- When CI reports test failures
- After refactoring to verify behavior preserved
- Before PR to catch issues early
Related Commands
/prepare-pr- Full pre-PR validation/prepare-release- Release preparation
Maintain Fix Tests?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Fix Tests on getagentictools](https://getagentictools.com/loops/joshsmithxrm-fix-tests?ref=badge)