@educa-corp/sdd-framework 0.6.0 → 0.7.1

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 (223) hide show
  1. package/bin/gate-trace.js +25 -2
  2. package/bin/index.js +32 -5
  3. package/bin/lint-trace.js +41 -0
  4. package/bin/self-check.js +430 -3
  5. package/bin/trace-schema.json +418 -31
  6. package/core/FRAMEWORK_VERSION +1 -1
  7. package/{commands/extend-prd.md → core/commands/amend-prd.md} +206 -173
  8. package/core/commands/dev-run-test.md +48 -10
  9. package/core/commands/extend-prd.md +39 -12
  10. package/core/commands/generate-bdd.md +52 -10
  11. package/core/commands/generate-code.md +35 -2
  12. package/core/commands/generate-tech-docs.md +36 -4
  13. package/core/commands/map-testids.md +1 -1
  14. package/core/commands/qc-run-test.md +29 -3
  15. package/core/commands/refine-prd.md +13 -2
  16. package/core/commands/review-context.md +43 -8
  17. package/core/commands/sync.md +105 -1
  18. package/core/commands/validate-traces.md +289 -16
  19. package/core/rules/workflow.md +34 -0
  20. package/core/steps/context-loader.md +27 -6
  21. package/core/templates/feature.template +1 -1
  22. package/core/templates/project-context.yaml +3 -3
  23. package/core/templates/tech-design.template.md +2 -2
  24. package/docs/02-concepts/architecture.md +37 -1
  25. package/docs/02-concepts/overview.md +1 -1
  26. package/docs/02-concepts/pipeline-steps/02-specification.md +13 -7
  27. package/docs/02-concepts/pipeline-steps/07-dev-selftest.md +2 -0
  28. package/docs/02-concepts/pipeline-steps/08-qc-automation.md +1 -0
  29. package/docs/02-concepts/pipeline-steps/09-validate-traces.md +34 -3
  30. package/docs/02-concepts/pipeline-steps/10-feedback-loop.md +10 -1
  31. package/docs/02-concepts/traceability.md +187 -183
  32. package/docs/03-guides/architect.md +13 -4
  33. package/docs/03-guides/developer.md +1 -0
  34. package/docs/03-guides/product-owner.md +89 -72
  35. package/docs/03-guides/tester-qa.md +81 -81
  36. package/docs/04-reference/commands.md +148 -134
  37. package/docs/04-reference/trace-schema.md +45 -1
  38. package/docs/explain/02b-extend-prd.md +1 -1
  39. package/docs/explain/02c-amend-prd.md +152 -0
  40. package/docs/explain/06-generate-bdd.md +1 -1
  41. package/docs/explain/13-dev-run-test.md +15 -1
  42. package/docs/explain/19-qc-run-test.md +91 -87
  43. package/docs/explain/21-validate-traces.md +79 -75
  44. package/docs/explain/28-sync.md +25 -0
  45. package/docs/explain/README.md +136 -135
  46. package/package.json +1 -8
  47. package/commands/debug.md +0 -529
  48. package/commands/debug.tmpl +0 -260
  49. package/commands/define-product.md +0 -438
  50. package/commands/define-product.tmpl +0 -225
  51. package/commands/dev-gen-test.md +0 -700
  52. package/commands/dev-gen-test.tmpl +0 -490
  53. package/commands/dev-run-test.md +0 -435
  54. package/commands/dev-run-test.tmpl +0 -225
  55. package/commands/dev-smoke-test.md +0 -374
  56. package/commands/dev-smoke-test.tmpl +0 -217
  57. package/commands/extend-prd.tmpl +0 -273
  58. package/commands/fix-bug.md +0 -519
  59. package/commands/fix-bug.tmpl +0 -197
  60. package/commands/generate-architecture.md +0 -354
  61. package/commands/generate-architecture.tmpl +0 -197
  62. package/commands/generate-bdd.md +0 -923
  63. package/commands/generate-bdd.tmpl +0 -590
  64. package/commands/generate-code.md +0 -859
  65. package/commands/generate-code.tmpl +0 -649
  66. package/commands/generate-design-spec.md +0 -737
  67. package/commands/generate-design-spec.tmpl +0 -524
  68. package/commands/generate-prd.md +0 -722
  69. package/commands/generate-prd.tmpl +0 -226
  70. package/commands/generate-spec-manifest.md +0 -321
  71. package/commands/generate-spec-manifest.tmpl +0 -164
  72. package/commands/generate-tech-docs.md +0 -920
  73. package/commands/generate-tech-docs.tmpl +0 -273
  74. package/commands/learn.md +0 -399
  75. package/commands/learn.tmpl +0 -130
  76. package/commands/map-testids.md +0 -238
  77. package/commands/map-testids.tmpl +0 -81
  78. package/commands/propose-scenario.md +0 -359
  79. package/commands/propose-scenario.tmpl +0 -202
  80. package/commands/qc-analyze.md +0 -269
  81. package/commands/qc-analyze.tmpl +0 -112
  82. package/commands/qc-design-test.md +0 -226
  83. package/commands/qc-design-test.tmpl +0 -69
  84. package/commands/qc-plan.md +0 -206
  85. package/commands/qc-plan.tmpl +0 -49
  86. package/commands/qc-report.md +0 -217
  87. package/commands/qc-report.tmpl +0 -60
  88. package/commands/qc-review.md +0 -210
  89. package/commands/qc-review.tmpl +0 -53
  90. package/commands/qc-run-test.md +0 -326
  91. package/commands/qc-run-test.tmpl +0 -116
  92. package/commands/refine-prd.md +0 -653
  93. package/commands/refine-prd.tmpl +0 -281
  94. package/commands/report-bug.md +0 -305
  95. package/commands/report-bug.tmpl +0 -148
  96. package/commands/review-code.md +0 -415
  97. package/commands/review-code.tmpl +0 -146
  98. package/commands/review-context.md +0 -902
  99. package/commands/review-context.tmpl +0 -530
  100. package/commands/review-tech-docs.md +0 -561
  101. package/commands/review-tech-docs.tmpl +0 -404
  102. package/commands/setup-ai-first.md +0 -602
  103. package/commands/setup-ai-first.tmpl +0 -450
  104. package/commands/sync.md +0 -430
  105. package/commands/sync.tmpl +0 -429
  106. package/commands/update-framework.md +0 -203
  107. package/commands/update-framework.tmpl +0 -202
  108. package/commands/validate-traces.md +0 -1077
  109. package/commands/validate-traces.tmpl +0 -920
  110. package/hooks/data-guard.js +0 -232
  111. package/hooks/settings.json +0 -19
  112. package/modules/android-compose/module.yaml +0 -13
  113. package/modules/android-compose/stack-profile.yaml +0 -57
  114. package/modules/angular/architecture-snippets/component-patterns.md +0 -187
  115. package/modules/angular/module.yaml +0 -6
  116. package/modules/angular/stack-profile.yaml +0 -38
  117. package/modules/context-engineering/architecture-snippets/context-design.md +0 -119
  118. package/modules/context-engineering/module.yaml +0 -9
  119. package/modules/context-engineering/stack-profile.yaml +0 -61
  120. package/modules/dotnet/architecture-snippets/clean-arch.md +0 -160
  121. package/modules/dotnet/module.yaml +0 -6
  122. package/modules/dotnet/stack-profile.yaml +0 -50
  123. package/modules/flutter/module.yaml +0 -14
  124. package/modules/flutter/stack-profile.yaml +0 -59
  125. package/modules/golang/architecture-snippets/domain-layout.md +0 -283
  126. package/modules/golang/module.yaml +0 -6
  127. package/modules/golang/stack-profile.yaml +0 -40
  128. package/modules/ios-swiftui/module.yaml +0 -13
  129. package/modules/ios-swiftui/stack-profile.yaml +0 -55
  130. package/modules/java-spring/architecture-snippets/layered-arch.md +0 -201
  131. package/modules/java-spring/module.yaml +0 -15
  132. package/modules/java-spring/stack-profile.yaml +0 -28
  133. package/modules/nextjs/architecture-snippets/app-router-patterns.md +0 -269
  134. package/modules/nextjs/module.yaml +0 -14
  135. package/modules/nextjs/stack-profile.yaml +0 -74
  136. package/modules/nuxt/module.yaml +0 -14
  137. package/modules/nuxt/stack-profile.yaml +0 -58
  138. package/modules/phaser-game/architecture-snippets/phaser-scene-patterns.md +0 -646
  139. package/modules/phaser-game/module.yaml +0 -15
  140. package/modules/phaser-game/stack-profile.yaml +0 -90
  141. package/modules/php-laravel/architecture-snippets/service-repository.md +0 -302
  142. package/modules/php-laravel/module.yaml +0 -15
  143. package/modules/php-laravel/stack-profile.yaml +0 -56
  144. package/modules/qc-playwright/stack-profile.yaml +0 -66
  145. package/modules/react/architecture-snippets/hooks-query-patterns.md +0 -254
  146. package/modules/react/module.yaml +0 -14
  147. package/modules/react/stack-profile.yaml +0 -63
  148. package/modules/react-native/module.yaml +0 -14
  149. package/modules/react-native/stack-profile.yaml +0 -56
  150. package/modules/vue/module.yaml +0 -14
  151. package/modules/vue/stack-profile.yaml +0 -65
  152. package/rules/data-protection.md +0 -80
  153. package/rules/workflow.md +0 -99
  154. package/skills/code/SKILL.md +0 -19
  155. package/skills/code/SKILL.tmpl +0 -19
  156. package/skills/debug/SKILL.md +0 -19
  157. package/skills/debug/SKILL.tmpl +0 -19
  158. package/skills/design-spec/SKILL.md +0 -11
  159. package/skills/design-spec/SKILL.tmpl +0 -11
  160. package/skills/discovery/SKILL.md +0 -14
  161. package/skills/discovery/SKILL.tmpl +0 -14
  162. package/skills/prd/SKILL.md +0 -19
  163. package/skills/prd/SKILL.tmpl +0 -19
  164. package/skills/qc/qa-analyst/DOC_GAPS.template.md +0 -63
  165. package/skills/qc/qa-analyst/acceptance-criteria.md +0 -60
  166. package/skills/qc/qa-analyst/business-rules.md +0 -59
  167. package/skills/qc/qa-analyst/data-flow.md +0 -64
  168. package/skills/qc/qa-analyst/spec-breakdown.md +0 -61
  169. package/skills/qc/qa-designer/e2e/journey.md +0 -41
  170. package/skills/qc/qa-designer/exploratory/charter.md +0 -68
  171. package/skills/qc/qa-designer/exploratory/explore-to-functional.md +0 -43
  172. package/skills/qc/qa-designer/functional/api.md +0 -45
  173. package/skills/qc/qa-designer/functional/gui-feature.md +0 -46
  174. package/skills/qc/qa-designer/functional/gui-screen.md +0 -52
  175. package/skills/qc/qa-designer/integration/api.md +0 -42
  176. package/skills/qc/qa-designer/integration/db.md +0 -39
  177. package/skills/qc/qa-designer/integration/gui.md +0 -40
  178. package/skills/qc/qa-designer/integration/kafka.md +0 -40
  179. package/skills/qc/qa-designer/non-functional.md +0 -40
  180. package/skills/qc/qa-planner/test-plan.md +0 -120
  181. package/skills/qc/qa-reviewer/script/e2e.md +0 -87
  182. package/skills/qc/qa-reviewer/script/exploratory.md +0 -45
  183. package/skills/qc/qa-reviewer/script/functional.md +0 -101
  184. package/skills/qc/qa-reviewer/script/integration.md +0 -91
  185. package/skills/qc/qa-reviewer/script/non-functional.md +0 -126
  186. package/skills/qc/qa-reviewer/test-case/e2e.md +0 -73
  187. package/skills/qc/qa-reviewer/test-case/exploratory.md +0 -43
  188. package/skills/qc/qa-reviewer/test-case/functional.md +0 -76
  189. package/skills/qc/qa-reviewer/test-case/integration.md +0 -69
  190. package/skills/qc/qa-reviewer/test-case/non-functional.md +0 -73
  191. package/skills/qc/qa-runner/e2e.md +0 -49
  192. package/skills/qc/qa-runner/exploratory/session.md +0 -36
  193. package/skills/qc/qa-runner/functional/api.md +0 -35
  194. package/skills/qc/qa-runner/functional/gui-feature.md +0 -51
  195. package/skills/qc/qa-runner/functional/gui-screen.md +0 -55
  196. package/skills/qc/qa-runner/integration.md +0 -47
  197. package/skills/qc/qa-runner/non-functional.md +0 -49
  198. package/skills/qc/qa-runner/report/report.md +0 -37
  199. package/skills/setup-ai-first/SKILL.md +0 -19
  200. package/skills/setup-ai-first/SKILL.tmpl +0 -19
  201. package/skills/spec/SKILL.md +0 -19
  202. package/skills/spec/SKILL.tmpl +0 -19
  203. package/skills/test/SKILL.md +0 -18
  204. package/skills/test/SKILL.tmpl +0 -18
  205. package/steps/business-language.md +0 -56
  206. package/steps/capture-lesson.md +0 -112
  207. package/steps/context-loader.md +0 -406
  208. package/steps/gate.md +0 -151
  209. package/steps/report-footer.md +0 -125
  210. package/steps/review-fanout.md +0 -159
  211. package/steps/spawn-agent.md +0 -129
  212. package/steps/trace-mirror.md +0 -53
  213. package/templates/README.md +0 -70
  214. package/templates/architecture.template.md +0 -394
  215. package/templates/ci/trace-gate.yml +0 -146
  216. package/templates/design-spec.template.md +0 -217
  217. package/templates/feature.template +0 -123
  218. package/templates/hooks/pre-push +0 -61
  219. package/templates/platform-guide.template.md +0 -145
  220. package/templates/prd.template.md +0 -283
  221. package/templates/product-definition.template.md +0 -188
  222. package/templates/project-context.yaml +0 -212
  223. package/templates/tech-design.template.md +0 -490
@@ -1,490 +0,0 @@
1
- # /dev-gen-test — Sinh Dev Self-Check Tests
2
-
3
- > **Scope — dev self-check (smoke), không phải bộ test chính thức.** Các test này để
4
- > dev nhanh chóng kiểm chứng code mình sinh ra so với các BDD scenario. Đây là một
5
- > self-check của dev, **không** phải bộ test authoritative của QC/dev-team (cái đó có
6
- > flow riêng, implement ở nơi khác). Kết quả hiện lên dashboard Living Docs như một tín hiệu
7
- > **dev self-test** để QC thấy dev đã tự chạy check của mình.
8
-
9
- ## Gate
10
- {{include:steps/gate.md}}
11
-
12
- *Lưu ý: Với lệnh này, target ở Bước 1 là một UC-ID hoặc path file `.feature`. Tìm file feature tại `{paths.specs_dir}/{domain}/*/bdd/**/{UC-ID}-*.feature` (glob khớp xuyên các PRD — filename gồm hậu tố slug) và các file implementation gắn tag `@trace.implements={UC-ID}`.*
13
-
14
- ## Context
15
- {{include:steps/context-loader.md}}
16
-
17
- ---
18
-
19
- ## Service Detection
20
-
21
- Đọc `@trace.service` và `@trace.module` từ header file feature.
22
-
23
- | Điều kiện | Hành động |
24
- |---|---|
25
- | `@trace.module` có mặt | Dùng làm `active_module` |
26
- | `@trace.module` vắng | Dùng `tech_stack.module` từ project-context.yaml |
27
- | `@trace.service` có mặt | Lưu làm `active_service` |
28
- | `@trace.service` vắng | Dùng domain của `{UC-ID}` làm fallback |
29
-
30
- **Phân loại platform type:**
31
-
32
- | Platform | Modules |
33
- |---|---|
34
- | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
35
- | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
36
- | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
37
-
38
- ---
39
-
40
- ## CHECKPOINT — Test Plan
41
-
42
- Trước khi sinh, quét file feature tìm scenario và các file implementation tìm class/function. Hiện:
43
-
44
- ```
45
- Test Plan — {UC-ID} ({active_module})
46
- ──────────────────────────────────────
47
- Platform : {backend | web-frontend | mobile}
48
- Scenarios : {N} scenario từ file .feature
49
- Impl files : {danh sách file gắn tag @trace.implements={UC-ID}}
50
-
51
- Test cần sinh:
52
- {danh sách riêng theo platform — xem template bên dưới}
53
-
54
- Proceed? (Y/N)
55
- ```
56
-
57
- Chờ "Y" rõ ràng trước khi sinh.
58
-
59
- ---
60
-
61
- ## Generate
62
-
63
- ### Nếu `platform_type = backend`
64
-
65
- #### java-spring
66
-
67
- ```java
68
- // @trace.verifies={UC-ID}
69
- // @trace.service={active_service}
70
- // @trace.test_type=unit
71
- class {Resource}ServiceImplTest {
72
- @Mock {Repository} {repository};
73
- @InjectMocks {Resource}ServiceImpl service;
74
-
75
- // methodName_whenValid_shouldReturnExpected()
76
- // Given — mock repository returns data
77
- // When — call service method
78
- // Then — assert result matches expected
79
-
80
- // methodName_whenNotFound_shouldThrowException()
81
- // Given — mock returns Optional.empty()
82
- // When & Then — assertThrows({NotFoundException}.class, ...)
83
- }
84
-
85
- // @trace.verifies={UC-ID}
86
- // @trace.service={active_service}
87
- // @trace.test_type=integration
88
- @WebMvcTest({Resource}Controller.class)
89
- class {Resource}ControllerTest {
90
- @MockBean {Facade | Service} facade;
91
-
92
- // endpoint_shouldReturn200WhenValid()
93
- // endpoint_shouldReturn400WhenInvalid()
94
- // endpoint_shouldReturn404WhenNotFound()
95
- // endpoint_shouldReturn401WhenUnauthenticated()
96
- }
97
- ```
98
-
99
- Rules:
100
- - Unit test: mock ở layer Repository, test logic Service
101
- - Integration test: mock ở layer Facade/Service, chỉ test HTTP contract
102
- - Không bao giờ mock class đang được test
103
- - Theo naming: `methodName_whenCondition_shouldOutcome` (từ CLAUDE.md §6)
104
-
105
- #### golang
106
-
107
- ```go
108
- // @trace.verifies={UC-ID}
109
- // Unit: table-driven tests for service layer
110
- func Test{Resource}Service_{Method}(t *testing.T) {
111
- tests := []struct {
112
- name string
113
- input {InputType}
114
- want {OutputType}
115
- wantErr bool
116
- }{
117
- {"valid input", ..., ..., false},
118
- {"not found", ..., nil, true},
119
- }
120
- for _, tt := range tests {
121
- t.Run(tt.name, func(t *testing.T) { ... })
122
- }
123
- }
124
-
125
- // @trace.verifies={UC-ID}
126
- // Integration: HTTP handler tests using httptest
127
- func Test{Resource}Handler_{Endpoint}(t *testing.T) {
128
- // setup router, mock service, fire request
129
- // assert status code and response body
130
- }
131
- ```
132
-
133
- #### dotnet
134
-
135
- ```csharp
136
- // @trace.verifies={UC-ID}
137
- // Unit: xUnit + Moq
138
- public class {Resource}ServiceTests {
139
- private readonly Mock<I{Repository}> _repoMock = new();
140
- private readonly {Resource}Service _sut;
141
-
142
- [Fact]
143
- public async Task {Method}_WhenValid_Returns{Expected}() { }
144
-
145
- [Fact]
146
- public async Task {Method}_WhenNotFound_ThrowsNotFoundException() { }
147
- }
148
-
149
- // @trace.verifies={UC-ID}
150
- // Integration: WebApplicationFactory
151
- public class {Resource}ControllerTests : IClassFixture<WebApplicationFactory<Program>> {
152
- [Fact]
153
- public async Task {Endpoint}_Returns200_WhenValid() { }
154
-
155
- [Fact]
156
- public async Task {Endpoint}_Returns400_WhenInvalid() { }
157
- }
158
- ```
159
-
160
- #### php-laravel
161
-
162
- ```php
163
- // @trace.verifies={UC-ID}
164
- // Unit: PHPUnit
165
- class {Resource}ServiceTest extends TestCase {
166
- public function test_{method}_when_valid_should_return_expected(): void { }
167
- public function test_{method}_when_not_found_should_throw(): void { }
168
- }
169
-
170
- // @trace.verifies={UC-ID}
171
- // Feature: Laravel HTTP tests
172
- class {Resource}ControllerTest extends TestCase {
173
- use RefreshDatabase;
174
- public function test_{endpoint}_returns_200_when_valid(): void {
175
- $response = $this->getJson('/api/{resource}');
176
- $response->assertStatus(200)->assertJsonStructure([...]);
177
- }
178
- }
179
- ```
180
-
181
- #### context-engineering
182
-
183
- Kiểm tra `tech_stack.language` từ project-context.yaml để chọn đúng cú pháp test:
184
-
185
- **Nếu language = Python** (mặc định):
186
-
187
- ```python
188
- # @trace.verifies={UC-ID}
189
- # @trace.test_type=unit
190
- # Unit: test prompt orchestration functions
191
-
192
- import pytest
193
- from unittest.mock import patch, MagicMock
194
-
195
- class Test{Resource}Prompt:
196
- # test_{function}_when_valid_input_should_return_expected_output()
197
- # Given — mock LLM client returns controlled response
198
- # When — call prompt function with valid input
199
- # Then — assert output matches expected structure/content
200
-
201
- # test_{function}_when_llm_unavailable_should_raise()
202
- # Given — mock LLM client raises connection error
203
- # When & Then — assert specific exception is raised
204
-
205
- # test_{function}_trace_assertions()
206
- # Given — run function with trace capture enabled
207
- # Then — assert @trace.implements tag present in function definition
208
- # assert output conforms to expected schema
209
-
210
- def test_{function}_when_valid_should_return_expected(self, mock_llm):
211
- # Arrange
212
- mock_llm.complete.return_value = "{expected response}"
213
- # Act
214
- result = {function}(input={test_input})
215
- # Assert
216
- assert result == {expected_output}
217
- mock_llm.complete.assert_called_once_with(...)
218
-
219
- def test_{function}_when_invalid_input_should_raise(self):
220
- with pytest.raises({ExpectedError}):
221
- {function}(input=None)
222
- ```
223
-
224
- **Nếu language = TypeScript / JavaScript** (Node.js LangChain.js, v.v.):
225
-
226
- ```typescript
227
- // @trace.verifies={UC-ID}
228
- // @trace.test_type=unit
229
- import { jest } from '@jest/globals'
230
-
231
- describe('{Resource}Prompt', () => {
232
- const mockLlm = { complete: jest.fn() }
233
-
234
- it('{scenario description}', async () => {
235
- mockLlm.complete.mockResolvedValue('{expected response}')
236
- const result = await {function}({ input: '{test_input}', llm: mockLlm })
237
- expect(result).toEqual({expected_output})
238
- expect(mockLlm.complete).toHaveBeenCalledWith(expect.objectContaining({ ... }))
239
- })
240
-
241
- it('throws when input is invalid', async () => {
242
- await expect({function}({ input: null, llm: mockLlm })).rejects.toThrow('{ExpectedError}')
243
- })
244
- })
245
- ```
246
-
247
- **Nếu language = Java** (LangChain4j, v.v.): dùng JUnit 5 + Mockito, cùng pattern như unit test java-spring ở trên — mock interface `ChatLanguageModel`.
248
-
249
- Rules:
250
- - Mock LLM client ở boundary — không bao giờ gọi LLM thật trong unit test
251
- - Validate input schema và output schema riêng biệt
252
- - Mỗi scenario trong `.feature` map sang một test function
253
- - Dùng parameterized test cho nhiều biến thể input
254
-
255
- ---
256
-
257
- ### Nếu `platform_type = web-frontend`
258
-
259
- #### react / nextjs / vue / nuxt / angular
260
-
261
- ```typescript
262
- // @trace.verifies={UC-ID}
263
- // @trace.service={active_service}
264
- // @trace.test_type=component
265
-
266
- // Component tests (Vitest + Testing Library)
267
- describe('{ComponentName}', () => {
268
- it('renders correctly when data is loaded', () => {
269
- render(<{ComponentName} {...props} />)
270
- expect(screen.getByText('...')).toBeInTheDocument()
271
- })
272
-
273
- it('shows loading state while fetching', () => { })
274
-
275
- it('shows error message on API failure', () => { })
276
-
277
- it('calls handler when user interacts', async () => {
278
- await userEvent.click(screen.getByRole('button', { name: '...' }))
279
- expect(mockHandler).toHaveBeenCalledWith(...)
280
- })
281
- })
282
-
283
- // @trace.verifies={UC-ID}
284
- // @trace.test_type=e2e
285
-
286
- // E2E tests (Playwright or Cypress — use whichever is in project)
287
- test('{scenario from .feature}', async ({ page }) => {
288
- await page.goto('/{route}')
289
- await page.getByRole('button', { name: '...' }).click()
290
- await expect(page.getByText('...')).toBeVisible()
291
- })
292
- ```
293
-
294
- Rules:
295
- - Một file component test cho mỗi component liên quan tới UC
296
- - Một file E2E test cho mỗi UC, phủ happy path + các error scenario chính
297
- - Mock API call ở network layer (MSW hoặc cy.intercept), không phải ở component props
298
- - Dùng accessible query (`getByRole`, `getByLabelText`) — tránh `getByTestId` trừ khi cần
299
- - Mỗi test map đúng một scenario trong file `.feature`
300
-
301
- ---
302
-
303
- ### Nếu `platform_type = mobile`
304
-
305
- #### flutter
306
-
307
- ```dart
308
- // @trace.verifies={UC-ID}
309
- // @trace.service={active_service}
310
- // @trace.test_type=widget
311
-
312
- // Widget tests
313
- group('{FeatureName} widget tests', () {
314
- testWidgets('renders correctly when state is loaded', (tester) async {
315
- await tester.pumpWidget(MaterialApp(home: {Widget}()));
316
- await tester.pumpAndSettle();
317
- expect(find.text('...'), findsOneWidget);
318
- });
319
-
320
- testWidgets('shows loading indicator while fetching', (tester) async { });
321
- testWidgets('shows error widget on failure', (tester) async { });
322
- testWidgets('calls handler on tap', (tester) async {
323
- await tester.tap(find.byType(ElevatedButton));
324
- await tester.pumpAndSettle();
325
- verify(() => mockBloc.add({Event}())).called(1);
326
- });
327
- });
328
-
329
- // @trace.verifies={UC-ID}
330
- // @trace.test_type=integration
331
- // Integration test (flutter_test / integration_test package)
332
- void main() {
333
- IntegrationTestWidgetsFlutterBinding.ensureInitialized();
334
- testWidgets('{scenario from .feature}', (tester) async {
335
- app.main();
336
- await tester.pumpAndSettle();
337
- // Navigate, interact, assert
338
- });
339
- }
340
- ```
341
-
342
- #### react-native
343
-
344
- ```typescript
345
- // @trace.verifies={UC-ID}
346
- // @trace.service={active_service}
347
- // @trace.test_type=component
348
-
349
- // Jest + React Native Testing Library
350
- describe('{ComponentName}', () => {
351
- it('{scenario description}', () => {
352
- const { getByText, getByRole } = render(<{ComponentName} {...props} />)
353
- expect(getByText('...')).toBeTruthy()
354
- })
355
-
356
- it('calls navigation on button press', () => {
357
- const mockNavigate = jest.fn()
358
- const { getByRole } = render(<{ComponentName} navigation={{ navigate: mockNavigate }} />)
359
- fireEvent.press(getByRole('button'))
360
- expect(mockNavigate).toHaveBeenCalledWith('...')
361
- })
362
- })
363
- ```
364
-
365
- #### ios-swiftui
366
-
367
- ```swift
368
- // @trace.verifies={UC-ID}
369
- // @trace.service={active_service}
370
- // @trace.test_type=unit
371
-
372
- // XCTest — ViewModel unit tests
373
- @MainActor
374
- final class {Feature}ViewModelTests: XCTestCase {
375
- var sut: {Feature}ViewModel!
376
- var mockRepo: Mock{Repository}!
377
-
378
- override func setUp() async throws {
379
- mockRepo = Mock{Repository}()
380
- sut = {Feature}ViewModel(repository: mockRepo)
381
- }
382
-
383
- func test_{method}_whenValid_shouldUpdate{State}() async throws {
384
- // Given
385
- mockRepo.stub{Method}Result = {expected}
386
- // When
387
- await sut.{method}()
388
- // Then
389
- XCTAssertEqual(sut.{state}, {expected})
390
- }
391
-
392
- func test_{method}_whenError_shouldSetErrorState() async throws { }
393
- }
394
- ```
395
-
396
- #### android-compose
397
-
398
- ```kotlin
399
- // @trace.verifies={UC-ID}
400
- // @trace.service={active_service}
401
- // @trace.test_type=unit
402
-
403
- // Unit test — ViewModel
404
- class {Feature}ViewModelTest {
405
- @get:Rule val mainDispatcherRule = MainDispatcherRule()
406
- private val mockRepo: {Repository} = mockk()
407
- private lateinit var sut: {Feature}ViewModel
408
-
409
- @Before fun setup() { sut = {Feature}ViewModel(mockRepo) }
410
-
411
- @Test fun `{method} when valid should emit success state`() = runTest {
412
- coEvery { mockRepo.{method}(any()) } returns Result.success({data})
413
- sut.{method}({input})
414
- assertEquals(UiState.Success({data}), sut.uiState.value)
415
- }
416
- }
417
-
418
- // @trace.verifies={UC-ID}
419
- // @trace.test_type=ui
420
-
421
- // UI test — Compose
422
- @HiltAndroidTest
423
- class {Feature}ScreenTest {
424
- @get:Rule(order = 0) val hiltRule = HiltAndroidRule(this)
425
- @get:Rule(order = 1) val composeRule = createAndroidComposeRule<MainActivity>()
426
-
427
- @Test fun {scenario}_displaysExpectedUi() {
428
- composeRule.onNodeWithText("...").assertIsDisplayed()
429
- composeRule.onNodeWithContentDescription("...").performClick()
430
- composeRule.onNodeWithText("...").assertIsDisplayed()
431
- }
432
- }
433
- ```
434
-
435
- ---
436
-
437
- ## Checklist
438
-
439
- **Mọi platform:**
440
- - [ ] `@trace.verifies` trên mỗi test class / test group
441
- - [ ] `@trace.service` trên mỗi test class / test group
442
- - [ ] Mỗi scenario trong file `.feature` có ≥ 1 test tương ứng
443
- - [ ] Phủ happy path
444
- - [ ] Phủ các scenario error / edge case chính
445
-
446
- **Chỉ backend:**
447
- - [ ] Mock đúng layer (Repository trong unit test, Facade/Service trong controller test)
448
- - [ ] Không gọi DB thật trong unit test
449
- - [ ] Test naming theo `methodName_whenCondition_shouldOutcome` (CLAUDE.md §6)
450
-
451
- **Chỉ Frontend / Mobile:**
452
- - [ ] Không hardcode delay (`sleep`, `setTimeout`) trong test — dùng `waitFor` / `pumpAndSettle`
453
- - [ ] Dùng accessible query (role, label) không phải selector phụ thuộc implementation
454
- - [ ] Mock API call ở network layer, không phải ở component level
455
-
456
- ---
457
-
458
- ## Write Trace State
459
-
460
- Sau khi sinh tất cả file test, cập nhật **sổ của platform đang test** `{paths.trace_dir}/{domain}/{prd-slug}/{UC-ID}-{platform}.tsv` (`{platform}` = platform của code/`.feature` đang test) — với mỗi scenario, tìm row có sẵn theo `sc_id` và cập nhật:
461
-
462
- | Cột | Giá trị |
463
- |--------|-------|
464
- | `test_count` | số test method phủ SC này |
465
- | `test_classes` | tên test class / describe-block, ngăn cách bởi dấu phẩy |
466
- | `dev_selftest` | `not_run` (test giờ đã tồn tại nhưng chưa chạy — `/dev-run-test` set pass/fail) |
467
- | `last_updated` | hôm nay `YYYY-MM-DD` |
468
-
469
- Giữ nguyên mọi cột khác (gồm `dev_selftest_at`, do `/dev-run-test` sở hữu, và `qc_status`/`qc_run_at`, do `/qc-run-test` sở hữu).
470
-
471
- ---
472
-
473
- ## Refresh Panel Mirror
474
- {{include:steps/trace-mirror.md}}
475
-
476
- ---
477
-
478
- ## Output
479
-
480
- {{include:steps/report-footer.md}}
481
-
482
- ```
483
- /dev-gen-test Hoàn tất — {UC-ID} ({active_module})
484
- ✅ {TestClass1} ({N} tests)
485
- ✅ {TestClass2} ({N} tests)
486
- Trace: {paths.trace_dir}/{domain}/{prd-slug}/{UC-ID}-{platform}.tsv updated
487
- Next: /dev-run-test {UC-ID}
488
-
489
- 📊 Living Docs: chạy /validate-traces (hoặc /sync) để push trace này lên dashboard spec-module.
490
- ```