pi-maestro-flow 0.2.0 → 0.3.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 (235) hide show
  1. package/README.md +44 -72
  2. package/agents/cross-role-reviewer.md +1 -1
  3. package/agents/impeccable-agent.md +1 -1
  4. package/agents/ralph-executor.md +1 -1
  5. package/agents/team-worker.md +1 -1
  6. package/agents/workflow-analyzer.md +1 -1
  7. package/agents/workflow-codebase-mapper.md +1 -1
  8. package/agents/workflow-collab-planner.md +1 -1
  9. package/agents/workflow-debugger.md +1 -1
  10. package/agents/workflow-executor.md +1 -1
  11. package/agents/workflow-integration-checker.md +1 -1
  12. package/agents/workflow-nyquist-auditor.md +1 -1
  13. package/agents/workflow-phase-researcher.md +1 -1
  14. package/agents/workflow-planner.md +1 -1
  15. package/agents/workflow-project-researcher.md +1 -1
  16. package/agents/workflow-reviewer.md +1 -1
  17. package/agents/workflow-verifier.md +1 -1
  18. package/package.json +13 -4
  19. package/skills/codify-to-knowhow/SKILL.md +1 -1
  20. package/skills/delegation-check/SKILL.md +1 -1
  21. package/skills/domain-add/SKILL.md +5 -7
  22. package/skills/insight-challenge/SKILL.md +1 -1
  23. package/skills/learn-decompose/SKILL.md +4 -4
  24. package/skills/learn-follow/SKILL.md +5 -5
  25. package/skills/learn-investigate/SKILL.md +5 -5
  26. package/skills/learn-second-opinion/SKILL.md +5 -5
  27. package/skills/maestro/SKILL.md +9 -10
  28. package/skills/maestro-amend/SKILL.md +3 -3
  29. package/skills/maestro-analyze/SKILL.md +10 -13
  30. package/skills/maestro-blueprint/SKILL.md +8 -11
  31. package/skills/maestro-brainstorm/SKILL.md +11 -14
  32. package/skills/maestro-collab/SKILL.md +4 -4
  33. package/skills/maestro-companion/SKILL.md +3 -3
  34. package/skills/maestro-composer/SKILL.md +11 -12
  35. package/skills/maestro-execute/SKILL.md +9 -12
  36. package/skills/maestro-fork/SKILL.md +8 -11
  37. package/skills/maestro-grill/SKILL.md +13 -16
  38. package/skills/maestro-guard/SKILL.md +5 -5
  39. package/skills/maestro-help/SKILL.md +3 -3
  40. package/skills/maestro-impeccable/SKILL.md +7 -7
  41. package/skills/maestro-init/SKILL.md +9 -12
  42. package/skills/maestro-merge/SKILL.md +6 -8
  43. package/skills/maestro-milestone-audit/SKILL.md +3 -5
  44. package/skills/maestro-milestone-complete/SKILL.md +9 -12
  45. package/skills/maestro-milestone-release/SKILL.md +9 -11
  46. package/skills/maestro-next/SKILL.md +5 -5
  47. package/skills/maestro-overlay/SKILL.md +16 -16
  48. package/skills/maestro-plan/SKILL.md +9 -12
  49. package/skills/maestro-player/SKILL.md +5 -5
  50. package/skills/maestro-quick/SKILL.md +5 -7
  51. package/skills/maestro-ralph/SKILL.md +16 -17
  52. package/skills/maestro-ralph-cli/SKILL.md +6 -6
  53. package/skills/maestro-ralph-cli-execute/SKILL.md +2 -2
  54. package/skills/maestro-ralph-execute/SKILL.md +4 -4
  55. package/skills/maestro-ralph-v2/SKILL.md +18 -19
  56. package/skills/maestro-roadmap/SKILL.md +8 -9
  57. package/skills/maestro-swarm-workflow/SKILL.md +9 -9
  58. package/skills/maestro-tools-execute/SKILL.md +5 -7
  59. package/skills/maestro-tools-register/SKILL.md +7 -9
  60. package/skills/maestro-ui-codify/SKILL.md +9 -10
  61. package/skills/maestro-universal-workflow/SKILL.md +15 -15
  62. package/skills/maestro-update/SKILL.md +10 -10
  63. package/skills/manage-codebase-rebuild/SKILL.md +4 -6
  64. package/skills/manage-drift-realign/SKILL.md +8 -11
  65. package/skills/manage-harvest/SKILL.md +6 -9
  66. package/skills/manage-issue/SKILL.md +5 -8
  67. package/skills/manage-issue-discover/SKILL.md +8 -11
  68. package/skills/manage-kg-extractors/SKILL.md +3 -3
  69. package/skills/manage-knowhow/SKILL.md +3 -5
  70. package/skills/manage-knowhow-capture/SKILL.md +4 -6
  71. package/skills/manage-knowledge-audit/SKILL.md +6 -9
  72. package/skills/manage-status/SKILL.md +3 -5
  73. package/skills/manage-wiki/SKILL.md +5 -7
  74. package/skills/odyssey-debug/SKILL.md +13 -13
  75. package/skills/odyssey-improve/SKILL.md +15 -15
  76. package/skills/odyssey-planex/SKILL.md +16 -16
  77. package/skills/odyssey-review-test-fix/SKILL.md +11 -11
  78. package/skills/odyssey-ui/SKILL.md +10 -10
  79. package/skills/prompt-generator/SKILL.md +5 -5
  80. package/skills/quality-auto-test/SKILL.md +3 -5
  81. package/skills/quality-debug/SKILL.md +3 -5
  82. package/skills/quality-refactor/SKILL.md +3 -5
  83. package/skills/quality-retrospective/SKILL.md +10 -13
  84. package/skills/quality-review/SKILL.md +5 -8
  85. package/skills/quality-sync/SKILL.md +3 -5
  86. package/skills/quality-test/SKILL.md +4 -6
  87. package/skills/scholar-anti-ai-writing/SKILL.md +1 -1
  88. package/skills/scholar-citation-verify/SKILL.md +1 -1
  89. package/skills/scholar-experiment/SKILL.md +2 -2
  90. package/skills/scholar-ideation/SKILL.md +7 -7
  91. package/skills/scholar-latex-organizer/SKILL.md +1 -1
  92. package/skills/scholar-publish/SKILL.md +3 -3
  93. package/skills/scholar-rebuttal-pro/SKILL.md +3 -3
  94. package/skills/scholar-review/SKILL.md +1 -1
  95. package/skills/scholar-writing/SKILL.md +1 -1
  96. package/skills/security-audit/SKILL.md +2 -4
  97. package/skills/skill-generator/SKILL.md +3 -3
  98. package/skills/skill-iter-tune/SKILL.md +3 -3
  99. package/skills/skill-simplify/SKILL.md +1 -1
  100. package/skills/skill-tuning/SKILL.md +1 -1
  101. package/skills/spec-add/SKILL.md +5 -7
  102. package/skills/spec-load/SKILL.md +3 -5
  103. package/skills/spec-remove/SKILL.md +4 -6
  104. package/skills/spec-setup/SKILL.md +6 -8
  105. package/skills/team-adversarial-swarm/SKILL.md +5 -5
  106. package/skills/team-arch-opt/SKILL.md +2 -2
  107. package/skills/team-brainstorm/SKILL.md +3 -3
  108. package/skills/team-coordinate/SKILL.md +4 -4
  109. package/skills/team-designer/SKILL.md +1 -1
  110. package/skills/team-executor/SKILL.md +3 -3
  111. package/skills/team-frontend/SKILL.md +2 -2
  112. package/skills/team-frontend-debug/SKILL.md +3 -3
  113. package/skills/team-interactive-craft/SKILL.md +2 -2
  114. package/skills/team-issue/SKILL.md +3 -3
  115. package/skills/team-lifecycle-v4/SKILL.md +4 -4
  116. package/skills/team-motion-design/SKILL.md +2 -2
  117. package/skills/team-perf-opt/SKILL.md +3 -3
  118. package/skills/team-planex/SKILL.md +2 -2
  119. package/skills/team-quality-assurance/SKILL.md +3 -3
  120. package/skills/team-review/SKILL.md +3 -3
  121. package/skills/team-roadmap-dev/SKILL.md +3 -3
  122. package/skills/team-swarm/SKILL.md +4 -4
  123. package/skills/team-tech-debt/SKILL.md +2 -2
  124. package/skills/team-testing/SKILL.md +3 -3
  125. package/skills/team-ui-polish/SKILL.md +2 -2
  126. package/skills/team-uidesign/SKILL.md +2 -2
  127. package/skills/team-ultra-analyze/SKILL.md +4 -4
  128. package/skills/team-ux-improve/SKILL.md +3 -3
  129. package/skills/team-visual-a11y/SKILL.md +2 -2
  130. package/skills/workflow-skill-designer/SKILL.md +8 -8
  131. package/templates/business-test-report.json +68 -0
  132. package/templates/config.json +48 -0
  133. package/templates/context.md +16 -0
  134. package/templates/doc-index.json +11 -0
  135. package/templates/index.json +68 -0
  136. package/templates/issue.json +36 -0
  137. package/templates/plan.json +38 -0
  138. package/templates/project.md +60 -0
  139. package/templates/reflection-log.md +20 -0
  140. package/templates/roadmap.md +45 -0
  141. package/templates/scratch-index.json +19 -0
  142. package/templates/search-tool.json +1 -0
  143. package/templates/search-tools.md +47 -0
  144. package/templates/state.json +18 -0
  145. package/templates/task-summary.md +21 -0
  146. package/templates/task.json +89 -0
  147. package/templates/terminology-template.json +22 -0
  148. package/templates/uat.md +21 -0
  149. package/templates/validation.json +31 -0
  150. package/templates/verification.json +37 -0
  151. package/templates/workflow.md +14 -0
  152. package/templates/worktree-scope.json +9 -0
  153. package/templates/worktrees.json +26 -0
  154. package/workflows/agy-instructions.md +156 -0
  155. package/workflows/analyze.md +768 -0
  156. package/workflows/auto-test.md +705 -0
  157. package/workflows/blueprint.md +406 -0
  158. package/workflows/boundary-grill.md +50 -0
  159. package/workflows/brainstorm.md +508 -0
  160. package/workflows/business-test.md +574 -0
  161. package/workflows/chinese-response.md +25 -0
  162. package/workflows/claude-instructions.md +167 -0
  163. package/workflows/codebase-rebuild.md +267 -0
  164. package/workflows/codebase-refresh.md +168 -0
  165. package/workflows/codex-instructions.md +156 -0
  166. package/workflows/coding-philosophy.md +70 -0
  167. package/workflows/command-authoring.md +823 -0
  168. package/workflows/debug.md +409 -0
  169. package/workflows/delegate-usage.md +99 -0
  170. package/workflows/domain-add.md +121 -0
  171. package/workflows/drift-realign.md +396 -0
  172. package/workflows/execute.md +631 -0
  173. package/workflows/explore-usage.md +93 -0
  174. package/workflows/finish-work.md +124 -0
  175. package/workflows/fork.md +162 -0
  176. package/workflows/grill.md +494 -0
  177. package/workflows/harvest.md +478 -0
  178. package/workflows/impeccable.md +168 -0
  179. package/workflows/init.md +157 -0
  180. package/workflows/instruction-authoring-guide.md +97 -0
  181. package/workflows/integration-test.md +186 -0
  182. package/workflows/interview-mechanics.md +8 -0
  183. package/workflows/issue-analyze.md +20 -0
  184. package/workflows/issue-discover.md +238 -0
  185. package/workflows/issue-execute.md +110 -0
  186. package/workflows/issue-gaps-analyze.codex.md +256 -0
  187. package/workflows/issue-gaps-analyze.md +215 -0
  188. package/workflows/issue-plan.md +110 -0
  189. package/workflows/issue.md +338 -0
  190. package/workflows/knowhow.md +429 -0
  191. package/workflows/knowledge-audit.md +355 -0
  192. package/workflows/learn.md +271 -0
  193. package/workflows/maestro-chain-execute.md +20 -0
  194. package/workflows/maestro-link-coordinate.md +114 -0
  195. package/workflows/maestro-super.md +120 -0
  196. package/workflows/maestro.md +501 -0
  197. package/workflows/map.md +74 -0
  198. package/workflows/merge.md +122 -0
  199. package/workflows/milestone-audit.md +155 -0
  200. package/workflows/milestone-complete.md +167 -0
  201. package/workflows/milestone-release.md +82 -0
  202. package/workflows/odyssey-base-codex.md +305 -0
  203. package/workflows/odyssey-base.md +256 -0
  204. package/workflows/overlays.md +109 -0
  205. package/workflows/plan.md +520 -0
  206. package/workflows/quick.md +350 -0
  207. package/workflows/ralph-amend-goal.md +177 -0
  208. package/workflows/refactor.md +87 -0
  209. package/workflows/retrospective.md +471 -0
  210. package/workflows/review.md +448 -0
  211. package/workflows/roadmap-common.md +193 -0
  212. package/workflows/roadmap.md +106 -0
  213. package/workflows/shell-exec-protocol.md +30 -0
  214. package/workflows/skill-authoring.md +265 -0
  215. package/workflows/spec-generate.md +475 -0
  216. package/workflows/specs-add.md +123 -0
  217. package/workflows/specs-load.md +76 -0
  218. package/workflows/specs-remove.md +104 -0
  219. package/workflows/specs-setup.md +316 -0
  220. package/workflows/status.md +149 -0
  221. package/workflows/sync.md +116 -0
  222. package/workflows/tdd.md +255 -0
  223. package/workflows/test-gen.md +226 -0
  224. package/workflows/test.md +385 -0
  225. package/workflows/tools-spec.md +70 -0
  226. package/workflows/ui-codify-extract.md +372 -0
  227. package/workflows/ui-codify-knowhow.md +258 -0
  228. package/workflows/ui-codify-package.md +159 -0
  229. package/workflows/ui-codify.md +227 -0
  230. package/workflows/ui-design.md +393 -0
  231. package/workflows/ui-style.md +201 -0
  232. package/workflows/verify.md +557 -0
  233. package/workflows/wiki-connect.md +153 -0
  234. package/workflows/wiki-digest.md +180 -0
  235. package/workflows/wiki-manage.md +113 -0
@@ -0,0 +1,705 @@
1
+ # Auto-Test Workflow (Unified)
2
+
3
+ Unified automated testing with intelligent state-based routing. Merges test generation (gap-forward), business testing (PRD-forward), and integration testing (code-forward) into a single pipeline.
4
+
5
+ **Core idea: read project state → auto-select scenario source → shared pipeline from plan through iteration.**
6
+
7
+ Pipeline: Parse → Route → Source Scenarios → Discover Infrastructure → Plan → Write Tests → Execute → Iterate → Report
8
+ Only Step 2 diverges (scenario source). Everything else is shared.
9
+
10
+ ---
11
+
12
+ ### Step 0: Parse Input & Load Specs
13
+
14
+ **Parse arguments:**
15
+
16
+ | Input | Result |
17
+ |-------|--------|
18
+ | No arguments | Error E001 |
19
+ | Phase number | Resolve phase dir from artifact registry |
20
+ | `--max-iter N` | Set MAX_ITER = N (default 5). **1 = single-pass** (no iteration loop) |
21
+ | `--layer L` | Start from / restrict to specific layer (L0\|L1\|L2\|L3) |
22
+ | `--dry-run` | Generate plan only, do not execute |
23
+ | `--re-run` | Re-run only previously failed scenarios |
24
+
25
+ **Resolve phase dir:** from `state.json` artifact registry (`type='execute'`, matching phase). Error E002 if not found.
26
+
27
+ **Load specs:**
28
+ ```
29
+ # MANDATORY, NOT SUBSTITUTABLE by manual Read/Grep
30
+ specs_test = maestro spec load --category test
31
+ specs_arch = maestro spec load --category arch
32
+ ```
33
+
34
+ `specs_test` for test conventions (Steps 3-5); `specs_arch` for module boundaries (Step 2).
35
+
36
+ ---
37
+
38
+ ### Step 1: Read State & Route
39
+
40
+ Read project state signals and auto-select scenario source. This is the **primary branch point, with Route-specific extraction in Step 2** (after Step 2 normalization, the downstream pipeline is identical).
41
+
42
+ ```
43
+ Priority: Resume > Re-run > Spec > Gap > Code
44
+
45
+ 1. RESUME:
46
+ Check: ${PHASE_DIR}/.tests/auto-test/state.json exists AND status == "running"
47
+ Compat: also check ${PHASE_DIR}/.tests/integration/state.json (old format)
48
+ Action: offer resume or restart
49
+ If resume: restore session, jump to Step 6 at saved iteration/layer
50
+ If restart: archive to .history/, continue as new
51
+
52
+ 2. RE-RUN:
53
+ Check: --re-run flag AND .tests/auto-test/report.json has failed/blocked scenarios
54
+ Compat: also check .tests/business/business-test-report.json (old format)
55
+ Action: load failed/blocked scenarios with status reset to pending
56
+ Skip to Step 4 (scenarios pre-loaded, plan confirmation)
57
+
58
+ # Note: `integration/state.json` and `business/business-test-report.json` are
59
+ # legacy compat paths read for backward compatibility only. The new pipeline
60
+ # writes exclusively to `.tests/auto-test/state.json` and `.tests/auto-test/report.json`
61
+ # (these legacy paths are superseded; see migration table at end of file).
62
+
63
+ 3. SPEC:
64
+ Check: .workflow/blueprint/BLP-*/requirements/REQ-*.md exists
65
+ Resolve: SPEC_DIR from index.json.blueprint_ref or most recent BLP-*/
66
+ If SPEC_DIR found: set ROUTE = "spec", SPEC_MODE = "full"
67
+ If no spec but has success_criteria: set ROUTE = "spec", SPEC_MODE = "degraded"
68
+
69
+ 4. GAP:
70
+ Check: ${PHASE_DIR}/verification.json has gaps[] with status MISSING or PARTIAL
71
+ OR: ${PHASE_DIR}/.tests/coverage-report.json has requirements_uncovered[]
72
+ Action: set ROUTE = "gap"
73
+
74
+ 5. CODE:
75
+ Default fallback when no spec package and no gaps detected.
76
+ Action: set ROUTE = "code"
77
+ ```
78
+
79
+ **Display route selection:**
80
+ ```
81
+ === AUTO-TEST ===
82
+ 来源: {ROUTE} ({reason})
83
+ 阶段: {phase_name}
84
+ {IF spec: "Spec: {SPEC_DIR} (mode: {SPEC_MODE})"}
85
+ ```
86
+
87
+ ---
88
+
89
+ ### Step 2: Source Scenarios
90
+
91
+ Execute the route-specific scenario extraction, then normalize ALL scenarios into the unified format. **After this step, the pipeline is identical regardless of source.**
92
+
93
+ #### Route A: `spec` source (PRD-forward)
94
+
95
+ 1. Load spec package:
96
+ - `requirements/REQ-*.md` — functional requirements with acceptance criteria
97
+ - `requirements/NFR-*.md` — non-functional requirements
98
+ - `architecture/_index.md` — API endpoints, data model, state machines
99
+ - `epics/EPIC-*.md` — user stories for E2E scenarios
100
+
101
+ 2. For each `REQ-NNN-{slug}.md`, parse `## Acceptance Criteria`:
102
+ - Extract each numbered criterion as a scenario seed
103
+ - Map RFC 2119 keywords to priority:
104
+
105
+ | Keyword | Priority | Failure Severity |
106
+ |---------|----------|-----------------|
107
+ | MUST / MUST NOT / SHALL / SHALL NOT | critical | blocker |
108
+ | SHOULD / SHOULD NOT / RECOMMENDED | high | major |
109
+ | MAY / OPTIONAL | medium | minor |
110
+
111
+ 3. Classify scenario into layer:
112
+
113
+ | Source | Layer | Category |
114
+ |--------|-------|----------|
115
+ | Architecture API endpoints + REQ AC about request/response | L1 | api_contract |
116
+ | REQ AC about business logic, validation, state changes | L2 | business_rule |
117
+ | REQ AC about state transitions (from architecture state machines) | L2 | state_transition |
118
+ | Epic user stories (multi-step flows) | L3 | user_flow |
119
+ | NFR performance/security constraints | L2 | non_functional |
120
+
121
+ 4. **Generate Fixtures** (conditional sub-step):
122
+
123
+ **Tier 1: Schema-derived fixtures**
124
+ ```
125
+ FOR each entity in REQ data model:
126
+ valid: object satisfying all field constraints
127
+ invalid: one variant per constraint violation (null_required, empty_string, overflow, wrong_type)
128
+ boundary: edge value variants (min_value, max_value, min_minus_one, max_plus_one)
129
+ ```
130
+
131
+ **Tier 2: Acceptance-criteria-derived expectations**
132
+ ```
133
+ FOR each "MUST return X when Y": fixture { input: Y, expected: X }
134
+ FOR each "MUST validate Z": fixture { input: invalid_Z, expected: validation_error }
135
+ ```
136
+
137
+ **Tier 3: Business-scenario-derived data sets (L3 only)**
138
+ ```
139
+ FOR each Epic user story:
140
+ scenario_pack: coordinated data set across story steps
141
+ ```
142
+
143
+ **Mock contracts:**
144
+ ```
145
+ FOR each API endpoint in architecture/_index.md:
146
+ mock_contract: { request_pattern, response_fixture }
147
+ ```
148
+
149
+ 5. **Degraded mode** (SPEC_MODE = "degraded"):
150
+ - Extract from `index.json.success_criteria` (each → one L2 scenario)
151
+ - Extract from `plan.json` task convergence criteria (each → one L1/L2 scenario)
152
+ - Extract from `.summaries/TASK-*-summary.md` (each → one L1 scenario)
153
+ - All default to priority: "high". No L3 in degraded mode.
154
+
155
+ 6. Convert to unified scenario format.
156
+
157
+ #### Route B: `gap` source (coverage-forward)
158
+
159
+ 1. Read gap sources:
160
+ - `verification.json` → `gaps[]` with status MISSING or PARTIAL
161
+ - `coverage-report.json` → `requirements_uncovered[]`
162
+ - Task summaries → modified files list
163
+
164
+ 2. Priority: MISSING or uncovered → HIGH; PARTIAL → MEDIUM.
165
+
166
+ 3. Classify each changed file:
167
+
168
+ | File Type | Category | Layer |
169
+ |-----------|----------|-------|
170
+ | Pure function / utility | unit | L1 |
171
+ | React component | unit + e2e | L1 + L3 |
172
+ | API route / handler | integration | L2 |
173
+ | Database model / query | integration | L2 |
174
+ | CLI command | e2e | L3 |
175
+ | Config / types / constants / CSS / test files | skip | — |
176
+
177
+ 4. **Optional: CLI supplementary analysis** (skip if no CLI tools enabled or all files "skip"):
178
+ ```
179
+ Bash({
180
+ command: 'maestro delegate "PURPOSE: Analyze source files for test-worthy edge cases
181
+ TASK: Identify error handling | boundary conditions | state transitions | external dependencies
182
+ MODE: analysis
183
+ CONTEXT: @${target_files}
184
+ EXPECTED: JSON array of { file, edge_cases: [{ description, type, priority }] }
185
+ CONSTRAINTS: Non-obvious cases only | Max 5 per file
186
+ " --role analyze --mode analysis',
187
+ run_in_background: true
188
+ })
189
+ ```
190
+ On callback: merge edge_cases into scenarios, mark `source: "cli-analysis"`.
191
+
192
+ 5. Convert to unified scenario format.
193
+
194
+ #### Route C: `code` source (exploration-forward)
195
+
196
+ 1. Explore codebase for testable integration points:
197
+ - Module boundaries and cross-module calls
198
+ - API endpoints and their handlers
199
+ - Database interactions and queries
200
+ - External service integrations
201
+ - Event flows and message passing
202
+
203
+ 2. Scan for cross-module imports, API route definitions, database calls.
204
+
205
+ 3. Map integration points: which modules communicate through what interfaces.
206
+
207
+ 4. Infer layer from integration type:
208
+ - Isolated function → L1
209
+ - Cross-module call / API handler → L2
210
+ - Full user flow → L3
211
+
212
+ 5. Convert to unified scenario format.
213
+
214
+ #### Unified Scenario Format
215
+
216
+ All routes produce this identical structure:
217
+
218
+ ```json
219
+ {
220
+ "id": "AT-{NNN}",
221
+ "source": "spec|gap|code|re-run",
222
+ "layer": "L0|L1|L2|L3",
223
+ "priority": "critical|high|medium",
224
+ "category": "api_contract|business_rule|state_transition|user_flow|non_functional|unit|integration|e2e|static",
225
+ "name": "descriptive scenario name",
226
+ "target_file": "src/path/to/file.ts",
227
+ "test_file": "src/path/__tests__/file.test.ts",
228
+ "req_ref": "REQ-NNN:AC-N | gap-id | null",
229
+ "description": "what this scenario validates",
230
+ "test_cases": ["case 1", "case 2"],
231
+ "input": { "$fixture_ref": "..." },
232
+ "expected": {
233
+ "status": 200,
234
+ "behavior": "description of expected outcome"
235
+ },
236
+ "preconditions": [],
237
+ "postconditions": [],
238
+ "mock_services": [],
239
+ "fixtures": {}
240
+ }
241
+ ```
242
+
243
+ **Field population by route:**
244
+
245
+ | Field | spec | gap | code |
246
+ |-------|------|-----|------|
247
+ | `req_ref` | REQ-NNN:AC-N | gap ID from verification.json | null |
248
+ | `fixtures` | Tier 1-3 generated | empty (inferred in Step 5) | empty (inferred in Step 5) |
249
+ | `mock_services` | from architecture/_index.md | empty | discovered from imports |
250
+ | `preconditions` | from REQ AC text | empty | empty |
251
+
252
+ ---
253
+
254
+ ### Step 3: Discover Test Infrastructure
255
+
256
+ Detect existing test framework and patterns:
257
+
258
+ 1. **Config files**: `jest.config.*`, `vitest.config.*`, `pytest.ini`, `pyproject.toml`, `.mocharc.*`
259
+ 2. **Existing tests**: `*.test.*`, `*.spec.*`, `test_*` (exclude node_modules, .git)
260
+ 3. **Utilities**: `test-utils.*`, `testHelper*`, `conftest.py`, `setup.*`
261
+
262
+ Extract: framework, directory structure, naming convention, test utilities, run command.
263
+
264
+ Read 2-3 existing test files to learn: import style, describe/it nesting, assertion library, mock patterns, setup/teardown.
265
+
266
+ **Detect tech stack for generation:**
267
+
268
+ | Stack | L1 | L2 | L3 |
269
+ |-------|----|----|-----|
270
+ | Java/Spring Boot | MockMvc | JUnit 5 + WireMock | TestContainers |
271
+ | TypeScript/Node | vitest | supertest + nock | playwright/cypress |
272
+ | Python | pytest | httpx + responses | selenium |
273
+
274
+ If no test framework detected: Error E003.
275
+
276
+ Output: `infrastructure` object passed to Steps 5-6.
277
+
278
+ ---
279
+
280
+ ### Step 4: Generate Test Plan & Confirm
281
+
282
+ 1. **Merge pre-existing tests** from `.tests/test-gen-report.json` (if exists):
283
+ - Mark as "pre-existing" so Step 5 skips writing them
284
+ - Step 6 includes them in execution
285
+
286
+ 2. Apply `--layer` filter if specified.
287
+
288
+ 3. **Archive previous plan** to `.history/` if exists.
289
+
290
+ 4. Write `.tests/auto-test/test-plan.json`:
291
+ ```json
292
+ {
293
+ "phase": "{phase}",
294
+ "source_route": "{ROUTE}",
295
+ "blueprint_ref": "{SPEC_DIR name or null}",
296
+ "spec_mode": "full|degraded|null",
297
+ "generated_at": "{ISO timestamp}",
298
+ "infrastructure": { "framework": "...", "run_command": "..." },
299
+ "layers": {
300
+ "L0": { "scenario_count": N, "commands": ["tsc --noEmit", "eslint src/"] },
301
+ "L1": { "scenario_count": N, "priority_distribution": { "critical": X, "high": Y, "medium": Z } },
302
+ "L2": { "scenario_count": N, "priority_distribution": { ... } },
303
+ "L3": { "scenario_count": N, "priority_distribution": { ... } }
304
+ },
305
+ "scenarios": [ "...unified format..." ],
306
+ "fixtures": { "...if spec source..." },
307
+ "requirement_coverage_plan": { "requirements_targeted": [], "requirements_skipped": [] }
308
+ }
309
+ ```
310
+
311
+ 5. Display and confirm:
312
+ ```
313
+ === AUTO-TEST PLAN ===
314
+ 来源: {ROUTE}
315
+ 阶段: {phase_name}
316
+ Blueprint: {blueprint_ref or "N/A"}
317
+
318
+ 层级分布:
319
+ L0 Static: {N} checks
320
+ L1 Unit/API: {N} scenarios ({X} critical, {Y} high)
321
+ L2 Integration: {N} scenarios ({X} critical, {Y} high)
322
+ L3 E2E: {N} scenarios ({X} critical, {Y} high)
323
+
324
+ Total: {N} scenarios, {M} test cases
325
+ Max iterations: {max_iter}
326
+
327
+ Proceed? (yes/edit/cancel)
328
+ ```
329
+
330
+ - `--dry-run`: stop here, report plan
331
+ - User "edit": modify plan interactively
332
+ - User "cancel": abort
333
+
334
+ ---
335
+
336
+ ### Step 5: Write Tests (RED-GREEN) via CSV Parallel
337
+
338
+ **Parallel strategy**: Build `layer-L{N}-write.csv` per layer, execute via `spawn_agents_on_csv`. Each agent writes one test file independently.
339
+
340
+ #### 5a. Build Write CSV
341
+
342
+ For each layer (L1, L2, L3 — sequential):
343
+
344
+ ```
345
+ Extract pending scenarios for this layer from test-plan.json
346
+ Build layer-L{N}-write.csv:
347
+ Columns: id, name, target_file, test_file, description, test_cases, fixtures, req_ref, infrastructure_hints, prev_context
348
+
349
+ prev_context = findings from completed prior-layer scenarios (cross-layer propagation)
350
+ ```
351
+
352
+ #### 5b. Parallel Test Writing via spawn_agents_on_csv — MANDATORY, NOT SUBSTITUTABLE
353
+
354
+ ```javascript
355
+ spawn_agents_on_csv({
356
+ csv_path: `.tests/auto-test/.csv-session/layer-L${N}-write.csv`,
357
+ id_column: "id",
358
+ instruction: `
359
+ Write ONE test file for the given scenario using RED-GREEN methodology.
360
+
361
+ Rules:
362
+ - Read target_file to understand module under test
363
+ - Write test at test_file path following infrastructure_hints patterns
364
+ - Each test_case → one it() block, include id in describe("AT-NNN: {name}")
365
+ - Use fixtures column (infer from source if empty)
366
+ - Run test once after writing: report red_result
367
+ - NEVER modify source code — only write/fix test files
368
+
369
+ RED results:
370
+ - pass: test passes immediately (may need strengthening)
371
+ - expected_fail: test correctly targets real behavior
372
+ - unexpected_fail: setup/import error — fix test, re-run
373
+
374
+ Read discoveries.ndjson for shared patterns. Append if you find reusable ones.
375
+ `,
376
+ max_concurrency: 5,
377
+ max_runtime_seconds: 1800,
378
+ output_csv_path: `.tests/auto-test/.csv-session/layer-L${N}-write-results.csv`,
379
+ output_schema: { id, status: [written|failed], red_result: [expected_fail|unexpected_fail|pass], findings, error }
380
+ })
381
+ ```
382
+
383
+ #### 5c. Merge & Continue
384
+
385
+ Merge write-results into master state. Delete temp CSV. Proceed to next layer or Step 6.
386
+
387
+ **If `--max-iter 1`:** After all layers written and run once, jump directly to Step 8 (single-pass mode, replaces test-gen behavior). Skip Steps 6-7.
388
+
389
+ **GATE Step 5→6**: write-results merged into master state BEFORE execution; REQUIRED: `.tests/auto-test/.csv-session/layer-L*-write-results.csv` merged and temp CSV deleted; BLOCKED if write-results missing or unmerged.
390
+
391
+ ---
392
+
393
+ ### Step 6: Execute (Progressive Layers)
394
+
395
+ Run tests progressively through layers with fail-fast on critical:
396
+
397
+ - L0: `tsc --noEmit` + `eslint src/` (static analysis)
398
+ - L1: unit tests (`--testPathPattern="unit|__tests__"`)
399
+ - L2: integration tests (`--testPathPattern="integration"`)
400
+ - L3: E2E tests (`--testPathPattern="e2e"`)
401
+
402
+ **Fail-fast rule:**
403
+ - L0 must pass before L1
404
+ - If ANY "critical" priority failure in L1 → do NOT proceed to L2
405
+ - If ANY "critical" priority failure in L2 → do NOT proceed to L3
406
+ - "high" and "medium" failures do NOT block next layer
407
+
408
+ Record per-scenario results: `{ status, actual_response, duration_ms, error_detail, classification: null }`.
409
+
410
+ Write iteration results to `.tests/auto-test/results-iter-{N}.json`.
411
+
412
+ ---
413
+
414
+ ### Step 7: Reflect & Adjust (Unified Iteration Engine)
415
+
416
+ Single engine that subsumes both Generator-Critic (per-layer inner) and Reflect-Adjust (global outer). Uses `spawn_agents_on_csv` for parallel failure diagnosis.
417
+
418
+ ```
419
+ OUTER LOOP (max_iter iterations):
420
+
421
+ FOR each active layer (L0 through current):
422
+
423
+ INNER LOOP (max 3 iterations per layer — Generator-Critic):
424
+
425
+ 1. Build diagnosis CSV from failed scenarios:
426
+
427
+ Build diagnosis-iter-{N}.csv:
428
+ Columns: id, scenario_id, layer, test_file, error_detail, expected, actual, target_file, source_context
429
+
430
+ # MANDATORY, NOT SUBSTITUTABLE by manual Read/Grep
431
+ spawn_agents_on_csv({
432
+ csv_path: `.tests/auto-test/.csv-session/diagnosis-iter-${iter}.csv`,
433
+ id_column: "id",
434
+ instruction: `
435
+ Classify ONE test failure and provide fix if applicable.
436
+
437
+ Classifications:
438
+ - test_defect: Test wrong (bad import, endpoint, fixture, assertion)
439
+ - code_defect: Source violates business rule (actual != expected)
440
+ - env_issue: Environment problem (service down, config missing)
441
+
442
+ If test_defect: provide fix_code (old → new)
443
+ If code_defect/env_issue: leave fix_code empty, provide evidence
444
+
445
+ Rules:
446
+ - NEVER suggest source code changes
447
+ - A test correctly catching a real bug = code_defect, not test_defect
448
+ - When uncertain: prefer code_defect (conservative)
449
+ `,
450
+ max_concurrency: 5,
451
+ max_runtime_seconds: 1200,
452
+ output_csv_path: `.tests/auto-test/.csv-session/diagnosis-iter-${iter}-results.csv`,
453
+ output_schema: { id, classification, fix_code, evidence, error }
454
+ })
455
+
456
+ 2. Merge diagnosis results:
457
+ - test_defect with fix_code → apply fix to test file
458
+ - code_defect → mark as confirmed failure (stop retrying)
459
+ - env_issue → mark as blocked
460
+
461
+ 3. IF test_defects found:
462
+ Re-run ALL scenarios in this layer (catch regressions)
463
+
464
+ 4. IF no test_defects remain: break inner loop
465
+
466
+ END INNER
467
+
468
+ Record final layer results
469
+ IF critical code_defects in this layer: stop layer progression (fail-fast)
470
+
471
+ END FOR
472
+
473
+ REFLECT:
474
+ Analyze: which tests failed, pass rate improving/plateauing/regressing,
475
+ failures clustered by component, strategy effectiveness.
476
+ Append to reflection-log.md:
477
+ iteration, strategy, pass_rate delta, what worked/failed,
478
+ detected patterns, strategy assessment (effective/ineffective + recommendation)
479
+
480
+ ADJUST (Adaptive Strategy Engine):
481
+
482
+ | Condition | Strategy | Behavior |
483
+ |-----------|----------|----------|
484
+ | Iteration 1-2 | Conservative | Fix obvious test_defects only, don't refactor |
485
+ | Pass rate >80% AND failures similar | Aggressive | Batch-fix related failures together |
486
+ | New regressions appeared | Surgical | Revert last changes, fix regression only |
487
+ | Stuck 3+ iterations (rate not improving) | Reflective | Step back, re-analyze root cause pattern |
488
+
489
+ Transitions:
490
+ Conservative --(>80%)--> Aggressive
491
+ Aggressive --(regression)--> Surgical --(fixed)--> Aggressive
492
+ Any --(stuck 3+ iters)--> Reflective --(insight)--> Conservative
493
+
494
+ CONVERGENCE CHECK:
495
+ pass_rate >= threshold (95%) → Step 8 (converged)
496
+ iteration >= max_iter → Step 8 (max_iter_reached)
497
+ all remaining failures = code_defect → Step 8 (confirmed_defects)
498
+ ELSE → next outer iteration (back to Execute)
499
+
500
+ END OUTER
501
+ ```
502
+
503
+ **Degenerate cases:**
504
+ - `max_iter=1`: Step 5 writes tests, Step 6 executes once, Step 7 runs Reflect only (log results), no Adjust, no loop → Step 8. Equivalent to test-gen single pass.
505
+ - `max_iter=3`: Inner loop cleans test_defects. Up to 3 outer passes. Similar to business-test.
506
+ - `max_iter=5`: Full adaptive strategy progression. Similar to integration-test.
507
+
508
+ ---
509
+
510
+ ### Step 7.5: Test Confidence Scoring
511
+
512
+ Scored after each REFLECT step. Dimensions (5): scenario_coverage, test_quality, diagnostic_accuracy, strategy_effectiveness, infrastructure_fitness. Factors (weights): completeness(.30), pass_rate_trend(.25), classification_accuracy(.20), coverage_breadth(.15), consistency(.10). Append confidence table to reflection-log.md.
513
+
514
+ **Enhanced Convergence**: pass_rate ≥ 95% AND confidence ≥ 60% → converged. pass_rate ≥ 95% BUT confidence < 60% → continue (tests may be weak). max_iter reached or all failures = code_defect → Step 8.
515
+
516
+ **Quality mechanisms**: Pressure Pass (before Step 8) — select 2-3 passing tests from highest-pass-rate layer, verify they exercise real behavior (not mock-only, non-trivial assertions). Devil's Advocate — pass_rate > 80% → challenge assertion specificity, error path coverage, mock over-reliance. Stall Detection — delta < 5% for 2 iterations + pass_rate flat → force Reflective strategy.
517
+
518
+ **Readiness Gate** (before Step 8, skip if max_iter=1): scenario_coverage < 40% | no pressure pass | diagnostic_accuracy < 40% | unclassified failures. If blocked → force one additional iteration. Add confidence section to report.json.
519
+
520
+ ---
521
+
522
+ ### Step 8: Complete & Write Artifacts
523
+
524
+ 1. Update session state:
525
+ ```json
526
+ // .tests/auto-test/state.json
527
+ {
528
+ "session_id": "auto-test-{YYYYMMDD-HHmmss}",
529
+ "phase": "{phase}",
530
+ "phase_dir": "{PHASE_DIR}",
531
+ "source_route": "spec|gap|code|re-run",
532
+ "blueprint_ref": "SPEC-001 | null",
533
+ "spec_mode": "full|degraded|null",
534
+ "status": "converged|max_iter_reached|confirmed_defects|single_pass",
535
+ "flags": { "max_iter": 5, "layer": null, "dry_run": false, "re_run": false },
536
+ "iteration": 2,
537
+ "strategy": "conservative",
538
+ "strategy_history": ["conservative", "aggressive"],
539
+ "threshold": 95,
540
+ "current_layer": "L2",
541
+ "layer_state": {
542
+ "L0": { "inner_iter": 1, "pass_rate": 100.0, "status": "passed" },
543
+ "L1": { "inner_iter": 2, "pass_rate": 95.0, "status": "passed" },
544
+ "L2": { "inner_iter": 1, "pass_rate": 87.5, "status": "completed" },
545
+ "L3": { "inner_iter": 0, "pass_rate": 0, "status": "pending" }
546
+ },
547
+ "pass_rate_history": [72.0, 85.0, 95.0],
548
+ "scenario_count": 30,
549
+ "infrastructure": { "framework": "vitest", "run_command": "npm test" },
550
+ "started_at": "{ISO}",
551
+ "updated_at": "{ISO}"
552
+ }
553
+ ```
554
+
555
+ 2. Archive previous report to `.history/` if exists.
556
+
557
+ 3. Write `.tests/auto-test/report.json`:
558
+ ```json
559
+ {
560
+ "phase": "{phase}",
561
+ "source_route": "{ROUTE}",
562
+ "blueprint_ref": "{spec ref or null}",
563
+ "spec_mode": "full|degraded|null",
564
+ "completed_at": "{ISO timestamp}",
565
+ "convergence": {
566
+ "status": "converged|max_iter_reached|confirmed_defects|single_pass",
567
+ "iterations": N,
568
+ "final_pass_rate": 95.0,
569
+ "threshold": 95,
570
+ "strategy_history": ["conservative", "aggressive"]
571
+ },
572
+ "infrastructure": { "framework": "vitest", "test_dir": "__tests__/", "run_command": "npm test" },
573
+ "layers": {
574
+ "L0": { "total": N, "passed": P, "failed": F, "blocked": B, "pass_rate": 100.0 },
575
+ "L1": { "total": N, "passed": P, "failed": F, "blocked": B, "pass_rate": 95.0 },
576
+ "L2": { ... },
577
+ "L3": { ... }
578
+ },
579
+ "scenarios": [
580
+ {
581
+ "id": "AT-001", "source": "spec", "layer": "L1", "name": "...",
582
+ "test_file": "...", "req_ref": "REQ-001:AC-1",
583
+ "status": "passed|failed|blocked",
584
+ "classification": "null|test_defect|code_defect|env_issue",
585
+ "iterations_to_pass": 2
586
+ }
587
+ ],
588
+ "failures": [
589
+ {
590
+ "id": "AF-001", "scenario_id": "AT-005", "req_ref": "REQ-001:AC-3",
591
+ "layer": "L1", "severity": "critical", "classification": "code_defect",
592
+ "description": "...", "expected": "...", "actual": "...",
593
+ "fix_suggestion": { "file": "src/...", "line": 42, "direction": "..." }
594
+ }
595
+ ],
596
+ "requirement_coverage": [],
597
+ "summary": {
598
+ "source_route": "{ROUTE}",
599
+ "total_scenarios": 30, "total_passed": 26, "total_failed": 3, "total_blocked": 1,
600
+ "bugs_discovered": 3, "test_defects_fixed": 5, "coverage_pct": 85.0
601
+ }
602
+ }
603
+ ```
604
+
605
+ 4. Update `validation.json`: if gap source, change MISSING → COVERED for passing tests.
606
+ 5. Update `index.json` with `auto_test` section.
607
+
608
+ **Artifact file mapping (old → new):**
609
+
610
+ | Old file | New file |
611
+ |----------|----------|
612
+ | `.tests/test-gen-report.json` | `.tests/auto-test/report.json` (source_route: "gap") |
613
+ | `.tests/integration/state.json` | `.tests/auto-test/state.json` |
614
+ | `.tests/integration/summary.json` | Merged into report.json |
615
+ | `.tests/integration/reflection-log.md` | `.tests/auto-test/reflection-log.md` |
616
+ | `.tests/business/business-test-report.json` | `.tests/auto-test/report.json` (source_route: "spec") |
617
+ | `.tests/business/business-test-summary.md` | `.tests/auto-test/traceability.md` (conditional) |
618
+
619
+ **GATE Step 8→9**: Glob `.tests/auto-test/report.json` MUST exist before Step 9 post-processing; BLOCKED if missing.
620
+
621
+ ---
622
+
623
+ ### Step 9: Post-Processing & Routing
624
+
625
+ #### Conditional: Traceability Matrix (spec source only)
626
+
627
+ Build REQ → AC → scenario → result mapping:
628
+
629
+ ```
630
+ FOR each REQ in requirements targeted:
631
+ FOR each AC in REQ:
632
+ scenarios_for_ac = filter scenarios where req_ref == "REQ-NNN:AC-{N}"
633
+ ac_status = "passed" if ALL passed
634
+ "failed" if ANY failed
635
+ "blocked" if ANY blocked and none failed
636
+ "untested" if no scenarios mapped
637
+
638
+ req.coverage_pct = passed_criteria / total_criteria * 100
639
+ req.verdict = "verified" if all MUST+SHOULD passed
640
+ "partial" if some failed
641
+ "unverified" if all failed or untested
642
+ ```
643
+
644
+ Populate `requirement_coverage[]` in report.json.
645
+ Write `.tests/auto-test/traceability.md` (human-readable table).
646
+
647
+ #### Conditional: Issue Creation (when failures exist)
648
+
649
+ ```
650
+ FOR each failure in report.failures WHERE classification == "code_defect":
651
+ issue = {
652
+ id: "ISS-{YYYYMMDD}-{counter:03d}",
653
+ title: "Auto-Test: " + failure.req_ref + " - " + failure.description,
654
+ status: "registered",
655
+ priority: severity_to_priority(failure.severity),
656
+ source: "auto-test",
657
+ phase_ref: PHASE_NUM,
658
+ description: "Expected: " + failure.expected + ". Actual: " + failure.actual,
659
+ fix_direction: failure.fix_suggestion.direction,
660
+ context: { location: failure.fix_suggestion.file + ":" + failure.fix_suggestion.line },
661
+ tags: ["auto-test", failure.layer]
662
+ }
663
+ Append to .workflow/issues/issues.jsonl
664
+ ```
665
+
666
+ #### Report Display
667
+
668
+ ```
669
+ === AUTO-TEST RESULTS ===
670
+ 阶段: {phase_name}
671
+ 来源: {ROUTE}
672
+ 迭代: {N} (策略: {strategy_history})
673
+ 收敛: {status} ({final_pass_rate}%)
674
+
675
+ 层级结果:
676
+ L0 Static: {pass_rate}% ({passed}/{total})
677
+ L1 Unit/API: {pass_rate}% ({passed}/{total})
678
+ L2 Integration: {pass_rate}% ({passed}/{total})
679
+ L3 E2E: {pass_rate}% ({passed}/{total})
680
+
681
+ 场景: {passed} passed, {failed} failed, {blocked} blocked
682
+ Bugs: {N} discovered
683
+ {IF spec: "需求覆盖: {pct}% | 已验证: {n}/{total}"}
684
+
685
+ Files:
686
+ .tests/auto-test/state.json
687
+ .tests/auto-test/test-plan.json
688
+ .tests/auto-test/report.json
689
+ .tests/auto-test/reflection-log.md
690
+ {IF spec: ".tests/auto-test/traceability.md"}
691
+ ```
692
+
693
+ #### Next-step routing
694
+
695
+ | Result | Suggestion |
696
+ |--------|------------|
697
+ | Converged (>=threshold) | `/quality-review {phase}` to update validation |
698
+ | All requirements verified (spec) | `/maestro-milestone-audit` |
699
+ | Bugs discovered (code_defects) | `/quality-debug --from-auto-test {phase}` |
700
+ | Max iter, >80% | `/quality-test {phase}` for manual UAT on remaining gaps |
701
+ | Max iter, <80% | `/quality-debug {phase}` for deep investigation |
702
+ | Coverage still low | `/quality-auto-test {phase} --layer {missing}` |
703
+ | Re-run all pass | `/quality-review {phase}` |
704
+ | Single pass (max_iter=1), bugs found | `/quality-debug --from-auto-test {phase}` |
705
+ | Single pass, all pass | `/quality-test {phase}` |