qaa-agent 1.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/.claude/commands/create-test.md +40 -0
- package/.claude/commands/qa-analyze.md +60 -0
- package/.claude/commands/qa-audit.md +37 -0
- package/.claude/commands/qa-blueprint.md +54 -0
- package/.claude/commands/qa-fix.md +36 -0
- package/.claude/commands/qa-from-ticket.md +88 -0
- package/.claude/commands/qa-gap.md +54 -0
- package/.claude/commands/qa-pom.md +36 -0
- package/.claude/commands/qa-pyramid.md +37 -0
- package/.claude/commands/qa-report.md +38 -0
- package/.claude/commands/qa-start.md +33 -0
- package/.claude/commands/qa-testid.md +54 -0
- package/.claude/commands/qa-validate.md +54 -0
- package/.claude/commands/update-test.md +58 -0
- package/.claude/settings.json +19 -0
- package/.claude/skills/qa-bug-detective/SKILL.md +122 -0
- package/.claude/skills/qa-repo-analyzer/SKILL.md +88 -0
- package/.claude/skills/qa-self-validator/SKILL.md +109 -0
- package/.claude/skills/qa-template-engine/SKILL.md +113 -0
- package/.claude/skills/qa-testid-injector/SKILL.md +93 -0
- package/.claude/skills/qa-workflow-documenter/SKILL.md +87 -0
- package/CLAUDE.md +543 -0
- package/README.md +418 -0
- package/agents/qa-pipeline-orchestrator.md +1217 -0
- package/agents/qaa-analyzer.md +508 -0
- package/agents/qaa-bug-detective.md +444 -0
- package/agents/qaa-executor.md +618 -0
- package/agents/qaa-planner.md +374 -0
- package/agents/qaa-scanner.md +422 -0
- package/agents/qaa-testid-injector.md +583 -0
- package/agents/qaa-validator.md +450 -0
- package/bin/install.cjs +176 -0
- package/bin/lib/commands.cjs +709 -0
- package/bin/lib/config.cjs +307 -0
- package/bin/lib/core.cjs +497 -0
- package/bin/lib/frontmatter.cjs +299 -0
- package/bin/lib/init.cjs +989 -0
- package/bin/lib/milestone.cjs +241 -0
- package/bin/lib/model-profiles.cjs +60 -0
- package/bin/lib/phase.cjs +911 -0
- package/bin/lib/roadmap.cjs +306 -0
- package/bin/lib/state.cjs +748 -0
- package/bin/lib/template.cjs +222 -0
- package/bin/lib/verify.cjs +842 -0
- package/bin/qaa-tools.cjs +607 -0
- package/package.json +34 -0
- package/templates/failure-classification.md +391 -0
- package/templates/gap-analysis.md +409 -0
- package/templates/pr-template.md +48 -0
- package/templates/qa-analysis.md +381 -0
- package/templates/qa-audit-report.md +465 -0
- package/templates/qa-repo-blueprint.md +636 -0
- package/templates/scan-manifest.md +312 -0
- package/templates/test-inventory.md +582 -0
- package/templates/testid-audit-report.md +354 -0
- package/templates/validation-report.md +243 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
---
|
|
2
|
+
template_name: qa-analysis
|
|
3
|
+
version: "1.0"
|
|
4
|
+
artifact_type: analysis
|
|
5
|
+
produces: QA_ANALYSIS.md
|
|
6
|
+
producer_agent: qa-analyzer
|
|
7
|
+
consumer_agents:
|
|
8
|
+
- qa-planner
|
|
9
|
+
- qa-executor
|
|
10
|
+
required_sections:
|
|
11
|
+
- architecture-overview
|
|
12
|
+
- external-dependencies
|
|
13
|
+
- risk-assessment
|
|
14
|
+
- top-10-unit-targets
|
|
15
|
+
- api-contract-targets
|
|
16
|
+
- recommended-testing-pyramid
|
|
17
|
+
example_domain: shopflow
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# QA_ANALYSIS.md Template
|
|
21
|
+
|
|
22
|
+
**Purpose:** Comprehensive testability report for a codebase. Provides downstream agents with a complete understanding of the application architecture, risk areas, priority test targets, and recommended testing strategy. This is the primary analysis artifact that drives all test planning and generation decisions.
|
|
23
|
+
|
|
24
|
+
**Producer:** `qa-analyzer` agent
|
|
25
|
+
**Consumers:** `qa-planner` (reads targets and pyramid to create generation plan), `qa-executor` (reads architecture and risks to write informed tests)
|
|
26
|
+
|
|
27
|
+
**Input required:** `SCAN_MANIFEST.md` must exist before this artifact is produced. The analyzer reads the file list, testable surfaces, and project detection data from the scan manifest.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Required Sections
|
|
32
|
+
|
|
33
|
+
### Section 1: Architecture Overview
|
|
34
|
+
|
|
35
|
+
**Description:** System-level summary of the application under analysis. Provides the foundational context that all other sections reference. Must be specific to the actual codebase -- never generic.
|
|
36
|
+
|
|
37
|
+
#### Properties Table
|
|
38
|
+
|
|
39
|
+
| Field | Type | Required | Description |
|
|
40
|
+
|-------|------|----------|-------------|
|
|
41
|
+
| system_type | string | YES | Application category (e.g., REST API, monolith, microservice, SPA, full-stack) |
|
|
42
|
+
| language | string | YES | Primary language and version |
|
|
43
|
+
| runtime | string | YES | Runtime environment and version |
|
|
44
|
+
| framework | string | YES | Primary framework and version |
|
|
45
|
+
| database | string | YES | Database technology and access layer (e.g., PostgreSQL 15 via Prisma 5.7) |
|
|
46
|
+
| authentication | string | YES | Auth mechanism (e.g., JWT, session-based, OAuth2, API key) |
|
|
47
|
+
| integrations | string | NO | External service integrations (e.g., Stripe, SendGrid, S3) |
|
|
48
|
+
| deployment | string | NO | Deployment target (e.g., Docker + AWS ECS, Vercel, Railway) |
|
|
49
|
+
|
|
50
|
+
#### Entry Points Table
|
|
51
|
+
|
|
52
|
+
| Field | Type | Required | Description |
|
|
53
|
+
|-------|------|----------|-------------|
|
|
54
|
+
| route_file | string | YES | Path to the route definition file |
|
|
55
|
+
| base_path | string | YES | URL prefix for this route group |
|
|
56
|
+
| methods | string | YES | HTTP methods and endpoint names handled |
|
|
57
|
+
| auth_required | string | YES | Which endpoints require authentication |
|
|
58
|
+
|
|
59
|
+
#### Internal Layers
|
|
60
|
+
|
|
61
|
+
**Description:** Directory structure showing the application's layered architecture. Each directory listed with its purpose and relationship to other layers. Show the data flow direction (routes -> controllers -> services -> models).
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### Section 2: External Dependencies
|
|
66
|
+
|
|
67
|
+
**Description:** Third-party libraries and services that the application depends on, each assessed for testing risk. HIGH-risk dependencies handle money, authentication, or critical data. MEDIUM-risk dependencies are important but failures are recoverable. LOW-risk dependencies are utilities.
|
|
68
|
+
|
|
69
|
+
**Fields:**
|
|
70
|
+
|
|
71
|
+
| Field | Type | Required | Description |
|
|
72
|
+
|-------|------|----------|-------------|
|
|
73
|
+
| dependency | string | YES | Package or service name with version |
|
|
74
|
+
| purpose | string | YES | What the application uses it for |
|
|
75
|
+
| risk_level | enum | YES | `HIGH`, `MEDIUM`, or `LOW` |
|
|
76
|
+
| justification | string | YES | Why this risk level -- specific to how the app uses it |
|
|
77
|
+
|
|
78
|
+
**Risk classification rules:**
|
|
79
|
+
- **HIGH:** Handles payments, authentication, sensitive data encryption, critical business rules, or data persistence. Failure = data loss, security breach, or revenue impact.
|
|
80
|
+
- **MEDIUM:** Important functionality but recoverable. Email sending, file uploads, caching, logging. Failure = degraded experience but no data loss.
|
|
81
|
+
- **LOW:** Utility functions, formatting, development tooling. Failure = minor inconvenience.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
### Section 3: Risk Assessment
|
|
86
|
+
|
|
87
|
+
**Description:** Prioritized list of specific risks identified in the codebase. Every risk MUST reference actual code, files, or patterns found during analysis. Generic risks without evidence are not acceptable.
|
|
88
|
+
|
|
89
|
+
**Fields per risk:**
|
|
90
|
+
|
|
91
|
+
| Field | Type | Required | Description |
|
|
92
|
+
|-------|------|----------|-------------|
|
|
93
|
+
| risk_id | string | YES | Format: `RISK-NNN` (e.g., RISK-001) |
|
|
94
|
+
| area | string | YES | Module or feature area (e.g., "Payment Processing", "Order State Machine") |
|
|
95
|
+
| severity | enum | YES | `HIGH`, `MEDIUM`, or `LOW` |
|
|
96
|
+
| description | string | YES | What could go wrong, specifically |
|
|
97
|
+
| evidence | string | YES | Code file, function, or pattern that demonstrates this risk |
|
|
98
|
+
| testing_implication | string | YES | What tests are needed to mitigate this risk |
|
|
99
|
+
|
|
100
|
+
**Anti-pattern:** "SQL injection is possible" without pointing to a specific vulnerable query is NOT acceptable. Risks must cite specific files and patterns.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### Section 4: Top 10 Unit Test Targets
|
|
105
|
+
|
|
106
|
+
**Description:** The ten highest-priority modules or functions for unit testing, ranked by a composite score of business impact, code complexity, and change frequency. These targets drive the bulk of the test inventory.
|
|
107
|
+
|
|
108
|
+
**Fields:**
|
|
109
|
+
|
|
110
|
+
| Field | Type | Required | Description |
|
|
111
|
+
|-------|------|----------|-------------|
|
|
112
|
+
| rank | number | YES | 1-10 priority ranking |
|
|
113
|
+
| module_path | string | YES | File path relative to project root |
|
|
114
|
+
| function_or_method | string | YES | Specific function or method name to test |
|
|
115
|
+
| why_high_priority | string | YES | Business justification for testing this target |
|
|
116
|
+
| complexity | string | YES | Assessment: lines of code, branch count, dependency count |
|
|
117
|
+
| suggested_test_count | number | YES | Estimated number of test cases needed |
|
|
118
|
+
|
|
119
|
+
**Ranking criteria:** business_impact (40%) x complexity (30%) x change_frequency (30%). Business impact means: what breaks if this function has a bug? Complexity means: how many code paths exist? Change frequency means: how often is this file modified?
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### Section 5: API/Contract Test Targets
|
|
124
|
+
|
|
125
|
+
**Description:** HTTP endpoints that need contract testing to ensure request/response shapes are maintained. Grouped by resource. Each entry defines the expected request and response contract.
|
|
126
|
+
|
|
127
|
+
**Fields:**
|
|
128
|
+
|
|
129
|
+
| Field | Type | Required | Description |
|
|
130
|
+
|-------|------|----------|-------------|
|
|
131
|
+
| endpoint | string | YES | HTTP method + path (e.g., `POST /api/v1/orders`) |
|
|
132
|
+
| request_contract | string | YES | Expected request params, body shape, and content type |
|
|
133
|
+
| response_contract | string | YES | Expected status code + response body shape (key fields and types) |
|
|
134
|
+
| auth_required | boolean | YES | Whether this endpoint requires authentication |
|
|
135
|
+
| test_priority | enum | YES | `P0` (blocks release), `P1` (should fix), `P2` (nice to have) |
|
|
136
|
+
|
|
137
|
+
**Grouping:** Organize endpoints by resource (e.g., Auth, Products, Orders, Payments). Within each group, list by HTTP method order: POST (create) -> GET (read) -> PUT/PATCH (update) -> DELETE (remove).
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### Section 6: Recommended Testing Pyramid
|
|
142
|
+
|
|
143
|
+
**Description:** Testing strategy with percentage allocations tailored to THIS specific application's architecture. Must justify any deviation from the standard 65/15/15/5 distribution.
|
|
144
|
+
|
|
145
|
+
**Format:**
|
|
146
|
+
|
|
147
|
+
1. ASCII pyramid visualization with percentages
|
|
148
|
+
2. Table with tier, percentage, count, and rationale specific to this app
|
|
149
|
+
3. Justification paragraph explaining why these percentages were chosen
|
|
150
|
+
|
|
151
|
+
**Fields per tier:**
|
|
152
|
+
|
|
153
|
+
| Field | Type | Required | Description |
|
|
154
|
+
|-------|------|----------|-------------|
|
|
155
|
+
| tier | string | YES | Unit, Integration, API, or E2E |
|
|
156
|
+
| percentage | number | YES | Percentage of total test count |
|
|
157
|
+
| test_count | number | YES | Estimated number of tests at this tier |
|
|
158
|
+
| rationale | string | YES | Why this percentage for THIS app (not generic) |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Worked Example (ShopFlow E-Commerce API)
|
|
163
|
+
|
|
164
|
+
> The following is a complete, filled QA_ANALYSIS.md for the ShopFlow e-commerce application. This example demonstrates the expected depth, specificity, and quality level.
|
|
165
|
+
|
|
166
|
+
### Architecture Overview
|
|
167
|
+
|
|
168
|
+
| Property | Value |
|
|
169
|
+
|----------|-------|
|
|
170
|
+
| System Type | REST API with React SPA (monolith) |
|
|
171
|
+
| Language | TypeScript 5.3 |
|
|
172
|
+
| Runtime | Node.js 20 LTS |
|
|
173
|
+
| Framework | Express 4.18 (backend), React 18.2 (frontend) |
|
|
174
|
+
| Database | PostgreSQL 15 via Prisma 5.7 ORM |
|
|
175
|
+
| Authentication | JWT (jsonwebtoken 9.x + bcrypt 5.x) |
|
|
176
|
+
| Integrations | Stripe SDK 14.x (payments), Resend (transactional email) |
|
|
177
|
+
| Deployment | Docker + AWS ECS (production), Docker Compose (local dev) |
|
|
178
|
+
|
|
179
|
+
#### Entry Points
|
|
180
|
+
|
|
181
|
+
| Route File | Base Path | Methods | Auth Required |
|
|
182
|
+
|------------|-----------|---------|---------------|
|
|
183
|
+
| src/routes/api/v1/auth.ts | /api/v1/auth | POST register, POST login, POST refresh, POST logout | No (register, login), Yes (refresh, logout) |
|
|
184
|
+
| src/routes/api/v1/products.ts | /api/v1/products | GET list, GET :id, POST create, PUT :id, DELETE :id | No (GET), Yes (POST, PUT, DELETE) |
|
|
185
|
+
| src/routes/api/v1/orders.ts | /api/v1/orders | GET list, GET :id, POST create, PATCH :id/status | Yes (all) |
|
|
186
|
+
| src/routes/api/v1/payments.ts | /api/v1/payments | POST charge, POST refund, POST webhook | Yes (charge, refund), No (webhook) |
|
|
187
|
+
|
|
188
|
+
#### Internal Layers
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
src/
|
|
192
|
+
routes/ -> HTTP routing, input validation, request parsing
|
|
193
|
+
controllers/ -> Request/response handling, calls services, formats output
|
|
194
|
+
services/ -> Business logic, state transitions, external API calls
|
|
195
|
+
models/ -> Prisma schema definitions, custom model methods
|
|
196
|
+
middleware/ -> Auth (JWT verify), rate limiting, error handler, CORS
|
|
197
|
+
utils/ -> Price calculator, validators, date helpers, formatters
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Data flow: `Routes -> Controllers -> Services -> Models (Prisma) -> PostgreSQL`
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### External Dependencies
|
|
205
|
+
|
|
206
|
+
| Dependency | Purpose | Version | Risk Level | Justification |
|
|
207
|
+
|-----------|---------|---------|------------|---------------|
|
|
208
|
+
| express | HTTP server framework | 4.18.x | MEDIUM | Core routing -- well-tested library but misconfiguration possible |
|
|
209
|
+
| @prisma/client | Database ORM | 5.7.x | HIGH | All data persistence flows through Prisma -- query bugs = data corruption |
|
|
210
|
+
| stripe | Payment processing | 14.x | HIGH | Handles real money -- charge errors = revenue loss, webhook failures = order stuck |
|
|
211
|
+
| jsonwebtoken | JWT token signing/verification | 9.x | HIGH | Authentication barrier -- token bugs = unauthorized access |
|
|
212
|
+
| bcrypt | Password hashing | 5.x | HIGH | Password security -- weak hashing = credential exposure |
|
|
213
|
+
| zod | Input validation schemas | 3.22.x | MEDIUM | Request validation -- bypass = invalid data reaching services |
|
|
214
|
+
| resend | Transactional email | 2.x | LOW | Order confirmation emails -- failure = no email, order still processes |
|
|
215
|
+
| helmet | Security headers | 7.x | MEDIUM | HTTP security headers -- misconfiguration = XSS/clickjacking risk |
|
|
216
|
+
| cors | Cross-origin resource sharing | 2.x | MEDIUM | Frontend access -- misconfiguration = blocked requests or open access |
|
|
217
|
+
| winston | Structured logging | 3.x | LOW | Logging -- failure = no logs, app still works |
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### Risk Assessment
|
|
222
|
+
|
|
223
|
+
#### RISK-001: Stripe Webhook Signature Verification
|
|
224
|
+
- **Area:** Payment Processing
|
|
225
|
+
- **Severity:** HIGH
|
|
226
|
+
- **Description:** Stripe webhooks deliver payment status updates (succeeded, failed, refunded). If webhook signature verification is bypassed or incorrectly implemented, an attacker could forge webhook events to mark unpaid orders as paid.
|
|
227
|
+
- **Evidence:** `src/controllers/paymentController.ts:handleWebhook` calls `stripe.webhooks.constructEvent()` -- must verify the raw body is passed (not parsed JSON) and the signing secret matches the environment variable.
|
|
228
|
+
- **Testing Implication:** Need integration tests that send webhooks with valid and invalid signatures, plus unit tests for the webhook handler logic with mocked Stripe responses.
|
|
229
|
+
|
|
230
|
+
#### RISK-002: Order State Machine Transition Logic
|
|
231
|
+
- **Area:** Order Management
|
|
232
|
+
- **Severity:** HIGH
|
|
233
|
+
- **Description:** Orders follow a state machine (pending -> confirmed -> shipped -> delivered, with cancel possible from pending/confirmed). Invalid transitions (e.g., delivered -> pending) could corrupt order history and trigger incorrect refunds.
|
|
234
|
+
- **Evidence:** `src/services/orderService.ts:transitionOrderStatus` contains a transition map -- every valid from/to pair must be explicitly tested, including boundary cases.
|
|
235
|
+
- **Testing Implication:** Unit tests for every valid transition, every invalid transition (expect error), and edge cases (cancelling a shipped order). Minimum 8-10 test cases for this function alone.
|
|
236
|
+
|
|
237
|
+
#### RISK-003: JWT Token Expiry and Refresh Race Condition
|
|
238
|
+
- **Area:** Authentication
|
|
239
|
+
- **Severity:** MEDIUM
|
|
240
|
+
- **Description:** If access tokens expire during a multi-step checkout flow, the refresh endpoint must issue new tokens without losing the user's cart state. Concurrent refresh requests from multiple tabs could invalidate tokens unexpectedly.
|
|
241
|
+
- **Evidence:** `src/services/authService.ts:refreshToken` reads the refresh token from the database -- concurrent calls could race on token rotation, leaving one tab with an invalidated token.
|
|
242
|
+
- **Testing Implication:** Unit tests for token generation and validation, integration tests for the refresh flow, and a concurrency test for simultaneous refresh requests.
|
|
243
|
+
|
|
244
|
+
#### RISK-004: Inventory Reservation Without Release on Payment Failure
|
|
245
|
+
- **Area:** Inventory Management
|
|
246
|
+
- **Severity:** HIGH
|
|
247
|
+
- **Description:** When a customer starts checkout, inventory is reserved. If payment fails, reserved stock must be released. A bug in the release path leads to phantom reservations that reduce available stock permanently.
|
|
248
|
+
- **Evidence:** `src/services/inventoryService.ts:reserveStock` decrements available count, but `releaseStock` is only called in the payment failure handler in `src/services/paymentService.ts:chargeCustomer` -- if chargeCustomer throws before reaching the release call, stock is permanently locked.
|
|
249
|
+
- **Testing Implication:** Integration tests for the full checkout-to-payment flow, specifically testing the failure path. Unit tests for reserveStock and releaseStock independently.
|
|
250
|
+
|
|
251
|
+
#### RISK-005: Price Calculation Floating-Point Precision
|
|
252
|
+
- **Area:** Pricing
|
|
253
|
+
- **Severity:** MEDIUM
|
|
254
|
+
- **Description:** JavaScript floating-point arithmetic can produce rounding errors in price calculations (e.g., 0.1 + 0.2 = 0.30000000000000004). If the price calculator does not round correctly, customers could be charged incorrect amounts.
|
|
255
|
+
- **Evidence:** `src/utils/priceCalculator.ts:calculateOrderTotal` multiplies quantity by unit price and sums -- without explicit rounding to 2 decimal places, accumulated errors across multiple line items could produce incorrect totals.
|
|
256
|
+
- **Testing Implication:** Unit tests with known inputs that trigger floating-point edge cases (e.g., quantities with prices like $19.99, $9.95). Verify outputs are rounded to exactly 2 decimal places.
|
|
257
|
+
|
|
258
|
+
#### RISK-006: Missing Rate Limiting on Auth Endpoints
|
|
259
|
+
- **Area:** Security
|
|
260
|
+
- **Severity:** MEDIUM
|
|
261
|
+
- **Description:** Login and registration endpoints without rate limiting are vulnerable to brute-force attacks and credential stuffing.
|
|
262
|
+
- **Evidence:** `src/middleware/rateLimiter.ts` exists but the limit configuration for auth endpoints needs verification -- the general limit (100 req/min) may be too permissive for login (should be 5-10 req/min).
|
|
263
|
+
- **Testing Implication:** Integration tests that verify rate limiting kicks in at the configured threshold for auth endpoints specifically.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### Top 10 Unit Test Targets
|
|
268
|
+
|
|
269
|
+
| Rank | Module Path | Function/Method | Why High-Priority | Complexity | Suggested Tests |
|
|
270
|
+
|------|------------|-----------------|-------------------|-----------|----------------|
|
|
271
|
+
| 1 | src/utils/priceCalculator.ts | calculateOrderTotal | Core revenue logic -- wrong totals = financial loss | 45 lines, 4 branches, 0 deps | 6 |
|
|
272
|
+
| 2 | src/utils/priceCalculator.ts | applyDiscount | Discount logic affects revenue -- percentage and fixed discounts | 30 lines, 3 branches, 0 deps | 5 |
|
|
273
|
+
| 3 | src/services/orderService.ts | transitionOrderStatus | State machine -- invalid transitions corrupt order history | 60 lines, 8 branches, 2 deps | 10 |
|
|
274
|
+
| 4 | src/services/authService.ts | hashPassword / verifyPassword | Security-critical -- weak hashing = credential exposure | 20 lines, 2 branches, 1 dep (bcrypt) | 4 |
|
|
275
|
+
| 5 | src/services/authService.ts | generateToken / refreshToken | Auth tokens -- wrong claims or expiry = security holes | 35 lines, 4 branches, 1 dep (jwt) | 6 |
|
|
276
|
+
| 6 | src/services/paymentService.ts | chargeCustomer | Stripe integration -- charge errors = lost revenue | 50 lines, 5 branches, 2 deps (stripe, orderService) | 7 |
|
|
277
|
+
| 7 | src/services/inventoryService.ts | reserveStock / releaseStock | Stock management -- reservation bugs = phantom inventory | 40 lines, 4 branches, 1 dep (prisma) | 6 |
|
|
278
|
+
| 8 | src/utils/validators.ts | validateEmail / validatePassword | Input validation -- bypasses = bad data in DB | 25 lines, 6 branches, 0 deps | 8 |
|
|
279
|
+
| 9 | src/services/orderService.ts | createOrder | Order creation orchestrates inventory + payment | 55 lines, 5 branches, 3 deps | 6 |
|
|
280
|
+
| 10 | src/middleware/authMiddleware.ts | verifyToken (middleware) | Auth gate -- bypass = unauthorized access to all protected routes | 30 lines, 4 branches, 1 dep (jwt) | 5 |
|
|
281
|
+
|
|
282
|
+
**Total suggested unit tests from top 10:** 63
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
### API/Contract Test Targets
|
|
287
|
+
|
|
288
|
+
#### Auth Resource
|
|
289
|
+
|
|
290
|
+
| Endpoint | Request Contract | Response Contract | Auth | Priority |
|
|
291
|
+
|----------|-----------------|-------------------|------|----------|
|
|
292
|
+
| POST /api/v1/auth/register | `{name: string, email: string, password: string}` | `201 {id: string, email: string, token: string}` | No | P0 |
|
|
293
|
+
| POST /api/v1/auth/login | `{email: string, password: string}` | `200 {token: string, refreshToken: string, user: {id, name, email}}` | No | P0 |
|
|
294
|
+
| POST /api/v1/auth/refresh | `{refreshToken: string}` | `200 {token: string, refreshToken: string}` | Yes | P1 |
|
|
295
|
+
| POST /api/v1/auth/logout | `{}` (token in Authorization header) | `200 {message: "Logged out"}` | Yes | P2 |
|
|
296
|
+
|
|
297
|
+
#### Products Resource
|
|
298
|
+
|
|
299
|
+
| Endpoint | Request Contract | Response Contract | Auth | Priority |
|
|
300
|
+
|----------|-----------------|-------------------|------|----------|
|
|
301
|
+
| GET /api/v1/products | `?page=1&limit=20&category=string` | `200 {products: [{id, name, price, sku, category, imageUrl}], total: number, page: number}` | No | P1 |
|
|
302
|
+
| GET /api/v1/products/:id | `params: {id: string}` | `200 {id, name, description, price, sku, category, imageUrl, stock}` or `404 {error: "Product not found"}` | No | P1 |
|
|
303
|
+
| POST /api/v1/products | `{name: string, description: string, price: number, sku: string, category: string, stock: number}` | `201 {id: string, name, price, sku, ...}` | Yes (admin) | P1 |
|
|
304
|
+
|
|
305
|
+
#### Orders Resource
|
|
306
|
+
|
|
307
|
+
| Endpoint | Request Contract | Response Contract | Auth | Priority |
|
|
308
|
+
|----------|-----------------|-------------------|------|----------|
|
|
309
|
+
| POST /api/v1/orders | `{items: [{productId: string, qty: number}], shippingAddress: {street, city, state, zip}}` | `201 {orderId: string, status: "pending", total: number, items: [...]}` | Yes | P0 |
|
|
310
|
+
| GET /api/v1/orders/:id | `params: {id: string}` | `200 {orderId, status, items, total, createdAt, updatedAt}` or `404` | Yes | P1 |
|
|
311
|
+
| PATCH /api/v1/orders/:id/status | `{status: "confirmed" \| "shipped" \| "delivered" \| "cancelled"}` | `200 {orderId, status: newStatus, updatedAt}` or `400 {error: "Invalid transition"}` | Yes | P0 |
|
|
312
|
+
|
|
313
|
+
#### Payments Resource
|
|
314
|
+
|
|
315
|
+
| Endpoint | Request Contract | Response Contract | Auth | Priority |
|
|
316
|
+
|----------|-----------------|-------------------|------|----------|
|
|
317
|
+
| POST /api/v1/payments/charge | `{orderId: string, paymentMethodId: string}` | `200 {paymentId: string, status: "succeeded", amount: number}` or `402 {error: "Payment failed"}` | Yes | P0 |
|
|
318
|
+
| POST /api/v1/payments/webhook | `Stripe-Signature header + raw body` | `200 {received: true}` or `400 {error: "Invalid signature"}` | No (Stripe signature) | P0 |
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### Recommended Testing Pyramid
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
/ E2E \ 5% (2 tests)
|
|
326
|
+
/ API \ 20% (8 tests)
|
|
327
|
+
/ Integration\ 10% (4 tests)
|
|
328
|
+
/ Unit \ 65% (28 tests)
|
|
329
|
+
/________________\
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
| Tier | Percentage | Count | Rationale |
|
|
333
|
+
|------|-----------|-------|-----------|
|
|
334
|
+
| Unit | 65% | 28 | Heavy business logic in services layer (price calculation, order state machine, auth) -- pure functions and isolated logic are ideal unit test targets |
|
|
335
|
+
| Integration | 10% | 4 | Key integration points: order-creation-to-inventory, payment-to-order-status, auth-middleware-to-routes, webhook-to-order-update |
|
|
336
|
+
| API | 20% | 8 | 12 endpoints but grouped by resource -- test contracts for create/read/update on each resource plus error responses |
|
|
337
|
+
| E2E | 5% | 2 | Only 2 critical paths need full browser testing: complete purchase flow and user registration to first order |
|
|
338
|
+
|
|
339
|
+
**Total: 42 tests**
|
|
340
|
+
|
|
341
|
+
**Justification:** ShopFlow is a services-heavy API with React frontend. The majority of business logic lives in service modules (orderService, paymentService, priceCalculator) that are pure or near-pure functions -- ideal for unit testing. The API layer is a thin HTTP wrapper, so API contract tests verify shapes without duplicating business logic tests. Integration tests focus only on cross-service interactions (payment triggers order status change). E2E tests are limited to the 2 most critical user journeys since the React frontend is primarily data display with forms.
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Guidelines
|
|
346
|
+
|
|
347
|
+
### DO
|
|
348
|
+
|
|
349
|
+
- **DO** reference specific file paths and function names from the actual codebase in every section
|
|
350
|
+
- **DO** justify every risk level with evidence -- cite the file, function, or pattern that creates the risk
|
|
351
|
+
- **DO** rank unit test targets by business impact, not just code complexity
|
|
352
|
+
- **DO** include both happy-path and error-response contracts for API targets
|
|
353
|
+
- **DO** tailor the testing pyramid percentages to this specific application's architecture
|
|
354
|
+
- **DO** explain why integration tests target specific module interactions, not just "test integrations"
|
|
355
|
+
- **DO** list the actual entry points (route files with methods) -- downstream agents need this to plan test files
|
|
356
|
+
|
|
357
|
+
### DON'T
|
|
358
|
+
|
|
359
|
+
- **DON'T** use generic risks like "SQL injection" without pointing to a specific vulnerable query or ORM misuse
|
|
360
|
+
- **DON'T** recommend 50%+ E2E tests for API-heavy applications -- the pyramid should reflect where the logic lives
|
|
361
|
+
- **DON'T** list dependencies without justifying their risk level -- "express: HIGH" is wrong without an explanation
|
|
362
|
+
- **DON'T** include dependencies that are dev-only (eslint, prettier, typescript) in the external dependencies table
|
|
363
|
+
- **DON'T** rank test targets by alphabetical order -- rank by the composite score (impact x complexity x frequency)
|
|
364
|
+
- **DON'T** produce a testing pyramid with generic rationale ("unit tests are fast") -- rationale must reference this app
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Quality Gate
|
|
369
|
+
|
|
370
|
+
Before delivering this artifact, verify all of the following:
|
|
371
|
+
|
|
372
|
+
- [ ] Architecture Overview has all required fields populated with specific values (not placeholders)
|
|
373
|
+
- [ ] Entry Points table lists every route file with methods and auth requirements
|
|
374
|
+
- [ ] External Dependencies table includes every production dependency with risk justification
|
|
375
|
+
- [ ] Every risk in Risk Assessment cites a specific file or function as evidence
|
|
376
|
+
- [ ] Top 10 Unit Test Targets are ranked by composite score, not alphabetical
|
|
377
|
+
- [ ] Every unit test target has a specific function/method name (not just a file)
|
|
378
|
+
- [ ] API/Contract Test Targets include request and response shapes with specific field names
|
|
379
|
+
- [ ] Testing Pyramid percentages sum to 100%
|
|
380
|
+
- [ ] Testing Pyramid rationale references this specific application's architecture
|
|
381
|
+
- [ ] No risk, target, or dependency uses generic justification without evidence from the codebase
|