Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. ---
  2. name: 'step-04-generate-tests'
  3. description: 'Orchestrate adaptive red-phase test scaffold generation (TDD red phase)'
  4. nextStepFile: '{skill-root}/steps-c/step-04c-aggregate.md'
  5. ---
  6. # Step 4: Orchestrate Adaptive Red-Phase Test Scaffold Generation
  7. ## STEP GOAL
  8. Select execution mode deterministically, then generate red-phase API and E2E test scaffolds (TDD RED PHASE) with consistent output contracts across agent-team, subagent, or sequential execution.
  9. ## MANDATORY EXECUTION RULES
  10. - 📖 Read the entire step file before acting
  11. - ✅ Speak in `{communication_language}`
  12. - ✅ Resolve execution mode from config (`tea_execution_mode`, `tea_capability_probe`)
  13. - ✅ Apply fallback rules deterministically when requested mode is unsupported
  14. - ✅ Generate red-phase test scaffolds only (TDD red phase)
  15. - ✅ Wait for required worker steps to complete
  16. - ❌ Do NOT skip capability checks when probing is enabled
  17. - ❌ Do NOT generate active passing tests (this is red phase)
  18. - ❌ Do NOT proceed until required worker steps finish
  19. ---
  20. ## EXECUTION PROTOCOLS:
  21. - 🎯 Follow the MANDATORY SEQUENCE exactly
  22. - 💾 Wait for subagent outputs
  23. - 📖 Load the next step only when instructed
  24. ## CONTEXT BOUNDARIES:
  25. - Available context: config, acceptance criteria from Step 1, test strategy from Step 3
  26. - Focus: orchestration only (mode selection + worker dispatch)
  27. - Limits: do not generate tests directly (delegate to worker steps)
  28. - Dependencies: Steps 1-3 outputs
  29. ---
  30. ## MANDATORY SEQUENCE
  31. **CRITICAL:** Follow this sequence exactly. Do not skip, reorder, or improvise.
  32. ### 1. Prepare Execution Context
  33. **Generate unique timestamp** for temp file naming:
  34. ```javascript
  35. const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
  36. ```
  37. **Prepare input context for both subagents:**
  38. ```javascript
  39. const parseBooleanFlag = (value, defaultValue = true) => {
  40. if (typeof value === 'string') {
  41. const normalized = value.trim().toLowerCase();
  42. if (['false', '0', 'off', 'no'].includes(normalized)) return false;
  43. if (['true', '1', 'on', 'yes'].includes(normalized)) return true;
  44. }
  45. if (value === undefined || value === null) return defaultValue;
  46. return Boolean(value);
  47. };
  48. const subagentContext = {
  49. story_acceptance_criteria: /* from Step 1 */,
  50. test_strategy: /* from Step 3 */,
  51. knowledge_fragments_loaded: /* list of fragments */,
  52. config: {
  53. test_framework: config.test_framework,
  54. use_playwright_utils: config.tea_use_playwright_utils,
  55. use_pactjs_utils: config.tea_use_pactjs_utils,
  56. pact_mcp: config.tea_pact_mcp, // "mcp" | "none"
  57. browser_automation: config.tea_browser_automation,
  58. execution_mode: config.tea_execution_mode || 'auto', // "auto" | "subagent" | "agent-team" | "sequential"
  59. capability_probe: parseBooleanFlag(config.tea_capability_probe, true), // supports booleans and "false"/"true" strings
  60. provider_endpoint_map: /* from Step 1/3 context, if use_pactjs_utils enabled */,
  61. },
  62. timestamp: timestamp
  63. };
  64. ```
  65. ---
  66. ### 2. Resolve Execution Mode with Capability Probe
  67. ```javascript
  68. const normalizeUserExecutionMode = (mode) => {
  69. if (typeof mode !== 'string') return null;
  70. const normalized = mode.trim().toLowerCase().replace(/[-_]/g, ' ').replace(/\s+/g, ' ');
  71. if (normalized === 'auto') return 'auto';
  72. if (normalized === 'sequential') return 'sequential';
  73. if (normalized === 'subagent' || normalized === 'sub agent' || normalized === 'subagents' || normalized === 'sub agents') {
  74. return 'subagent';
  75. }
  76. if (normalized === 'agent team' || normalized === 'agent teams' || normalized === 'agentteam') {
  77. return 'agent-team';
  78. }
  79. return null;
  80. };
  81. const normalizeConfigExecutionMode = (mode) => {
  82. if (mode === 'subagent') return 'subagent';
  83. if (mode === 'auto' || mode === 'sequential' || mode === 'subagent' || mode === 'agent-team') {
  84. return mode;
  85. }
  86. return null;
  87. };
  88. // Explicit user instruction in the active run takes priority over config.
  89. const explicitModeFromUser = normalizeUserExecutionMode(runtime.getExplicitExecutionModeHint?.() || null);
  90. const requestedMode = explicitModeFromUser || normalizeConfigExecutionMode(subagentContext.config.execution_mode) || 'auto';
  91. const probeEnabled = subagentContext.config.capability_probe;
  92. const supports = {
  93. subagent: runtime.canLaunchSubagents?.() === true,
  94. agentTeam: runtime.canLaunchAgentTeams?.() === true,
  95. };
  96. let resolvedMode = requestedMode;
  97. if (requestedMode === 'auto') {
  98. if (supports.agentTeam) resolvedMode = 'agent-team';
  99. else if (supports.subagent) resolvedMode = 'subagent';
  100. else resolvedMode = 'sequential';
  101. } else if (probeEnabled && requestedMode === 'agent-team' && !supports.agentTeam) {
  102. resolvedMode = supports.subagent ? 'subagent' : 'sequential';
  103. } else if (probeEnabled && requestedMode === 'subagent' && !supports.subagent) {
  104. resolvedMode = 'sequential';
  105. }
  106. subagentContext.execution = {
  107. requestedMode,
  108. resolvedMode,
  109. probeEnabled,
  110. supports,
  111. };
  112. if (!probeEnabled && (requestedMode === 'agent-team' || requestedMode === 'subagent')) {
  113. const unsupportedRequestedMode =
  114. (requestedMode === 'agent-team' && !supports.agentTeam) || (requestedMode === 'subagent' && !supports.subagent);
  115. if (unsupportedRequestedMode) {
  116. subagentContext.execution.error = `Requested execution mode "${requestedMode}" is unavailable because capability probing is disabled.`;
  117. throw new Error(subagentContext.execution.error);
  118. }
  119. }
  120. ```
  121. Resolution precedence:
  122. 1. Explicit user request in this run (`agent team` => `agent-team`; `subagent` => `subagent`; `sequential`; `auto`)
  123. 2. `tea_execution_mode` from config
  124. 3. Runtime capability fallback (when probing enabled)
  125. If probing is disabled, honor the requested mode strictly. If that mode cannot be executed at runtime, fail with explicit error instead of silent fallback.
  126. ---
  127. ### 3. Dispatch Worker A: Red-Phase API Test Generation
  128. **Dispatch worker:**
  129. - **Subagent File:** `./step-04a-subagent-api-failing.md`
  130. - **Output File:** `/tmp/tea-atdd-api-tests-${timestamp}.json`
  131. - **Context:** Pass `subagentContext`
  132. - **Execution:**
  133. - `agent-team` or `subagent`: launch non-blocking
  134. - `sequential`: run blocking and wait before next dispatch
  135. - **TDD Phase:** RED (scaffold tests with `test.skip()`)
  136. **System Action:**
  137. ```
  138. 🚀 Launching Subagent A: RED-PHASE API Test Generation
  139. 📝 Output: /tmp/tea-atdd-api-tests-${timestamp}.json
  140. ⚙️ Mode: ${resolvedMode}
  141. 🔴 TDD Phase: RED (tests emitted as `test.skip()` scaffolds)
  142. ⏳ Status: Running...
  143. ```
  144. ---
  145. ### 4. Dispatch Worker B: Red-Phase E2E Test Generation
  146. **Dispatch worker:**
  147. - **Subagent File:** `./step-04b-subagent-e2e-failing.md`
  148. - **Output File:** `/tmp/tea-atdd-e2e-tests-${timestamp}.json`
  149. - **Context:** Pass `subagentContext`
  150. - **Execution:**
  151. - `agent-team` or `subagent`: launch non-blocking
  152. - `sequential`: run blocking and wait before next dispatch
  153. - **TDD Phase:** RED (scaffold tests with `test.skip()`)
  154. **System Action:**
  155. ```
  156. 🚀 Launching Subagent B: RED-PHASE E2E Test Generation
  157. 📝 Output: /tmp/tea-atdd-e2e-tests-${timestamp}.json
  158. ⚙️ Mode: ${resolvedMode}
  159. 🔴 TDD Phase: RED (tests emitted as `test.skip()` scaffolds)
  160. ⏳ Status: Running...
  161. ```
  162. ---
  163. ### 5. Wait for Required Worker Completion
  164. **If `resolvedMode` is `agent-team` or `subagent`:**
  165. ```
  166. ⏳ Waiting for subagents to complete...
  167. ├── Subagent A (API RED): Running... ⟳
  168. └── Subagent B (E2E RED): Running... ⟳
  169. [... time passes ...]
  170. ├── Subagent A (API RED): Complete ✅
  171. └── Subagent B (E2E RED): Complete ✅
  172. ✅ All subagents completed successfully!
  173. ```
  174. **If `resolvedMode` is `sequential`:**
  175. ```
  176. ✅ Sequential mode: each worker already completed during dispatch.
  177. ```
  178. **Verify both outputs exist:**
  179. ```javascript
  180. const apiOutputExists = fs.existsSync(`/tmp/tea-atdd-api-tests-${timestamp}.json`);
  181. const e2eOutputExists = fs.existsSync(`/tmp/tea-atdd-e2e-tests-${timestamp}.json`);
  182. if (!apiOutputExists || !e2eOutputExists) {
  183. throw new Error('One or both subagent outputs missing!');
  184. }
  185. ```
  186. ---
  187. ### 6. TDD Red Phase Report
  188. **Display TDD status:**
  189. ```
  190. 🔴 TDD RED PHASE: Test Scaffolds Generated
  191. ✅ Both subagents completed:
  192. - API Tests: Generated with test.skip()
  193. - E2E Tests: Generated with test.skip()
  194. 📋 All tests assert EXPECTED behavior
  195. 📋 Activated tests will FAIL until feature is implemented
  196. 📋 Scaffolds stay skipped until a developer activates the current task
  197. 📋 This is INTENTIONAL (TDD red phase)
  198. Next: Aggregation will verify TDD compliance
  199. ```
  200. ---
  201. ### 7. Execution Report
  202. **Display performance metrics:**
  203. ```
  204. 🚀 Performance Report:
  205. - Execution Mode: {resolvedMode}
  206. - API Test Generation: ~X minutes
  207. - E2E Test Generation: ~Y minutes
  208. - Total Elapsed: ~mode-dependent
  209. - Parallel Gain: ~50% faster when mode is subagent/agent-team
  210. ```
  211. ---
  212. ### 8. Proceed to Aggregation
  213. **Load aggregation step:**
  214. Load next step: `{nextStepFile}`
  215. The aggregation step (4C) will:
  216. - Read both subagent outputs
  217. - Verify TDD red phase compliance (all tests have test.skip())
  218. - Write all test files to disk
  219. - Generate ATDD checklist
  220. - Calculate summary statistics
  221. ---
  222. ## EXIT CONDITION
  223. Proceed to Step 4C (Aggregation) when:
  224. - ✅ Subagent A (API red-phase tests) completed successfully
  225. - ✅ Subagent B (E2E red-phase tests) completed successfully
  226. - ✅ Both output files exist and are valid JSON
  227. - ✅ TDD red phase status reported
  228. **Do NOT proceed if:**
  229. - ❌ One or both subagents failed
  230. - ❌ Output files missing or corrupted
  231. - ❌ Subagent generated active passing tests (wrong - must be red-phase scaffolds)
  232. ---
  233. ## 🚨 SYSTEM SUCCESS/FAILURE METRICS:
  234. ### ✅ SUCCESS:
  235. - Both subagents launched successfully
  236. - Both worker steps completed without errors
  237. - Output files generated and valid
  238. - Tests generated with test.skip() (TDD red phase)
  239. - Fallback behavior respected configuration and capability probe rules
  240. ### ❌ SYSTEM FAILURE:
  241. - Failed to launch subagents
  242. - One or both subagents failed
  243. - Output files missing or invalid
  244. - Tests generated without test.skip() (wrong phase)
  245. - Unsupported requested mode with probing disabled
  246. **Master Rule:** TDD RED PHASE requires acceptance test scaffolds marked with `test.skip()`. Mode selection changes orchestration, never red-phase requirements.