@boyingliu01/xp-gate 0.9.0 → 0.9.2

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 (72) hide show
  1. package/adapters/cpp.sh +3 -3
  2. package/adapters/dart.sh +2 -2
  3. package/adapters/flutter.sh +2 -2
  4. package/adapters/java.sh +4 -4
  5. package/adapters/kotlin.sh +4 -4
  6. package/adapters/objectivec.sh +2 -2
  7. package/adapters/plugins/p3c-java/scripts/install-maven-p3c.sh +3 -3
  8. package/adapters/plugins/whalecloud-java/scripts/install-maven-whalecloud.sh +3 -3
  9. package/adapters/powershell.sh +3 -3
  10. package/adapters/python.sh +2 -2
  11. package/adapters/shell.sh +3 -3
  12. package/adapters/swift.sh +2 -2
  13. package/package.json +1 -1
  14. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  15. package/plugins/claude-code/skills/admin-template-guidelines/SKILL.md +6 -797
  16. package/plugins/claude-code/skills/admin-template-guidelines/references/rule-1.md +91 -0
  17. package/plugins/claude-code/skills/admin-template-guidelines/references/rule-2.md +155 -0
  18. package/plugins/claude-code/skills/admin-template-guidelines/references/rule-3.md +70 -0
  19. package/plugins/claude-code/skills/admin-template-guidelines/references/rule-4.md +154 -0
  20. package/plugins/claude-code/skills/admin-template-guidelines/references/rule-5.md +126 -0
  21. package/plugins/claude-code/skills/admin-template-guidelines/references/rule-6.md +180 -0
  22. package/plugins/claude-code/skills/delphi-review/SKILL.md +59 -361
  23. package/plugins/claude-code/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
  24. package/plugins/claude-code/skills/delphi-review/references/round-templates.md +67 -0
  25. package/plugins/claude-code/skills/ralph-loop/SKILL.md +87 -429
  26. package/plugins/claude-code/skills/ralph-loop/references/components.md +113 -0
  27. package/plugins/claude-code/skills/ralph-loop/references/workflow-details.md +99 -0
  28. package/plugins/claude-code/skills/test-specification-alignment/SKILL.md +97 -599
  29. package/plugins/opencode/package.json +1 -1
  30. package/plugins/opencode/skills/admin-template-guidelines/SKILL.md +6 -797
  31. package/plugins/opencode/skills/admin-template-guidelines/references/rule-1.md +91 -0
  32. package/plugins/opencode/skills/admin-template-guidelines/references/rule-2.md +155 -0
  33. package/plugins/opencode/skills/admin-template-guidelines/references/rule-3.md +70 -0
  34. package/plugins/opencode/skills/admin-template-guidelines/references/rule-4.md +154 -0
  35. package/plugins/opencode/skills/admin-template-guidelines/references/rule-5.md +126 -0
  36. package/plugins/opencode/skills/admin-template-guidelines/references/rule-6.md +180 -0
  37. package/plugins/opencode/skills/delphi-review/SKILL.md +59 -361
  38. package/plugins/opencode/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
  39. package/plugins/opencode/skills/delphi-review/references/round-templates.md +67 -0
  40. package/plugins/opencode/skills/ralph-loop/SKILL.md +87 -429
  41. package/plugins/opencode/skills/ralph-loop/references/components.md +113 -0
  42. package/plugins/opencode/skills/ralph-loop/references/workflow-details.md +99 -0
  43. package/plugins/opencode/skills/test-specification-alignment/SKILL.md +97 -599
  44. package/skills/admin-template-guidelines/SKILL.md +6 -797
  45. package/skills/admin-template-guidelines/references/rule-1.md +91 -0
  46. package/skills/admin-template-guidelines/references/rule-2.md +155 -0
  47. package/skills/admin-template-guidelines/references/rule-3.md +70 -0
  48. package/skills/admin-template-guidelines/references/rule-4.md +154 -0
  49. package/skills/admin-template-guidelines/references/rule-5.md +126 -0
  50. package/skills/admin-template-guidelines/references/rule-6.md +180 -0
  51. package/skills/delphi-review/SKILL.md +59 -361
  52. package/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
  53. package/skills/delphi-review/references/round-templates.md +67 -0
  54. package/skills/ralph-loop/SKILL.md +87 -429
  55. package/skills/ralph-loop/references/components.md +113 -0
  56. package/skills/ralph-loop/references/workflow-details.md +99 -0
  57. package/skills/test-specification-alignment/SKILL.md +97 -599
  58. package/plugins/claude-code/skills/ralph-loop/references/components/memory.md +0 -55
  59. package/plugins/claude-code/skills/ralph-loop/references/components/middleware.md +0 -54
  60. package/plugins/claude-code/skills/ralph-loop/references/components/skill-invocations.md +0 -39
  61. package/plugins/claude-code/skills/ralph-loop/references/components/system-prompt.md +0 -24
  62. package/plugins/claude-code/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
  63. package/plugins/opencode/skills/ralph-loop/references/components/memory.md +0 -55
  64. package/plugins/opencode/skills/ralph-loop/references/components/middleware.md +0 -54
  65. package/plugins/opencode/skills/ralph-loop/references/components/skill-invocations.md +0 -39
  66. package/plugins/opencode/skills/ralph-loop/references/components/system-prompt.md +0 -24
  67. package/plugins/opencode/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
  68. package/skills/ralph-loop/references/components/memory.md +0 -55
  69. package/skills/ralph-loop/references/components/middleware.md +0 -54
  70. package/skills/ralph-loop/references/components/skill-invocations.md +0 -39
  71. package/skills/ralph-loop/references/components/system-prompt.md +0 -24
  72. package/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
@@ -7,30 +7,30 @@ description: "Use when asked to run tests, verify tests, align tests with specif
7
7
 
8
8
  ## Workflow Steps
9
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
10
+ 1. **Load Phase 0** — Verify `specification.yaml` and `tests/` directory exist; BLOCK if missing with guidance to complete brainstorming → delphi-review → specification-generator flow first
11
+ 2. **Phase 1 Alignment (Modify Allowed)** — Parse specification.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 with `@test` annotation; map each AC-* to at least one assertion; verify `@test`, `@intent`, `@covers` tags
13
+ 4. **Pre-Phase 2 Freeze** — Invoke `/freeze` skill to lock test directories; return confirmation before proceeding
14
+ 5. **Phase 2 Execution (Frozen)** — Run all tests; Agent BLOCKED from modifying/deleting/skipping tests; analyze failures into 4 categories
15
+ 6. **Failure Classification** — For each failing test, output with Type, Test, Root Cause, Action fields; SPECIFICATION_ERROR requires ESCALATE_TO_HUMAN with 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
17
17
 
18
18
  ## 核心原则
19
19
 
20
20
  **测试是系统的防护网,也是系统的使用手册。测试必须准确反映原始需求和设计方案。**
21
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 绝对禁止修改/删除/跳过测试
22
+ | 特性 | 说明 |
23
+ |------|------|
24
+ | **两阶段分离** | Phase 1 可修改测试对齐,Phase 2 禁止修改测试执行 |
25
+ | **结构化验证** | YAML specification + AST 解析,确定性验证 |
26
+ | **freeze 约束** | Phase 2 调用 freeze skill 锁定测试目录 |
27
+ | **失败分类** | 业务代码/测试数据/Specification/环境 四类错误分流 |
28
+ | **零容忍** | Phase 2 绝对禁止修改/删除/跳过测试 |
29
29
 
30
30
  ---
31
31
 
32
32
  ## Output Format (MANDATORY)
33
- Alignment report MUST be output as valid JSON:
33
+
34
34
  ```json
35
35
  {
36
36
  "alignment_status": "PASS|FAIL|BLOCKED",
@@ -43,660 +43,158 @@ Alignment report MUST be output as valid JSON:
43
43
  "errors": []
44
44
  }
45
45
  ```
46
+
46
47
  **Eval assertions check for:** `alignment_status`, `phase`, `score`, `anti_pattern_detected`.
47
48
 
48
49
  ---
49
50
 
50
51
  ## Triggers
51
52
 
52
- ### Automatic Triggers
53
+ ### Automatic
53
54
  - BUILD (TDD + review) Round 1 after Driver outputs tests
54
55
  - Gate 1 verification before proceeding
55
56
  - gstack-ship release before deployment
56
57
 
57
- ### Manual Triggers
58
- - `/test-specification-alignment` command
59
- - `/verify-tests` command
60
- - "run tests" phrase
61
- - "verify tests" phrase
62
- - before gstack-ship
58
+ ### Manual
59
+ - `/test-specification-alignment`, `/verify-tests`, "run tests", "verify tests"
63
60
 
64
61
  ---
65
62
 
66
63
  ## Scope
67
64
 
68
65
  ### 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
66
+ - Validation of test alignment against `specification.yaml`
67
+ - Phase 1: Test modification to improve alignment
68
+ - Phase 2: Test execution with frozen test files
69
+ - Failure classification (BUSINESS_CODE_ERROR, TEST_DATA_ERROR, SPECIFICATION_ERROR, ENVIRONMENT_ERROR)
70
+ - JSON report generation
74
71
 
75
72
  ### OUT Scope
76
73
  - 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)
74
+ - Skipping/deleting/skipping tests
75
+ - Modifying test assertions to force passes
76
+ - Business logic implementation (BUILD phase)
77
+ - Environment configuration
81
78
 
82
79
  ### Boundaries
83
80
  - **Start**: After BUILD (TDD + review) Round 1 outputs tests
84
- - **End**: Terminal State ✅ ALL_TESTS_PASS or ESCALATE_TO_HUMAN for specification issues
81
+ - **End**: Terminal State ✅ ALL_TESTS_PASS or ESCALATE_TO_HUMAN
85
82
  - **Inputs**: `specification.yaml`, `tests/` directory
86
83
  - **Outputs**: Alignment report (JSON), test execution report, failure classification
87
84
 
88
85
  ---
89
86
 
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
87
  ## 核心流程
171
88
 
172
89
  ```
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
- ---
90
+ Phase 0: 准备
91
+ ├─ 验证 specification.yaml 存在
92
+ ├─ 验证 tests/ 目录存在
93
+ └─ ❌ 缺失 → BLOCK + 提示用户
212
94
 
213
- ## ⚠️ Phase 0 缺失 Specification 处理
95
+ Phase 1: 对齐验证 (可修改测试)
96
+ ├─ 解析 specification.yaml (YAML parser)
97
+ ├─ 解析测试文件 (AST parser)
98
+ ├─ 验证对齐规则
99
+ └─ (可选) 修复测试
214
100
 
215
- ### 错误提示格式
101
+ Checkpoint: Alignment Score >= 80%?
102
+ ├─ NO → BLOCK
103
+ └─ YES → 继续
216
104
 
217
- 如果 `specification.yaml` 不存在,必须 BLOCK 并提供清晰的流程指引:
105
+ Pre-Phase 2: 调用 freeze skill 锁定测试目录
218
106
 
219
- ```
220
- BLOCKED: specification.yaml 不存在
221
-
222
- 要生成 specification.yaml,请先完成需求流程:
107
+ Phase 2: 执行测试 (禁止修改测试)
108
+ ├─ 运行所有测试
109
+ ├─ IF Agent 尝试修改测试 → freeze 拦截
110
+ ├─ 失败分析: 业务代码/测试数据/Specification/环境
111
+ │ └─ Specification 错误 → ESCALATE_TO_HUMAN
112
+ └─ 全部通过 → 继续
223
113
 
224
- 流程步骤:
225
- 1. brainstorming → 需求探索,生成设计文档
226
- 2. delphi-review → 需求评审(多轮直到 APPROVED)
227
- 3. spec 自动生成(从 APPROVED 设计文档提取 specification.yaml)
114
+ ⭐ Post-Phase 2: 调用 unfreeze skill
228
115
 
229
- 为什么必须这样?
230
- - 在 delphi-review APPROVED 后生成,避免设计文档修改时 spec 也需重新生成
231
- - 遵循"问题发现越早修复成本越低"原则
232
-
233
- 请先完成上述流程,然后再运行 test-specification-alignment。
116
+ Terminal State: ✅ ALL_TESTS_PASS
234
117
  ```
235
118
 
236
119
  ---
237
120
 
238
121
  ## 强制对齐规则
239
122
 
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
- | 维度 | 权重 | 验证内容 |
123
+ | 规则 | 说明 | 语言示例 |
301
124
  |------|------|----------|
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%**
125
+ | **每个 REQ 必须有测试** | 每个 REQ-* 对应至少一个 test case | TS: `@test REQ-AUTH-001` / Py: `# @test REQ-AUTH-001` / Go: `// @test REQ-AUTH-001` |
126
+ | **每个 AC 必须有断言** | 每个 AC-* 必须有对应断言覆盖 | `// AC-AUTH-001-01: 返回 200` → `expect(response.status).toBe(200)` |
127
+ | **测试意图声明** | 每个 test case 必须有 `@test`, `@intent`, `@covers` 标签 | 详见 `references/specification-format.md` |
309
128
 
310
129
  ---
311
130
 
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: 解锁测试目录
131
+ ## Failure Classification
368
132
 
369
- ```yaml
370
- post_phase2:
371
- action: "INVOKE unfreeze skill"
372
- result: "测试目录解除冻结,允许后续修改"
373
- ```
374
-
375
- ---
376
-
377
- ## 失败分析分类
378
-
379
- | 失败类型 | 判断依据 | 处理方式 |
380
- |----------|----------|----------|
133
+ | 类型 | 判断依据 | 处理方式 |
134
+ |------|----------|----------|
381
135
  | **BUSINESS_CODE_ERROR** | 测试正确,业务代码有 bug | 修改业务代码 |
382
136
  | **TEST_DATA_ERROR** | 测试数据不符合业务逻辑 | 回滚到 Phase 1 |
383
137
  | **SPECIFICATION_ERROR** | 测试正确,但 specification 有误 | ESCALATE_TO_HUMAN |
384
138
  | **ENVIRONMENT_ERROR** | 环境/依赖问题 | 修复环境配置 |
385
139
 
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 集成
140
+ ### Specification 错误处理选项
455
141
 
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` 解锁
142
+ - **A**: 修正 Specification → 重新 Phase 1 (unfreeze tests)
143
+ - **B**: 确认 Specification 正确 → 修改业务代码 (用户明确授权)
144
+ - **C**: 补充 Specification 澄清歧义 (unfreeze tests)
484
145
 
485
146
  ---
486
147
 
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
- ```
148
+ ## State Machine
503
149
 
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
- ```
150
+ | State | Description |
151
+ |-------|------------|
152
+ | 0 IDLE | Initial |
153
+ | 1 PHASE0_PREPARING | Preparing |
154
+ | 3 PHASE1_ALIGNING | Aligning |
155
+ | 6 PHASE1_COMPLETE | Alignment done |
156
+ | 7 PRE_PHASE2_FREEZE | Freeze test dirs |
157
+ | 9 PHASE2_EXECUTING | Running tests |
158
+ | 12 PHASE2_FIXING_CODE | Fixing business code |
159
+ | 14 PHASE2_COMPLETE | Tests passed |
160
+ | 15 POST_PHASE2_UNFREEZE | Unfreeze test dirs |
161
+ | 16 ALL_TESTS_PASS | ✅ Done |
162
+ | 90 BLOCKED_MISSING_SPECIFICATION | Missing specification |
163
+ | 93 BLOCKED_SPECIFICATION_ISSUE | Spec issue needs user |
164
+ | 94 BLOCKED_MAX_RETRIES_EXCEEDED | Max retries hit |
520
165
 
521
166
  ---
522
167
 
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
- ## 成本控制
168
+ ## Anti-Patterns
617
169
 
618
- | 指标 | 阈值 |
619
- |------|------|
620
- | 单次对齐验证 | ~$0.02 |
621
- | 单次测试执行 | ~$0.01 |
622
- | 最大重试次数 | 5 |
623
- | 单次总成本上限 | $0.10 |
170
+ | Error | Correct |
171
+ |---------|-----------|
172
+ | Phase 2 修改/删除测试文件 | 只能修改业务代码 |
173
+ | Phase 2 跳过测试 (skip/xit) | 检测并拒绝 |
174
+ | 测试失败时修改断言 | 必须修改业务代码 |
175
+ | 缺少 @test 标签 | 强制标注 |
176
+ | Specification 错误时强行通过 | 必须 ESCALATE |
624
177
 
625
178
  ---
626
179
 
627
180
  ## Terminal State Checklist
628
181
 
629
- <MANDATORY-CHECKLIST>
630
-
631
- ### 只能在以下条件全部满足后声明 "test-specification-alignment complete":
632
-
633
- **Pre-requisites:**
634
182
  - [ ] specification.yaml 存在且可解析
635
183
  - [ ] 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 并记录违规**
184
+ - [ ] Phase 1 对齐验证完成, score ≥ 80%
185
+ - [ ] Pre-Phase 2: freeze skill 已调用
186
+ - [ ] Phase 2: 所有测试已执行, 无修改违规
187
+ - [ ] Post-Phase 2: unfreeze skill 已调用
188
+ - [ ] 所有测试通过, 报告已生成
660
189
 
661
- </MANDATORY-CHECKLIST>
190
+ **IF Specification 问题 → CANNOT claim complete → MUST ESCALATE_TO_HUMAN**
662
191
 
663
192
  ---
664
193
 
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
- ## 版本历史
194
+ ## Details → see `references/`
679
195
 
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`.
196
+ | Topic | File |
197
+ |-------|------|
198
+ | 对齐验证算法 (AST parsing, score calc, legacy mode) | `references/alignment-verification-algorithm.md` |
199
+ | Specification YAML 格式规范 (完整示例) | `references/specification-format.md` |
200
+ | Phase 2 freeze 约束执行机制 (违规日志, 异常处理, 状态转换) | `references/phase2-constraint-enforcement.md` |