---
name: step-02-v4-verify
description: Final verification gates, file reconciliation, BR coverage, and report generation
model: opus
---

# Step 02-v4: Verify + Report

## YOUR TASK

After ALL modules are implemented, run final verification across the ENTIRE project, then generate the completion report.

---

## VERSION GUARD

```javascript
// This step is ONLY for v4 PRDs. If a v3 PRD reaches here, route back to step-05-report.md.
const prd = readJSON(currentPrdPath);
if (prd.$version !== '4.0.0') {
  console.error(`step-02-v4-verify loaded with $version=${prd.$version} — expected 4.0.0`);
  console.log('Routing to step-05-report.md (v3 report generation)');
  // → Load steps/step-05-report.md instead
  return;
}
```

## FINAL VERIFICATION SEQUENCE

### 1. Full Solution Build

```bash
dotnet build 2>&1
```

This catches cross-module compilation issues that per-module builds might miss.

### 2. Full Test Suite

```bash
dotnet test 2>&1
```

Run ALL tests across ALL modules. This catches cross-module integration issues.

### 3. Frontend Verification

```bash
npm run typecheck 2>&1
npm test -- --run 2>&1
```

### 4. File Reconciliation

For each module's PRD, compare expected files against actual files on disk:

```javascript
// v4 uses prd.expectedFiles, v3 uses prd.implementation.filesToCreate (guard: should be v4 here)
const fileManifest = prd.expectedFiles || prd.implementation?.filesToCreate;
if (!fileManifest) {
  console.error('BLOCKING: PRD has no file manifest (neither expectedFiles nor implementation.filesToCreate)');
  STOP;
}

for (const category of ['domain', 'application', 'infrastructure', 'api', 'frontend', 'seedData', 'tests', 'documentation']) {
  const expected = fileManifest[category] || [];
  for (const file of expected) {
    if (!existsOnDisk(file.path)) {
      MISSING.push({ category, path: file.path, type: file.type });
    }
  }
}
```

**If missing files found:**
- List them clearly with category and expected path
- Delegate to `/apex`: "Create missing files: {list}"
- Re-verify after creation

### 5. Business Rule Coverage

For each BR in ALL modules' `brToCodeMapping`:
1. Verify target file exists
2. Verify implementation is present (grep for method/class name)
3. Verify test coverage (grep test files for BR reference)

Output:
```
BR Coverage: {covered}/{total} ({pct}%)
Missing: BR-VAL-INV-003 (no test), BR-CALC-INV-005 (no implementation)
```

**If coverage < 100%:** Delegate remediation to `/apex`.

### 6. MCP Final Scan

```javascript
// Security validation (BLOCKING)
mcp__smartstack__validate_security({ projectPath: "." })

// Convention validation (report)
mcp__smartstack__validate_conventions({ projectPath: "." })

// Code review — semantic permission check (BLOCKING if write endpoint has Read permission)
mcp__smartstack__review_code({ files: changedFiles, focus: "security" })

// Test convention validation (report)
mcp__smartstack__validate_test_conventions({ projectPath: "." })
```

Log results. Security and permission mismatches are BLOCKING. Convention/test findings go in the report.

---

## REPORT GENERATION

Generate `.ralph/reports/{feature}.md`:

```markdown
# Feature Report: {applicationName}

**Generated:** {date}
**Modules:** {moduleCount}
**Duration:** {startTime} → {endTime}

## Summary

| Module | Entities | BRs | Sections | Build | Tests | Coverage |
|--------|----------|-----|----------|-------|-------|----------|
| {mod1} | {n}      | {n} | {n}      | PASS  | PASS  | {pct}%   |
| {mod2} | {n}      | {n} | {n}      | PASS  | PASS  | {pct}%   |

## Objectives

| Objective | Status | Acceptance Criteria |
|-----------|--------|---------------------|
| {obj.description} | PASS/FAIL | {criteria results} |

## File Reconciliation

| Category | Expected | Present | Missing |
|----------|----------|---------|---------|
| domain | {n} | {n} | {list} |
| ... | | | |

## Business Rule Coverage

| BR ID | Name | Implementation | Test | Status |
|-------|------|----------------|------|--------|
| {id} | {name} | {file}:{method} | {testFile} | PASS/FAIL |

## Quality Gates

| Gate | Result |
|------|--------|
| dotnet build | PASS |
| dotnet test | PASS ({n} tests) |
| npm typecheck | PASS |
| npm test | PASS ({n} tests) |
| MCP security | {findings} |
| MCP conventions | {findings} |

## Git Commits

{list of commits with hashes and messages}
```

---

## COMPLETION

After report is generated:
1. Display report path: `.ralph/reports/{feature}.md`
2. Display summary stats
3. If completion_promise was set: output the promise text
4. Ralph-Loop is DONE
