@atlashub/smartstack-cli 2.9.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.documentation/business-analyse.html +81 -17
- package/dist/mcp-entry.mjs +1302 -223
- package/dist/mcp-entry.mjs.map +1 -1
- package/package.json +1 -1
- package/templates/agents/efcore/db-deploy.md +1 -1
- package/templates/agents/efcore/migration.md +26 -10
- package/templates/agents/efcore/rebase-snapshot.md +24 -7
- package/templates/agents/efcore/squash.md +73 -57
- package/templates/agents/gitflow/commit.md +138 -18
- package/templates/agents/gitflow/exec.md +1 -1
- package/templates/agents/gitflow/finish.md +79 -62
- package/templates/agents/gitflow/init-clone.md +186 -0
- package/templates/agents/gitflow/init-detect.md +137 -0
- package/templates/agents/gitflow/init-validate.md +210 -0
- package/templates/agents/gitflow/init.md +231 -74
- package/templates/agents/gitflow/merge.md +65 -33
- package/templates/agents/gitflow/pr.md +93 -49
- package/templates/agents/gitflow/start.md +76 -33
- package/templates/agents/gitflow/status.md +41 -71
- package/templates/hooks/appsettings-guard.sh +76 -0
- package/templates/hooks/ef-migration-check.md +1 -1
- package/templates/hooks/hooks.json +9 -0
- package/templates/project/test-frontend/msw/handlers.ts +58 -0
- package/templates/project/test-frontend/msw/server.ts +25 -0
- package/templates/project/test-frontend/setup.ts +16 -0
- package/templates/project/test-frontend/test-utils.tsx +59 -0
- package/templates/project/test-frontend/vitest.config.ts +31 -0
- package/templates/skills/_resources/config-safety.md +61 -0
- package/templates/skills/_resources/formatting-guide.md +2 -2
- package/templates/skills/application/SKILL.md +12 -3
- package/templates/skills/application/steps/step-04-backend.md +21 -0
- package/templates/skills/application/steps/step-07-tests.md +259 -120
- package/templates/skills/business-analyse/SKILL.md +57 -28
- package/templates/skills/business-analyse/_shared.md +70 -39
- package/templates/skills/business-analyse/html/ba-interactive.html +2622 -0
- package/templates/skills/business-analyse/questionnaire/00-application.md +123 -131
- package/templates/skills/business-analyse/questionnaire/01-context.md +173 -24
- package/templates/skills/business-analyse/questionnaire/02-stakeholders.md +170 -50
- package/templates/skills/business-analyse/questionnaire/03-scope.md +154 -48
- package/templates/skills/business-analyse/questionnaire/10-documentation.md +1 -1
- package/templates/skills/business-analyse/questionnaire/14-risk-assumptions.md +135 -0
- package/templates/skills/business-analyse/questionnaire/15-success-metrics.md +136 -0
- package/templates/skills/business-analyse/questionnaire.md +55 -46
- package/templates/skills/business-analyse/steps/step-00-init.md +24 -2
- package/templates/skills/business-analyse/steps/step-01-cadrage.md +31 -20
- package/templates/skills/business-analyse/steps/step-03-specify.md +1 -0
- package/templates/skills/business-analyse/steps/step-05-handoff.md +103 -1
- package/templates/skills/business-analyse/steps/step-06-extract.md +518 -0
- package/templates/skills/check-version/SKILL.md +1 -1
- package/templates/skills/efcore/steps/db/step-deploy.md +22 -3
- package/templates/skills/efcore/steps/db/step-reset.md +27 -4
- package/templates/skills/efcore/steps/db/step-seed.md +46 -2
- package/templates/skills/efcore/steps/db/step-status.md +14 -0
- package/templates/skills/efcore/steps/migration/step-01-check.md +31 -5
- package/templates/skills/efcore/steps/migration/step-02-create.md +20 -4
- package/templates/skills/efcore/steps/rebase-snapshot/step-03-create.md +60 -0
- package/templates/skills/efcore/steps/shared/step-00-init.md +47 -8
- package/templates/skills/efcore/steps/squash/step-03-create.md +27 -5
- package/templates/skills/gitflow/SKILL.md +91 -29
- package/templates/skills/gitflow/_shared.md +144 -2
- package/templates/skills/gitflow/phases/status.md +11 -1
- package/templates/skills/gitflow/steps/step-commit.md +1 -1
- package/templates/skills/gitflow/steps/step-init.md +202 -39
- package/templates/skills/gitflow/templates/config.json +10 -1
- package/templates/skills/ralph-loop/steps/step-03-commit.md +2 -2
- package/templates/skills/validate-feature/SKILL.md +83 -0
- package/templates/skills/validate-feature/steps/step-01-compile.md +38 -0
- package/templates/skills/validate-feature/steps/step-02-unit-tests.md +45 -0
- package/templates/skills/validate-feature/steps/step-03-integration-tests.md +53 -0
- package/templates/skills/validate-feature/steps/step-04-api-smoke.md +157 -0
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: step-07-tests
|
|
3
|
-
description: Generate backend
|
|
3
|
+
description: Generate backend tests with real integration testing and security coverage
|
|
4
4
|
prev_step: steps/step-06-migration.md
|
|
5
5
|
next_step: steps/step-08-documentation.md
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# Step 7: Test Generation
|
|
8
|
+
# Step 7: Test Generation & Verification
|
|
9
9
|
|
|
10
10
|
## MANDATORY EXECUTION RULES
|
|
11
11
|
|
|
12
12
|
- ALWAYS use MCP `scaffold_tests` for test generation
|
|
13
|
+
- ALWAYS generate test infrastructure FIRST (once per project)
|
|
13
14
|
- ALWAYS generate at least 3 test categories: controller, service, entity
|
|
14
15
|
- ALWAYS follow naming convention: `{Method}_When{Condition}_Should{Result}`
|
|
16
|
+
- ALWAYS pass `testTypes: ['unit', 'integration']` for controller tests
|
|
17
|
+
- ALWAYS pass `testTypes: ['integration']` for repository tests
|
|
18
|
+
- **ALL tests MUST compile AND pass** - this step is BLOCKING
|
|
15
19
|
- YOU ARE AN ORCHESTRATOR calling MCP, not a generator
|
|
16
20
|
|
|
17
21
|
## YOUR TASK
|
|
18
22
|
|
|
19
23
|
Use MCP tools to generate test files covering:
|
|
20
|
-
1.
|
|
21
|
-
2.
|
|
22
|
-
3.
|
|
23
|
-
4.
|
|
24
|
-
5.
|
|
25
|
-
6.
|
|
24
|
+
1. **Test infrastructure** (WebApplicationFactory, IntegrationTestBase, TestAuthHandler)
|
|
25
|
+
2. Controller integration tests (REAL API endpoints with real DB)
|
|
26
|
+
3. Service unit tests (business logic)
|
|
27
|
+
4. Entity unit tests (domain rules)
|
|
28
|
+
5. Validator unit tests (input validation)
|
|
29
|
+
6. Repository integration tests (data access)
|
|
30
|
+
7. Security tests (OWASP coverage)
|
|
26
31
|
|
|
27
32
|
---
|
|
28
33
|
|
|
@@ -68,6 +73,8 @@ The test project MUST have these packages:
|
|
|
68
73
|
| `FluentAssertions` | Assertion library |
|
|
69
74
|
| `Moq` | Mocking framework |
|
|
70
75
|
| `Microsoft.AspNetCore.Mvc.Testing` | Integration test support |
|
|
76
|
+
| `Microsoft.EntityFrameworkCore.Sqlite` | SQLite in-memory for REAL integration tests |
|
|
77
|
+
| `Microsoft.Data.Sqlite` | SQLite connection support |
|
|
71
78
|
| `Microsoft.EntityFrameworkCore.InMemory` | In-memory DB for repository tests |
|
|
72
79
|
| `FluentValidation.TestHelper` | Validator testing support |
|
|
73
80
|
|
|
@@ -76,21 +83,74 @@ cd tests/{SolutionName}.Tests
|
|
|
76
83
|
dotnet add package FluentAssertions
|
|
77
84
|
dotnet add package Moq
|
|
78
85
|
dotnet add package Microsoft.AspNetCore.Mvc.Testing
|
|
86
|
+
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
|
|
87
|
+
dotnet add package Microsoft.Data.Sqlite
|
|
79
88
|
dotnet add package Microsoft.EntityFrameworkCore.InMemory
|
|
80
89
|
dotnet add package FluentValidation.TestHelper
|
|
81
90
|
```
|
|
82
91
|
|
|
92
|
+
### 3. Add Project References
|
|
93
|
+
|
|
94
|
+
The test project MUST reference the API project (for WebApplicationFactory):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cd tests/{SolutionName}.Tests
|
|
98
|
+
dotnet add reference ../../src/{SolutionName}.Api/{SolutionName}.Api.csproj
|
|
99
|
+
dotnet add reference ../../src/{SolutionName}.Application/{SolutionName}.Application.csproj
|
|
100
|
+
dotnet add reference ../../src/{SolutionName}.Domain/{SolutionName}.Domain.csproj
|
|
101
|
+
dotnet add reference ../../src/{SolutionName}.Infrastructure/{SolutionName}.Infrastructure.csproj
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 4. Ensure Program.cs is Accessible (BLOCKING)
|
|
105
|
+
|
|
106
|
+
The API project's `Program` class must be accessible for `WebApplicationFactory<Program>`.
|
|
107
|
+
|
|
108
|
+
Check if `Program.cs` ends with `public partial class Program { }`. If not, add it:
|
|
109
|
+
|
|
110
|
+
```csharp
|
|
111
|
+
// At the very end of Program.cs
|
|
112
|
+
public partial class Program { }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Alternatively**, add to the API `.csproj`:
|
|
116
|
+
|
|
117
|
+
```xml
|
|
118
|
+
<ItemGroup>
|
|
119
|
+
<InternalsVisibleTo Include="{SolutionName}.Tests" />
|
|
120
|
+
</ItemGroup>
|
|
121
|
+
```
|
|
122
|
+
|
|
83
123
|
---
|
|
84
124
|
|
|
85
125
|
## EXECUTION SEQUENCE
|
|
86
126
|
|
|
127
|
+
### 0. Generate Test Infrastructure (ONCE PER PROJECT)
|
|
128
|
+
|
|
129
|
+
Check if `Tests/Integration/SmartStackTestFactory.cs` exists. If NOT:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Tool: mcp__smartstack__scaffold_tests
|
|
133
|
+
Args:
|
|
134
|
+
target: "infrastructure"
|
|
135
|
+
name: "{SolutionName}"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This generates:
|
|
139
|
+
- `Tests/Integration/SmartStackTestFactory.cs` - WebApplicationFactory with SQLite
|
|
140
|
+
- `Tests/Integration/IntegrationTestBase.cs` - Base class for integration tests
|
|
141
|
+
- `Tests/Integration/TestAuthHandler.cs` - Fake auth handler (bypasses JWT)
|
|
142
|
+
- `Tests/Integration/TestDataSeeder.cs` - Minimal test data seeder
|
|
143
|
+
|
|
144
|
+
**Review** `TestDataSeeder.cs` and add project-specific seeding logic if needed (tenant creation, base permissions, etc.).
|
|
145
|
+
|
|
87
146
|
### 1. Generate Controller Tests
|
|
88
147
|
|
|
89
148
|
```
|
|
90
149
|
Tool: mcp__smartstack__scaffold_tests
|
|
91
150
|
Args:
|
|
92
|
-
|
|
151
|
+
target: "controller"
|
|
93
152
|
name: "{entity_name}"
|
|
153
|
+
testTypes: ["unit", "integration"]
|
|
94
154
|
options:
|
|
95
155
|
namespace: "{namespace}"
|
|
96
156
|
navRoute: "{full_path}"
|
|
@@ -99,26 +159,30 @@ Args:
|
|
|
99
159
|
```
|
|
100
160
|
|
|
101
161
|
This generates:
|
|
102
|
-
- `Tests/Integration/Controllers/{EntityName}ControllerTests.cs`
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
- GET
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
162
|
+
- `Tests/Integration/Controllers/{EntityName}ControllerTests.cs` (mock-based, validates controller routing)
|
|
163
|
+
- `Tests/Integration/Controllers/{EntityName}ControllerIntegrationTests.cs` (REAL tests with actual DB)
|
|
164
|
+
|
|
165
|
+
**REAL Integration Test Coverage:**
|
|
166
|
+
- GET all -> 200 with list
|
|
167
|
+
- GET by ID -> 200 when exists, 404 when not
|
|
168
|
+
- POST -> 201/200 when valid, persist to DB, read back to verify
|
|
169
|
+
- POST -> 400 when invalid data
|
|
170
|
+
- POST -> 409 when duplicate code
|
|
171
|
+
- PUT -> 200 when valid, persist changes, read back to verify
|
|
172
|
+
- PUT -> 404 when not exists
|
|
173
|
+
- DELETE -> 204 when exists
|
|
174
|
+
- DELETE -> 404 when not exists
|
|
175
|
+
- Tenant isolation -> create in tenant A, invisible in tenant B (REAL DB)
|
|
176
|
+
- Authorization -> 401 when not authenticated
|
|
114
177
|
|
|
115
178
|
### 2. Generate Service Tests
|
|
116
179
|
|
|
117
180
|
```
|
|
118
181
|
Tool: mcp__smartstack__scaffold_tests
|
|
119
182
|
Args:
|
|
120
|
-
|
|
183
|
+
target: "service"
|
|
121
184
|
name: "{entity_name}"
|
|
185
|
+
testTypes: ["unit"]
|
|
122
186
|
options:
|
|
123
187
|
namespace: "{namespace}"
|
|
124
188
|
includeSoftDelete: true
|
|
@@ -128,22 +192,14 @@ Args:
|
|
|
128
192
|
This generates:
|
|
129
193
|
- `Tests/Unit/Services/{EntityName}ServiceTests.cs`
|
|
130
194
|
|
|
131
|
-
**Coverage:**
|
|
132
|
-
- GetById → entity when exists, null when not
|
|
133
|
-
- GetAll → list when entities exist, empty when none
|
|
134
|
-
- Create → success, duplicate code rejection
|
|
135
|
-
- Update → success, not found exception
|
|
136
|
-
- Delete → soft delete, already deleted, not found
|
|
137
|
-
- Tenant isolation → correct tenant assignment
|
|
138
|
-
- Error handling → repository failure, concurrency conflict
|
|
139
|
-
|
|
140
195
|
### 3. Generate Entity Tests
|
|
141
196
|
|
|
142
197
|
```
|
|
143
198
|
Tool: mcp__smartstack__scaffold_tests
|
|
144
199
|
Args:
|
|
145
|
-
|
|
200
|
+
target: "entity"
|
|
146
201
|
name: "{entity_name}"
|
|
202
|
+
testTypes: ["unit"]
|
|
147
203
|
options:
|
|
148
204
|
namespace: "{namespace}"
|
|
149
205
|
includeSoftDelete: true
|
|
@@ -154,20 +210,14 @@ Args:
|
|
|
154
210
|
This generates:
|
|
155
211
|
- `Tests/Unit/Domain/{EntityName}Tests.cs`
|
|
156
212
|
|
|
157
|
-
**Coverage:**
|
|
158
|
-
- Factory method Create → valid data, empty tenant, invalid code
|
|
159
|
-
- Update → audit fields
|
|
160
|
-
- Soft delete → mark as deleted, already deleted, restore
|
|
161
|
-
- Audit trail → creation fields, update fields
|
|
162
|
-
- Tenant isolation → immutable TenantId
|
|
163
|
-
|
|
164
213
|
### 4. Generate Validator Tests
|
|
165
214
|
|
|
166
215
|
```
|
|
167
216
|
Tool: mcp__smartstack__scaffold_tests
|
|
168
217
|
Args:
|
|
169
|
-
|
|
218
|
+
target: "validator"
|
|
170
219
|
name: "{entity_name}"
|
|
220
|
+
testTypes: ["unit"]
|
|
171
221
|
options:
|
|
172
222
|
namespace: "{namespace}"
|
|
173
223
|
```
|
|
@@ -175,21 +225,14 @@ Args:
|
|
|
175
225
|
This generates:
|
|
176
226
|
- `Tests/Unit/Validators/{EntityName}ValidatorTests.cs`
|
|
177
227
|
|
|
178
|
-
**Coverage:**
|
|
179
|
-
- Code validation → valid, null/empty, max length, valid format, invalid characters
|
|
180
|
-
- Name validation → valid, max length
|
|
181
|
-
- Update validation → valid data, optional null fields
|
|
182
|
-
- Security → XSS, SQL injection, prototype pollution
|
|
183
|
-
- Cross-field validation → dependent fields
|
|
184
|
-
- Multiple errors → all errors returned
|
|
185
|
-
|
|
186
228
|
### 5. Generate Repository Tests
|
|
187
229
|
|
|
188
230
|
```
|
|
189
231
|
Tool: mcp__smartstack__scaffold_tests
|
|
190
232
|
Args:
|
|
191
|
-
|
|
233
|
+
target: "repository"
|
|
192
234
|
name: "{entity_name}"
|
|
235
|
+
testTypes: ["integration"]
|
|
193
236
|
options:
|
|
194
237
|
namespace: "{namespace}"
|
|
195
238
|
includeSoftDelete: true
|
|
@@ -199,24 +242,14 @@ Args:
|
|
|
199
242
|
This generates:
|
|
200
243
|
- `Tests/Integration/Repositories/{EntityName}RepositoryTests.cs`
|
|
201
244
|
|
|
202
|
-
**Coverage:**
|
|
203
|
-
- GetById → exists, not exists, soft deleted
|
|
204
|
-
- GetAll → entities exist, empty, exclude soft deleted
|
|
205
|
-
- Add → persist, generate ID
|
|
206
|
-
- Update → persist changes
|
|
207
|
-
- Remove → delete entity
|
|
208
|
-
- ExistsByCode → exists, not exists, soft deleted
|
|
209
|
-
- Tenant isolation → current tenant only, cross-tenant returns null
|
|
210
|
-
- Pagination → correct page and counts
|
|
211
|
-
- Concurrency → concurrent modification exception
|
|
212
|
-
|
|
213
245
|
### 6. Generate Security Tests
|
|
214
246
|
|
|
215
247
|
```
|
|
216
248
|
Tool: mcp__smartstack__scaffold_tests
|
|
217
249
|
Args:
|
|
218
|
-
|
|
250
|
+
target: "controller"
|
|
219
251
|
name: "{entity_name}"
|
|
252
|
+
testTypes: ["security"]
|
|
220
253
|
options:
|
|
221
254
|
namespace: "{namespace}"
|
|
222
255
|
isSystemEntity: false
|
|
@@ -225,17 +258,6 @@ Args:
|
|
|
225
258
|
This generates:
|
|
226
259
|
- `Tests/Security/{EntityName}SecurityTests.cs`
|
|
227
260
|
|
|
228
|
-
**Coverage:**
|
|
229
|
-
- Authentication → 401 for unauthenticated, expired token, malformed token
|
|
230
|
-
- Authorization → 403 for insufficient permissions
|
|
231
|
-
- Tenant isolation → cross-tenant access returns 404, tenant ID not injectable
|
|
232
|
-
- Input validation → XSS prevention, SQL injection prevention, path traversal, prototype pollution
|
|
233
|
-
- IDOR → no data leakage via ID guessing
|
|
234
|
-
- Rate limiting → 429 on excessive requests
|
|
235
|
-
- Sensitive data → no passwords/secrets/stack traces exposed
|
|
236
|
-
- CORS → no wildcard origins
|
|
237
|
-
- Security headers → X-Content-Type-Options, X-Frame-Options, X-XSS-Protection
|
|
238
|
-
|
|
239
261
|
---
|
|
240
262
|
|
|
241
263
|
## POST-GENERATION VERIFICATION (MANDATORY)
|
|
@@ -260,7 +282,7 @@ REQUIRED pattern:
|
|
|
260
282
|
All tests MUST follow Arrange-Act-Assert:
|
|
261
283
|
|
|
262
284
|
```csharp
|
|
263
|
-
//
|
|
285
|
+
// CORRECT
|
|
264
286
|
[Fact]
|
|
265
287
|
public async Task GetById_WhenExists_ShouldReturn200()
|
|
266
288
|
{
|
|
@@ -274,14 +296,6 @@ public async Task GetById_WhenExists_ShouldReturn200()
|
|
|
274
296
|
// Assert
|
|
275
297
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
276
298
|
}
|
|
277
|
-
|
|
278
|
-
// ❌ FORBIDDEN - No AAA structure
|
|
279
|
-
[Fact]
|
|
280
|
-
public async Task TestGetById()
|
|
281
|
-
{
|
|
282
|
-
var response = await _client.GetAsync("/api/test/123");
|
|
283
|
-
Assert.True(response.IsSuccessStatusCode);
|
|
284
|
-
}
|
|
285
299
|
```
|
|
286
300
|
|
|
287
301
|
### 3. Dependencies Check (BLOCKING)
|
|
@@ -297,7 +311,8 @@ Minimum test coverage per category:
|
|
|
297
311
|
|
|
298
312
|
| Category | Minimum Tests |
|
|
299
313
|
|----------|---------------|
|
|
300
|
-
| Controller | 10 (CRUD + auth + tenant) |
|
|
314
|
+
| Controller (mock) | 10 (CRUD + auth + tenant) |
|
|
315
|
+
| Controller (real integration) | 8 (CRUD + persistence + tenant isolation) |
|
|
301
316
|
| Service | 8 (CRUD + errors) |
|
|
302
317
|
| Entity | 5 (factory + update + validation) |
|
|
303
318
|
| Validator | 8 (code + name + security) |
|
|
@@ -312,13 +327,91 @@ dotnet build tests/{SolutionName}.Tests/{SolutionName}.Tests.csproj
|
|
|
312
327
|
|
|
313
328
|
If build fails, fix compilation errors before proceeding.
|
|
314
329
|
|
|
315
|
-
### 6. Test Run (
|
|
330
|
+
### 6. Test Run (BLOCKING)
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
dotnet test tests/{SolutionName}.Tests/{SolutionName}.Tests.csproj --no-build --verbosity normal
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**ALL tests MUST pass.** If tests fail:
|
|
337
|
+
1. Read the failure output carefully
|
|
338
|
+
2. Fix the failing tests or the code they test
|
|
339
|
+
3. Re-run until all tests pass
|
|
340
|
+
4. Do NOT proceed to the next step until all tests are green
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## FRONTEND TESTS (React Components)
|
|
345
|
+
|
|
346
|
+
### 7. Check Frontend Test Infrastructure
|
|
347
|
+
|
|
348
|
+
Verify that the frontend project has Vitest + Testing Library configured:
|
|
316
349
|
|
|
317
350
|
```bash
|
|
318
|
-
|
|
351
|
+
# Check if vitest.config.ts exists in the web/frontend project
|
|
352
|
+
ls {WebProjectPath}/vitest.config.ts 2>/dev/null
|
|
319
353
|
```
|
|
320
354
|
|
|
321
|
-
|
|
355
|
+
If NOT found, deploy the test infrastructure:
|
|
356
|
+
|
|
357
|
+
1. **Install packages:**
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
cd {WebProjectPath}
|
|
361
|
+
npm install -D vitest @testing-library/react @testing-library/jest-dom @testing-library/user-event jsdom msw
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
2. **Copy infrastructure files** from SmartStack templates:
|
|
365
|
+
|
|
366
|
+
| Template Source | Destination |
|
|
367
|
+
|----------------|-------------|
|
|
368
|
+
| `templates/project/test-frontend/vitest.config.ts` | `{WebProjectPath}/vitest.config.ts` |
|
|
369
|
+
| `templates/project/test-frontend/setup.ts` | `{WebProjectPath}/src/test/setup.ts` |
|
|
370
|
+
| `templates/project/test-frontend/test-utils.tsx` | `{WebProjectPath}/src/test/test-utils.tsx` |
|
|
371
|
+
| `templates/project/test-frontend/msw/server.ts` | `{WebProjectPath}/src/test/msw/server.ts` |
|
|
372
|
+
| `templates/project/test-frontend/msw/handlers.ts` | `{WebProjectPath}/src/test/msw/handlers.ts` |
|
|
373
|
+
|
|
374
|
+
3. **Add test script** to `package.json` (if missing):
|
|
375
|
+
|
|
376
|
+
```json
|
|
377
|
+
{
|
|
378
|
+
"scripts": {
|
|
379
|
+
"test": "vitest run",
|
|
380
|
+
"test:watch": "vitest",
|
|
381
|
+
"test:coverage": "vitest run --coverage"
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### 8. Generate Frontend Tests
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
Tool: mcp__smartstack__scaffold_frontend_tests
|
|
390
|
+
Args:
|
|
391
|
+
name: "{entity_name}"
|
|
392
|
+
components: ["all"]
|
|
393
|
+
apiRoute: "/api/{entity_code}"
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
This generates:
|
|
397
|
+
- `src/pages/{context}/{application}/__tests__/{EntityName}Page.test.tsx` - Page rendering, loading, error states
|
|
398
|
+
- `src/pages/{context}/{application}/__tests__/{EntityName}ListView.test.tsx` - List display, pagination, view toggle
|
|
399
|
+
- `src/pages/{context}/{application}/__tests__/{EntityName}DetailPage.test.tsx` - Detail view, tabs, back navigation
|
|
400
|
+
- `src/hooks/__tests__/use{EntityName}Preferences.test.ts` - Preference get/set
|
|
401
|
+
- `src/services/api/__tests__/{entityName}Api.test.ts` - API client calls with MSW
|
|
402
|
+
|
|
403
|
+
### 9. Run Frontend Tests (BLOCKING)
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
cd {WebProjectPath}
|
|
407
|
+
npx vitest run --reporter=default
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**ALL frontend tests MUST pass.** If tests fail:
|
|
411
|
+
1. Read the failure output carefully
|
|
412
|
+
2. Fix the failing tests or the components they test
|
|
413
|
+
3. Re-run until all tests pass
|
|
414
|
+
4. Do NOT proceed to the next step until all tests are green
|
|
322
415
|
|
|
323
416
|
---
|
|
324
417
|
|
|
@@ -331,7 +424,12 @@ Note: Some tests may fail initially because the service/repository implementatio
|
|
|
331
424
|
|
|
332
425
|
| File | Category | Tests |
|
|
333
426
|
|------|----------|-------|
|
|
334
|
-
| `Tests/Integration/
|
|
427
|
+
| `Tests/Integration/SmartStackTestFactory.cs` | Infrastructure | - |
|
|
428
|
+
| `Tests/Integration/IntegrationTestBase.cs` | Infrastructure | - |
|
|
429
|
+
| `Tests/Integration/TestAuthHandler.cs` | Infrastructure | - |
|
|
430
|
+
| `Tests/Integration/TestDataSeeder.cs` | Infrastructure | - |
|
|
431
|
+
| `Tests/Integration/Controllers/{EntityName}ControllerTests.cs` | Controller (mock) | ~12 |
|
|
432
|
+
| `Tests/Integration/Controllers/{EntityName}ControllerIntegrationTests.cs` | Controller (REAL) | ~12 |
|
|
335
433
|
| `Tests/Unit/Services/{EntityName}ServiceTests.cs` | Service | ~10 |
|
|
336
434
|
| `Tests/Unit/Domain/{EntityName}Tests.cs` | Entity | ~8 |
|
|
337
435
|
| `Tests/Unit/Validators/{EntityName}ValidatorTests.cs` | Validator | ~12 |
|
|
@@ -342,58 +440,97 @@ Note: Some tests may fail initially because the service/repository implementatio
|
|
|
342
440
|
|
|
343
441
|
| Category | Coverage |
|
|
344
442
|
|----------|----------|
|
|
345
|
-
| CRUD Operations |
|
|
346
|
-
|
|
|
347
|
-
|
|
|
348
|
-
|
|
|
349
|
-
|
|
|
350
|
-
|
|
|
351
|
-
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
2. Run `dotnet test` to verify test compilation
|
|
368
|
-
3. Achieve >80% code coverage
|
|
443
|
+
| CRUD Operations | All endpoints tested with REAL database |
|
|
444
|
+
| Data Persistence | POST then GET to verify data in DB |
|
|
445
|
+
| Authentication | 401 for unauthenticated |
|
|
446
|
+
| Authorization | 403 for insufficient permissions |
|
|
447
|
+
| Tenant Isolation | Cross-tenant access blocked (REAL) |
|
|
448
|
+
| Input Validation | XSS, SQL injection, path traversal |
|
|
449
|
+
| Error Handling | ProblemDetails format |
|
|
450
|
+
|
|
451
|
+
### Frontend Tests
|
|
452
|
+
|
|
453
|
+
| File | Category | Tests |
|
|
454
|
+
|------|----------|-------|
|
|
455
|
+
| `src/pages/.../__tests__/{EntityName}Page.test.tsx` | Page | ~5 |
|
|
456
|
+
| `src/pages/.../__tests__/{EntityName}ListView.test.tsx` | List | ~8 |
|
|
457
|
+
| `src/pages/.../__tests__/{EntityName}DetailPage.test.tsx` | Detail | ~5 |
|
|
458
|
+
| `src/hooks/__tests__/use{EntityName}Preferences.test.ts` | Hooks | ~6 |
|
|
459
|
+
| `src/services/api/__tests__/{entityName}Api.test.ts` | API Client | ~5 |
|
|
460
|
+
|
|
461
|
+
### Test Execution Result
|
|
462
|
+
- Backend Build: PASS
|
|
463
|
+
- Backend Tests: PASS ({backend_test_count} tests)
|
|
464
|
+
- Frontend Tests: PASS ({frontend_test_count} tests)
|
|
369
465
|
```
|
|
370
466
|
|
|
371
467
|
---
|
|
372
468
|
|
|
373
469
|
## SUCCESS METRICS
|
|
374
470
|
|
|
471
|
+
### Backend
|
|
375
472
|
- Test project exists in solution
|
|
376
|
-
-
|
|
473
|
+
- Test infrastructure generated (SmartStackTestFactory, IntegrationTestBase, TestAuthHandler)
|
|
474
|
+
- All 7 test categories generated (infrastructure + 6 test types)
|
|
377
475
|
- Naming convention `{Method}_When{Condition}_Should{Result}` respected
|
|
378
476
|
- Arrange-Act-Assert structure in all tests
|
|
379
477
|
- FluentAssertions used (not Assert.Equal)
|
|
380
|
-
- Moq used for mocking
|
|
381
|
-
- Test project builds successfully
|
|
478
|
+
- Moq used for mocking (only in mock-based tests)
|
|
479
|
+
- **Test project builds successfully**
|
|
480
|
+
- **ALL backend tests pass** (BLOCKING)
|
|
382
481
|
- Minimum test count met per category
|
|
482
|
+
- Real integration tests verify actual DB persistence
|
|
483
|
+
|
|
484
|
+
### Frontend
|
|
485
|
+
- Vitest + Testing Library + MSW infrastructure deployed
|
|
486
|
+
- Test files generated for all scaffolded components (page, list, detail, hooks, api)
|
|
487
|
+
- MSW handlers mock API endpoints correctly
|
|
488
|
+
- **ALL frontend tests pass** (BLOCKING)
|
|
383
489
|
|
|
384
490
|
## FAILURE MODES
|
|
385
491
|
|
|
386
|
-
|
|
387
|
-
-
|
|
388
|
-
-
|
|
389
|
-
-
|
|
390
|
-
-
|
|
492
|
+
### Backend
|
|
493
|
+
- Test project doesn't exist -> Create it first
|
|
494
|
+
- Missing NuGet packages -> Install them
|
|
495
|
+
- Program.cs not accessible -> Add `public partial class Program { }`
|
|
496
|
+
- Build failures -> Fix compilation errors
|
|
497
|
+
- **Test failures -> Fix the code or tests before proceeding**
|
|
498
|
+
- Wrong naming convention -> Rename tests
|
|
499
|
+
- Missing test categories -> Generate missing ones
|
|
500
|
+
|
|
501
|
+
### Frontend
|
|
502
|
+
- Vitest not configured -> Deploy infrastructure templates
|
|
503
|
+
- Missing npm packages -> Run `npm install -D vitest @testing-library/react ...`
|
|
504
|
+
- MSW handlers missing -> Check `src/test/msw/handlers.ts`
|
|
505
|
+
- Import errors -> Check path aliases in `vitest.config.ts`
|
|
506
|
+
- **Test failures -> Fix the components or tests before proceeding**
|
|
507
|
+
|
|
508
|
+
---
|
|
509
|
+
|
|
510
|
+
## CODE REVIEW (RECOMMENDED)
|
|
511
|
+
|
|
512
|
+
After all tests pass, run a code quality audit on the generated feature:
|
|
513
|
+
|
|
514
|
+
```
|
|
515
|
+
Tool: mcp__smartstack__review_code
|
|
516
|
+
Args:
|
|
517
|
+
scope: "{entity_name}"
|
|
518
|
+
focus: ["security", "architecture", "clean-code", "performance"]
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
This reviews:
|
|
522
|
+
- **Security (OWASP)**: SQL injection, XSS, CSRF, auth bypass, tenant isolation
|
|
523
|
+
- **Architecture**: Layer violations, DI patterns, SOLID principles
|
|
524
|
+
- **Clean Code**: Naming, complexity, duplication, dead code
|
|
525
|
+
- **Performance**: N+1 queries, missing indexes, unnecessary allocations
|
|
526
|
+
|
|
527
|
+
IF critical issues found: Fix them before proceeding. Non-critical findings can be noted for future improvement.
|
|
391
528
|
|
|
392
529
|
---
|
|
393
530
|
|
|
394
531
|
## END OF WORKFLOW
|
|
395
532
|
|
|
396
|
-
This
|
|
533
|
+
This step concludes the test generation. The user now has:
|
|
397
534
|
- Full navigation structure (step 01)
|
|
398
535
|
- RBAC permissions (step 02)
|
|
399
536
|
- Role mappings (step 03)
|
|
@@ -401,4 +538,6 @@ This is the final step of the /application skill workflow. The user now has:
|
|
|
401
538
|
- Backend CRUD API (step 04)
|
|
402
539
|
- Frontend components + i18n + routes (step 05)
|
|
403
540
|
- Database migration (step 06)
|
|
404
|
-
- **Complete test suite (step 07)**
|
|
541
|
+
- **Complete backend test suite with REAL integration tests (step 07)**
|
|
542
|
+
- **Complete frontend test suite with Vitest + Testing Library + MSW (step 07)**
|
|
543
|
+
- All backend and frontend tests compile and pass
|