---
name: step-04-validate
description: MCP validation, build verification, seed data check, acceptance criteria
model: opus
prev_step: steps/step-03-execute.md
next_step: steps/step-05-examine.md
---

# Step 4: Validate

**Goal:** Verify everything works. MCP conventions, build, seed data, acceptance criteria.

---

## 1. MCP Convention Validation

```
Call: mcp__smartstack__validate_conventions

Expected: 0 errors
If errors found:
  → Fix each error (use appropriate skill/MCP)
  → Re-validate until 0 errors
```

---

## 2. EF Core Migration Check (if needs_migration)

```
Call: mcp__smartstack__check_migrations

Verify:
- Migration exists and is applied
- No pending model changes
- ModelSnapshot matches
```

---

## 3. Frontend Route Validation (if frontend modified)

```
Call: mcp__smartstack__validate_frontend_routes

Verify:
- Routes nested inside correct Layout wrapper
- Route paths match controller patterns
- No orphan routes
```

---

## 4. Build Verification

```bash
# Backend
dotnet clean && dotnet restore && dotnet build

# Frontend (if applicable)
npm run typecheck
```

**BLOCKING:** Both must pass. If failure, fix and retry.

---

## 5. Database & Migration Validation (if needs_migration)

### 5a. Pending Model Changes Check

```bash
INFRA_PROJECT=$(ls src/*Infrastructure*/*.csproj 2>/dev/null | head -1)
API_PROJECT=$(ls src/*Api*/*.csproj 2>/dev/null | head -1)

dotnet ef migrations has-pending-model-changes \
  --project "$INFRA_PROJECT" \
  --startup-project "$API_PROJECT"
```

**BLOCKING** if pending changes detected → migration is missing.

### 5b. Migration Application Test (SQL Server LocalDB)

```bash
DB_NAME="SmartStack_Apex_Validate_$(date +%s)"
CONN_STRING="Server=(localdb)\\MSSQLLocalDB;Database=$DB_NAME;Integrated Security=true;TrustServerCertificate=true;Connect Timeout=120;"

dotnet ef database update \
  --connection "$CONN_STRING" \
  --project "$INFRA_PROJECT" \
  --startup-project "$API_PROJECT"
```

**BLOCKING** if migration fails on SQL Server. Common issues:
- SQLite-only syntax in migrations (fix: regenerate migration)
- Column type mismatches (fix: update EF configuration)
- Missing foreign key targets (fix: reorder migrations)

### 5c. Integration Tests on Real SQL Server

```bash
# Integration tests use DatabaseFixture → real SQL Server LocalDB
# This validates: LINQ→SQL, multi-tenant isolation, soft delete, EF configs
INT_TEST_PROJECT=$(ls tests/*Tests.Integration*/*.csproj 2>/dev/null | head -1)
if [ -n "$INT_TEST_PROJECT" ]; then
  dotnet test "$INT_TEST_PROJECT" --no-build --verbosity normal
fi
```

Tests running against SQL Server catch issues that SQLite misses:
- Case sensitivity in string comparisons
- Date/time function differences
- IDENTITY vs AUTOINCREMENT behavior
- Global query filter translation to T-SQL

### 5d. Cleanup

```bash
sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "IF DB_ID('$DB_NAME') IS NOT NULL BEGIN ALTER DATABASE [$DB_NAME] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [$DB_NAME]; END" 2>/dev/null
```

---

## 6. Seed Data Completeness Check (if needs_seed_data)

| File | Checks |
|------|--------|
| NavigationModuleSeedData | Deterministic GUIDs (SHA256), 4 languages, GetModuleEntry + GetTranslationEntries |
| PermissionsSeedData | MCP generate_permissions used, paths match Permissions.cs, wildcard + CRUD |
| RolesSeedData | Admin=wildcard, Manager=CRU, Contributor=CR, Viewer=R |
| IClientSeedDataProvider | 3 Seed methods, idempotent, factory methods, SaveChanges per group |
| DI Registration | `services.AddScoped<IClientSeedDataProvider, {App}SeedDataProvider>()` |

---

## 7. Acceptance Criteria POST-CHECK

For each AC inferred in step-01:

```
AC1: {criterion} → PASS / FAIL (evidence: {file:line or test})
AC2: {criterion} → PASS / FAIL (evidence: {file:line or test})
...
```

**All ACs must PASS. If any FAIL, go back to step-03 to fix.**

---

## 8. Validation Summary

```
**APEX SmartStack - Validation Complete**

| Check | Status |
|-------|--------|
| MCP validate_conventions | PASS (0 errors) |
| EF Core migrations | PASS / N/A |
| DB: Migrations apply (SQL Server) | PASS / N/A |
| DB: Integration tests (SQL Server) | PASS / N/A |
| Frontend routes | PASS / N/A |
| dotnet build | PASS |
| npm typecheck | PASS / N/A |
| Seed data | PASS / N/A |
| Acceptance criteria | {X}/{Y} PASS |
```

---

## 9. Save Output (if save_mode)

Write to `{output_dir}/04-validate.md` with validation results.

---

## 10. Route to Next Step

```
IF examine_mode = true:
  → Load steps/step-05-examine.md

ELSE IF test_mode = true:
  → Load steps/step-07-tests.md

ELSE IF pr_mode = true:
  → Create PR and show final summary

ELSE:
  → Show final summary and exit
```

---

## FINAL SUMMARY (if no more steps)

Display: task, context, files created/modified, validation status, commits count, next steps (git diff, dotnet test, deploy).
