# Quality Gates Reference (v4)

> **Used by:** step-01-v4-execute.md and step-02-v4-verify.md

## Gate Definitions

| Gate | Command | Blocking | When |
|------|---------|----------|------|
| Backend build | `dotnet build --no-restore` | YES | After each module |
| Backend tests | `dotnet test --no-build` | YES | After build passes |
| Frontend typecheck | `npm run typecheck` | YES | After backend gates |
| Frontend tests | `npm test -- --run` | YES | After typecheck |
| MCP security | `validate_security` | YES | After all tests |
| MCP code review | `review_code` | YES (if perm mismatch) | After security |
| MCP conventions | `validate_conventions` | NO (report) | After code review |
| MCP test conventions | `validate_test_conventions` | NO (report) | After conventions |
| BR coverage | grep implementation | YES (100%) | After MCP gates |
| File reconciliation | compare expectedFiles vs disk | YES | After BR coverage |
| Stub test detection | grep stub patterns | YES | During test gate |

## Stub Test Patterns (AUTO-REJECT)

```
Assert.True(true)
Assert.Pass()
[Fact] + empty body
// TODO
throw new NotImplementedException
[Test] public void Test1() { }
```

If any pattern found in test files → gate FAILS.

## Gate Failure Recovery (v4)

In v4 mode, gate failures are handled IN THE SAME SESSION:

1. Gate fails → error output captured
2. Error shown to Claude (compaction preserves all prior context)
3. `/apex -d "Fix: {error description}"` — Claude sees what it generated + the error
4. Re-run gate
5. Max 3 fix attempts per gate before marking as failed

**Key difference from v3:** No context loss between retry attempts. Claude knows exactly what code it wrote and what went wrong.

## Gate Execution Order

```
dotnet build
    ↓ (pass)
dotnet test
    ↓ (pass)
npm run typecheck
    ↓ (pass)
npm test
    ↓ (pass)
validate_security
    ↓ (pass)
validate_conventions
    ↓ (report)
review_code (semantic permission check)
    ↓ (pass)
validate_test_conventions
    ↓ (report)
BR coverage check
    ↓ (100%)
File reconciliation
    ↓ (all present)
MODULE COMPLETE
```
