Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

step-03-generate-tests.md 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. ---
  2. name: 'step-03-generate-tests'
  3. description: 'Orchestrate adaptive test generation (agent-team, subagent, or sequential)'
  4. nextStepFile: '{skill-root}/steps-c/step-03c-aggregate.md'
  5. ---
  6. # Step 3: Orchestrate Adaptive Test Generation
  7. ## STEP GOAL
  8. Select execution mode deterministically, then generate tests using agent-team, subagent, or sequential execution while preserving the same output contract. Worker selection depends on `{detected_stack}`.
  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. - ✅ Preserve output schema and temp file naming across all modes
  15. - ❌ Do NOT skip capability checks when probing is enabled
  16. - ❌ Do NOT change output paths or JSON schema by mode
  17. ---
  18. ## EXECUTION PROTOCOLS:
  19. - 🎯 Follow the MANDATORY SEQUENCE exactly
  20. - 💾 Wait for subagent outputs
  21. - 📖 Load the next step only when instructed
  22. ## CONTEXT BOUNDARIES:
  23. - Available context: config, coverage plan from Step 2, knowledge fragments
  24. - Focus: orchestration only (mode selection + worker dispatch)
  25. - Limits: do not generate tests directly (delegate to worker steps)
  26. - Dependencies: Step 2 outputs (coverage plan, target features)
  27. ---
  28. ## MANDATORY SEQUENCE
  29. **CRITICAL:** Follow this sequence exactly. Do not skip, reorder, or improvise.
  30. ### 1. Prepare Execution Context
  31. **Generate unique timestamp** for temp file naming:
  32. ```javascript
  33. const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
  34. ```
  35. **Prepare input context for subagents:**
  36. ```javascript
  37. const parseBooleanFlag = (value, defaultValue = true) => {
  38. if (typeof value === 'string') {
  39. const normalized = value.trim().toLowerCase();
  40. if (['false', '0', 'off', 'no'].includes(normalized)) return false;
  41. if (['true', '1', 'on', 'yes'].includes(normalized)) return true;
  42. }
  43. if (value === undefined || value === null) return defaultValue;
  44. return Boolean(value);
  45. };
  46. const subagentContext = {
  47. features: /* from Step 2 coverage plan */,
  48. knowledge_fragments_loaded: /* list of fragments */,
  49. config: {
  50. test_framework: config.test_framework,
  51. use_playwright_utils: config.tea_use_playwright_utils,
  52. use_pactjs_utils: config.tea_use_pactjs_utils,
  53. pact_mcp: config.tea_pact_mcp, // "mcp" | "none"
  54. browser_automation: config.tea_browser_automation, // "auto" | "cli" | "mcp" | "none"
  55. detected_stack: '{detected_stack}', // "frontend" | "backend" | "fullstack"
  56. execution_mode: config.tea_execution_mode || 'auto', // "auto" | "subagent" | "agent-team" | "sequential"
  57. capability_probe: parseBooleanFlag(config.tea_capability_probe, true), // supports booleans and "false"/"true" strings
  58. provider_endpoint_map: /* from Step 2 coverage plan, if use_pactjs_utils enabled */,
  59. },
  60. timestamp: timestamp
  61. };
  62. ```
  63. ---
  64. ### 2. Resolve Execution Mode with Capability Probe
  65. ```javascript
  66. const normalizeUserExecutionMode = (mode) => {
  67. if (typeof mode !== 'string') return null;
  68. const normalized = mode.trim().toLowerCase().replace(/[-_]/g, ' ').replace(/\s+/g, ' ');
  69. if (normalized === 'auto') return 'auto';
  70. if (normalized === 'sequential') return 'sequential';
  71. if (normalized === 'subagent' || normalized === 'sub agent' || normalized === 'subagents' || normalized === 'sub agents') {
  72. return 'subagent';
  73. }
  74. if (normalized === 'agent team' || normalized === 'agent teams' || normalized === 'agentteam') {
  75. return 'agent-team';
  76. }
  77. return null;
  78. };
  79. const normalizeConfigExecutionMode = (mode) => {
  80. if (mode === 'subagent') return 'subagent';
  81. if (mode === 'auto' || mode === 'sequential' || mode === 'subagent' || mode === 'agent-team') {
  82. return mode;
  83. }
  84. return null;
  85. };
  86. // Explicit user instruction in the active run takes priority over config.
  87. const explicitModeFromUser = normalizeUserExecutionMode(runtime.getExplicitExecutionModeHint?.() || null);
  88. const requestedMode = explicitModeFromUser || normalizeConfigExecutionMode(subagentContext.config.execution_mode) || 'auto';
  89. const probeEnabled = subagentContext.config.capability_probe;
  90. const supports = {
  91. subagent: false,
  92. agentTeam: false,
  93. };
  94. if (probeEnabled) {
  95. // Probe using runtime-native capability checks or a no-op launch test.
  96. supports.subagent = runtime.canLaunchSubagents?.() === true;
  97. supports.agentTeam = runtime.canLaunchAgentTeams?.() === true;
  98. }
  99. let resolvedMode = requestedMode;
  100. if (requestedMode === 'auto') {
  101. if (supports.agentTeam) resolvedMode = 'agent-team';
  102. else if (supports.subagent) resolvedMode = 'subagent';
  103. else resolvedMode = 'sequential';
  104. } else if (probeEnabled && requestedMode === 'agent-team' && !supports.agentTeam) {
  105. resolvedMode = supports.subagent ? 'subagent' : 'sequential';
  106. } else if (probeEnabled && requestedMode === 'subagent' && !supports.subagent) {
  107. resolvedMode = 'sequential';
  108. }
  109. subagentContext.execution = {
  110. requestedMode,
  111. resolvedMode,
  112. probeEnabled,
  113. supports,
  114. };
  115. ```
  116. Resolution precedence:
  117. 1. Explicit user request in this run (`agent team` => `agent-team`; `subagent` => `subagent`; `sequential`; `auto`)
  118. 2. `tea_execution_mode` from config
  119. 3. Runtime capability fallback (when probing enabled)
  120. 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.
  121. Report selected mode before dispatch:
  122. ```
  123. ⚙️ Execution Mode Resolution:
  124. - Requested: {requestedMode}
  125. - Probe Enabled: {probeEnabled}
  126. - Supports agent-team: {supports.agentTeam}
  127. - Supports subagent: {supports.subagent}
  128. - Resolved: {resolvedMode}
  129. ```
  130. ---
  131. ### 3. Subagent Dispatch Matrix
  132. **Select subagents based on `{detected_stack}`:**
  133. | `{detected_stack}` | Subagent A (API) | Subagent B (E2E) | Subagent B-backend |
  134. | ------------------ | ---------------- | ---------------- | ------------------ |
  135. | `frontend` | Launch | Launch | Skip |
  136. | `backend` | Launch | Skip | Launch |
  137. | `fullstack` | Launch | Launch | Launch |
  138. ### 3A. Runtime-Managed Parallelism
  139. When `resolvedMode` is `agent-team` or `subagent`, let the runtime decide concurrency and scheduling. TEA does not impose an additional worker ceiling.
  140. ---
  141. ### Contract Test Generation Note
  142. When `use_pactjs_utils` is enabled, the API test generation subagent (step-03a) also generates:
  143. - **Consumer contract tests**: Using `createProviderState` for type-safe provider states
  144. - **Provider verification tests**: Using `buildVerifierOptions` for one-call verifier setup
  145. - **Message contract tests**: Using `buildMessageVerifierOptions` if async/Kafka patterns detected
  146. - **Helper files**: Request filter setup with `createRequestFilter`, shared state constants
  147. - **Provider scrutiny**: Subagent reads provider route handlers, types, and validation schemas before generating each interaction (see `contract-testing.md` Provider Scrutiny Protocol)
  148. When `pact_mcp` is `"mcp"`, the subagent can use SmartBear MCP tools to fetch existing provider states and generate tests informed by broker data.
  149. ---
  150. ### 4. Dispatch Worker A: API Test Generation (always)
  151. **Dispatch worker:**
  152. - **Subagent File:** `./step-03a-subagent-api.md`
  153. - **Output File:** `/tmp/tea-automate-api-tests-${timestamp}.json`
  154. - **Context:** Pass `subagentContext`
  155. - **Execution:**
  156. - `agent-team` or `subagent`: launch non-blocking
  157. - `sequential`: run blocking and wait before next dispatch
  158. **System Action:**
  159. ```
  160. 🚀 Launching Subagent A: API Test Generation
  161. 📝 Output: /tmp/tea-automate-api-tests-${timestamp}.json
  162. ⚙️ Mode: ${resolvedMode}
  163. ⏳ Status: Running...
  164. ```
  165. ---
  166. ### 5. Dispatch Worker B: E2E Test Generation (frontend/fullstack only)
  167. **If {detected_stack} is `frontend` or `fullstack`:**
  168. **Dispatch worker:**
  169. - **Subagent File:** `./step-03b-subagent-e2e.md`
  170. - **Output File:** `/tmp/tea-automate-e2e-tests-${timestamp}.json`
  171. - **Context:** Pass `subagentContext`
  172. - **Execution:**
  173. - `agent-team` or `subagent`: launch non-blocking
  174. - `sequential`: run blocking and wait before next dispatch
  175. **System Action:**
  176. ```
  177. 🚀 Launching Subagent B: E2E Test Generation
  178. 📝 Output: /tmp/tea-automate-e2e-tests-${timestamp}.json
  179. ⚙️ Mode: ${resolvedMode}
  180. ⏳ Status: Running...
  181. ```
  182. **If {detected_stack} is `backend`:** Skip this subagent.
  183. ---
  184. ### 6. Dispatch Worker B-backend: Backend Test Generation (backend/fullstack only)
  185. **If {detected_stack} is `backend` or `fullstack`:**
  186. **Dispatch worker:**
  187. - **Subagent File:** `./step-03b-subagent-backend.md`
  188. - **Output File:** `/tmp/tea-automate-backend-tests-${timestamp}.json`
  189. - **Context:** Pass `subagentContext`
  190. - **Execution:**
  191. - `agent-team` or `subagent`: launch non-blocking
  192. - `sequential`: run blocking and wait before next dispatch
  193. **System Action:**
  194. ```
  195. 🚀 Launching Subagent B-backend: Backend Test Generation
  196. 📝 Output: /tmp/tea-automate-backend-tests-${timestamp}.json
  197. ⚙️ Mode: ${resolvedMode}
  198. ⏳ Status: Running...
  199. ```
  200. **If {detected_stack} is `frontend`:** Skip this subagent.
  201. ---
  202. ### 7. Wait for Expected Worker Completion
  203. **If `resolvedMode` is `agent-team` or `subagent`:**
  204. ```
  205. ⏳ Waiting for subagents to complete...
  206. ├── Subagent A (API): Running... ⟳
  207. ├── Subagent B (E2E): Running... ⟳ [if frontend/fullstack]
  208. └── Subagent B-backend: Running... ⟳ [if backend/fullstack]
  209. [... time passes ...]
  210. ├── Subagent A (API): Complete ✅
  211. ├── Subagent B (E2E): Complete ✅ [if frontend/fullstack]
  212. └── Subagent B-backend: Complete ✅ [if backend/fullstack]
  213. ✅ All subagents completed successfully!
  214. ```
  215. **If `resolvedMode` is `sequential`:**
  216. ```
  217. ✅ Sequential mode: each worker already completed during dispatch.
  218. ```
  219. **Verify outputs exist (based on `{detected_stack}`):**
  220. ```javascript
  221. const apiOutputExists = fs.existsSync(`/tmp/tea-automate-api-tests-${timestamp}.json`);
  222. // Check based on detected_stack
  223. if (detected_stack === 'frontend' || detected_stack === 'fullstack') {
  224. const e2eOutputExists = fs.existsSync(`/tmp/tea-automate-e2e-tests-${timestamp}.json`);
  225. if (!e2eOutputExists) throw new Error('E2E subagent output missing!');
  226. }
  227. if (detected_stack === 'backend' || detected_stack === 'fullstack') {
  228. const backendOutputExists = fs.existsSync(`/tmp/tea-automate-backend-tests-${timestamp}.json`);
  229. if (!backendOutputExists) throw new Error('Backend subagent output missing!');
  230. }
  231. if (!apiOutputExists) throw new Error('API subagent output missing!');
  232. ```
  233. ---
  234. ### Subagent Output Schema Contract
  235. The aggregate step expects both outputs to include `success`, but the payload shapes are intentionally different:
  236. - `step-03b-subagent-e2e.md` output includes `success`, `subagent`, `tests`, `fixture_needs`, `knowledge_fragments_used`, `test_count`, and `summary`.
  237. - `step-03b-subagent-backend.md` output includes `success`, `subagent`, `subagentType`, `testsGenerated`, `coverageSummary` (with `fixtureNeeds`), `status`, `knowledge_fragments_used`, and `summary`.
  238. The aggregate step reads whichever output file(s) exist based on `{detected_stack}` and must use the matching schema per subagent type.
  239. ---
  240. ### 8. Execution Report
  241. **Display performance metrics:**
  242. ```
  243. 🚀 Performance Report:
  244. - Execution Mode: {resolvedMode}
  245. - Stack Type: {detected_stack}
  246. - API Test Generation: ~X minutes
  247. - E2E Test Generation: ~Y minutes [if frontend/fullstack]
  248. - Backend Test Generation: ~Z minutes [if backend/fullstack]
  249. - Total Elapsed: ~mode-dependent
  250. - Parallel Gain: ~40-70% faster when mode is subagent/agent-team
  251. ```
  252. ---
  253. ### 9. Proceed to Aggregation
  254. **Load aggregation step:**
  255. Load next step: `{nextStepFile}`
  256. The aggregation step (3C) will:
  257. - Read all subagent outputs (based on `{detected_stack}`)
  258. - Write all test files to disk
  259. - Generate shared fixtures and helpers
  260. - Calculate summary statistics
  261. ---
  262. ## EXIT CONDITION
  263. Proceed to Step 3C (Aggregation) when:
  264. - ✅ Subagent A (API tests) completed successfully
  265. - ✅ Subagent B (E2E tests) completed successfully [if frontend/fullstack]
  266. - ✅ Subagent B-backend (Backend tests) completed successfully [if backend/fullstack]
  267. - ✅ All expected output files exist and are valid JSON
  268. - ✅ Execution metrics displayed
  269. **Do NOT proceed if:**
  270. - ❌ Any launched subagent failed
  271. - ❌ Output files missing or corrupted
  272. - ❌ Timeout occurred (parallel mode only)
  273. ---
  274. ## 🚨 SYSTEM SUCCESS/FAILURE METRICS:
  275. ### ✅ SUCCESS:
  276. - All required subagents launched successfully (based on `{detected_stack}`)
  277. - All required worker steps completed without errors
  278. - Output files generated and valid
  279. - Fallback behavior respected configuration and capability probe rules
  280. ### ❌ SYSTEM FAILURE:
  281. - Failed to launch subagents
  282. - One or more subagents failed
  283. - Output files missing or invalid
  284. - Unsupported requested mode with probing disabled
  285. **Master Rule:** Deterministic mode selection + stable output contract. Use the best supported mode, then aggregate normally.