@boyingliu01/xp-gate 0.7.0 → 0.8.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 (197) hide show
  1. package/bin/xp-gate.js +4 -9
  2. package/lib/__tests__/audit-log.test.ts +107 -0
  3. package/lib/__tests__/detect-deps.test.js +212 -42
  4. package/lib/__tests__/doctor.test.js +1 -0
  5. package/lib/__tests__/gate-audit.test.ts +59 -0
  6. package/lib/__tests__/init.test.js +47 -1
  7. package/lib/__tests__/install-skill.test.js +1 -45
  8. package/lib/__tests__/ui-detector.test.ts +186 -26
  9. package/lib/__tests__/ui-review.test.ts +119 -0
  10. package/lib/__tests__/uninstall.test.js +1 -0
  11. package/lib/detect-deps.js +180 -37
  12. package/lib/doctor.js +7 -9
  13. package/lib/gate-audit.ts +26 -42
  14. package/lib/init.js +42 -13
  15. package/lib/install-skill.js +20 -48
  16. package/lib/rollback.js +1 -16
  17. package/lib/shared-paths.js +30 -0
  18. package/lib/shared-utils.js +25 -0
  19. package/lib/ui-detector.ts +20 -14
  20. package/lib/ui-review.ts +58 -53
  21. package/lib/uninstall.js +8 -9
  22. package/package.json +1 -1
  23. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  24. package/plugins/claude-code/skills/admin-template-guidelines/SKILL.md +904 -0
  25. package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +45 -0
  26. package/plugins/claude-code/skills/delphi-review/AGENTS.md +66 -0
  27. package/plugins/claude-code/skills/delphi-review/INSTALL.md +152 -0
  28. package/plugins/claude-code/skills/delphi-review/SKILL.md +454 -0
  29. package/plugins/claude-code/skills/delphi-review/opencode.json.delphi.example +56 -0
  30. package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +486 -0
  31. package/plugins/claude-code/skills/improve-codebase-architecture/SKILL.md +156 -0
  32. package/plugins/claude-code/skills/ralph-loop/SKILL.md +501 -0
  33. package/plugins/claude-code/skills/ralph-loop/references/components/memory.md +55 -0
  34. package/plugins/claude-code/skills/ralph-loop/references/components/middleware.md +54 -0
  35. package/plugins/claude-code/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  36. package/plugins/claude-code/skills/ralph-loop/references/components/system-prompt.md +24 -0
  37. package/plugins/claude-code/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  38. package/plugins/claude-code/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  39. package/plugins/claude-code/skills/ralph-loop/templates/progress-log.md +36 -0
  40. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +68 -0
  41. package/plugins/claude-code/skills/sprint-flow/SKILL.md +1248 -0
  42. package/plugins/claude-code/skills/sprint-flow/references/components/memory.md +87 -0
  43. package/plugins/claude-code/skills/sprint-flow/references/components/middleware.md +72 -0
  44. package/plugins/claude-code/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  45. package/plugins/claude-code/skills/sprint-flow/references/components/system-prompt.md +27 -0
  46. package/plugins/claude-code/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  47. package/plugins/claude-code/skills/sprint-flow/references/force-levels.md +203 -0
  48. package/plugins/claude-code/skills/sprint-flow/references/phase-0-think.md +115 -0
  49. package/plugins/claude-code/skills/sprint-flow/references/phase-1-plan.md +178 -0
  50. package/plugins/claude-code/skills/sprint-flow/references/phase-2-build.md +198 -0
  51. package/plugins/claude-code/skills/sprint-flow/references/phase-3-review.md +213 -0
  52. package/plugins/claude-code/skills/sprint-flow/references/phase-4-uat.md +125 -0
  53. package/plugins/claude-code/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  54. package/plugins/claude-code/skills/sprint-flow/references/phase-6-ship.md +193 -0
  55. package/plugins/claude-code/skills/sprint-flow/references/phase-7-land.md +140 -0
  56. package/plugins/claude-code/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  57. package/plugins/claude-code/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
  58. package/plugins/claude-code/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  59. package/plugins/claude-code/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
  60. package/plugins/claude-code/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  61. package/plugins/claude-code/skills/sprint-flow/templates/pain-document-template.md +115 -0
  62. package/plugins/claude-code/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  63. package/plugins/claude-code/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  64. package/plugins/claude-code/skills/test-driven-development/SKILL.md +71 -0
  65. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +56 -0
  66. package/plugins/claude-code/skills/test-specification-alignment/SKILL.md +702 -0
  67. package/plugins/claude-code/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  68. package/plugins/claude-code/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  69. package/plugins/claude-code/skills/test-specification-alignment/references/specification-format.md +348 -0
  70. package/plugins/claude-code/skills/to-issues/SKILL.md +277 -0
  71. package/plugins/opencode/README.md +38 -0
  72. package/plugins/opencode/index.ts +85 -0
  73. package/plugins/opencode/package.json +18 -0
  74. package/plugins/opencode/skills/admin-template-guidelines/SKILL.md +904 -0
  75. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +45 -0
  76. package/plugins/opencode/skills/delphi-review/AGENTS.md +66 -0
  77. package/plugins/opencode/skills/delphi-review/INSTALL.md +152 -0
  78. package/plugins/opencode/skills/delphi-review/SKILL.md +454 -0
  79. package/plugins/opencode/skills/delphi-review/opencode.json.delphi.example +56 -0
  80. package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +486 -0
  81. package/plugins/opencode/skills/improve-codebase-architecture/SKILL.md +156 -0
  82. package/plugins/opencode/skills/ralph-loop/SKILL.md +501 -0
  83. package/plugins/opencode/skills/ralph-loop/references/components/memory.md +55 -0
  84. package/plugins/opencode/skills/ralph-loop/references/components/middleware.md +54 -0
  85. package/plugins/opencode/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  86. package/plugins/opencode/skills/ralph-loop/references/components/system-prompt.md +24 -0
  87. package/plugins/opencode/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  88. package/plugins/opencode/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  89. package/plugins/opencode/skills/ralph-loop/templates/progress-log.md +36 -0
  90. package/plugins/opencode/skills/sprint-flow/AGENTS.md +68 -0
  91. package/plugins/opencode/skills/sprint-flow/SKILL.md +1248 -0
  92. package/plugins/opencode/skills/sprint-flow/references/components/memory.md +87 -0
  93. package/plugins/opencode/skills/sprint-flow/references/components/middleware.md +72 -0
  94. package/plugins/opencode/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  95. package/plugins/opencode/skills/sprint-flow/references/components/system-prompt.md +27 -0
  96. package/plugins/opencode/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  97. package/plugins/opencode/skills/sprint-flow/references/force-levels.md +203 -0
  98. package/plugins/opencode/skills/sprint-flow/references/phase-0-think.md +115 -0
  99. package/plugins/opencode/skills/sprint-flow/references/phase-1-plan.md +178 -0
  100. package/plugins/opencode/skills/sprint-flow/references/phase-2-build.md +198 -0
  101. package/plugins/opencode/skills/sprint-flow/references/phase-3-review.md +213 -0
  102. package/plugins/opencode/skills/sprint-flow/references/phase-4-uat.md +125 -0
  103. package/plugins/opencode/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  104. package/plugins/opencode/skills/sprint-flow/references/phase-6-ship.md +193 -0
  105. package/plugins/opencode/skills/sprint-flow/references/phase-7-land.md +140 -0
  106. package/plugins/opencode/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  107. package/plugins/opencode/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
  108. package/plugins/opencode/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  109. package/plugins/opencode/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
  110. package/plugins/opencode/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  111. package/plugins/opencode/skills/sprint-flow/templates/pain-document-template.md +115 -0
  112. package/plugins/opencode/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  113. package/plugins/opencode/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  114. package/plugins/opencode/skills/test-driven-development/SKILL.md +71 -0
  115. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +56 -0
  116. package/plugins/opencode/skills/test-specification-alignment/SKILL.md +702 -0
  117. package/plugins/opencode/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  118. package/plugins/opencode/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  119. package/plugins/opencode/skills/test-specification-alignment/references/specification-format.md +348 -0
  120. package/plugins/opencode/skills/to-issues/SKILL.md +277 -0
  121. package/plugins/opencode/tsconfig.json +15 -0
  122. package/plugins/qoder/skills/admin-template-guidelines/SKILL.md +904 -0
  123. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +45 -0
  124. package/plugins/qoder/skills/delphi-review/AGENTS.md +66 -0
  125. package/plugins/qoder/skills/delphi-review/INSTALL.md +152 -0
  126. package/plugins/qoder/skills/delphi-review/SKILL.md +454 -0
  127. package/plugins/qoder/skills/delphi-review/opencode.json.delphi.example +56 -0
  128. package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +486 -0
  129. package/plugins/qoder/skills/improve-codebase-architecture/SKILL.md +156 -0
  130. package/plugins/qoder/skills/ralph-loop/SKILL.md +501 -0
  131. package/plugins/qoder/skills/ralph-loop/references/components/memory.md +55 -0
  132. package/plugins/qoder/skills/ralph-loop/references/components/middleware.md +54 -0
  133. package/plugins/qoder/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  134. package/plugins/qoder/skills/ralph-loop/references/components/system-prompt.md +24 -0
  135. package/plugins/qoder/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  136. package/plugins/qoder/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  137. package/plugins/qoder/skills/ralph-loop/templates/progress-log.md +36 -0
  138. package/plugins/qoder/skills/sprint-flow/AGENTS.md +68 -0
  139. package/plugins/qoder/skills/sprint-flow/SKILL.md +1248 -0
  140. package/plugins/qoder/skills/sprint-flow/references/components/memory.md +87 -0
  141. package/plugins/qoder/skills/sprint-flow/references/components/middleware.md +72 -0
  142. package/plugins/qoder/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  143. package/plugins/qoder/skills/sprint-flow/references/components/system-prompt.md +27 -0
  144. package/plugins/qoder/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  145. package/plugins/qoder/skills/sprint-flow/references/force-levels.md +203 -0
  146. package/plugins/qoder/skills/sprint-flow/references/phase-0-think.md +115 -0
  147. package/plugins/qoder/skills/sprint-flow/references/phase-1-plan.md +178 -0
  148. package/plugins/qoder/skills/sprint-flow/references/phase-2-build.md +198 -0
  149. package/plugins/qoder/skills/sprint-flow/references/phase-3-review.md +213 -0
  150. package/plugins/qoder/skills/sprint-flow/references/phase-4-uat.md +125 -0
  151. package/plugins/qoder/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  152. package/plugins/qoder/skills/sprint-flow/references/phase-6-ship.md +193 -0
  153. package/plugins/qoder/skills/sprint-flow/references/phase-7-land.md +140 -0
  154. package/plugins/qoder/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  155. package/plugins/qoder/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
  156. package/plugins/qoder/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  157. package/plugins/qoder/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
  158. package/plugins/qoder/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  159. package/plugins/qoder/skills/sprint-flow/templates/pain-document-template.md +115 -0
  160. package/plugins/qoder/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  161. package/plugins/qoder/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  162. package/plugins/qoder/skills/test-driven-development/SKILL.md +71 -0
  163. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +56 -0
  164. package/plugins/qoder/skills/test-specification-alignment/SKILL.md +702 -0
  165. package/plugins/qoder/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  166. package/plugins/qoder/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  167. package/plugins/qoder/skills/test-specification-alignment/references/specification-format.md +348 -0
  168. package/plugins/qoder/skills/to-issues/SKILL.md +277 -0
  169. package/skills/admin-template-guidelines/SKILL.md +904 -0
  170. package/skills/delphi-review/SKILL.md +112 -77
  171. package/skills/improve-codebase-architecture/SKILL.md +156 -0
  172. package/skills/ralph-loop/SKILL.md +165 -34
  173. package/skills/sprint-flow/SKILL.md +448 -107
  174. package/skills/sprint-flow/references/components/skill-invocations.md +1 -1
  175. package/skills/sprint-flow/references/components/tool-descriptions.md +1 -1
  176. package/skills/sprint-flow/references/force-levels.md +203 -0
  177. package/skills/sprint-flow/references/phase-1-plan.md +4 -4
  178. package/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +20 -1
  179. package/skills/sprint-flow/templates/auto-estimate-output-template.md +7 -5
  180. package/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  181. package/skills/test-driven-development/SKILL.md +71 -0
  182. package/skills/test-specification-alignment/SKILL.md +98 -24
  183. package/skills/to-issues/SKILL.md +277 -0
  184. package/plugins/qoder/AGENTS.md +0 -93
  185. package/plugins/qoder/README.md +0 -87
  186. package/plugins/qoder/widgets/quality-report.html +0 -163
  187. package/plugins/qoder/widgets/sprint-dashboard.html +0 -172
  188. package/skills/delphi-review/evals/evals.json +0 -82
  189. package/skills/delphi-review/references/qoder-multi-model.md +0 -191
  190. package/skills/ralph-loop/evals/evals.json +0 -311
  191. package/skills/ralph-loop/evolution-history.json +0 -59
  192. package/skills/ralph-loop/evolution-log.md +0 -16
  193. package/skills/sprint-flow/evals/evals.json +0 -130
  194. package/skills/sprint-flow/evolution-history.json +0 -39
  195. package/skills/sprint-flow/evolution-log.md +0 -23
  196. package/skills/sprint-flow/references/qoder-adaptation.md +0 -173
  197. package/skills/test-specification-alignment/evals/evals.json +0 -75
@@ -0,0 +1,702 @@
1
+ ---
2
+ name: test-specification-alignment
3
+ description: "Use when asked to run tests, verify tests, align tests with specification.yaml, before BUILD verification, or before release/ship."
4
+ ---
5
+
6
+ # Test-Specification Alignment Engine
7
+
8
+ ## Workflow Steps
9
+
10
+ 1. **Load Phase 0** — Verify `specification.yaml` and `tests/` directory exist; BLOCK if missing with clear guidance to complete brainstorming → delphi-review → specification-generator flow first
11
+ 2. **Phase 1 Alignment (Modify Allowed)** — Parse specification.yaml (YAML) + test files (AST); validate alignment rules; generate alignment report; optionally fix tests to align with requirements; require score ≥80% to proceed
12
+ 3. **Coverage Mapping** — Map each REQ-* to at least one test case with `@test` annotation; map each AC-* to at least one assertion; verify test intent declarations (`@test`, `@intent`, `@covers` tags)
13
+ 4. **Pre-Phase 2 Freeze** — Invoke `/freeze` skill to lock test directories (`tests/`, `test/`, `__tests__/`, `*.test.ts`, `*.spec.ts`, `*_test.py`, etc.); return confirmation before proceeding
14
+ 5. **Phase 2 Execution (Frozen)** — Run all tests; Agent is BLOCKED from modifying/deleting/skipping tests; analyze failures into 4 categories: BUSINESS_CODE_ERROR, TEST_DATA_ERROR, SPECIFICATION_ERROR, ENVIRONMENT_ERROR; SPECIFICATION_ERROR requires ESCALATE_TO_HUMAN
15
+ 6. **Failure Classification** — For each failing test, output classification in mandatory format with Type, Test, Root Cause, Action fields; if SPECIFICATION_ERROR detected, offer user options (A: fix spec → re-Phase 1, B: confirm spec → modify code, C: clarify ambiguity)
16
+ 7. **JSON Report Output** — Generate alignment report as valid JSON with fields: `alignment_status` (PASS|FAIL|BLOCKED), `phase` (1|2), `score`, `misaligned_tests[]`, `anti_pattern_detected`, `errors[]`; Terminal State: ✅ ALL_TESTS_PASS
17
+
18
+ ## 核心原则
19
+
20
+ **测试是系统的防护网,也是系统的使用手册。测试必须准确反映原始需求和设计方案。**
21
+
22
+ ### 五大特性
23
+
24
+ 1. **两阶段分离** — Phase 1 可修改测试对齐,Phase 2 禁止修改测试执行
25
+ 2. **结构化验证** — YAML specification + AST 解析,确定性验证
26
+ 3. **freeze 约束** — Phase 2 调用 freeze skill 锁定测试目录
27
+ 4. **失败分类** — 业务代码/测试数据/Specification/环境 四类错误分流
28
+ 5. **零容忍** — Phase 2 绝对禁止修改/删除/跳过测试
29
+
30
+ ---
31
+
32
+ ## Output Format (MANDATORY)
33
+ Alignment report MUST be output as valid JSON:
34
+ ```json
35
+ {
36
+ "alignment_status": "PASS|FAIL|BLOCKED",
37
+ "phase": "1|2",
38
+ "score": 85.5,
39
+ "misaligned_tests": [
40
+ {"test_name": "test_checkout", "spec_requirement": "REQ-003", "gap": "Missing @test annotation"}
41
+ ],
42
+ "anti_pattern_detected": false,
43
+ "errors": []
44
+ }
45
+ ```
46
+ **Eval assertions check for:** `alignment_status`, `phase`, `score`, `anti_pattern_detected`.
47
+
48
+ ---
49
+
50
+ ## Triggers
51
+
52
+ ### Automatic Triggers
53
+ - BUILD (TDD + review) Round 1 after Driver outputs tests
54
+ - Gate 1 verification before proceeding
55
+ - gstack-ship release before deployment
56
+
57
+ ### Manual Triggers
58
+ - `/test-specification-alignment` command
59
+ - `/verify-tests` command
60
+ - "run tests" phrase
61
+ - "verify tests" phrase
62
+ - before gstack-ship
63
+
64
+ ---
65
+
66
+ ## Scope
67
+
68
+ ### IN Scope
69
+ - Validation of test alignment against `specification.yaml` (Requirements, User Stories, Acceptance Criteria)
70
+ - Phase 1: Test modification to improve alignment (add missing tests, fix annotations, correct intent)
71
+ - Phase 2: Test execution with frozen test files (no modifications allowed)
72
+ - Failure classification into BUSINESS_CODE_ERROR, TEST_DATA_ERROR, SPECIFICATION_ERROR, ENVIRONMENT_ERROR
73
+ - JSON report generation with alignment status, score, misaligned tests, and errors
74
+
75
+ ### OUT Scope
76
+ - Modifying `specification.yaml` during Phase 2 (requires ESCALATE_TO_HUMAN)
77
+ - Skipping or deleting tests to make tests pass
78
+ - Modifying test assertions to force tests to pass
79
+ - Business logic implementation (handled by BUILD phase)
80
+ - Environment configuration issues (handled separately)
81
+
82
+ ### Boundaries
83
+ - **Start**: After BUILD (TDD + review) Round 1 outputs tests
84
+ - **End**: Terminal State ✅ ALL_TESTS_PASS or ESCALATE_TO_HUMAN for specification issues
85
+ - **Inputs**: `specification.yaml`, `tests/` directory
86
+ - **Outputs**: Alignment report (JSON), test execution report, failure classification
87
+
88
+ ---
89
+
90
+ ## Examples
91
+
92
+ ### Example 1: Normal Trigger (Should Execute)
93
+ **User Input**: "run tests for login feature" or `/test-specification-alignment`
94
+
95
+ **Expected Flow**:
96
+ 1. Load Phase 0: Check `specification.yaml` exists → ✅ Found
97
+ 2. Check `tests/` directory exists → ✅ Found
98
+ 3. Phase 1: Parse spec and tests → Alignment score 85% → ✅ Pass threshold
99
+ 4. Pre-Phase 2: Call `/freeze tests/` → ✅ Locked
100
+ 5. Phase 2: Run tests → 12 passed, 0 failed → ✅ ALL_TESTS_PASS
101
+ 6. Output JSON report with `alignment_status: "PASS"`, `phase: "2"`, `score: 85`
102
+ 7. Call `/unfreeze tests/` → ✅ Unlocked
103
+ 8. Terminal State: ✅ Test-specification-alignment complete
104
+
105
+ ---
106
+
107
+ ### Example 2: Should NOT Trigger (Missing Specification)
108
+ **User Input**: "run tests" in a project without `specification.yaml`
109
+
110
+ **Expected Flow**:
111
+ 1. Load Phase 0: Check `specification.yaml` exists → ❌ Not Found
112
+ 2. BLOCK with message:
113
+ ```
114
+ ❌ BLOCKED: specification.yaml 不存在
115
+
116
+ 要生成 specification.yaml,请先完成需求流程:
117
+
118
+ 流程步骤:
119
+ 1. brainstorming → 需求探索,生成设计文档
120
+ 2. delphi-review → 需求评审 (多轮直到 APPROVED)
121
+ 3. spec 自动生成 (从 APPROVED 设计文档提取 specification.yaml)
122
+
123
+ 为什么必须这样?
124
+ - 在 delphi-review APPROVED 后生成,避免设计文档修改时 spec 也需重新生成
125
+ - 遵循"问题发现越早修复成本越低"原则
126
+
127
+ 请先完成上述流程,然后再运行 test-specification-alignment。
128
+ ```
129
+ 3. Terminal State: ❌ BLOCKED_MISSING_SPECIFICATION
130
+
131
+ ---
132
+
133
+ ## 触发条件
134
+
135
+ ### 自动触发
136
+
137
+ - BUILD (TDD + review) Round 1 后(Driver 输出 tests)
138
+ - Gate 1 验证前
139
+ - gstack-ship 发布前
140
+
141
+ ### 手动触发
142
+
143
+ - `/test-specification-alignment` 命令
144
+ - `/verify-tests` 命令
145
+
146
+ ---
147
+
148
+ ## Specification 定义
149
+
150
+ **Specification = Requirements + Design Decisions + API Contracts**
151
+
152
+ | 组成部分 | 文件 | 格式 |
153
+ |----------|------|------|
154
+ | User Stories | `specification.yaml` → `user_stories[]` | YAML: id, actor, feature, benefit, linked_requirements |
155
+ | Requirements | `specification.yaml` | YAML |
156
+ | Acceptance Criteria | `specification.yaml` | YAML |
157
+ | Design Decisions | `specification.yaml` | YAML |
158
+ | API Contracts | `specification.yaml` | YAML |
159
+
160
+ **User Stories 追溯链**:
161
+ ```
162
+ US-001 (actor/feature/benefit)
163
+ → REQ-XXX-001 (requirement)
164
+ → AC-XXX-001-01 (acceptance criteria)
165
+ → test('REQ-XXX-001: ...') (@test annotation)
166
+ ```
167
+
168
+ ---
169
+
170
+ ## 核心流程
171
+
172
+ ```
173
+ ┌─────────────────────────────────────────────────────────────┐
174
+ │ Test-Specification Alignment Flow │
175
+ ├─────────────────────────────────────────────────────────────┤
176
+ │ │
177
+ │ Phase 0: 准备 │
178
+ │ ├─ 验证 specification.yaml 存在 │
179
+ │ ├─ 验证 tests/ 目录存在 │
180
+ │ └─ ❌ 缺失 → BLOCK + 提示用户 │
181
+ │ └─ 提示: "先完成需求流程: │
182
+ │ brainstorming → delphi-review → specification-generator" │
183
+ │ │
184
+ │ Phase 1: 对齐验证 (可修改测试) │
185
+ │ ├─ 解析 specification.yaml (YAML parser) │
186
+ │ ├─ 解析测试文件 (AST parser) │
187
+ │ ├─ 验证对齐规则 │
188
+ │ ├─ 生成 Alignment Report │
189
+ │ └─ (可选) 修复测试 │
190
+ │ │
191
+ │ Checkpoint: Alignment Score >= 80%? │
192
+ │ ├─ NO → BLOCK │
193
+ │ └─ YES → 继续 │
194
+ │ │
195
+ │ ⭐ Pre-Phase 2: 调用 freeze skill 锁定测试目录 │
196
+ │ │
197
+ │ Phase 2: 执行测试 (禁止修改测试) │
198
+ │ ├─ 运行所有测试 │
199
+ │ ├─ IF Agent 尝试修改测试 → freeze 拦截 │
200
+ │ ├─ 失败分析: 业务代码/测试数据/Specification/环境 │
201
+ │ │ └─ Specification 错误 → ESCALATE_TO_HUMAN │
202
+ │ └─ 全部通过 → 继续 │
203
+ │ │
204
+ │ ⭐ Post-Phase 2: 调用 unfreeze skill 解锁测试目录 │
205
+ │ │
206
+ │ Terminal State: ✅ ALL_TESTS_PASS │
207
+ │ │
208
+ └─────────────────────────────────────────────────────────────┘
209
+ ```
210
+
211
+ ---
212
+
213
+ ## ⚠️ Phase 0 缺失 Specification 处理
214
+
215
+ ### 错误提示格式
216
+
217
+ 如果 `specification.yaml` 不存在,必须 BLOCK 并提供清晰的流程指引:
218
+
219
+ ```
220
+ ❌ BLOCKED: specification.yaml 不存在
221
+
222
+ 要生成 specification.yaml,请先完成需求流程:
223
+
224
+ 流程步骤:
225
+ 1. brainstorming → 需求探索,生成设计文档
226
+ 2. delphi-review → 需求评审(多轮直到 APPROVED)
227
+ 3. spec 自动生成(从 APPROVED 设计文档提取 specification.yaml)
228
+
229
+ 为什么必须这样?
230
+ - 在 delphi-review APPROVED 后生成,避免设计文档修改时 spec 也需重新生成
231
+ - 遵循"问题发现越早修复成本越低"原则
232
+
233
+ 请先完成上述流程,然后再运行 test-specification-alignment。
234
+ ```
235
+
236
+ ---
237
+
238
+ ## 强制对齐规则
239
+
240
+ ### 规则 1: 每个 Requirement 必须有测试
241
+
242
+ ```yaml
243
+ requirement_to_test:
244
+ rule: "每个 REQ-* 必须对应至少一个 test case"
245
+ format: "test name 包含 REQ ID 或 JSDoc @test 标签"
246
+
247
+ # TypeScript 示例
248
+ example_ts: |
249
+ /**
250
+ * @test REQ-AUTH-001
251
+ * @intent 验证用户使用正确凭据可以成功登录
252
+ * @covers AC-AUTH-001-01, AC-AUTH-001-02
253
+ */
254
+ test('REQ-AUTH-001: login success', () => { ... });
255
+
256
+ # Python 示例
257
+ example_py: |
258
+ # @test REQ-AUTH-001
259
+ # @intent 验证用户使用正确凭据可以成功登录
260
+ # @covers AC-AUTH-001-01, AC-AUTH-001-02
261
+ def test_req_auth_001_login_success():
262
+ ...
263
+
264
+ # Go 示例
265
+ example_go: |
266
+ // @test REQ-AUTH-001
267
+ // @intent 验证用户使用正确凭据可以成功登录
268
+ // @covers AC-AUTH-001-01, AC-AUTH-001-02
269
+ func Test_REQ_AUTH_001_LoginSuccess(t *testing.T) { ... }
270
+ ```
271
+
272
+ ### 规则 2: 每个 Acceptance Criteria 必须有断言
273
+
274
+ ```yaml
275
+ ac_to_assertion:
276
+ rule: "每个 AC-* 必须有对应断言覆盖"
277
+ format: "断言注释标注 AC ID"
278
+ example: |
279
+ // AC-AUTH-001-01: 返回 200 和 token
280
+ expect(response.status).toBe(200);
281
+ expect(response.body.token).toBeDefined();
282
+ ```
283
+
284
+ ### 规则 3: 测试意图必须明确声明
285
+
286
+ ```yaml
287
+ test_intent_declaration:
288
+ rule: "每个 test case 必须有意图声明"
289
+ format: "@test, @intent, @covers JSDoc 标签"
290
+ required_tags:
291
+ - "@test REQ-XXX-XXX" # 关联的 requirement ID
292
+ - "@intent 描述测试意图" # 测试目的
293
+ - "@covers AC-XXX-XX" # 覆盖的 acceptance criteria (可选)
294
+ ```
295
+
296
+ ---
297
+
298
+ ## 对齐验证维度
299
+
300
+ | 维度 | 权重 | 验证内容 |
301
+ |------|------|----------|
302
+ | Requirement Coverage | 30% | 每个 REQ-* 是否有对应测试 |
303
+ | Acceptance Criteria Coverage | 25% | 每个 AC-* 是否被断言覆盖 |
304
+ | Test Intent Correctness | 20% | 测试意图是否正确声明 |
305
+ | Edge Case Coverage | 15% | 边界条件是否覆盖 |
306
+ | Test Data Validity | 10% | 测试数据是否合理 |
307
+
308
+ **Pass Threshold: 80%**
309
+
310
+ ---
311
+
312
+ ## Phase 2: freeze 约束机制
313
+
314
+ ### Pre-Phase 2: 锁定测试目录
315
+
316
+ ```yaml
317
+ pre_phase2:
318
+ action: "INVOKE freeze skill"
319
+ parameters:
320
+ freeze_boundary:
321
+ - "tests/"
322
+ - "test/"
323
+ - "__tests__/"
324
+ - "*.test.ts"
325
+ - "*.test.js"
326
+ - "*.spec.ts"
327
+ - "*.spec.js"
328
+ - "*_test.py"
329
+ - "*_test.go"
330
+ - "cypress/"
331
+ - "playwright/"
332
+ mode: "strict"
333
+
334
+ result:
335
+ - "测试目录被 freeze skill 锁定"
336
+ - "Agent 的 Edit/Write 调用被预拦截"
337
+ - "返回: ✅ 测试文件已冻结"
338
+ ```
339
+
340
+ ### Phase 2 约束
341
+
342
+ ```yaml
343
+ phase2_constraints:
344
+ forbidden_actions:
345
+ - action: "修改测试文件"
346
+ severity: "CRITICAL"
347
+ response: "freeze skill 返回 BLOCKED_ERROR"
348
+
349
+ - action: "删除测试文件"
350
+ severity: "CRITICAL"
351
+ response: "freeze skill 返回 BLOCKED_ERROR"
352
+
353
+ - action: "跳过测试 (test.skip, @skip, xit)"
354
+ severity: "CRITICAL"
355
+ response: "检测并拒绝"
356
+
357
+ - action: "修改断言使其永远通过"
358
+ severity: "CRITICAL"
359
+ response: "检测并拒绝"
360
+
361
+ allowed_actions:
362
+ - "修改业务代码"
363
+ - "修改配置文件"
364
+ - "修改环境变量"
365
+ ```
366
+
367
+ ### Post-Phase 2: 解锁测试目录
368
+
369
+ ```yaml
370
+ post_phase2:
371
+ action: "INVOKE unfreeze skill"
372
+ result: "测试目录解除冻结,允许后续修改"
373
+ ```
374
+
375
+ ---
376
+
377
+ ## 失败分析分类
378
+
379
+ | 失败类型 | 判断依据 | 处理方式 |
380
+ |----------|----------|----------|
381
+ | **BUSINESS_CODE_ERROR** | 测试正确,业务代码有 bug | 修改业务代码 |
382
+ | **TEST_DATA_ERROR** | 测试数据不符合业务逻辑 | 回滚到 Phase 1 |
383
+ | **SPECIFICATION_ERROR** | 测试正确,但 specification 有误 | ESCALATE_TO_HUMAN |
384
+ | **ENVIRONMENT_ERROR** | 环境/依赖问题 | 修复环境配置 |
385
+
386
+ ### 失败分类强制输出格式
387
+
388
+ 任何 Phase 2 测试失败时,**必须**按以下格式输出:
389
+
390
+ ```markdown
391
+ ### Failure Classification
392
+ - **Type**: [BUSINESS_CODE_ERROR | TEST_DATA_ERROR | SPECIFICATION_ERROR | ENVIRONMENT_ERROR]
393
+ - **Test**: [失败的测试名称]
394
+ - **Root Cause**: [简要原因]
395
+ - **Action**: [对应处理方式]
396
+ ```
397
+
398
+ ### Specification 错误处理
399
+
400
+ ```yaml
401
+ specification_issue_flow:
402
+ state: "ESCALATE_SPECIFICATION_ISSUE"
403
+
404
+ user_options:
405
+ - option: "A"
406
+ action: "修正 Specification → 重新 Phase 1"
407
+ unfreeze_tests: true
408
+
409
+ - option: "B"
410
+ action: "确认 Specification 正确 → 修改业务代码"
411
+ note: "用户明确授权"
412
+
413
+ - option: "C"
414
+ action: "补充 Specification 澄清歧义"
415
+ unfreeze_tests: true
416
+ ```
417
+
418
+ ---
419
+
420
+ ## 状态机
421
+
422
+ | State | 名称 | 说明 |
423
+ |-------|------|------|
424
+ | 0 | IDLE | 初始状态 |
425
+ | 1 | PHASE0_PREPARING | 准备阶段 |
426
+ | 2 | PHASE0_COMPLETE | 准备完成 |
427
+ | 3 | PHASE1_ALIGNING | 对齐验证中 |
428
+ | 4 | PHASE1_ALIGNMENT_ISSUES | 发现对齐问题 |
429
+ | 5 | PHASE1_FIXING_TESTS | 修复测试中 |
430
+ | 6 | PHASE1_COMPLETE | 对齐完成 |
431
+ | 7 | PRE_PHASE2_FREEZE | 冻结测试目录 |
432
+ | 8 | CHECKPOINT_VERIFIED | 检查点通过 |
433
+ | 9 | PHASE2_EXECUTING | 执行测试中 |
434
+ | 10 | PHASE2_TEST_FAILURE | 测试失败 |
435
+ | 11 | PHASE2_FAILURE_ANALYSIS | 失败分析中 |
436
+ | 12 | PHASE2_FIXING_CODE | 修复业务代码中 |
437
+ | 13 | PHASE2_SPECIFICATION_ISSUE | Specification 问题 |
438
+ | 14 | PHASE2_COMPLETE | 测试通过 |
439
+ | 15 | POST_PHASE2_UNFREEZE | 解冻测试目录 |
440
+ | 16 | ALL_TESTS_PASS | 全部通过 |
441
+
442
+ ### 阻塞状态
443
+
444
+ | State | 名称 | 说明 |
445
+ |-------|------|------|
446
+ | 90 | BLOCKED_MISSING_SPECIFICATION | 缺少 specification |
447
+ | 91 | BLOCKED_ALIGNMENT_TOO_LOW | 对齐分数过低 |
448
+ | 92 | BLOCKED_TEST_MODIFICATION_VIOLATION | 测试修改违规 |
449
+ | 93 | BLOCKED_SPECIFICATION_ISSUE | Specification 问题需用户决策 |
450
+ | 94 | BLOCKED_MAX_RETRIES_EXCEEDED | 超过最大重试次数 |
451
+
452
+ ---
453
+
454
+ ## 与现有 Skills 集成
455
+
456
+ ### 与 BUILD (TDD + review) 集成
457
+
458
+ ```
459
+ BUILD (TDD + review) Round 1: Driver
460
+ ├─ 输出: sealed{code, decisions} + public{tests}
461
+ └────────────────────────────────────────────┘
462
+
463
+
464
+ test-specification-alignment (本 skill)
465
+ ├─ Phase 1: 验证 Driver 生成的 tests 与 requirements 对齐
466
+ ├─ Phase 2: 执行测试验证实现
467
+ └────────────────────────────────────────────┘
468
+
469
+
470
+ Gate 1 (verification-loop)
471
+ ├─ Static Analysis
472
+ └────────────────────────────────────────────┘
473
+
474
+
475
+ BUILD (TDD + review) Round 3: Arbiter
476
+ └─ 收到 test-specification-alignment 结果
477
+ ```
478
+
479
+ ### 与 freeze skill 集成
480
+
481
+ - Phase 2 开始前: 调用 `/freeze` 锁定测试目录
482
+ - Phase 2 执行中: freeze 拦截所有测试文件修改
483
+ - Phase 2 结束后: 调用 `/unfreeze` 解锁
484
+
485
+ ---
486
+
487
+ ## Agent 配置
488
+
489
+ ### Phase 1 Agent
490
+
491
+ ```yaml
492
+ phase1_agent:
493
+ type: oracle
494
+ model: Qwen3.5-Plus
495
+ skills:
496
+ - test-driven-development
497
+ - coding-standards
498
+
499
+ constraints:
500
+ can_modify_tests: true
501
+ must_preserve_test_intent: true
502
+ ```
503
+
504
+ ### Phase 2 Agent
505
+
506
+ ```yaml
507
+ phase2_agent:
508
+ type: build
509
+ model: GLM-5
510
+ skills:
511
+ - test-driven-development
512
+ - coding-standards
513
+
514
+ constraints:
515
+ can_modify_tests: false # ❌ 禁止
516
+ can_delete_tests: false # ❌ 禁止
517
+ can_skip_tests: false # ❌ 禁止
518
+ can_modify_business_code: true # ✅ 允许
519
+ ```
520
+
521
+ ---
522
+
523
+ ## 输出报告格式
524
+
525
+ ### Alignment Report (Phase 1)
526
+
527
+ ```markdown
528
+ ## Test-Specification Alignment Report
529
+
530
+ ### Summary
531
+ - Alignment Score: 85/100
532
+ - Total Requirements: 15
533
+ - Covered Requirements: 14/15 (93%)
534
+ - Total Acceptance Criteria: 42
535
+ - Covered AC: 38/42 (90%)
536
+
537
+ ### Coverage by Dimension
538
+ | Dimension | Score | Weight | Weighted |
539
+ |-----------|-------|--------|----------|
540
+ | Requirement Coverage | 93% | 30% | 27.9 |
541
+ | Acceptance Criteria Coverage | 90% | 25% | 22.5 |
542
+ | Test Intent Correctness | 88% | 20% | 17.6 |
543
+ | Edge Case Coverage | 80% | 15% | 12.0 |
544
+ | Test Data Validity | 90% | 10% | 9.0 |
545
+ | **Total** | | | **89.0** |
546
+
547
+ ### Misaligned Tests
548
+ | Test ID | Issue | Specification Ref | Recommendation |
549
+ |---------|-------|-------------------|----------------|
550
+ | TEST-012 | Incorrect intent | REQ-AUTH-003 | 修改断言验证 |
551
+
552
+ ### Missing Tests
553
+ | Requirement ID | Description | Priority |
554
+ |----------------|-------------|----------|
555
+ | REQ-AUTH-006 | Token 刷新机制 | Critical |
556
+
557
+ ### Status
558
+ ✅ Alignment Score >= 80%, 可以进入 Phase 2
559
+ ```
560
+
561
+ ### Test Execution Report (Phase 2)
562
+
563
+ ```markdown
564
+ ## Test Execution Report
565
+
566
+ ### Summary
567
+ - Total Tests: 67
568
+ - Passed: 65
569
+ - Failed: 2
570
+ - Skipped: 0
571
+
572
+ ### Failed Tests
573
+ | Test ID | Error | Root Cause | Fix Applied |
574
+ |---------|-------|------------|-------------|
575
+ | TEST-034 | AssertionError | 业务代码逻辑错误 | 已修复 |
576
+
577
+ ### Freeze Status
578
+ - Pre-Phase 2: ✅ 测试目录已冻结
579
+ - Phase 2: ✅ 无违规尝试
580
+ - Post-Phase 2: ✅ 测试目录已解冻
581
+
582
+ ### Status
583
+ ✅ All tests pass. Ready for next stage.
584
+ ```
585
+
586
+ ---
587
+
588
+ ## Legacy 模式
589
+
590
+ ### 缺失 Specification 的 fallback
591
+
592
+ ```yaml
593
+ legacy_mode:
594
+ trigger: "specification.yaml 不存在"
595
+
596
+ options:
597
+ - option: "从测试逆向生成 specification"
598
+ steps:
599
+ - 解析现有测试
600
+ - 提取测试意图和断言
601
+ - 生成 draft specification
602
+ - 用户确认后保存
603
+
604
+ - option: "放宽对齐验证"
605
+ rules:
606
+ - 只验证测试覆盖率 >= 80%
607
+ - 不验证测试意图对齐
608
+ - 标记为 "LEGACY_MODE"
609
+
610
+ - option: "用户提供 specification"
611
+ action: "BLOCK until specification provided"
612
+ ```
613
+
614
+ ---
615
+
616
+ ## 成本控制
617
+
618
+ | 指标 | 阈值 |
619
+ |------|------|
620
+ | 单次对齐验证 | ~$0.02 |
621
+ | 单次测试执行 | ~$0.01 |
622
+ | 最大重试次数 | 5 |
623
+ | 单次总成本上限 | $0.10 |
624
+
625
+ ---
626
+
627
+ ## Terminal State Checklist
628
+
629
+ <MANDATORY-CHECKLIST>
630
+
631
+ ### 只能在以下条件全部满足后声明 "test-specification-alignment complete":
632
+
633
+ **Pre-requisites:**
634
+ - [ ] specification.yaml 存在且可解析
635
+ - [ ] tests/ 目录存在且有测试文件
636
+ - [ ] Phase 1 对齐验证完成
637
+
638
+ **CRITICAL - Alignment Verification:**
639
+ - [ ] Alignment Score >= 80%
640
+ - [ ] 所有 Critical 对齐问题已修复
641
+ - [ ] 所有 Major 对齐问题已处理
642
+
643
+ **CRITICAL - Phase 2 Execution:**
644
+ - [ ] freeze skill 已调用,测试目录已锁定
645
+ - [ ] 所有测试已执行
646
+ - [ ] 无测试修改违规
647
+ - [ ] unfreeze skill 已调用
648
+
649
+ **Final Requirements:**
650
+ - [ ] 所有测试通过
651
+ - [ ] 报告已生成
652
+
653
+ **IF 有 Specification 问题:**
654
+ - **CANNOT claim complete**
655
+ - **MUST ESCALATE_TO_HUMAN**
656
+
657
+ **IF Phase 2 测试修改违规:**
658
+ - **CANNOT claim complete**
659
+ - **MUST BLOCK 并记录违规**
660
+
661
+ </MANDATORY-CHECKLIST>
662
+
663
+ ---
664
+
665
+ ## Anti-Patterns
666
+
667
+ | 错误 | 正确 |
668
+ |------|------|
669
+ | Phase 2 修改测试文件 | ❌ 禁止 — 只能修改业务代码 |
670
+ | Phase 2 删除测试文件 | ❌ 禁止 — freeze 会拦截 |
671
+ | Phase 2 跳过测试 | ❌ 禁止 — 检测并拒绝 |
672
+ | 测试失败时修改断言 | ❌ 禁止 — 必须修改业务代码 |
673
+ | 缺少 @test 标签 | ❌ 必须 — 强制标注 |
674
+ | Specification 错误时强行通过 | ❌ 禁止 — 必须 ESCALATE |
675
+
676
+ ---
677
+
678
+ ## 版本历史
679
+
680
+ | 版本 | 日期 | 变更 |
681
+ |------|------|------|
682
+ | V1.0 | 2026-04-06 | 初始设计 |
683
+ | V2.0 | 2026-04-06 | Delphi Review 共识版本 |
684
+ | V2.1 | 2026-06-02 | Added parser-friendly sections: Workflow Steps (7 steps), Triggers (5+ phrases), Scope (IN/OUT/Boundaries), Examples (2 scenarios) |
685
+
686
+ ---
687
+
688
+ ## Output Format (MANDATORY)
689
+ Alignment report MUST be output as valid JSON:
690
+ ```json
691
+ {
692
+ "alignment_status": "PASS|FAIL|BLOCKED",
693
+ "phase": "1|2",
694
+ "score": 85.5,
695
+ "misaligned_tests": [
696
+ {"test_name": "test_checkout", "spec_requirement": "REQ-003", "gap": "Missing @test annotation"}
697
+ ],
698
+ "anti_pattern_detected": false,
699
+ "errors": []
700
+ }
701
+ ```
702
+ **Eval assertions check for:** `alignment_status`, `phase`, `score`, `anti_pattern_detected`.