ai-developer-skill-os 1.8.1 → 2.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.
Files changed (55) hide show
  1. package/README.md +130 -171
  2. package/docs/CHI_TIET_SKILLS.md +89 -81
  3. package/docs/HUONG_DAN_SU_DUNG.md +120 -152
  4. package/package.json +1 -1
  5. package/skills/{qk-accessibility-audit → _archive_old_skills/qk-accessibility-audit}/SKILL.md +1 -1
  6. package/skills/{qk-agent-orchestrator → _archive_old_skills/qk-agent-orchestrator}/SKILL.md +1 -1
  7. package/skills/{qk-bug-fix → _archive_old_skills/qk-bug-fix}/SKILL.md +1 -1
  8. package/skills/{qk-component-generator → _archive_old_skills/qk-component-generator}/SKILL.md +1 -1
  9. package/skills/{qk-database-engineer → _archive_old_skills/qk-database-engineer}/SKILL.md +1 -1
  10. package/skills/{qk-design-system → _archive_old_skills/qk-design-system}/SKILL.md +1 -1
  11. package/skills/{qk-form-builder → _archive_old_skills/qk-form-builder}/SKILL.md +1 -1
  12. package/skills/{qk-frontend-architecture → _archive_old_skills/qk-frontend-architecture}/SKILL.md +1 -1
  13. package/skills/{qk-frontend-debug → _archive_old_skills/qk-frontend-debug}/SKILL.md +1 -1
  14. package/skills/{qk-frontend-performance → _archive_old_skills/qk-frontend-performance}/SKILL.md +1 -1
  15. package/skills/{qk-git-engineer → _archive_old_skills/qk-git-engineer}/SKILL.md +1 -1
  16. package/skills/_archive_old_skills/qk-help/SKILL.md +67 -0
  17. package/skills/{qk-state-management → _archive_old_skills/qk-state-management}/SKILL.md +1 -1
  18. package/skills/{qk-table-crud-generator → _archive_old_skills/qk-table-crud-generator}/SKILL.md +1 -1
  19. package/skills/qk-access-policy/SKILL.md +127 -0
  20. package/skills/qk-ai-builder/SKILL.md +33 -0
  21. package/skills/qk-api-lifecycle/SKILL.md +420 -0
  22. package/skills/qk-bug-resolution/SKILL.md +371 -0
  23. package/skills/qk-context-loader/SKILL.md +206 -0
  24. package/skills/qk-data-lifecycle/SKILL.md +135 -0
  25. package/skills/qk-design-to-code/SKILL.md +33 -0
  26. package/skills/qk-docs/SKILL.md +335 -0
  27. package/skills/qk-documentation-system/SKILL.md +33 -0
  28. package/skills/qk-engineering-standard/SKILL.md +171 -0
  29. package/skills/qk-engineering-standard/rules/backend.md +122 -0
  30. package/skills/qk-engineering-standard/rules/database.md +3 -0
  31. package/skills/qk-engineering-standard/rules/frontend.md +152 -0
  32. package/skills/qk-engineering-standard/rules/security.md +3 -0
  33. package/skills/qk-engineering-standard/rules/testing.md +3 -0
  34. package/skills/qk-feature-delivery/SKILL.md +432 -0
  35. package/skills/qk-help/SKILL.md +95 -67
  36. package/skills/qk-orchestrator/SKILL.md +272 -0
  37. package/skills/qk-policy-engine/SKILL.md +33 -0
  38. package/skills/qk-production-release/SKILL.md +127 -0
  39. package/skills/qk-project-bootstrap/SKILL.md +33 -0
  40. package/skills/qk-project-health/SKILL.md +650 -0
  41. package/skills/qk-project-memory/SKILL.md +33 -0
  42. package/skills/qk-system-evolution/SKILL.md +315 -0
  43. package/skills/qk-ui-audit/SKILL.md +152 -0
  44. package/skills/qk-ui-system-builder/SKILL.md +444 -0
  45. package/skills/qk-validation-gate/SKILL.md +33 -0
  46. /package/skills/{qk-api-integration → _archive_old_skills/qk-api-integration}/SKILL.md +0 -0
  47. /package/skills/{qk-auth-security → _archive_old_skills/qk-auth-security}/SKILL.md +0 -0
  48. /package/skills/{qk-backend-architecture → _archive_old_skills/qk-backend-architecture}/SKILL.md +0 -0
  49. /package/skills/{qk-context-manager → _archive_old_skills/qk-context-manager}/SKILL.md +0 -0
  50. /package/skills/{qk-deployment → _archive_old_skills/qk-deployment}/SKILL.md +0 -0
  51. /package/skills/{qk-frontend-testing → _archive_old_skills/qk-frontend-testing}/SKILL.md +0 -0
  52. /package/skills/{qk-migration → _archive_old_skills/qk-migration}/SKILL.md +0 -0
  53. /package/skills/{qk-project-audit → _archive_old_skills/qk-project-audit}/SKILL.md +0 -0
  54. /package/skills/{qk-refactor → _archive_old_skills/qk-refactor}/SKILL.md +0 -0
  55. /package/skills/{qk-ui-builder → _archive_old_skills/qk-ui-builder}/SKILL.md +0 -0
@@ -0,0 +1,152 @@
1
+ # Frontend Rules
2
+
3
+ - Define rules here.
4
+
5
+ ---
6
+
7
+ ## 🔄 [Merged from qk-frontend-architecture]
8
+
9
+ # Frontend Architecture
10
+
11
+ > **Language rule:**
12
+ > Use English for: code, identifiers, file names, architecture terms, technical decisions.
13
+ > Use the user's language for: explanations, questions, summaries, and feedback.
14
+ > The user may write in any language — detect and match it automatically.
15
+
16
+ ---
17
+
18
+ ## Trigger
19
+
20
+ Activate this skill when:
21
+ - About to create new files or components
22
+ - User asks "where should I put this file?" or "how should I organize this?"
23
+ - Moving or refactoring code across different modules
24
+ - Inheriting an unfamiliar frontend project
25
+
26
+ ---
27
+
28
+ ## Scope
29
+
30
+ - ✅ Discover the existing frontend folder structure
31
+ - ✅ Define where new components, hooks, services, and types should be placed
32
+ - ✅ Enforce separation of concerns (e.g., UI vs. Business Logic vs. Data)
33
+ - ✅ Identify architectural patterns in use (e.g., Feature-based, Layer-based)
34
+ - ✅ Validate file placement before execution by other skills
35
+
36
+ ---
37
+
38
+ ## Non-goals
39
+
40
+ - ❌ Do NOT rewrite the entire project architecture unless explicitly asked
41
+ - ❌ Do NOT generate code (delegate to `component-generator` or `ui-builder`)
42
+ - ❌ Do NOT enforce personal preferences over established project conventions
43
+
44
+ ---
45
+
46
+ ## Severity Levels
47
+
48
+ | Level | Meaning |
49
+ |-------|---------|
50
+ | P0 | Architectural violation that breaks the build or creates circular dependencies |
51
+ | P1 | File placed in completely wrong layer (e.g., API logic in UI component) |
52
+ | P2 | Inconsistent folder or file naming |
53
+ | P3 | Minor deviation from convention |
54
+
55
+ ---
56
+
57
+ ## Workflow
58
+
59
+ ### Phase 1 — Structure Discovery
60
+
61
+ *(Relies on `context-manager` if already loaded)*
62
+
63
+ Analyze the root source directory (e.g., `src/`, `app/`):
64
+ 1. **Layer-based:** `components/`, `hooks/`, `services/`, `utils/`, `types/`
65
+ 2. **Feature-based:** `features/auth/`, `features/products/`
66
+ 3. **Framework-specific:** `app/` (Next.js App Router), `pages/` (Next.js Pages Router, Nuxt)
67
+ 4. **Domain-driven:** `domains/user/`, `domains/payment/`
68
+ 5. **FSD (Feature Sliced Design):** `app/`, `processes/`, `pages/`, `widgets/`, `features/`, `entities/`, `shared/`
69
+
70
+ ---
71
+
72
+ ### Phase 2 — Rule Extraction
73
+
74
+ Based on discovery, define the project's rules for:
75
+ - **Components:** Are they flat? Grouped by feature? Atomic design?
76
+ - **Hooks:** Shared in `src/hooks/` or collocated with components?
77
+ - **State:** Global store vs. feature stores?
78
+ - **API/Services:** Where are HTTP calls made?
79
+ - **Types:** Centralized `types/` or collocated?
80
+ - **Naming Conventions:** PascalCase, camelCase, kebab-case, `index.ts` usage?
81
+
82
+ ---
83
+
84
+ ### Phase 3 — File Placement Decision
85
+
86
+ When a new feature/component is requested, map it to the structure:
87
+
88
+ **Input:** "Create a User Profile card that fetches user data."
89
+ **Decision:**
90
+ - UI Component: `src/features/user/components/UserProfileCard.tsx`
91
+ - API Hook: `src/features/user/api/useUser.ts`
92
+ - Types: `src/features/user/types/index.ts`
93
+
94
+ ---
95
+
96
+ ### Phase 4 — Enforcement & Validation
97
+
98
+ Before passing control to a generation skill (like `ui-builder`), ensure the plan adheres to the rules.
99
+
100
+ - [ ] Does it mix concerns? (e.g., putting an API call directly in a shared UI button)
101
+ - [ ] Does it violate import boundaries? (e.g., a shared component importing from a specific feature)
102
+ - [ ] Is the naming consistent?
103
+
104
+ ---
105
+
106
+ ## Decision Tree
107
+
108
+ ```
109
+ Is the project using a Feature-based structure?
110
+ ├── Yes → Place feature-specific code in `features/<feature-name>/`
111
+ └── No → Use Layer-based structure (`components/`, `hooks/`, etc.)
112
+
113
+ Is the code shared across multiple domains/features?
114
+ ├── Yes → Place in `shared/` or global `components/` / `hooks/`
115
+ └── No → Collocate with the specific domain/feature
116
+
117
+ Are there existing examples of this type of file?
118
+ ├── Yes → Copy their placement and naming pattern
119
+ └── No → Propose a standard location and ask user to confirm
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Output Format
125
+
126
+ ```
127
+ 🏗️ Frontend Architecture Plan
128
+ ─────────────────────────────────────────────────
129
+ Structure Type: [Feature-based / Layer-based / FSD / etc.]
130
+ Naming: [PascalCase for components, camelCase for functions]
131
+
132
+ File Placement:
133
+ 📄 [path/to/new/file1.tsx] — [Why it goes here]
134
+ 📄 [path/to/new/file2.ts] — [Why it goes here]
135
+
136
+ ⚠️ Constraints enforced:
137
+ • [Constraint 1, e.g., "API calls must be in hooks, not components"]
138
+ • [Constraint 2, e.g., "Shared UI components cannot import from features/"]
139
+
140
+ 🔗 Next Steps:
141
+ Delegating to `[skill-name]` to generate the files.
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Validation Checklist
147
+
148
+ - [ ] Structure type identified correctly
149
+ - [ ] File placement follows existing conventions
150
+ - [ ] Naming matches project standards
151
+ - [ ] Separation of concerns maintained
152
+ - [ ] Plan ready to be executed by generation skills
@@ -0,0 +1,3 @@
1
+ # Security Rules
2
+
3
+ - Define rules here.
@@ -0,0 +1,3 @@
1
+ # Testing Rules
2
+
3
+ - Define rules here.
@@ -0,0 +1,432 @@
1
+ ---
2
+ name: qk-feature-delivery
3
+ purpose: Phân tích, Code và Test tính năng mới hoàn chỉnh (E2E).
4
+ mode_supported: [quick, standard, enterprise]
5
+ input: [Feature requirement]
6
+ output: [Completed feature code, tests]
7
+ workflow: [1. Requirement -> 2. Design -> 3. DB -> 4. API -> 5. UI -> 6. Test]
8
+ allowed_tools: [write_to_file, run_command]
9
+ handoff_to: [qk-validation-gate]
10
+ ---
11
+
12
+ # 🛠️ qk-feature-delivery - Quy Trình Vận Hành Chuẩn (SOP)
13
+
14
+ > **Mô tả:** Phân tích, Code và Test tính năng mới hoàn chỉnh (E2E).
15
+
16
+ ## 🎯 1. Mục Tiêu (Goal)
17
+ - Hoàn thành thành công tác vụ được giao liên quan đến nhiệm vụ của skill.
18
+ - Đảm bảo chất lượng mã nguồn và tính nhất quán của hệ thống.
19
+
20
+ ## 🔄 2. Chuỗi Hành Động (Chain of Thought / SOP)
21
+ *(Bắt buộc AI phải suy nghĩ và làm theo đúng thứ tự)*
22
+ 1. **Phân tích (Analyze):** Thu thập ngữ cảnh và hiểu rõ yêu cầu đầu vào.
23
+ 2. **Lên kế hoạch (Plan):** Xác định các bước cần thay đổi/tạo mới dựa trên bộ luật (rules).
24
+ 3. **Thực thi (Execute):** Tiến hành sửa đổi mã nguồn hoặc tạo tài liệu.
25
+ 4. **Xác thực (Verify):** Đảm bảo đầu ra đáp ứng đúng yêu cầu và không vi phạm quy định.
26
+
27
+ ## 🛡️ 3. Ràng Buộc & Quy Tắc (Constraints)
28
+ - CẤM bỏ qua việc kiểm tra `qk-engineering-standard` trước khi viết code.
29
+ - Mọi quyết định kỹ thuật phải dựa trên nội dung tại phần Deep Knowledge (nếu có).
30
+
31
+ ## 🤝 4. Giao Thức Bàn Giao (Handoff Protocol)
32
+ - Đích đến: `qk-validation-gate`
33
+ - Nội dung bàn giao: Chuyển toàn bộ ngữ cảnh và kết quả đã thực thi cho bước tiếp theo.
34
+
35
+ ## 📚 5. Kiến Thức Chuyên Sâu (Deep Knowledge)
36
+
37
+ *(Nền tảng kiến thức và quy tắc chi tiết kế thừa từ kỹ sư)*
38
+
39
+ ---
40
+
41
+
42
+
43
+ # Form Builder
44
+
45
+ > **Language rule:**
46
+ > Use English for: code, identifiers, file names, architecture terms, technical decisions.
47
+ > Use the user's language for: explanations, questions, summaries, and feedback.
48
+ > The user may write in any language — detect and match it automatically.
49
+
50
+ ---
51
+
52
+ ## Trigger
53
+
54
+ Activate this skill when:
55
+ - User says "create a login form", "add a settings page", "build a contact form"
56
+ - User provides a data model and needs a UI to create/edit it
57
+ - A form needs complex validation logic added
58
+ - Refactoring a messy form into a structured library pattern (e.g., React Hook Form)
59
+
60
+ ---
61
+
62
+ ## Scope
63
+
64
+ - ✅ Define the form data schema and validation rules
65
+ - ✅ Manage form state efficiently (preventing unnecessary re-renders)
66
+ - ✅ Map form fields to the project's design system components
67
+ - ✅ Handle submission state (loading, success, error)
68
+ - ✅ Handle validation errors and display them accessibly
69
+ - ✅ Integrate with `api-integration` for submission
70
+
71
+ ---
72
+
73
+ ## Non-goals
74
+
75
+ - ❌ Do NOT reinvent form state management if a library is present
76
+ - ❌ Do NOT use raw HTML inputs if design system components exist
77
+ - ❌ Do NOT skip validation (client-side validation is required)
78
+
79
+ ---
80
+
81
+ ## Workflow
82
+
83
+ ### Phase 1 — Schema Design
84
+
85
+ Define the exact shape of the data the form collects.
86
+ Determine validation rules for each field (required, min length, email format, etc.).
87
+
88
+ If the project uses Zod, Yup, or Joi, define the schema first.
89
+ *Example:*
90
+ ```typescript
91
+ const userFormSchema = z.object({
92
+ email: z.string().email("Invalid email address"),
93
+ password: z.string().min(8, "Password must be at least 8 characters"),
94
+ });
95
+ ```
96
+
97
+ ---
98
+
99
+ ### Phase 2 — State Management Selection
100
+
101
+ Check project dependencies for form libraries:
102
+ 1. `react-hook-form` (Preferred for React)
103
+ 2. `formik`
104
+ 3. Custom Vue/Svelte bindings
105
+ 4. Standard controlled components (`useState`) if no library exists and form is simple.
106
+
107
+ ---
108
+
109
+ ### Phase 3 — Component Assembly
110
+
111
+ 1. Set up the form wrapper and submission handler.
112
+ 2. For each field in the schema, render the appropriate UI component (from `design-system`).
113
+ 3. Connect the UI component to the form state (register / Controller).
114
+ 4. Render error messages below fields if validation fails.
115
+
116
+ ---
117
+
118
+ ### Phase 4 — Submission & Integration
119
+
120
+ - Add `isLoading` state to the submit button.
121
+ - Disable submit button during submission.
122
+ - On success: Show success message or redirect, and optionally reset form.
123
+ - On error: Display backend error messages (toast or form-level alert).
124
+
125
+ ---
126
+
127
+ ## Decision Tree
128
+
129
+ ```
130
+ Does the project use a validation library (Zod, Yup)?
131
+ ├── Yes → Use it to define schema and pass to form resolver
132
+ └── No → Implement standard HTML5 validation or simple manual validation logic
133
+
134
+ Is it a complex multi-step form (wizard)?
135
+ ├── Yes → Break into sub-components, use global or lifted state for form data
136
+ └── No → Handle state locally within the single form component
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Output Format
142
+
143
+ ```
144
+ 📝 Form Built
145
+ ─────────────────────────────────────────────────
146
+ Name: [FormName]
147
+ Schema: [Zod / Yup / Manual]
148
+ Library: [React Hook Form / Formik / Native]
149
+
150
+ Fields Implemented:
151
+ ✅ email (string, required, email)
152
+ ✅ password (string, required, min: 8)
153
+
154
+ Integration:
155
+ - Validation: Client-side wired up
156
+ - Submission: Wired to `[submitFunction]`
157
+ - Loading UI: Handled on submit button
158
+
159
+ 🔗 Next Steps:
160
+ Make sure the API endpoint is ready to accept this payload.
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Validation Checklist
166
+
167
+ - [ ] Form uses existing design system components (Inputs, Buttons)
168
+ - [ ] Client-side validation is implemented
169
+ - [ ] Error messages are displayed properly
170
+ - [ ] Loading state disables the submit button
171
+ - [ ] Accessibility: Inputs have associated labels and error ARIA attributes
172
+
173
+ ---
174
+
175
+
176
+
177
+ # Table & CRUD Generator
178
+
179
+ > **Language rule:**
180
+ > Use English for: code, identifiers, file names, architecture terms, technical decisions.
181
+ > Use the user's language for: explanations, questions, summaries, and feedback.
182
+ > The user may write in any language — detect and match it automatically.
183
+
184
+ ---
185
+
186
+ ## Trigger
187
+
188
+ Activate this skill when:
189
+ - User says "create an admin table", "build a user list", "add data grid"
190
+ - User needs a view to manage a list of entities with CRUD capabilities
191
+ - A feature requires complex data presentation (sorting, filtering, pagination)
192
+
193
+ ---
194
+
195
+ ## Scope
196
+
197
+ - ✅ Generate a data table using design system components or libraries (e.g., TanStack Table)
198
+ - ✅ Implement client-side or server-side pagination, sorting, and filtering
199
+ - ✅ Add UI actions for Create, Edit, and Delete (modals or routing)
200
+ - ✅ Integrate with `api-integration` hooks for data fetching and mutations
201
+ - ✅ Handle loading, error, and empty states gracefully
202
+
203
+ ---
204
+
205
+ ## Non-goals
206
+
207
+ - ❌ Do NOT build the backend API for the CRUD operations (assume they exist or delegate)
208
+ - ❌ Do NOT use raw `<table>` tags if a powerful data-grid library is already installed
209
+
210
+ ---
211
+
212
+ ## Workflow
213
+
214
+ ### Phase 1 — Data Model & Requirements
215
+
216
+ 1. Understand the entity (e.g., `User`, `Product`).
217
+ 2. Identify columns to display.
218
+ 3. Determine operations needed (e.g., just Read/Delete, or full CRUD).
219
+ 4. Decide on Pagination strategy: Server-side (URL params) or Client-side (in-memory).
220
+
221
+ ---
222
+
223
+ ### Phase 2 — Table Component Setup
224
+
225
+ 1. Check for table libraries (e.g., `@tanstack/react-table`, MUI DataGrid, AntD Table).
226
+ 2. Define column definitions (headers, accessor keys, cell formatters).
227
+ 3. Set up the table UI wrapper.
228
+
229
+ ---
230
+
231
+ ### Phase 3 — Data Integration
232
+
233
+ Connect to the state/API layer (e.g., React Query).
234
+ - `useQuery` for fetching the list. Pass pagination/sorting state.
235
+ - Handle `isLoading` → show skeleton or spinner.
236
+ - Handle empty data → show empty state component.
237
+
238
+ ---
239
+
240
+ ### Phase 4 — CRUD Actions
241
+
242
+ Implement actions (usually in an "Actions" column or toolbar):
243
+ - **Create:** Button opening a Modal (delegate to `form-builder`) or routing to `/new`.
244
+ - **Edit:** Button opening an Edit Modal or routing to `/edit/:id`.
245
+ - **Delete:** Button opening a confirmation dialog, calling delete mutation on confirm.
246
+
247
+ ---
248
+
249
+ ## Decision Tree
250
+
251
+ ```
252
+ Is the dataset large (requires backend pagination)?
253
+ ├── Yes → Implement Server-side pagination (sync state with URL search params)
254
+ └── No → Implement Client-side pagination (fetch all once, slice in UI)
255
+
256
+ Does the project use TanStack Table (React Table)?
257
+ ├── Yes → Use `useReactTable` to manage table state and column definitions
258
+ └── No → Use the project's specific UI library table component
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Output Format
264
+
265
+ ```
266
+ 📊 Table & CRUD Generated
267
+ ─────────────────────────────────────────────────
268
+ Entity: [Entity Name]
269
+ Features: [Pagination (Server), Sorting, CRUD actions]
270
+
271
+ Components Created:
272
+ ✅ [Entity]Table.tsx
273
+ ✅ [Entity]Columns.tsx
274
+ ✅ DeleteConfirmModal.tsx
275
+
276
+ Integration:
277
+ - Fetching: Linked to `use[Entity]List` hook
278
+ - Mutations: Linked to Create/Update/Delete hooks
279
+
280
+ 🔗 Next Steps:
281
+ If Create/Edit forms are needed, delegate to `form-builder`.
282
+ ```
283
+
284
+ ---
285
+
286
+ ## Validation Checklist
287
+
288
+ - [ ] Columns are defined correctly
289
+ - [ ] Loading and empty states are handled
290
+ - [ ] Pagination/sorting state is managed properly
291
+ - [ ] CRUD actions trigger the correct mutations or navigations
292
+ - [ ] Delete actions have a confirmation step
293
+
294
+ ---
295
+
296
+
297
+
298
+ # Frontend Testing
299
+
300
+ > **Language rule:**
301
+ > Use English for: code, identifiers, file names, architecture terms, technical decisions.
302
+ > Use the user's language for: explanations, questions, summaries, and feedback.
303
+ > The user may write in any language — detect and match it automatically.
304
+
305
+ ---
306
+
307
+ ## Trigger
308
+
309
+ Activate this skill when:
310
+ - User asks to "write tests for this", "add unit tests", or "test this component"
311
+ - Fixing a critical bug where a regression test is required
312
+ - Preparing for a major release and increasing test coverage
313
+ - Project audit flags missing tests for core business logic
314
+
315
+ ---
316
+
317
+ ## Scope
318
+
319
+ - ✅ **Unit Tests:** Test pure functions, utilities, and custom hooks.
320
+ - ✅ **Component Tests:** Test UI components using React Testing Library (RTL). Focus on user interactions and accessibility roles.
321
+ - ✅ **Mocking:** Mock API calls (MSW, Jest mocks), modules, and timers.
322
+ - ✅ **E2E Tests:** Write Cypress or Playwright tests for critical user flows.
323
+ - ✅ Follow the project's existing testing framework (Jest vs Vitest).
324
+
325
+ ---
326
+
327
+ ## Non-goals
328
+
329
+ - ❌ Do NOT test implementation details (e.g., checking if a specific state variable changed). Test what the user sees/does.
330
+ - ❌ Do NOT write brittle tests (e.g., querying by CSS class names). Use ARIA roles or `data-testid`.
331
+ - ❌ Do NOT introduce a new testing framework if one already exists.
332
+
333
+ ---
334
+
335
+ ## Workflow
336
+
337
+ ### Phase 1 — Environment Check
338
+
339
+ Identify the testing stack:
340
+ - Runner: Jest or Vitest?
341
+ - DOM: React Testing Library, Vue Test Utils?
342
+ - E2E: Cypress, Playwright?
343
+ - Mocking: MSW (Mock Service Worker), `jest.mock`, `vi.mock`?
344
+
345
+ ---
346
+
347
+ ### Phase 2 — Strategy & Coverage
348
+
349
+ Determine what needs testing:
350
+ 1. **Critical Path:** Can the user complete the primary action?
351
+ 2. **Edge Cases:** What happens on API failure? Empty state? Invalid input?
352
+ 3. **Accessibility:** Can elements be found by role?
353
+
354
+ ---
355
+
356
+ ### Phase 3 — Writing the Test (RTL Example)
357
+
358
+ 1. **Setup:** Render the component, wrap with necessary providers (Theme, Store, QueryClient).
359
+ 2. **Query:** Find elements using `screen.getByRole`, `screen.getByLabelText`, or `screen.getByText`.
360
+ 3. **Act:** Simulate user events using `userEvent` (preferred over `fireEvent`).
361
+ 4. **Assert:** Expect elements to be in the document, disabled, or display specific text.
362
+
363
+ *Example:*
364
+ ```typescript
365
+ it('submits the form when fields are valid', async () => {
366
+ const mockSubmit = vi.fn();
367
+ render(<LoginForm onSubmit={mockSubmit} />);
368
+
369
+ await userEvent.type(screen.getByLabelText(/email/i), 'test@example.com');
370
+ await userEvent.type(screen.getByLabelText(/password/i), 'password123');
371
+ await userEvent.click(screen.getByRole('button', { name: /login/i }));
372
+
373
+ expect(mockSubmit).toHaveBeenCalledWith({
374
+ email: 'test@example.com',
375
+ password: 'password123'
376
+ });
377
+ });
378
+ ```
379
+
380
+ ---
381
+
382
+ ### Phase 4 — Mocking
383
+
384
+ If the component makes API calls:
385
+ - Prefer MSW (Mock Service Worker) for network-level mocking.
386
+ - Fallback: Mock the API service module or custom hook.
387
+
388
+ ---
389
+
390
+ ## Decision Tree
391
+
392
+ ```
393
+ Are we testing a pure function or utility?
394
+ ├── Yes → Write a standard Unit Test (Jest/Vitest).
395
+ └── No → Are we testing a UI component?
396
+ ├── Yes → Use React Testing Library (focus on user behavior).
397
+ └── No → Are we testing a full page flow?
398
+ ├── Yes → Write an E2E test (Cypress/Playwright) or integration test.
399
+ ```
400
+
401
+ ---
402
+
403
+ ## Output Format
404
+
405
+ ```
406
+ 🧪 Test Suite Generated
407
+ ─────────────────────────────────────────────────
408
+ Target: [ComponentName or Utility]
409
+ Type: [Unit / Component / E2E]
410
+ Framework: [Vitest + RTL]
411
+
412
+ Tests Added:
413
+ ✅ renders correctly in default state
414
+ ✅ displays error message on API failure
415
+ ✅ successfully submits user data
416
+
417
+ Mocking Used:
418
+ - MSW handlers for `/api/users`
419
+ - vi.fn() for onSubmit callback
420
+
421
+ 🔗 Next Steps:
422
+ Run `npm run test` to execute the suite.
423
+ ```
424
+
425
+ ---
426
+
427
+ ## Validation Checklist
428
+
429
+ - [ ] Queries use accessible methods (`getByRole`, `getByLabelText`)
430
+ - [ ] Events simulated with `userEvent` (if applicable)
431
+ - [ ] External dependencies/APIs are properly mocked
432
+ - [ ] Tests verify observable behavior, not internal state