@ngocsangairvds/vsaf 4.1.25 → 4.1.26

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.
@@ -0,0 +1,352 @@
1
+ ---
2
+ # model: sonnet
3
+ # findingsOutput: '{output_folder}/_validation_temp/findings-consistency.yaml'
4
+ # contextFile: '{output_folder}/_validation_temp/context.yaml'
5
+ # grepPatterns: '../data/grep-patterns-srs.yaml'
6
+ ---
7
+
8
+ # Step V-04: Consistency — Kiểm tra tính nhất quán
9
+
10
+ ---
11
+
12
+ ## 1. Intra-file consistency (trong cùng 1 file)
13
+
14
+ Với mỗi SRS file, kiểm tra:
15
+
16
+ ### 1.1 ID patterns
17
+
18
+ **Load context:** Read `{contextFile}` and `{grepPatterns}` → `id_patterns` group.
19
+
20
+ Run Grep using `id_patterns` patterns against `srs_path`:
21
+ - `uc_id_valid` pattern → find all UC IDs, check format UC-[A-Z]{2,4}-\d{2}
22
+ - `screen_id_valid` pattern → find all SCR IDs, check format SCR-[A-Z]{2,4}-\d{2}
23
+ - `br_id_valid` pattern → find all BR IDs
24
+ - `id_lowercase_violation` pattern → any lowercase ID violations?
25
+
26
+ Cross-check BR IDs: every BR referenced in flow tables must appear in Section 5 summary (C-4 check):
27
+ 1. Grep `BR-[A-Z]{2,4}-\d{2,3}-\d{2,3}|BR-[A-Z]{2,4}-\d{3}` in flow sections → extract all referenced BR IDs
28
+ 2. Grep same pattern in Section 5 → extract all defined BR IDs
29
+ 3. Referenced but not defined → MEDIUM finding
30
+ 4. Defined but not referenced anywhere → LOW finding
31
+
32
+ Item IDs: `uc_id_pattern`, `screen_id_pattern`, `error_code_consistency`, `br_code_consistency`
33
+
34
+ ### 1.2 Naming
35
+
36
+ > **Template note (2026-04):** ERD section đã bị xóa — không còn ERD để đối chiếu entity naming. Check entity naming INTRA-FILE: đối chiếu cột "Bảng/Thực thể liên quan" trong các flow tables với nhau và với Section 5 BRs.
37
+
38
+ - Actor names nhất quán giữa UC table và flow table (cột Đối tượng)? Đối chiếu với Section 1 row "Đối tượng sử dụng" (actor_naming)
39
+ - Entity names nhất quán GIỮA CÁC UC flow tables (cột "Bảng/Thực thể liên quan")? (entity_naming) — không cần ERD nữa
40
+ - State names nhất quán giữa State Diagram Section 8 và bảng mô tả? (state_naming)
41
+ - Screen control names dùng đúng prefix convention: `txt`, `btn`, `lbl`, `chk`, `lnk`, `ddl`, `dt`, `img`? (screen_control_naming)
42
+ - Steps trong Activity Diagram có đánh số `:(1)`, `:(2)` nhất quán không? (activity_diagram_step_numbering)
43
+
44
+ ### 1.3 References
45
+
46
+ > **Template note (2026-04):** Error code format mới: `REC-NNN`, `PAY-NNN` hoặc HTTP status (401, 403...) — không còn dùng `ERR-XX-NNN`. Check format nhất quán TRONG file.
47
+
48
+ - Error codes trong Section 3 khớp với bước trong flow (cột "Bước" trong bảng mã lỗi trỏ đến step trong activity diagram)? (error_code_consistency)
49
+ - Error code format nhất quán trong cùng file? (VD: không trộn lẫn `REC-NNN` với `ERR-XX-NNN`) (error_code_consistency)
50
+ - BR codes trong Section 5 khớp với nội dung UC? (br_code_consistency)
51
+ - FR IDs trong Mini-RTM Section 9 khớp? (rtm_fr_match)
52
+
53
+ ---
54
+
55
+ ## 2. Cross-file consistency (so sánh giữa các files)
56
+
57
+ **Cross-file consistency checks LUÔN LUÔN thực hiện** — KG cung cấp references tự động, không cần batch/full scope.
58
+
59
+ ### 2.1 Entity naming across files
60
+ - Cùng entity (VD: Policy) có cùng field names không? (data_model_fields)
61
+ - Ví dụ: `policyId` vs `policy_id`, `userId` vs `customer_id`
62
+ - Naming convention nhất quán? camelCase vs snake_case? (entity_naming)
63
+
64
+ ### 2.2 Entity naming across files (updated)
65
+
66
+ > **Template note (2026-04):** ERD và DB schema không còn trong SRS → không thể check field-level data model. Thay bằng entity name consistency ACROSS FILES: cùng entity phải dùng cùng tên table/collection.
67
+
68
+ - Cùng entity (VD: Policy, CustomerProfile) có cùng tên trong flow tables (cột "Bảng/Thực thể liên quan") giữa các SRS files không? (entity_naming)
69
+ - VD: FR4 dùng "CustomerProfile", FR2 dùng "customer_profile" → naming inconsistency
70
+ - ~~canonical_model_match~~ — REMOVED (no ERD/data model in SRS)
71
+ - ~~pk_fk_type_consistent~~ — REMOVED (no field-level schema in SRS)
72
+ - ~~currency_type_convention~~ — REMOVED (no field-level schema in SRS)
73
+
74
+ ### 2.3 API patterns
75
+
76
+ > **Template note (2026-04):** API endpoint specs không còn trong SRS. Check API path nhất quán chỉ khi API paths xuất hiện trong flow tables (cột Ghi chú hoặc ES: External System calls).
77
+
78
+ - API paths trong flow tables (nếu có) dùng prefix nhất quán `/api/v1/`? (api_naming_pattern)
79
+ - ~~api_contract_param_match~~ — REMOVED (API contracts in TSD, not SRS)
80
+
81
+ ### 2.4 State machine alignment (cross_file_state_machine_match)
82
+
83
+ **Structured extraction approach (C-5) — more reliable than pure semantic comparison.**
84
+
85
+ #### Step 1: Extract state lists via Grep (Haiku-tier work)
86
+
87
+ From `{grepPatterns}` → `state_machine` pattern group:
88
+ 1. Run `plantuml_state` pattern against SRS file → extract all state names from state diagrams
89
+ 2. Run `state_transition` pattern → extract transition triggers
90
+ 3. Build `srs_states` list from extracted names
91
+
92
+ From System SRS (use line range from `context.yaml` `kg.arch_key_sections` or targeted read of state section):
93
+ 4. Extract `system_states` list the same way
94
+
95
+ #### Step 2: Compare YAML lists (Sonnet judgment)
96
+
97
+ Compare `srs_states` vs `system_states`:
98
+ - States in SRS but not in System SRS → document in finding (may be legitimate decomposition)
99
+ - States in System SRS but not in feature SRS → check if applicable to this FR
100
+ - Transition triggers inconsistent → HIGH finding
101
+ - State count discrepancy > 2× → CRITICAL
102
+
103
+ This replaces full semantic comparison with structured list comparison.
104
+
105
+ Item IDs: `state_naming`, `cross_file_state_machine_match`
106
+
107
+ ### 2.5 Service ownership alignment (service_ownership_consistent)
108
+ - Với mỗi entity/resource quan trọng (voucher, promotion, claim, policy):
109
+ - Tìm tất cả files đề cập entity này và xem service nào được giao ownership
110
+ - **CRITICAL** nếu: File A giao voucher validate/reserve cho pricing-service, nhưng File B+C giao cho promotion-service
111
+ - Đây là lỗi boundary thực sự, không phải naming — có thể dẫn đến implement sai service
112
+ - Cách check: search tên entity + action (validate, reserve, apply) → xem subject service
113
+
114
+ ### 2.8 State name uc-vs-diagram alignment (state_name_uc_vs_diagram)
115
+ - So sánh tên states được dùng trong UC flow steps với tên states trong State Diagram (section 9):
116
+ - Mỗi status/state xuất hiện trong flow steps phải có node tương ứng trong diagram
117
+ - **CRITICAL**: flow steps dùng `PENDING_ACTIVATION` nhưng diagram chỉ có `PENDING_ISSUANCE` → dev không biết map vào đâu
118
+ - Xây danh sách states từ flow steps → đối chiếu với diagram nodes
119
+ - Chú ý: đây khác với state_naming check (mục 1.2) vốn chỉ check naming pattern
120
+
121
+ ### 2.9 Referenced FR existence check (referenced_fr_exists)
122
+ - Nếu SRS tham chiếu FR khác (VD: "cross-insurer fallback (FR29)", "see FR-15 for details"):
123
+ - FR được tham chiếu phải tồn tại trong danh sách FR đã định nghĩa trong project
124
+ - **HIGH**: tham chiếu FR không tồn tại → feature đó là out-of-scope thực chất, cần ghi rõ
125
+ - Cách check: extract tất cả FR references → đối chiếu với FR inventory (FR1–FR17 hoặc bất kỳ range nào project đang dùng)
126
+
127
+ ### 2.10 Technology stack alignment (tech_stack_consistent)
128
+ - Database technology nhất quán cho cùng entity/module? (tech_stack_consistent)
129
+ - VD: MongoDB vs MariaDB vs PostgreSQL cho cùng entity → CRITICAL
130
+ - Message broker: Kafka vs RabbitMQ → phải nhất quán
131
+ - Cache: Redis vs Memcached → phải nhất quán
132
+ - Thuật ngữ thống nhất, không dùng lẫn lộn? (terminology_consistent)
133
+ - VD: "Khách hàng" vs "Customer" vs "User" cho cùng concept
134
+
135
+ ### 2.11 Architecture alignment (MANDATORY via KG)
136
+
137
+ **Token-efficient:** Read Architecture entity → find service catalog section → targeted read.
138
+
139
+ 1. From KG: read architecture entity `key_sections` to find "Service Catalog" or "Technology Stack" sections
140
+ 2. From upstream context: check service/component definitions in `.vsaf/docs/features/{feature-name}/03-adr.md` or `graphify-out/graph.json`
141
+ 3. Targeted read of architecture sections
142
+ 4. Compare:
143
+ - SRS tech stack (DB, framework, broker) matches architecture decisions?
144
+ - SRS API patterns match architecture API conventions?
145
+ - SRS service boundaries align with architecture service mapping?
146
+
147
+ Item ID: `architecture_alignment`
148
+ Scoring: 1.0 (aligned) / 0.75 (minor deviation) / 0.5 (significant mismatch) / 0.0 (contradicts)
149
+
150
+ ### 2.12 Architecture Service Boundary Check (C-2 — new check)
151
+
152
+ **Zero extra token cost — pure Grep + KG lookup.**
153
+
154
+ 1. Load `arch_services` from `context.yaml` → list of valid service names (e.g., `ntbh-payment-service`, `ntbh-policy-service`)
155
+ 2. Run Grep `service_references` patterns from `{grepPatterns}` against `srs_path`:
156
+ - `service_name` pattern → find all service references in SRS flows/diagrams
157
+ - `infra_component` pattern → find Kafka, Redis, Keycloak, Kong references
158
+ 3. For each service name found in SRS:
159
+ - Is it in `arch_services` list? → OK
160
+ - Not in list → **CRITICAL: "SRS references non-existent service {name} — not in Architecture service catalog"**
161
+ 4. For each infra component found in SRS:
162
+ - Is it in the approved tech stack (from Architecture entity)? → OK
163
+ - Not approved → **HIGH: "Unapproved infrastructure component {name}"**
164
+
165
+ Item ID: `architecture_alignment` (extends existing check in 2.11)
166
+
167
+ ### 2.13 Error Code Completeness Cross-check (C-3 — new check)
168
+
169
+ **Zero extra token cost — pure Grep.**
170
+
171
+ 1. Grep Section 3 (error codes section, use `section_error_codes` line range from `section_index`):
172
+ - Extract all error code IDs defined in section 4
173
+ 2. For each error code ID, Grep full `srs_path` for that ID:
174
+ - Appears in at least one flow step → OK
175
+ - Never referenced in flows → MEDIUM: "Error code {ID} defined in Section 4 but never referenced in flow steps"
176
+ 3. Reverse check: Grep flow tables for any error code pattern not in Section 4:
177
+ - Referenced in flows but not defined → HIGH: "Error code {code} referenced in flows but not defined in Section 4"
178
+
179
+ Item ID: `error_code_consistency` (enhances existing check)
180
+
181
+ ### 2.14 Upstream structural consistency (upstream_structural_consistency)
182
+
183
+ **Complements all other cross-file checks in Section 2.**
184
+ Those checks validate SRS ↔ System SRS and SRS ↔ Architecture for tech stack/service boundaries.
185
+ This check validates SRS ↔ BRD/PRD for structural artifact consistency (state machines, entity schemas, events, API paths).
186
+
187
+ **Zero extra reads:** Reuses BRD/PRD/Architecture sections already loaded by V-02 context or V-04's architecture checks. If context.yaml contains `kg.brd_key_sections` and `kg.prd_key_sections`, use those line ranges. Otherwise, this check is skipped (KG not available).
188
+
189
+ #### Artifact Extraction
190
+
191
+ > **Template note (2026-04):** S3 (Kafka event coverage), S4 (Entity field schema), S5 (API endpoint paths) đã bị xóa — những artifact này không còn trong SRS. Chỉ giữ S1, S2, S6 (state machine + AC state names).
192
+
193
+ From upstream docs already in context, extract and compare against SRS:
194
+
195
+ | # | Check | Upstream Source | SRS Source | Diff Type |
196
+ |---|-------|----------------|------------|-----------|
197
+ | S1 | State machine states | BRD PlantUML `state` declarations | SRS Section 8 PlantUML states | Set diff: additions, removals |
198
+ | S2 | State transitions + order | BRD PlantUML `-->` arrows | SRS PlantUML `-->` arrows | Order comparison |
199
+ | ~~S3~~ | ~~Kafka event coverage~~ | ~~REMOVED~~ | ~~REMOVED~~ | ~~REMOVED~~ |
200
+ | ~~S4~~ | ~~Entity field schema~~ | ~~REMOVED~~ | ~~REMOVED~~ | ~~REMOVED~~ |
201
+ | ~~S5~~ | ~~API endpoint paths~~ | ~~REMOVED~~ | ~~REMOVED~~ | ~~REMOVED~~ |
202
+ | S6 | PRD AC state names | PRD AC text (`state_chain` pattern) | SRS canonical state names | Name alignment |
203
+
204
+ #### Diff Logic (same for all artifact types)
205
+
206
+ For each artifact type where both upstream and SRS have data:
207
+
208
+ 1. Extract `upstream_list` and `srs_list`
209
+ 2. Report:
210
+ - **In upstream, NOT in SRS** → severity depends on type:
211
+ - State/field dropped → CRITICAL
212
+ - Event not covered → HIGH
213
+ - API path missing → HIGH
214
+ - **In SRS, NOT in upstream** → typically OK (SRS refines), but flag if:
215
+ - Entirely new entity/state with no upstream trace → HIGH (possible invention)
216
+ - New API endpoint not in Architecture → MEDIUM
217
+ - **Same item, different name** → HIGH (naming inconsistency)
218
+ - **Same items, different order** → HIGH for transitions (logic change); LOW for fields (cosmetic)
219
+ - **Same field, different type** → HIGH (e.g., DECIMAL vs BIGINT)
220
+
221
+ 3. For each flagged item, include in finding:
222
+ - `upstream_source`: which doc and line
223
+ - `srs_source`: which section and line
224
+ - `diff_type`: addition | removal | rename | reorder | type_mismatch
225
+ - `severity`: per rules above
226
+ - `suggestion`: specific fix (e.g., "Align SRS state name to BRD: rename COMPLETED → PAID, or document the split in SRS changelog")
227
+
228
+ #### Interaction with V-02 6e
229
+
230
+ V-02 `upstream_artifact_alignment` checks business-level alignment (are the right things specified?).
231
+ V-04 `upstream_structural_consistency` checks structural-level consistency (are they specified the same way?).
232
+
233
+ Example: BRD says entity has field `claim_number` (VARCHAR 50). SRS has `claim_reference` (VARCHAR 50).
234
+ - V-02 asks: "Is this the same business concept or a new field?" → Business alignment question
235
+ - V-04 asks: "These are different field names for similar purpose — is naming consistent?" → Structural consistency question
236
+
237
+ Both checks may flag the same artifact from different angles. This is intentional — they serve different reviewers (BA vs Dev/Architect).
238
+
239
+ **Scoring:**
240
+ - All structural artifacts consistent across upstream and SRS → 1.0
241
+ - Minor: 1-2 naming variants with clear semantic equivalence → 0.75
242
+ - Significant: field type mismatches, missing events, or >3 naming divergences → 0.5
243
+ - Major: dropped upstream states/fields, reversed transitions → 0.25
244
+ - Fundamental: SRS structure contradicts upstream (different entity, different lifecycle) → 0.0
245
+
246
+ Item ID: `upstream_structural_consistency`
247
+
248
+ ---
249
+
250
+ ## 3. Ghi findings
251
+
252
+ Format:
253
+ ```markdown
254
+ | # | Severity | Dimension | File | Item ID | Score | Evidence | Suggestion | Business Impact | Source |
255
+ ```
256
+
257
+ Each finding MUST include `business_impact` with three sub-fields:
258
+ - **WHO**: Primary stakeholder affected (Dev, QA, PO, Ops, Customer)
259
+ - **WHAT**: Impact type (Blocked, Rework risk, UX degradation, Compliance risk)
260
+ - **WHEN**: When impact materializes (Before Sprint, During Sprint, After Release)
261
+ ```
262
+
263
+ Ghi rõ file(s) liên quan khi cross-file: `file1 AND file2`
264
+
265
+ ---
266
+
267
+ ## 4. Tính Consistency dimension score
268
+
269
+ ```
270
+ consistency_score = round(sum(item_scores.values()) / 19 × 100, 1)
271
+ ```
272
+
273
+ Canonical item IDs (N = 19, fixed):
274
+ `uc_id_pattern`, `screen_id_pattern`, `error_code_consistency`, `br_code_consistency`, `actor_naming`, `entity_naming`, `state_naming`, `screen_control_naming`, `activity_diagram_step_numbering`, `rtm_fr_match`, `api_naming_pattern`, `cross_file_state_machine_match`, `service_ownership_consistent`, `state_name_uc_vs_diagram`, `referenced_fr_exists`, `tech_stack_consistent`, `terminology_consistent`, `architecture_alignment`, `upstream_structural_consistency`
275
+
276
+ ⚠️ MANDATORY: N = 19 (fixed). N/A items → score = 1.0 (do not skip from denominator). No post-hoc calibration. dimension_score in YAML = formula result only.
277
+
278
+ ---
279
+
280
+ ## 5. Append findings vào report
281
+
282
+ Append CRITICAL/HIGH → section "4. Critical & High Findings". Append MEDIUM/LOW → section "5. Medium & Low Findings".
283
+
284
+ Update frontmatter: thêm `step-v-04-consistency` vào `stepsCompleted`.
285
+
286
+ ---
287
+
288
+ ## [NEW] Write Structured Findings
289
+
290
+ Write file `{findingsOutput}`:
291
+ ```yaml
292
+ # findings-consistency.yaml — generated by step-v-04
293
+ # model: sonnet | weight: 1.0
294
+
295
+ dimension: consistency
296
+ weight: 1.0
297
+ dimension_score: 0
298
+ status: OK
299
+ findings: []
300
+ summary:
301
+ total: 0
302
+ critical: 0
303
+ high: 0
304
+ medium: 0
305
+ low: 0
306
+ item_scores:
307
+ uc_id_pattern: 0.0
308
+ screen_id_pattern: 0.0
309
+ error_code_consistency: 0.0
310
+ br_code_consistency: 0.0
311
+ actor_naming: 0.0
312
+ entity_naming: 0.0
313
+ state_naming: 0.0
314
+ screen_control_naming: 0.0
315
+ activity_diagram_step_numbering: 0.0
316
+ rtm_fr_match: 0.0
317
+ api_naming_pattern: 0.0
318
+ cross_file_state_machine_match: 0.0
319
+ service_ownership_consistent: 0.0
320
+ state_name_uc_vs_diagram: 0.0
321
+ referenced_fr_exists: 0.0
322
+ tech_stack_consistent: 0.0
323
+ terminology_consistent: 0.0
324
+ architecture_alignment: 0.0
325
+ upstream_structural_consistency: 0.0
326
+ new_checks:
327
+ service_boundary_violations: [] # list of unauthorized service references
328
+ orphan_error_codes: [] # error codes defined but never referenced
329
+ undefined_error_codes: [] # error codes referenced but not defined
330
+ orphan_br_ids: [] # BR IDs defined but not referenced in flows
331
+ upstream_diffs: [] # list of {artifact_type, diff_type, upstream_source, upstream_value, srs_value, severity}
332
+ ```
333
+
334
+ ---
335
+
336
+ ## 6. Menu
337
+
338
+ ```
339
+ Consistency Score: {X}% ({status})
340
+ - CRITICAL: {count}
341
+ - HIGH: {count}
342
+ - MEDIUM: {count}
343
+ - LOW: {count}
344
+
345
+ [C] Continue — Sang Quality (Step V-05)
346
+ [D] Detail — Xem chi tiết findings
347
+ [X] Cancel
348
+ ```
349
+
350
+ **Chờ user chọn.**
351
+
352
+ Khi user chọn **C**: đọc fully và follow `./step-v-05-quality.md`
@@ -0,0 +1,347 @@
1
+ # Step V-05: Quality — Kiểm tra chất lượng nội dung
2
+
3
+ ---
4
+ # model: haiku
5
+ # findingsOutput: '{output_folder}/_validation_temp/findings-quality.yaml'
6
+ # contextFile: '{output_folder}/_validation_temp/context.yaml'
7
+ # grepPatterns: '../data/grep-patterns-srs.yaml'
8
+ ---
9
+
10
+ ## 0. Load Context and Patterns
11
+
12
+ Read `{contextFile}` → get `srs_path`, `srs_section_index`, `uc_cache`.
13
+ Read `{grepPatterns}` → load `vague_vietnamese`, `vague_english`, `ac_format`, `srs_structure`, `diagram_syntax` pattern groups.
14
+
15
+ **ALL checks in this step use Grep tool. Do NOT use Read on the SRS file.**
16
+ **Exception: Section 3 (cross-file duplicate detection) may use targeted Read.**
17
+
18
+ ---
19
+
20
+ ## 1. Ambiguous Language Check (Grep-only)
21
+
22
+ Run Grep patterns from `vague_vietnamese` and `vague_english` groups against `srs_path`:
23
+ - Each pattern: output_mode="content", -n=true to get line numbers
24
+ - For each match, check context: is this in a BR/NFR/AC statement (flag) or a capability description (OK)?
25
+ - Count flagged violations by category
26
+
27
+ **Scoring (same as before):**
28
+ - > 10 flagged → Score 0.0
29
+ - 5–10 → Score 0.5
30
+ - 1–4 → Score 0.75
31
+ - 0 → Score 1.0
32
+
33
+ Item ID: `no_ambiguous_language`
34
+
35
+ ---
36
+
37
+ ## 2. Acceptance Criteria Format Check (Grep-only)
38
+
39
+ Run patterns from `ac_format` group against `srs_path`:
40
+ - `gherkin_gwt` pattern → count GWT ACs
41
+ - `vietnamese_conditional_ac` pattern → count Vietnamese-style ACs
42
+ - `ac_id_pattern` → count AC IDs (confirms ACs are formally defined)
43
+
44
+ Also check from `uc_cache` in context.yaml: count UCs → expected ≥ 1 AC per UC.
45
+
46
+ **Scoring:** Same as before (GWT+measurable=1.0, AC no GWT=0.5, text only=0.25, none=0.0)
47
+
48
+ Item ID: `acceptance_criteria_format`
49
+
50
+ ---
51
+
52
+ ## 3. Duplicate requirements check
53
+
54
+ Tìm requirements trùng lặp:
55
+
56
+ ### 3.1 Intra-file
57
+ - Cùng requirement xuất hiện ở nhiều UC trong 1 file?
58
+
59
+ ### 3.2 Cross-file (nếu batch/full)
60
+ - Cùng requirement xuất hiện ở nhiều SRS files?
61
+ - VD: Consent management overlap giữa FR-1 và FR-15
62
+
63
+ **Nếu phát hiện overlap:**
64
+ - Đánh giá mức độ: identical (0.0) vs complementary (0.75)
65
+ - Gợi ý file nào nên own requirement
66
+
67
+ Item ID: `no_duplicate_requirements`
68
+
69
+ ---
70
+
71
+ ## 4. Scope clarity check
72
+
73
+ Kiểm tra mỗi SRS file có:
74
+
75
+ - Section "Phạm vi chức năng" hoặc In-scope?
76
+ - Section "Ngoài phạm vi" hoặc Out-of-scope?
77
+ - Ranh giới rõ ràng với FRs liên quan?
78
+
79
+ **Scoring:**
80
+ - Có cả In + Out scope → 1.0
81
+ - Có In scope nhưng thiếu Out scope → 0.5
82
+ - Có "Flow liên quan" nhưng không explicit scope → 0.5
83
+ - Không có gì → 0.0
84
+
85
+ Item ID: `clear_scope`
86
+
87
+ ---
88
+
89
+ ## 5. Opaque rule check
90
+
91
+ Kiểm tra các Business Rule và policy statements trong SRS:
92
+
93
+ - Rule phải tự giải thích được mà không cần PO interpret. Dấu hiệu rule mơ hồ:
94
+ - Tham chiếu undefined term: "sensitive details not exposed until acceptance" — "acceptance" là event gì?
95
+ - Điều kiện không rõ ràng: "khi phù hợp", "tùy context", "nếu cần thiết"
96
+ - Rule thiếu subject: "không exposed" — ai không exposed? service nào? endpoint nào?
97
+ - Mỗi rule mơ hồ → ghi finding với suggestion rewrite rõ ràng
98
+ - Phân biệt với `no_ambiguous_language` (mục 1): mục này focus vào rule semantics, không chỉ từ vựng
99
+
100
+ **Scoring:**
101
+ - Tất cả rule self-explanatory → 1.0
102
+ - 1-2 rule cần clarify nhỏ → 0.75
103
+ - 3+ rule mơ hồ, hoặc 1 rule core không hiểu được → 0.5
104
+ - Rule core hoàn toàn không interpret được → 0.0 (HIGH)
105
+
106
+ Item ID: `rules_self_explanatory`
107
+
108
+ ---
109
+
110
+ ## 5b. Cross-Role Readability Check
111
+
112
+ Kiểm tra requirement có thể hiểu giống nhau bởi BA, Dev, và QA không:
113
+
114
+ **Dấu hiệu viết sai:**
115
+ - Dùng thuật ngữ nghiệp vụ chưa được định nghĩa trong Glossary (section 1.2)
116
+ - Câu có thể hiểu theo 2 cách tuỳ người đọc — VD: "hệ thống kiểm tra hợp lệ" → BA hiểu là validate UI, Dev hiểu là DB check, QA hiểu là API check
117
+ - Subject không rõ — "sẽ gửi thông báo" → ai gửi? đến ai?
118
+ - Điều kiện dạng "nếu cần" / "nếu phù hợp" → Dev và QA không thể ra testcase
119
+
120
+ **Cách kiểm tra:**
121
+ - Với mỗi UC step có hành động quan trọng (validate, send, update, check): subject + verb + object có đủ không?
122
+ - Với mỗi business rule: trigger condition → action → result có viết đủ 3 phần không?
123
+ - Có term nào trong flow tables không có trong Glossary? → flag để bổ sung
124
+
125
+ **Scoring:**
126
+ - Tất cả requirements rõ subject/verb/result, dùng term đã glossarized → 1.0
127
+ - 1-3 steps có subject mơ hồ hoặc term chưa glossarize → 0.75
128
+ - Nhiều steps thiếu subject/result rõ ràng → 0.5
129
+ - Core flow steps không thể viết testcase vì quá mơ hồ → 0.25 (HIGH)
130
+
131
+ Item ID: `cross_role_readability`
132
+
133
+ ---
134
+
135
+ ## 5c. Testability per Requirement
136
+
137
+ Kiểm tra mỗi UC/AC có thể viết testcase độc lập không:
138
+
139
+ - Mỗi AC có exactly 1 expected outcome cụ thể không?
140
+ - BAD: "hệ thống xử lý phù hợp" / "hệ thống phản hồi kịp thời"
141
+ - GOOD: "hệ thống trả HTTP 200 với body `{status: 'CREATED'}` trong < 2s"
142
+ - Có AC nào kết quả phụ thuộc vào external state không rõ ràng không?
143
+ - VD: "nếu insurer accept" — điều kiện này có thể simulate trong test không?
144
+ - Có UC nào không có AC hoặc chỉ có AC chung chung → không thể viết test → CRITICAL
145
+
146
+ **Scoring:**
147
+ - Tất cả AC có expected outcome rõ, testable → 1.0
148
+ - Phần lớn rõ, 1-2 AC cần clarify expected result → 0.75
149
+ - Nhiều AC thiếu expected result cụ thể → 0.5
150
+ - AC chỉ describe behavior mà không có measurable outcome → 0.25 (HIGH)
151
+ - Không có AC → 0.0 (CRITICAL)
152
+
153
+ Item ID: `testability_per_requirement`
154
+
155
+ ---
156
+
157
+ ## 5d. Section Numbering Consistency (Grep-only)
158
+
159
+ Kiểm tra heading số thứ tự nhất quán với cấu trúc template mới:
160
+
161
+ **Template expected heading structure:**
162
+ ```
163
+ ## 1. Mô tả chung
164
+ ### 1.1 / 1.2 / 1.3
165
+ ## 2. Đặc tả Use Cases
166
+ ### 2.1 / 2.2 ...
167
+ ## 3. Danh sách mã lỗi
168
+ ## 4. Chức năng ảnh hưởng
169
+ ## 5. Business Rules
170
+ ## 6. Yêu cầu phi chức năng
171
+ ### 6.1 / 6.2 ... (not 7.1 / 7.2)
172
+ ## 7. Ràng buộc, Giả định & Phụ thuộc
173
+ ### 7.1 / 7.2 / 7.3 / 7.4 (not 8.1 / 8.2)
174
+ ## 8. State Diagrams
175
+ ## 9. Ma trận truy xuất
176
+ ```
177
+
178
+ **Grep checks:**
179
+ 1. Grep `^### [78]\.\d` in srs_path → if found inside a `## 6.` section (NFR section) → MEDIUM: section 6 has wrong sub-headings
180
+ 2. Grep `^### [89]\.\d` in srs_path → if found inside a `## 7.` section → MEDIUM: section 7 has wrong sub-headings
181
+
182
+ **Scoring:**
183
+ - Không có heading mismatch → 1.0
184
+ - 1 section có sub-heading dùng số section cha sai → 0.75 (MEDIUM finding)
185
+ - Nhiều sections bị mismatch → 0.5
186
+
187
+ Item ID: `section_numbering_consistent`
188
+
189
+ ---
190
+
191
+ ## 6. Flow Step Quality (Grep-only)
192
+
193
+ - Grep `^\d+\.\s` in `srs_path` → check step numbering exists and is sequential
194
+ - Grep `→ chuyển bước|→ kết thúc|→ hiển thị lỗi|→ bước` → verify steps have outcomes
195
+ - Grep `Nhánh [A-Z]|Branch [A-Z]` → verify branching is explicit
196
+
197
+ Item IDs: `flow_step_numbering`, `flow_clarity`, `branching`
198
+
199
+ ---
200
+
201
+ ## 6. Diagram Syntax Check (Grep-only)
202
+
203
+ Run patterns from `diagram_syntax` group:
204
+ - Count `@startuml` occurrences vs `@enduml` occurrences → must be equal
205
+ - Grep `unfilled_placeholder_in_diagram` → any {{...}} still in diagrams? → CRITICAL
206
+
207
+ Item ID: `diagram_syntax_valid`
208
+
209
+ ---
210
+
211
+ ## 6c. Atomicity Check (LLM analysis)
212
+
213
+ Kiểm tra mỗi requirement/UC có chứa đúng 1 ý duy nhất — có thể dev/estimate/test độc lập:
214
+
215
+ ### 6c.1 Single Responsibility per UC
216
+
217
+ - Mỗi UC title và scope có chỉ mô tả 1 hành vi duy nhất không?
218
+ - **Dấu hiệu vi phạm:**
219
+ - Title dạng "Mua bảo hiểm và thanh toán và nhận HĐ" → compound UC, nên tách
220
+ - UC mô tả cả happy path lẫn admin flow trong cùng 1 UC → scope quá rộng
221
+ - UC vừa handle user action vừa xử lý background job cùng lúc
222
+
223
+ **Item ID:** `requirement_single_responsibility`
224
+
225
+ **Scoring:**
226
+ - Tất cả UC có scope đơn → 1.0
227
+ - 1-2 UC bị compound nhưng minor (dễ tách) → 0.75
228
+ - Nhiều UC compound → 0.5
229
+ - Core UC gộp nhiều flow không thể tách scope → 0.25 (HIGH)
230
+
231
+ ---
232
+
233
+ ### 6c.2 No Compound Requirements
234
+
235
+ - Mỗi Business Rule, AC, hoặc NFR statement có chỉ phát biểu 1 điều kiện → 1 kết quả không?
236
+ - **Dấu hiệu vi phạm:**
237
+ - "Hệ thống validate form **và** gửi email **và** cập nhật DB" trong 1 câu requirement
238
+ - BR dùng "đồng thời", "cùng lúc đó", "và cũng" → 2 hành vi trong 1 rule
239
+ - AC có nhiều `Then` cho 1 `When` → nên tách thành 2 AC
240
+
241
+ **Item ID:** `no_compound_requirement`
242
+
243
+ **Scoring:**
244
+ - Tất cả BR/AC là single-statement → 1.0
245
+ - Vài BR có 2 điều kiện nhưng logic liên quan chặt → 0.75
246
+ - Nhiều BR/AC compound → 0.5
247
+ - Core BR không thể phân tách rõ → 0.25
248
+
249
+ ---
250
+
251
+ ### 6c.3 Independently Estimable
252
+
253
+ - Mỗi UC có thể được Dev estimate và implement mà không cần UC khác chưa done không?
254
+ - **Dấu hiệu vi phạm:**
255
+ - UC A hardcode phụ thuộc UC B nhưng UC B chưa trong sprint
256
+ - UC A chỉ có ý nghĩa khi UC C cũng deploy cùng lúc → không thể ship độc lập
257
+ - UC giả định API từ service khác đã sẵn sàng nhưng không nêu dependency rõ
258
+
259
+ **Lưu ý:** Có dependency ≠ vi phạm. Vi phạm là dependency KHÔNG ĐƯỢC GHI RÕ hoặc dependency chưa confirmed.
260
+
261
+ **Item ID:** `independently_estimable`
262
+
263
+ **Scoring:**
264
+ - Tất cả UC hoặc có dependency ghi rõ (và confirmed) hoặc independent → 1.0
265
+ - 1-2 UC có implied dependency chưa document → 0.75
266
+ - Nhiều UC phụ thuộc chéo nhau không rõ → 0.5
267
+ - Sprint không thể plan được vì UC entangled → 0.25 (HIGH)
268
+
269
+ ---
270
+
271
+ ## 7. Tính Quality dimension score
272
+
273
+ ```
274
+ quality_score = round(sum(item_scores.values()) / 15 × 100, 1)
275
+ ```
276
+
277
+ Canonical item IDs (N = 15, fixed):
278
+ `no_ambiguous_language`, `acceptance_criteria_format`, `no_duplicate_requirements`, `clear_scope`, `rules_self_explanatory`, `cross_role_readability`, `testability_per_requirement`, `section_numbering_consistent`, `flow_step_numbering`, `flow_clarity`, `branching`, `diagram_syntax_valid`, `requirement_single_responsibility`, `no_compound_requirement`, `independently_estimable`
279
+
280
+ ⚠️ MANDATORY: N = 15 (fixed). N/A items → score = 1.0 (do not skip from denominator). No post-hoc calibration. dimension_score in YAML = formula result only.
281
+
282
+ ---
283
+
284
+ ## 8. Append findings vào report
285
+
286
+ Append CRITICAL/HIGH → section "4. Critical & High Findings". Append MEDIUM/LOW → section "5. Medium & Low Findings".
287
+
288
+ Update frontmatter: thêm `step-v-05-quality` vào `stepsCompleted`.
289
+
290
+ ---
291
+
292
+ ## [NEW] Write Structured Findings
293
+
294
+ Write file `{findingsOutput}`:
295
+ ```yaml
296
+ # findings-quality.yaml — generated by step-v-05
297
+ # model: haiku | weight: 1.0
298
+
299
+ dimension: quality
300
+ weight: 1.0
301
+ dimension_score: 0 # calculated: sum(scores)/count × 100
302
+ status: OK # OK | WARN | FAIL
303
+ findings:
304
+ [] # list of {item_id, severity, score, evidence, suggestion, source}
305
+ summary:
306
+ total: 0
307
+ critical: 0
308
+ high: 0
309
+ medium: 0
310
+ low: 0
311
+ item_scores:
312
+ no_ambiguous_language: 0.0
313
+ acceptance_criteria_format: 0.0
314
+ no_duplicate_requirements: 0.0
315
+ clear_scope: 0.0
316
+ rules_self_explanatory: 0.0
317
+ cross_role_readability: 0.0
318
+ testability_per_requirement: 0.0
319
+ section_numbering_consistent: 0.0
320
+ flow_step_numbering: 0.0
321
+ flow_clarity: 0.0
322
+ branching: 0.0
323
+ diagram_syntax_valid: 0.0
324
+ requirement_single_responsibility: 0.0
325
+ no_compound_requirement: 0.0
326
+ independently_estimable: 0.0
327
+ ```
328
+
329
+ ---
330
+
331
+ ## 9. Menu
332
+
333
+ ```
334
+ Quality Score: {X}% ({status})
335
+ - CRITICAL: {count}
336
+ - HIGH: {count}
337
+ - MEDIUM: {count}
338
+ - LOW: {count}
339
+
340
+ [C] Continue — Sang System & NFR (Step V-06)
341
+ [D] Detail — Xem chi tiết findings
342
+ [X] Cancel
343
+ ```
344
+
345
+ **Chờ user chọn.**
346
+
347
+ Khi user chọn **C**: đọc fully và follow `./step-v-06-system-nfr.md`