Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

step-03-scaffold-framework.md 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. ---
  2. name: 'step-03-scaffold-framework'
  3. description: 'Create framework scaffold with adaptive orchestration (agent-team, subagent, or sequential)'
  4. nextStepFile: '{skill-root}/steps-c/step-04-docs-and-scripts.md'
  5. knowledgeIndex: './resources/tea-index.csv'
  6. outputFile: '{test_artifacts}/framework-setup-progress.md'
  7. ---
  8. # Step 3: Scaffold Framework
  9. ## STEP GOAL
  10. Generate the test directory structure, configuration files, fixtures, factories, helpers, and sample tests using deterministic mode selection with runtime fallback.
  11. ## MANDATORY EXECUTION RULES
  12. - 📖 Read the entire step file before acting
  13. - ✅ Speak in `{communication_language}`
  14. - ✅ Apply knowledge base patterns where required
  15. - ✅ Resolve execution mode from explicit user request first, then config
  16. - ✅ Apply fallback rules deterministically when requested mode is unsupported
  17. ---
  18. ## EXECUTION PROTOCOLS:
  19. - 🎯 Follow the MANDATORY SEQUENCE exactly
  20. - 💾 Record outputs before proceeding
  21. - 📖 Load the next step only when instructed
  22. ## CONTEXT BOUNDARIES:
  23. - Available context: config, loaded artifacts, and knowledge fragments
  24. - Focus: this step's goal only
  25. - Limits: do not execute future steps
  26. - Dependencies: prior steps' outputs (if any)
  27. ## MANDATORY SEQUENCE
  28. **CRITICAL:** Follow this sequence exactly. Do not skip, reorder, or improvise.
  29. ## 0. Resolve Execution Mode (User Override First)
  30. ```javascript
  31. const parseBooleanFlag = (value, defaultValue = true) => {
  32. if (typeof value === 'string') {
  33. const normalized = value.trim().toLowerCase();
  34. if (['false', '0', 'off', 'no'].includes(normalized)) return false;
  35. if (['true', '1', 'on', 'yes'].includes(normalized)) return true;
  36. }
  37. if (value === undefined || value === null) return defaultValue;
  38. return Boolean(value);
  39. };
  40. const orchestrationContext = {
  41. config: {
  42. execution_mode: config.tea_execution_mode || 'auto', // "auto" | "subagent" | "agent-team" | "sequential"
  43. capability_probe: parseBooleanFlag(config.tea_capability_probe, true), // supports booleans and "false"/"true" strings
  44. },
  45. timestamp: new Date().toISOString().replace(/[:.]/g, '-'),
  46. };
  47. const normalizeUserExecutionMode = (mode) => {
  48. if (typeof mode !== 'string') return null;
  49. const normalized = mode.trim().toLowerCase().replace(/[-_]/g, ' ').replace(/\s+/g, ' ');
  50. if (normalized === 'auto') return 'auto';
  51. if (normalized === 'sequential') return 'sequential';
  52. if (normalized === 'subagent' || normalized === 'sub agent' || normalized === 'subagents' || normalized === 'sub agents') {
  53. return 'subagent';
  54. }
  55. if (normalized === 'agent team' || normalized === 'agent teams' || normalized === 'agentteam') {
  56. return 'agent-team';
  57. }
  58. return null;
  59. };
  60. const normalizeConfigExecutionMode = (mode) => {
  61. if (mode === 'subagent') return 'subagent';
  62. if (mode === 'auto' || mode === 'sequential' || mode === 'subagent' || mode === 'agent-team') {
  63. return mode;
  64. }
  65. return null;
  66. };
  67. // Explicit user instruction in the active run takes priority over config.
  68. const explicitModeFromUser = normalizeUserExecutionMode(runtime.getExplicitExecutionModeHint?.() || null);
  69. const requestedMode = explicitModeFromUser || normalizeConfigExecutionMode(orchestrationContext.config.execution_mode) || 'auto';
  70. const probeEnabled = orchestrationContext.config.capability_probe;
  71. const supports = { subagent: false, agentTeam: false };
  72. if (probeEnabled) {
  73. supports.subagent = runtime.canLaunchSubagents?.() === true;
  74. supports.agentTeam = runtime.canLaunchAgentTeams?.() === true;
  75. }
  76. let resolvedMode = requestedMode;
  77. if (requestedMode === 'auto') {
  78. if (supports.agentTeam) resolvedMode = 'agent-team';
  79. else if (supports.subagent) resolvedMode = 'subagent';
  80. else resolvedMode = 'sequential';
  81. } else if (probeEnabled && requestedMode === 'agent-team' && !supports.agentTeam) {
  82. resolvedMode = supports.subagent ? 'subagent' : 'sequential';
  83. } else if (probeEnabled && requestedMode === 'subagent' && !supports.subagent) {
  84. resolvedMode = 'sequential';
  85. }
  86. ```
  87. Resolution precedence:
  88. 1. Explicit user request in this run (`agent team` => `agent-team`; `subagent` => `subagent`; `sequential`; `auto`)
  89. 2. `tea_execution_mode` from config
  90. 3. Runtime capability fallback (when probing enabled)
  91. ## 1. Create Directory Structure
  92. Use `{detected_stack}` from Step 1 to determine directory layout.
  93. **If {detected_stack} is `frontend` or `fullstack`:**
  94. - `{test_dir}/e2e/`
  95. - `{test_dir}/support/fixtures/`
  96. - `{test_dir}/support/helpers/`
  97. - `{test_dir}/support/page-objects/` (optional)
  98. **If {detected_stack} is `backend` or `fullstack`:**
  99. Create the idiomatic test directory for the detected language:
  100. - **Python (pytest)**: `tests/` with `conftest.py`, `tests/unit/`, `tests/integration/`, `tests/api/`
  101. - **Java/Kotlin (JUnit)**: `src/test/java/` mirroring `src/main/java/` package structure, with `unit/`, `integration/`, `api/` sub-packages
  102. - **Go**: `*_test.go` files alongside source files (Go convention), plus `testdata/` for fixtures
  103. - **C#/.NET (xUnit)**: `tests/` project with `Unit/`, `Integration/`, `Api/` directories
  104. - **Ruby (RSpec)**: `spec/` with `spec/unit/`, `spec/integration/`, `spec/api/`, `spec/support/`
  105. - **Rust**: `tests/` for integration tests, inline `#[cfg(test)]` modules for unit tests
  106. **If `config.tea_use_pactjs_utils` is enabled and runtime is Node.js/TypeScript** (i.e., `{detected_stack}` is `frontend` or `fullstack`, or `{detected_stack}` is `backend` with Node.js/TypeScript runtime):
  107. Create Node.js/TypeScript contract testing directory structure per `pact-consumer-framework-setup.md`:
  108. - `tests/contract/consumer/` — consumer contract test files (`.pacttest.ts` extension)
  109. - `tests/contract/support/` — pact config, provider state factories, consumer helpers shim
  110. - `scripts/` — shell scripts (`env-setup.sh`, `publish-pact.sh`, `can-i-deploy.sh`, `record-deployment.sh`)
  111. - `.github/actions/detect-breaking-change/` — PR checkbox-driven breaking change detection
  112. - `.github/workflows/contract-test-consumer.yml` — consumer CDC CI workflow
  113. ---
  114. ## 2. Generate Framework Config
  115. **If {detected_stack} is `frontend` or `fullstack`:**
  116. Create `playwright.config.ts` or `cypress.config.ts` with:
  117. - **Timeouts**: action 15s, navigation 30s, test 60s
  118. - **Base URL**: env fallback (`BASE_URL`)
  119. - **Artifacts**: trace `retain-on-failure-and-retries`, screenshot `only-on-failure`, video `retain-on-failure`
  120. - **Reporters**: HTML + JUnit + console
  121. - **Parallelism**: enabled (CI tuned)
  122. Use TypeScript if `use_typescript: true`.
  123. **If {detected_stack} is `backend` or `fullstack`:**
  124. Create the idiomatic test config for the detected framework:
  125. - **pytest**: `pyproject.toml` `[tool.pytest.ini_options]` or `pytest.ini` with markers, test paths, coverage settings
  126. - **JUnit**: `build.gradle`/`pom.xml` test configuration with JUnit 5 dependencies, Surefire/Failsafe plugins
  127. - **Go test**: no config file needed (Go convention); optionally create `Makefile` test targets
  128. - **xUnit**: `.csproj` test project with xUnit and coverlet dependencies
  129. - **RSpec**: `.rspec` config file with `spec_helper.rb` and `rails_helper.rb` (if Rails)
  130. ---
  131. ## 3. Environment Setup
  132. Create `.env.example` with `TEST_ENV`, `BASE_URL`, `API_URL`.
  133. **Stack-conditional environment files:**
  134. **If {detected_stack} is `frontend` or `fullstack` (Node.js):**
  135. - `.nvmrc` using current LTS Node (prefer Node 24+)
  136. **If {detected_stack} is `backend`:**
  137. Create the idiomatic version file for the detected language:
  138. - **Python**: `.python-version` with current stable Python (prefer 3.12+)
  139. - **Java**: `.java-version` or `JAVA_HOME` documentation in `.env.example`
  140. - **Go**: Go version is already in `go.mod` (no additional file needed)
  141. - **C#/.NET**: `global.json` with SDK version if not already present
  142. - **Ruby**: `.ruby-version` with current stable Ruby
  143. ---
  144. ## 4. Fixtures & Factories
  145. Read `{config_source}` and use `{knowledgeIndex}` to load fragments based on `config.tea_use_playwright_utils`:
  146. **If Playwright Utils enabled:**
  147. - `overview.md`, `fixtures-composition.md`, `auth-session.md`, `api-request.md`, `recurse.md`, `log.md`, `burn-in.md`, `network-error-monitor.md`, `data-factories.md`
  148. - If `{detected_stack}` is `frontend` or `fullstack`, also load `intercept-network-call.md`
  149. - Recommend installing `@seontechnologies/playwright-utils`
  150. **If disabled:**
  151. - `fixture-architecture.md`, `data-factories.md`, `network-first.md`, `playwright-config.md`, `test-quality.md`
  152. **If Pact.js Utils enabled** (`config.tea_use_pactjs_utils`):
  153. - `pact-consumer-framework-setup.md` (CRITICAL: load this for directory structure, scripts, CI workflow, and PactV4 patterns — includes `fileParallelism: false` + `pool: 'forks'` + `singleFork: true`, determinism gate, and `jq` publish normalization)
  154. - `pactjs-utils-overview.md`, `pactjs-utils-consumer-helpers.md` (one-interaction-per-`it()` rule), `pactjs-utils-provider-verifier.md` (same `pool: 'forks'` + `singleFork` rule applies to consumer AND provider), `pactjs-utils-request-filter.md`, `contract-testing.md`
  155. - `pact-broker-webhooks.md` — when scaffolding the provider repo and any CI step that depends on `can-i-deploy`
  156. - Recommend installing `@seontechnologies/pactjs-utils` and `@pact-foundation/pact`
  157. - Ensure `jq` is available on CI runners (default on `ubuntu-latest`; document `brew install jq` for macOS dev machines) — required by `scripts/check-pact-determinism.sh` and `scripts/publish-pact.sh`
  158. **If Pact.js Utils disabled but contract testing relevant:**
  159. - `contract-testing.md`
  160. **If Pact MCP enabled** (`config.tea_pact_mcp` is `"mcp"`):
  161. - `pact-mcp.md`
  162. Implement:
  163. - Fixture index with `mergeTests`
  164. - Auto-cleanup hooks
  165. - Faker-based data factories with overrides
  166. ---
  167. ## 5. Sample Tests & Helpers
  168. **If {detected_stack} is `frontend` or `fullstack`:**
  169. Create example tests in `{test_dir}/e2e/` demonstrating:
  170. - Given/When/Then format
  171. - data-testid selector strategy
  172. - Factory usage
  173. - Network interception pattern (if applicable)
  174. **If {detected_stack} is `backend` or `fullstack`:**
  175. Create example tests in the idiomatic location for the detected language:
  176. - **Python**: `tests/test_example.py` with pytest fixtures, parametrize, and factory usage
  177. - **Java**: `src/test/java/.../ExampleTest.java` with JUnit 5 annotations, `@BeforeEach` setup
  178. - **Go**: `example_test.go` alongside source with table-driven tests and `testify` assertions
  179. - **C#/.NET**: `tests/ExampleTests.cs` with xUnit `[Fact]`/`[Theory]` and fixture injection
  180. - **Ruby**: `spec/example_spec.rb` with RSpec `describe`/`context`/`it` and factory_bot
  181. Create helpers for:
  182. - API clients (if needed)
  183. - Network utilities (frontend/fullstack only)
  184. - Auth helpers
  185. - Test data factories (language-idiomatic patterns)
  186. **If `config.tea_use_pactjs_utils` is enabled and runtime is Node.js/TypeScript** (i.e., `{detected_stack}` is `frontend` or `fullstack`, or `{detected_stack}` is `backend` with Node.js/TypeScript runtime):
  187. Create Node.js/TypeScript contract test samples per `pact-consumer-framework-setup.md`:
  188. - **Consumer test**: Example using PactV4 `addInteraction()` builder + `createProviderState` + real consumer code with URL injection (`.pacttest.ts` extension). **One `addInteraction()` per `it()` block** — never chain multiple interactions in a single test (PactV4 FFI drops them non-deterministically; see `pactjs-utils-consumer-helpers.md` Example 6).
  189. - **Support files**: Pact config factory (`pact-config.ts`), provider state factories (`provider-states.ts`), local consumer-helpers shim (`consumer-helpers.ts`)
  190. - **Vitest config (consumer)**: Minimal `vitest.config.pact.ts` with **`fileParallelism: false` AND `pool: 'forks'` + `poolOptions.forks.singleFork: true`** (both required — `fileParallelism: false` prevents shared pact JSON corruption from parallel workers; forks pool + singleFork prevents the Pact Rust FFI from leaking state across files and flaking on Linux CI. See `pact-consumer-framework-setup.md` Example 2). Do NOT copy settings from unit config.
  191. - **Vitest config (provider)**: `vitest.config.contract.ts` with **`pool: 'forks'` + `poolOptions.forks.singleFork: true`** (same rule as consumer; required for message providers and multi-file HTTP providers; see `pactjs-utils-provider-verifier.md` Example 7).
  192. - **Shell scripts**: `env-setup.sh`, `check-pact-determinism.sh` (primary defense against non-deterministic pact generation), `publish-pact.sh` (with `jq -S` interaction sort normalization), `can-i-deploy.sh`, `record-deployment.sh` in `scripts/`
  193. - **package.json scripts**: Split `test:pact:consumer` (determinism gate — runs `check-pact-determinism.sh` with 3 runs) and `test:pact:consumer:run` (inner single-pass vitest invocation). CI and local both call `npm run test:pact:consumer` for 1:1 parity.
  194. - **CI workflow**: `contract-test-consumer.yml` with detect-breaking-change action
  195. - **package.json scripts**: `test:pact:consumer` (determinism gate), `test:pact:consumer:run` (inner single-pass vitest), `publish:pact`, `can:i:deploy:consumer`, `record:consumer:deployment`
  196. - **.gitignore**: Add `/pacts/` and `pact-logs/`
  197. ---
  198. ### 6. Orchestration Notes for This Step
  199. For this step, treat these work units as parallelizable when `resolvedMode` is `agent-team` or `subagent`:
  200. - Worker A: directory + framework config + env setup (sections 1-3)
  201. - Worker B: fixtures + factories (section 4)
  202. - Worker C: sample tests + helpers (section 5)
  203. In parallel-capable modes, runtime decides worker scheduling and concurrency.
  204. If `resolvedMode` is `sequential`, execute sections 1→5 in order.
  205. Regardless of mode, outputs must be identical in structure and quality.
  206. ### 7. Save Progress
  207. **Save this step's accumulated work to `{outputFile}`.**
  208. - **If `{outputFile}` does not exist** (first save), create it with YAML frontmatter:
  209. ```yaml
  210. ---
  211. stepsCompleted: ['step-03-scaffold-framework']
  212. lastStep: 'step-03-scaffold-framework'
  213. lastSaved: '{date}'
  214. ---
  215. ```
  216. Then write this step's output below the frontmatter.
  217. - **If `{outputFile}` already exists**, update:
  218. - Add `'step-03-scaffold-framework'` to `stepsCompleted` array (only if not already present)
  219. - Set `lastStep: 'step-03-scaffold-framework'`
  220. - Set `lastSaved: '{date}'`
  221. - Append this step's output to the appropriate section of the document.
  222. Load next step: `{nextStepFile}`
  223. ## 🚨 SYSTEM SUCCESS/FAILURE METRICS:
  224. ### ✅ SUCCESS:
  225. - Step completed in full with required outputs
  226. ### ❌ SYSTEM FAILURE:
  227. - Skipped sequence steps or missing outputs
  228. **Master Rule:** Skipping steps is FORBIDDEN.