@boyingliu01/xp-gate 0.18.5 → 0.19.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 (254) hide show
  1. package/adapter-common.sh +27 -0
  2. package/adapters/gate-3.sh +0 -0
  3. package/adapters/gate-4.sh +0 -0
  4. package/adapters/gate-7.sh +0 -0
  5. package/adapters/gate-8.sh +0 -0
  6. package/adapters/gate-9.sh +0 -0
  7. package/adapters/powershell.sh +85 -33
  8. package/adapters/typescript.sh +8 -8
  9. package/build-integrity/__tests__/import-resolver.test.ts +22 -0
  10. package/build-integrity/__tests__/orchestrator.test.ts +1 -2
  11. package/build-integrity/gate-10.ts +7 -0
  12. package/gate-12-file-hygiene.sh +230 -0
  13. package/hooks/adapter-common.sh +27 -0
  14. package/hooks/gate-10.sh +105 -0
  15. package/hooks/gate-12-file-hygiene.sh +0 -0
  16. package/hooks/lib/validate-code-walkthrough.cjs +125 -0
  17. package/hooks/pre-commit +130 -33
  18. package/hooks/pre-push +15 -91
  19. package/lib/__tests__/check-version.test.js +67 -46
  20. package/lib/__tests__/doctor.test.js +7 -6
  21. package/lib/__tests__/gate-runner.test.js +267 -0
  22. package/lib/__tests__/init.test.js +32 -0
  23. package/lib/__tests__/npm-package.test.js +13 -0
  24. package/lib/__tests__/phase-transition.test.js +604 -12
  25. package/lib/__tests__/sprint-discovery.test.ts +0 -1
  26. package/lib/__tests__/sprint-status-rework.test.js +100 -1
  27. package/lib/__tests__/update-hooks.test.js +143 -10
  28. package/lib/__tests__/upgrade-exec.test.js +73 -45
  29. package/lib/__tests__/upgrade-skill-sync.test.js +1 -1
  30. package/lib/__tests__/upgrade.test.js +12 -11
  31. package/lib/doctor.js +2 -1
  32. package/lib/gate-runner.js +68 -23
  33. package/lib/init.js +34 -5
  34. package/lib/install-skill.js +1 -0
  35. package/lib/mattpocock-license-verdict.json +1 -1
  36. package/lib/phase-transition.js +203 -23
  37. package/lib/shared-paths.js +2 -0
  38. package/lib/sprint-status.js +15 -4
  39. package/lib/test-alignment.ts +3 -13
  40. package/lib/update-hooks.js +129 -15
  41. package/mock-policy/AGENTS.md +5 -5
  42. package/mock-policy/__tests__/gate-m3.test.ts +0 -5
  43. package/mock-policy/__tests__/scope-scanner.test.ts +8 -2
  44. package/mutation/AGENTS.md +4 -4
  45. package/mutation/__tests__/mutmut-runner.test.ts +443 -2
  46. package/mutation/__tests__/update-baseline.test.ts +0 -2
  47. package/mutation/runners/mutmut-runner.ts +67 -17
  48. package/package.json +9 -3
  49. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  50. package/plugins/claude-code/skills/clipboard-vision/SKILL.md +47 -0
  51. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  52. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  53. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  54. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  55. package/plugins/claude-code/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  56. package/plugins/claude-code/skills/clipboard-vision/describe-clipboard.sh +161 -0
  57. package/plugins/claude-code/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  58. package/plugins/claude-code/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  59. package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +24 -27
  60. package/plugins/claude-code/skills/delphi-review/AGENTS.md +13 -12
  61. package/plugins/claude-code/skills/delphi-review/INSTALL.md +15 -17
  62. package/plugins/claude-code/skills/delphi-review/SKILL.md +30 -29
  63. package/plugins/claude-code/skills/delphi-review/opencode.json.delphi.example +6 -10
  64. package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +33 -49
  65. package/plugins/claude-code/skills/delphi-review/references/requirements.md +66 -54
  66. package/plugins/claude-code/skills/delphi-review/references/round-templates.md +7 -7
  67. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +5 -5
  68. package/plugins/claude-code/skills/sprint-flow/SKILL.md +4 -4
  69. package/plugins/claude-code/skills/sprint-flow/references/components/skill-invocations.md +2 -2
  70. package/plugins/claude-code/skills/sprint-flow/references/force-levels.md +37 -35
  71. package/plugins/claude-code/skills/sprint-flow/references/orchestration-rules.md +1 -1
  72. package/plugins/claude-code/skills/sprint-flow/references/phase-1-prep.md +1 -1
  73. package/plugins/claude-code/skills/sprint-flow/references/phase-2-design.md +24 -14
  74. package/plugins/claude-code/skills/sprint-flow/references/phase-4-verify.md +6 -6
  75. package/plugins/claude-code/skills/sprint-flow/references/phase-overview.md +2 -2
  76. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +4 -4
  77. package/plugins/dsh/README.md +25 -0
  78. package/plugins/dsh/cordis.patch.yml +7 -0
  79. package/plugins/dsh/package.json +70 -0
  80. package/plugins/dsh/scripts/prepack.cjs +82 -0
  81. package/plugins/dsh/skills/admin-template-guidelines/SKILL.md +113 -0
  82. package/plugins/dsh/skills/admin-template-guidelines/references/rule-1.md +91 -0
  83. package/plugins/dsh/skills/admin-template-guidelines/references/rule-2.md +155 -0
  84. package/plugins/dsh/skills/admin-template-guidelines/references/rule-3.md +70 -0
  85. package/plugins/dsh/skills/admin-template-guidelines/references/rule-4.md +154 -0
  86. package/plugins/dsh/skills/admin-template-guidelines/references/rule-5.md +126 -0
  87. package/plugins/dsh/skills/admin-template-guidelines/references/rule-6.md +180 -0
  88. package/plugins/dsh/skills/batch-grill-me/SKILL.md +15 -0
  89. package/plugins/dsh/skills/clipboard-vision/SKILL.md +47 -0
  90. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  91. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  92. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  93. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  94. package/plugins/dsh/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  95. package/plugins/dsh/skills/clipboard-vision/describe-clipboard.sh +161 -0
  96. package/plugins/dsh/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  97. package/plugins/dsh/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  98. package/plugins/dsh/skills/delphi-review/.delphi-config.json.example +70 -0
  99. package/plugins/dsh/skills/delphi-review/AGENTS.md +67 -0
  100. package/plugins/dsh/skills/delphi-review/INSTALL.md +150 -0
  101. package/plugins/dsh/skills/delphi-review/SKILL.md +559 -0
  102. package/plugins/dsh/skills/delphi-review/hooks.md +19 -0
  103. package/plugins/dsh/skills/delphi-review/opencode.json.delphi.example +52 -0
  104. package/plugins/dsh/skills/delphi-review/references/code-walkthrough.md +470 -0
  105. package/plugins/dsh/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
  106. package/plugins/dsh/skills/delphi-review/references/requirements.md +402 -0
  107. package/plugins/dsh/skills/delphi-review/references/round-templates.md +134 -0
  108. package/plugins/dsh/skills/delphi-review/scripts/verify-consensus.sh +43 -0
  109. package/plugins/dsh/skills/delphi-review/tools.md +29 -0
  110. package/plugins/dsh/skills/domain-modeling/ADR-FORMAT.md +64 -0
  111. package/plugins/dsh/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  112. package/plugins/dsh/skills/domain-modeling/SKILL.md +74 -0
  113. package/plugins/dsh/skills/grill-with-docs/SKILL.md +7 -0
  114. package/plugins/dsh/skills/grilling/SKILL.md +12 -0
  115. package/plugins/dsh/skills/improve-codebase-architecture/SKILL.md +156 -0
  116. package/plugins/dsh/skills/ralph-loop/SKILL.md +198 -0
  117. package/plugins/dsh/skills/ralph-loop/references/components.md +113 -0
  118. package/plugins/dsh/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  119. package/plugins/dsh/skills/ralph-loop/references/workflow-details.md +99 -0
  120. package/plugins/dsh/skills/ralph-loop/templates/progress-log.md +36 -0
  121. package/plugins/dsh/skills/sprint-flow/AGENTS.md +103 -0
  122. package/plugins/dsh/skills/sprint-flow/SKILL.md +411 -0
  123. package/plugins/dsh/skills/sprint-flow/__tests__/sprint-flow.test.cjs +457 -0
  124. package/plugins/dsh/skills/sprint-flow/hooks.md +18 -0
  125. package/plugins/dsh/skills/sprint-flow/references/components/memory.md +87 -0
  126. package/plugins/dsh/skills/sprint-flow/references/components/middleware.md +75 -0
  127. package/plugins/dsh/skills/sprint-flow/references/components/skill-invocations.md +105 -0
  128. package/plugins/dsh/skills/sprint-flow/references/components/system-prompt.md +27 -0
  129. package/plugins/dsh/skills/sprint-flow/references/components/tool-descriptions.md +95 -0
  130. package/plugins/dsh/skills/sprint-flow/references/force-levels.md +204 -0
  131. package/plugins/dsh/skills/sprint-flow/references/orchestration-rules.md +236 -0
  132. package/plugins/dsh/skills/sprint-flow/references/phase-1-prep.md +294 -0
  133. package/plugins/dsh/skills/sprint-flow/references/phase-2-design.md +273 -0
  134. package/plugins/dsh/skills/sprint-flow/references/phase-3-build.md +348 -0
  135. package/plugins/dsh/skills/sprint-flow/references/phase-4-verify.md +225 -0
  136. package/plugins/dsh/skills/sprint-flow/references/phase-5-ship.md +222 -0
  137. package/plugins/dsh/skills/sprint-flow/references/phase-6-close.md +266 -0
  138. package/plugins/dsh/skills/sprint-flow/references/phase-overview.md +486 -0
  139. package/plugins/dsh/skills/sprint-flow/scripts/verify-sprint-state.sh +38 -0
  140. package/plugins/dsh/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  141. package/plugins/dsh/skills/sprint-flow/templates/auto-estimate-output-template.md +110 -0
  142. package/plugins/dsh/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  143. package/plugins/dsh/skills/sprint-flow/templates/pain-document-template.md +115 -0
  144. package/plugins/dsh/skills/sprint-flow/templates/sprint-progress-template.md +140 -0
  145. package/plugins/dsh/skills/sprint-flow/templates/sprint-summary-template.md +121 -0
  146. package/plugins/dsh/skills/sprint-flow/tools.md +29 -0
  147. package/plugins/dsh/skills/test-driven-development/SKILL.md +371 -0
  148. package/plugins/dsh/skills/test-driven-development/testing-anti-patterns.md +299 -0
  149. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +56 -0
  150. package/plugins/dsh/skills/test-specification-alignment/SKILL.md +205 -0
  151. package/plugins/dsh/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  152. package/plugins/dsh/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  153. package/plugins/dsh/skills/test-specification-alignment/references/specification-format.md +348 -0
  154. package/plugins/dsh/skills/to-issues/SKILL.md +277 -0
  155. package/plugins/dsh/src/command.test.ts +102 -0
  156. package/plugins/dsh/src/command.ts +75 -0
  157. package/plugins/dsh/src/contract.test.ts +62 -0
  158. package/plugins/dsh/src/gate-runner.test.ts +100 -0
  159. package/plugins/dsh/src/gate-runner.ts +58 -0
  160. package/plugins/dsh/src/index.test.ts +97 -0
  161. package/plugins/dsh/src/index.ts +94 -0
  162. package/plugins/dsh/src/skills.test.ts +58 -0
  163. package/plugins/dsh/tsconfig.build.json +13 -0
  164. package/plugins/dsh/tsconfig.json +19 -0
  165. package/plugins/dsh/vitest.config.ts +8 -0
  166. package/plugins/opencode/package.json +1 -1
  167. package/plugins/opencode/scripts/prepack.cjs +1 -0
  168. package/plugins/opencode/skills/clipboard-vision/SKILL.md +47 -0
  169. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  170. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  171. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  172. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  173. package/plugins/opencode/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  174. package/plugins/opencode/skills/clipboard-vision/describe-clipboard.sh +161 -0
  175. package/plugins/opencode/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  176. package/plugins/opencode/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  177. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +24 -27
  178. package/plugins/opencode/skills/delphi-review/AGENTS.md +13 -12
  179. package/plugins/opencode/skills/delphi-review/INSTALL.md +15 -17
  180. package/plugins/opencode/skills/delphi-review/SKILL.md +30 -29
  181. package/plugins/opencode/skills/delphi-review/opencode.json.delphi.example +6 -10
  182. package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +33 -49
  183. package/plugins/opencode/skills/delphi-review/references/requirements.md +66 -54
  184. package/plugins/opencode/skills/delphi-review/references/round-templates.md +7 -7
  185. package/plugins/opencode/skills/sprint-flow/AGENTS.md +5 -5
  186. package/plugins/opencode/skills/sprint-flow/SKILL.md +4 -4
  187. package/plugins/opencode/skills/sprint-flow/references/components/skill-invocations.md +2 -2
  188. package/plugins/opencode/skills/sprint-flow/references/force-levels.md +37 -35
  189. package/plugins/opencode/skills/sprint-flow/references/orchestration-rules.md +1 -1
  190. package/plugins/opencode/skills/sprint-flow/references/phase-1-prep.md +1 -1
  191. package/plugins/opencode/skills/sprint-flow/references/phase-2-design.md +24 -14
  192. package/plugins/opencode/skills/sprint-flow/references/phase-4-verify.md +6 -6
  193. package/plugins/opencode/skills/sprint-flow/references/phase-overview.md +2 -2
  194. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +4 -4
  195. package/plugins/qoder/plugin.json +1 -1
  196. package/plugins/qoder/skills/clipboard-vision/SKILL.md +47 -0
  197. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  198. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  199. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  200. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  201. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/SKILL.md +47 -0
  202. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  203. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  204. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  205. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  206. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  207. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  208. package/plugins/qoder/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  209. package/plugins/qoder/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  210. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +3 -11
  211. package/plugins/qoder/skills/delphi-review/AGENTS.md +15 -17
  212. package/plugins/qoder/skills/delphi-review/INSTALL.md +12 -12
  213. package/plugins/qoder/skills/delphi-review/SKILL.md +58 -25
  214. package/plugins/qoder/skills/delphi-review/opencode.json.delphi.example +1 -1
  215. package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +33 -49
  216. package/plugins/qoder/skills/sprint-flow/AGENTS.md +5 -5
  217. package/plugins/qoder/skills/sprint-flow/SKILL.md +2 -2
  218. package/plugins/qoder/skills/sprint-flow/references/force-levels.md +38 -35
  219. package/plugins/qoder/skills/sprint-flow/references/phase-1-prep.md +1 -1
  220. package/plugins/qoder/skills/sprint-flow/references/phase-2-design.md +48 -6
  221. package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +5 -6
  222. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +4 -4
  223. package/principles/AGENTS.md +4 -4
  224. package/scripts/__tests__/sync-package-content.test.js +30 -0
  225. package/scripts/delphi-external-review.cjs +194 -63
  226. package/scripts/sync-package-content.js +9 -2
  227. package/skills/clipboard-vision/SKILL.md +47 -0
  228. package/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  229. package/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  230. package/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  231. package/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  232. package/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  233. package/skills/clipboard-vision/describe-clipboard.sh +161 -0
  234. package/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  235. package/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  236. package/skills/delphi-review/.delphi-config.json.example +24 -27
  237. package/skills/delphi-review/AGENTS.md +13 -12
  238. package/skills/delphi-review/INSTALL.md +15 -17
  239. package/skills/delphi-review/SKILL.md +30 -29
  240. package/skills/delphi-review/opencode.json.delphi.example +6 -10
  241. package/skills/delphi-review/references/code-walkthrough.md +33 -49
  242. package/skills/delphi-review/references/requirements.md +66 -54
  243. package/skills/delphi-review/references/round-templates.md +7 -7
  244. package/skills/sprint-flow/AGENTS.md +5 -5
  245. package/skills/sprint-flow/SKILL.md +4 -4
  246. package/skills/sprint-flow/references/components/skill-invocations.md +2 -2
  247. package/skills/sprint-flow/references/force-levels.md +37 -35
  248. package/skills/sprint-flow/references/orchestration-rules.md +1 -1
  249. package/skills/sprint-flow/references/phase-1-prep.md +1 -1
  250. package/skills/sprint-flow/references/phase-2-design.md +24 -14
  251. package/skills/sprint-flow/references/phase-4-verify.md +6 -6
  252. package/skills/sprint-flow/references/phase-overview.md +2 -2
  253. package/skills/test-specification-alignment/AGENTS.md +4 -4
  254. package/sprint-gate.sh +291 -0
@@ -0,0 +1,56 @@
1
+ # SKILLS/TEST-SPECIFICATION-ALIGNMENT KNOWLEDGE BASE
2
+
3
+ **Generated:** 2026-08-24
4
+ **Commit:** a1a4683
5
+ **Branch:** dsh-plugin
6
+ **Version:** 0.19.0.0
7
+
8
+ ## OVERVIEW
9
+ Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
10
+
11
+ ## STRUCTURE
12
+ ```
13
+ skills/test-specification-alignment/
14
+ ├── SKILL.md # Core alignment workflow (2-phase)
15
+ ├── AGENTS.md # This file
16
+ ├── evals/ # Evaluation test cases
17
+ └── references/ # Supporting documentation
18
+ ```
19
+
20
+ ## WHERE TO LOOK
21
+ | Task | Location | Notes |
22
+ |------|----------|-------|
23
+ | Core workflow | SKILL.md | Phase 1 (align) + Phase 2 (execute) |
24
+ | Freeze mechanism | SKILL.md | Prevents test modifications during Phase 2 |
25
+
26
+ ## CONVENTIONS
27
+ - Phase 1 (Align): test modifications ALLOWED to align with specification
28
+ - Phase 2 (Execute): test modifications FORBIDDEN (freeze enforced)
29
+ - Minimum 80% alignment score required to pass
30
+ - All `@test`, `@intent`, `@covers` JSDoc tags mandatory in test files
31
+ - Test annotations trace to REQ-XXX and AC-XXX
32
+
33
+ ## ANTI-PATTERNS (THIS PROJECT)
34
+ - Do NOT modify tests during Phase 2 execution
35
+ - Do NOT proceed with low alignment score (<80%)
36
+ - Do NOT skip specification validation if specification exists
37
+ - Do NOT delete test files in Phase 2 (freeze intercepts)
38
+ - Do NOT modify assertions when tests fail (modify business code instead)
39
+ - Missing @test tags → test rejected
40
+
41
+ ## UNIQUE STYLES
42
+ - Two-phase separation (modify vs. execute)
43
+ - Freeze/unfreeze test protection mechanism
44
+ - YAML specification-driven validation (specification.yaml)
45
+ - Structured JSDoc tag requirements (@test, @intent, @covers)
46
+
47
+ ## COMMANDS
48
+ ```bash
49
+ /test-specification-alignment # Run alignment check
50
+ ```
51
+
52
+ ## NOTES
53
+ - Runs during BUILD (Phase 2) after TDD
54
+ - Mandatory before gstack-ship release
55
+ - Integrates with test-driven-development skill
56
+ - Uses freeze skill to lock test directories during Phase 2
@@ -0,0 +1,205 @@
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 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** — Lock test directories via read-only subagent convention (reviewer tools restricted to `[Read, Grep, Glob]`, no Write/Edit/Bash); 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
+
18
+ ## 核心原则
19
+
20
+ **测试是系统的防护网,也是系统的使用手册。测试必须准确反映原始需求和设计方案。**
21
+
22
+ | 特性 | 说明 |
23
+ |------|------|
24
+ | **两阶段分离** | Phase 1 可修改测试对齐,Phase 2 禁止修改测试执行 |
25
+ | **结构化验证** | YAML specification + AST 解析,确定性验证 |
26
+ | **freeze 约束** | Phase 2 调用 freeze skill 锁定测试目录 |
27
+ | **失败分类** | 业务代码/测试数据/Specification/环境 四类错误分流 |
28
+ | **零容忍** | Phase 2 绝对禁止修改/删除/跳过测试 |
29
+
30
+ ---
31
+
32
+ ## Output Format (MANDATORY)
33
+
34
+ > **MANDATORY FILE OUTPUT**: When invoked, you MUST write this report as valid JSON to the file `.sprint-state/phase-outputs/test-alignment-report.json` in the project root. Stdout output alone is not sufficient — `xp-gate phase-transition 4 completed` validates the file, not the stdout.
35
+
36
+ ```json
37
+ {
38
+ "alignment_status": "PASS|FAIL|BLOCKED",
39
+ "phase": "1|2",
40
+ "score": 85.5,
41
+ "head_commit": "<git rev-parse HEAD output>",
42
+ "spec_hash": "<SHA-256 of specification.yaml if exists, else null>",
43
+ "timestamp": "<ISO 8601>",
44
+ "misaligned_tests": [
45
+ {"test_name": "test_checkout", "spec_requirement": "REQ-003", "gap": "Missing @test annotation"}
46
+ ],
47
+ "anti_pattern_detected": false,
48
+ "errors": []
49
+ }
50
+ ```
51
+
52
+ **Eval assertions check for:** `alignment_status`, `phase`, `score`, `head_commit`, `spec_hash`, `anti_pattern_detected`.
53
+
54
+ ---
55
+
56
+ ## Triggers
57
+
58
+ ### Automatic
59
+ - BUILD (TDD + review) Round 1 after Driver outputs tests
60
+ - Gate 1 verification before proceeding
61
+ - Phase 5 SHIP release before deployment (native phase-5 steps)
62
+
63
+ ### Manual
64
+ - `/test-specification-alignment`, `/verify-tests`, "run tests", "verify tests"
65
+
66
+ ---
67
+
68
+ ## Scope
69
+
70
+ ### IN Scope
71
+ - Validation of test alignment against `specification.yaml`
72
+ - Phase 1: Test modification to improve alignment
73
+ - Phase 2: Test execution with frozen test files
74
+ - Failure classification (BUSINESS_CODE_ERROR, TEST_DATA_ERROR, SPECIFICATION_ERROR, ENVIRONMENT_ERROR)
75
+ - JSON report generation
76
+
77
+ ### OUT Scope
78
+ - Modifying `specification.yaml` during Phase 2 (requires ESCALATE_TO_HUMAN)
79
+ - Skipping/deleting/skipping tests
80
+ - Modifying test assertions to force passes
81
+ - Business logic implementation (BUILD phase)
82
+ - Environment configuration
83
+
84
+ ### Boundaries
85
+ - **Start**: After BUILD (TDD + review) Round 1 outputs tests
86
+ - **End**: Terminal State ✅ ALL_TESTS_PASS or ESCALATE_TO_HUMAN
87
+ - **Inputs**: `specification.yaml`, `tests/` directory
88
+ - **Outputs**: Alignment report (JSON), test execution report, failure classification
89
+
90
+ ---
91
+
92
+ ## 核心流程
93
+
94
+ ```
95
+ Phase 0: 准备
96
+ ├─ 验证 specification.yaml 存在
97
+ ├─ 验证 tests/ 目录存在
98
+ └─ ❌ 缺失 → BLOCK + 提示用户
99
+
100
+ Phase 1: 对齐验证 (可修改测试)
101
+ ├─ 解析 specification.yaml (YAML parser)
102
+ ├─ 解析测试文件 (AST parser)
103
+ ├─ 验证对齐规则
104
+ └─ (可选) 修复测试
105
+
106
+ Checkpoint: Alignment Score >= 80%?
107
+ ├─ NO → BLOCK
108
+ └─ YES → 继续
109
+
110
+ ⭐ Pre-Phase 2: 调用 freeze skill 锁定测试目录
111
+
112
+ Phase 2: 执行测试 (禁止修改测试)
113
+ ├─ 运行所有测试
114
+ ├─ IF Agent 尝试修改测试 → freeze 拦截
115
+ ├─ 失败分析: 业务代码/测试数据/Specification/环境
116
+ │ └─ Specification 错误 → ESCALATE_TO_HUMAN
117
+ └─ 全部通过 → 继续
118
+
119
+ ⭐ Post-Phase 2: 调用 unfreeze skill
120
+
121
+ Terminal State: ✅ ALL_TESTS_PASS
122
+ ```
123
+
124
+ ---
125
+
126
+ ## 强制对齐规则
127
+
128
+ | 规则 | 说明 | 语言示例 |
129
+ |------|------|----------|
130
+ | **每个 REQ 必须有测试** | 每个 REQ-* 对应至少一个 test case | TS: `@test REQ-AUTH-001` / Py: `# @test REQ-AUTH-001` / Go: `// @test REQ-AUTH-001` |
131
+ | **每个 AC 必须有断言** | 每个 AC-* 必须有对应断言覆盖 | `// AC-AUTH-001-01: 返回 200` → `expect(response.status).toBe(200)` |
132
+ | **测试意图声明** | 每个 test case 必须有 `@test`, `@intent`, `@covers` 标签 | 详见 `references/specification-format.md` |
133
+
134
+ ---
135
+
136
+ ## Failure Classification
137
+
138
+ | 类型 | 判断依据 | 处理方式 |
139
+ |------|----------|----------|
140
+ | **BUSINESS_CODE_ERROR** | 测试正确,业务代码有 bug | 修改业务代码 |
141
+ | **TEST_DATA_ERROR** | 测试数据不符合业务逻辑 | 回滚到 Phase 1 |
142
+ | **SPECIFICATION_ERROR** | 测试正确,但 specification 有误 | ESCALATE_TO_HUMAN |
143
+ | **ENVIRONMENT_ERROR** | 环境/依赖问题 | 修复环境配置 |
144
+
145
+ ### Specification 错误处理选项
146
+
147
+ - **A**: 修正 Specification → 重新 Phase 1 (unfreeze tests)
148
+ - **B**: 确认 Specification 正确 → 修改业务代码 (用户明确授权)
149
+ - **C**: 补充 Specification 澄清歧义 (unfreeze tests)
150
+
151
+ ---
152
+
153
+ ## State Machine
154
+
155
+ | State | Description |
156
+ |-------|------------|
157
+ | 0 IDLE | Initial |
158
+ | 1 PHASE0_PREPARING | Preparing |
159
+ | 3 PHASE1_ALIGNING | Aligning |
160
+ | 6 PHASE1_COMPLETE | Alignment done |
161
+ | 7 PRE_PHASE2_FREEZE | Freeze test dirs |
162
+ | 9 PHASE2_EXECUTING | Running tests |
163
+ | 12 PHASE2_FIXING_CODE | Fixing business code |
164
+ | 14 PHASE2_COMPLETE | Tests passed |
165
+ | 15 POST_PHASE2_UNFREEZE | Unfreeze test dirs |
166
+ | 16 ALL_TESTS_PASS | ✅ Done |
167
+ | 90 BLOCKED_MISSING_SPECIFICATION | Missing specification |
168
+ | 93 BLOCKED_SPECIFICATION_ISSUE | Spec issue needs user |
169
+ | 94 BLOCKED_MAX_RETRIES_EXCEEDED | Max retries hit |
170
+
171
+ ---
172
+
173
+ ## Anti-Patterns
174
+
175
+ | ❌ Error | ✅ Correct |
176
+ |---------|-----------|
177
+ | Phase 2 修改/删除测试文件 | 只能修改业务代码 |
178
+ | Phase 2 跳过测试 (skip/xit) | 检测并拒绝 |
179
+ | 测试失败时修改断言 | 必须修改业务代码 |
180
+ | 缺少 @test 标签 | 强制标注 |
181
+ | Specification 错误时强行通过 | 必须 ESCALATE |
182
+
183
+ ---
184
+
185
+ ## Terminal State Checklist
186
+
187
+ - [ ] specification.yaml 存在且可解析
188
+ - [ ] tests/ 目录存在且有测试文件
189
+ - [ ] Phase 1 对齐验证完成, score ≥ 80%
190
+ - [ ] Pre-Phase 2: freeze skill 已调用
191
+ - [ ] Phase 2: 所有测试已执行, 无修改违规
192
+ - [ ] Post-Phase 2: unfreeze skill 已调用
193
+ - [ ] 所有测试通过, 报告已生成
194
+
195
+ **IF Specification 问题 → CANNOT claim complete → MUST ESCALATE_TO_HUMAN**
196
+
197
+ ---
198
+
199
+ ## Details → see `references/`
200
+
201
+ | Topic | File |
202
+ |-------|------|
203
+ | 对齐验证算法 (AST parsing, score calc, legacy mode) | `references/alignment-verification-algorithm.md` |
204
+ | Specification YAML 格式规范 (完整示例) | `references/specification-format.md` |
205
+ | Phase 2 freeze 约束执行机制 (违规日志, 异常处理, 状态转换) | `references/phase2-constraint-enforcement.md` |