# Verification Loop Skill

> **6-phase quality verification before any PR or commit.**

---

## The Verification Loop

```
┌─────────────────────────────────────────────────────────────┐
│                    VERIFICATION LOOP                        │
│                                                             │
│   Phase 1: Build      → Compilation succeeds               │
│   Phase 2: Types      → Type checking passes               │
│   Phase 3: Lint       → No lint errors                     │
│   Phase 4: Format     → Code properly formatted            │
│   Phase 5: Test       → All tests pass, coverage met       │
│   Phase 6: Security   → No vulnerabilities                 │
│                                                             │
│   All phases must pass before commit/PR                     │
└─────────────────────────────────────────────────────────────┘
```

---

## Phase 1: Build

### Python
```bash
python -m py_compile src/**/*.py
```

### TypeScript
```bash
npm run build
# or
tsc --noEmit
```

**Pass criteria:** No compilation errors

---

## Phase 2: Type Checking

### Python
```bash
mypy src/ --strict
```

### TypeScript
```bash
tsc --noEmit --strict
```

**Pass criteria:** No type errors

---

## Phase 3: Linting

### Python
```bash
ruff check src/ tests/
```

### TypeScript
```bash
eslint src/ --ext .ts,.tsx
```

**Pass criteria:** No lint errors (warnings may be acceptable)

---

## Phase 4: Formatting

### Python
```bash
ruff format --check src/ tests/
```

### TypeScript
```bash
prettier --check "src/**/*.{ts,tsx}"
```

**Pass criteria:** All files properly formatted

---

## Phase 5: Testing

### Python
```bash
pytest tests/ -v --cov=src --cov-fail-under=80
```

### TypeScript
```bash
npm test -- --coverage --coverageThreshold='{"global":{"lines":80}}'
```

**Pass criteria:**
- All tests pass
- Coverage meets threshold (aim for >80%)

---

## Phase 6: Security

### Python
```bash
pip-audit
bandit -r src/
```

### TypeScript
```bash
npm audit
```

**Pass criteria:** No high/critical vulnerabilities

---

## Quick Command

### Python
```bash
ruff check --fix . && ruff format . && mypy src/ && pytest tests/ -v
```

### TypeScript
```bash
npm run lint:fix && npm run format && npm run typecheck && npm test
```

---

## Integration with Git Hooks

Add to pre-commit:
```bash
#!/bin/bash
set -e

echo "Running verification loop..."

echo "Phase 1: Build"
npm run build || exit 1

echo "Phase 2: Types"
npm run typecheck || exit 1

echo "Phase 3: Lint"
npm run lint || exit 1

echo "Phase 4: Format"
npm run format:check || exit 1

echo "Phase 5: Test"
npm test || exit 1

echo "Phase 6: Security"
npm audit --audit-level=high || exit 1

echo "All verifications passed!"
```

---

## When to Run

| Trigger | Phases to Run |
|---------|---------------|
| Before commit | All 6 phases |
| Before PR | All 6 phases |
| During development | Phases 1-4 (quick feedback) |
| CI/CD | All 6 phases (blocking) |

---

## Handling Failures

### Build Failures
→ Use `/build-fix` command

### Type Errors
→ Use `/build-fix --types` command

### Lint Errors
```bash
ruff check --fix .  # Auto-fix
```

### Format Issues
```bash
ruff format .  # Auto-fix
```

### Test Failures
→ Fix tests before proceeding

### Security Issues
→ Use `/security-review` for guidance

---

## Related Skills

- [tdd-workflow](../tdd-workflow/) - Test writing
- [coding-standards](../coding-standards/) - Code quality
- [security-review](../security-review/) - Security checks
