---
description: Fix QA test failures
argument-hint: <feature-slug>
allowed-tools: Bash, Read, Write, Edit, Glob, Grep, Task
---

Fix QA failures for feature: $ARGUMENTS

## Instructions

### 1. Load QA Results

Read `.sdlc/features/$ARGUMENTS/qa-results.md` to get the full test results.

### 2. Parse Failed Scenarios

Collect all scenarios with status FAIL. For each failure, note:
- Scenario ID and description
- Expected vs actual behavior
- Error output or evidence

### 3. Diagnose Each Failure

For each failed scenario:
1. Read the test code or manual steps that failed
2. Read the production code being tested
3. Determine if the issue is in the implementation, the test, or the test data

### 4. Fix Implementation Issues

If the failure is due to incorrect implementation:
1. Fix the production code
2. Run the specific failing test to confirm the fix
3. Run the full test suite to ensure no regressions:

```bash
go test ./... 2>/dev/null || true
```

### 5. Fix Test Issues

If the failure is due to an incorrect test expectation:
1. Verify the test expectation against the spec
2. If the spec supports the test, fix the implementation (not the test)
3. If the test expectation was wrong, fix the test and document why

### 6. Re-run All Failed Scenarios

After all fixes, re-execute every previously failed scenario and confirm PASS.

### 7. Update QA Results

Update `.sdlc/features/$ARGUMENTS/qa-results.md`:
- Change FAIL to PASS for fixed scenarios
- Add a remediation note explaining what was fixed
- Verify the overall status (PASS only if all scenarios pass)

### 8. Update Artifact Status

After all fixes are applied and tests re-run:

- If **all scenarios now pass**: mark as passed
  ```bash
  sdlc artifact pass $ARGUMENTS qa_results
  ```
- If **failures remain**: keep as failed
  ```bash
  sdlc artifact fail $ARGUMENTS qa_results
  ```

### 9. Report

Summarize: failures fixed, root causes, regression status (all previously passing tests still pass), and artifact status.

## Critical Rules

- ALWAYS re-run failed tests after fixing -- verify with evidence
- NEVER mark a test as passing without actually running it
- NEVER fix tests to match broken behavior -- fix the implementation
- ALWAYS keep passing tests passing -- no regressions
- ALWAYS update the QA results document with resolution details
- ALWAYS set the artifact status after fixing (pass if all scenarios now pass)
