@exaudeus/workrail 3.27.0 → 3.29.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 (160) hide show
  1. package/dist/console/assets/{index-FtTaDku8.js → index-BZ6HkxGf.js} +1 -1
  2. package/dist/console/index.html +1 -1
  3. package/dist/manifest.json +3 -3
  4. package/docs/README.md +57 -0
  5. package/docs/adrs/001-hybrid-storage-backend.md +38 -0
  6. package/docs/adrs/002-four-layer-context-classification.md +38 -0
  7. package/docs/adrs/003-checkpoint-trigger-strategy.md +35 -0
  8. package/docs/adrs/004-opt-in-encryption-strategy.md +36 -0
  9. package/docs/adrs/005-agent-first-workflow-execution-tokens.md +105 -0
  10. package/docs/adrs/006-append-only-session-run-event-log.md +76 -0
  11. package/docs/adrs/007-resume-and-checkpoint-only-sessions.md +51 -0
  12. package/docs/adrs/008-blocked-nodes-architectural-upgrade.md +178 -0
  13. package/docs/adrs/009-bridge-mode-single-instance-mcp.md +195 -0
  14. package/docs/adrs/010-release-pipeline.md +89 -0
  15. package/docs/architecture/README.md +7 -0
  16. package/docs/architecture/refactor-audit.md +364 -0
  17. package/docs/authoring-v2.md +527 -0
  18. package/docs/authoring.md +873 -0
  19. package/docs/changelog-recent.md +201 -0
  20. package/docs/configuration.md +505 -0
  21. package/docs/ctc-mcp-proposal.md +518 -0
  22. package/docs/design/README.md +22 -0
  23. package/docs/design/agent-cascade-protocol.md +96 -0
  24. package/docs/design/autonomous-console-design-candidates.md +253 -0
  25. package/docs/design/autonomous-console-design-review.md +111 -0
  26. package/docs/design/autonomous-platform-mvp-discovery.md +525 -0
  27. package/docs/design/claude-code-source-deep-dive.md +713 -0
  28. package/docs/design/console-cyberpunk-ui-discovery.md +504 -0
  29. package/docs/design/console-execution-trace-candidates-final.md +160 -0
  30. package/docs/design/console-execution-trace-candidates.md +211 -0
  31. package/docs/design/console-execution-trace-design-candidates-v2.md +113 -0
  32. package/docs/design/console-execution-trace-design-review.md +74 -0
  33. package/docs/design/console-execution-trace-discovery.md +394 -0
  34. package/docs/design/console-execution-trace-final-review.md +77 -0
  35. package/docs/design/console-execution-trace-review.md +92 -0
  36. package/docs/design/console-performance-discovery.md +415 -0
  37. package/docs/design/console-ui-backlog.md +280 -0
  38. package/docs/design/daemon-architecture-discovery.md +853 -0
  39. package/docs/design/daemon-design-candidates.md +318 -0
  40. package/docs/design/daemon-design-review-findings.md +119 -0
  41. package/docs/design/daemon-engine-design-candidates.md +210 -0
  42. package/docs/design/daemon-engine-design-review.md +131 -0
  43. package/docs/design/daemon-execution-engine-discovery.md +280 -0
  44. package/docs/design/daemon-gap-analysis.md +554 -0
  45. package/docs/design/daemon-owns-console-plan.md +168 -0
  46. package/docs/design/daemon-owns-console-review.md +91 -0
  47. package/docs/design/daemon-owns-console.md +195 -0
  48. package/docs/design/data-model-erd.md +11 -0
  49. package/docs/design/design-candidates-consolidate-dev-staleness.md +98 -0
  50. package/docs/design/design-candidates-walk-cache-depth-limit.md +80 -0
  51. package/docs/design/design-review-consolidate-dev-staleness.md +54 -0
  52. package/docs/design/design-review-walk-cache-depth-limit.md +48 -0
  53. package/docs/design/implementation-plan-consolidate-dev-staleness.md +142 -0
  54. package/docs/design/implementation-plan-walk-cache-depth-limit.md +141 -0
  55. package/docs/design/layer3b-ghost-nodes-design-candidates.md +229 -0
  56. package/docs/design/layer3b-ghost-nodes-design-review.md +93 -0
  57. package/docs/design/layer3b-ghost-nodes-implementation-plan.md +219 -0
  58. package/docs/design/list-workflows-latency-fix-plan.md +128 -0
  59. package/docs/design/list-workflows-latency-fix-review.md +55 -0
  60. package/docs/design/list-workflows-latency-fix.md +109 -0
  61. package/docs/design/native-context-management-api.md +11 -0
  62. package/docs/design/performance-sweep-2026-04.md +96 -0
  63. package/docs/design/routines-guide.md +219 -0
  64. package/docs/design/sequence-diagrams.md +11 -0
  65. package/docs/design/subagent-design-principles.md +220 -0
  66. package/docs/design/temporal-patterns-design-candidates.md +312 -0
  67. package/docs/design/temporal-patterns-design-review-findings.md +163 -0
  68. package/docs/design/test-isolation-from-config-file.md +335 -0
  69. package/docs/design/v2-core-design-locks.md +2746 -0
  70. package/docs/design/v2-lock-registry.json +734 -0
  71. package/docs/design/workflow-authoring-v2.md +1044 -0
  72. package/docs/design/workflow-docs-spec.md +218 -0
  73. package/docs/design/workflow-extension-points.md +687 -0
  74. package/docs/design/workrail-auto-trigger-system.md +359 -0
  75. package/docs/design/workrail-config-file-discovery.md +513 -0
  76. package/docs/docker.md +110 -0
  77. package/docs/generated/v2-lock-closure-plan.md +26 -0
  78. package/docs/generated/v2-lock-coverage.json +797 -0
  79. package/docs/generated/v2-lock-coverage.md +177 -0
  80. package/docs/ideas/backlog.md +3927 -0
  81. package/docs/ideas/design-candidates-mcp-resilience.md +208 -0
  82. package/docs/ideas/design-review-findings-mcp-resilience.md +119 -0
  83. package/docs/ideas/implementation_plan.md +249 -0
  84. package/docs/ideas/third-party-workflow-setup-design-thinking.md +1948 -0
  85. package/docs/implementation/02-architecture.md +316 -0
  86. package/docs/implementation/04-testing-strategy.md +124 -0
  87. package/docs/implementation/09-simple-workflow-guide.md +835 -0
  88. package/docs/implementation/13-advanced-validation-guide.md +874 -0
  89. package/docs/implementation/README.md +21 -0
  90. package/docs/integrations/claude-code.md +300 -0
  91. package/docs/integrations/firebender.md +315 -0
  92. package/docs/migration/v0.1.0.md +147 -0
  93. package/docs/naming-conventions.md +45 -0
  94. package/docs/planning/README.md +104 -0
  95. package/docs/planning/github-ticketing-playbook.md +195 -0
  96. package/docs/plans/README.md +24 -0
  97. package/docs/plans/agent-managed-ticketing-design.md +605 -0
  98. package/docs/plans/agentic-orchestration-roadmap.md +112 -0
  99. package/docs/plans/assessment-gates-engine-handoff.md +536 -0
  100. package/docs/plans/content-coherence-and-references.md +151 -0
  101. package/docs/plans/library-extraction-plan.md +340 -0
  102. package/docs/plans/mr-review-workflow-redesign.md +1451 -0
  103. package/docs/plans/native-context-management-epic.md +11 -0
  104. package/docs/plans/perf-fixes-design-candidates.md +225 -0
  105. package/docs/plans/perf-fixes-design-review-findings.md +61 -0
  106. package/docs/plans/perf-fixes-new-issues-candidates.md +264 -0
  107. package/docs/plans/perf-fixes-new-issues-review.md +110 -0
  108. package/docs/plans/prompt-fragments.md +53 -0
  109. package/docs/plans/ui-ux-workflow-design-candidates.md +120 -0
  110. package/docs/plans/ui-ux-workflow-discovery.md +100 -0
  111. package/docs/plans/ui-ux-workflow-review.md +48 -0
  112. package/docs/plans/v2-followup-enhancements.md +587 -0
  113. package/docs/plans/workflow-categories-candidates.md +105 -0
  114. package/docs/plans/workflow-categories-discovery.md +110 -0
  115. package/docs/plans/workflow-categories-review.md +51 -0
  116. package/docs/plans/workflow-discovery-model-candidates.md +94 -0
  117. package/docs/plans/workflow-discovery-model-discovery.md +74 -0
  118. package/docs/plans/workflow-discovery-model-review.md +48 -0
  119. package/docs/plans/workflow-source-setup-phase-1.md +245 -0
  120. package/docs/plans/workflow-source-setup-phase-2.md +361 -0
  121. package/docs/plans/workflow-staleness-detection-candidates.md +104 -0
  122. package/docs/plans/workflow-staleness-detection-review.md +58 -0
  123. package/docs/plans/workflow-staleness-detection.md +80 -0
  124. package/docs/plans/workflow-v2-design.md +69 -0
  125. package/docs/plans/workflow-v2-roadmap.md +74 -0
  126. package/docs/plans/workflow-validation-design.md +98 -0
  127. package/docs/plans/workflow-validation-roadmap.md +108 -0
  128. package/docs/plans/workrail-platform-vision.md +420 -0
  129. package/docs/reference/agent-context-cleaner-snippet.md +94 -0
  130. package/docs/reference/agent-context-guidance.md +140 -0
  131. package/docs/reference/context-optimization.md +284 -0
  132. package/docs/reference/example-workflow-repository-template/.github/workflows/validate.yml +125 -0
  133. package/docs/reference/example-workflow-repository-template/README.md +268 -0
  134. package/docs/reference/example-workflow-repository-template/workflows/example-workflow.json +80 -0
  135. package/docs/reference/external-workflow-repositories.md +916 -0
  136. package/docs/reference/feature-flags-architecture.md +472 -0
  137. package/docs/reference/feature-flags.md +349 -0
  138. package/docs/reference/god-tier-workflow-validation.md +272 -0
  139. package/docs/reference/loop-optimization.md +209 -0
  140. package/docs/reference/loop-validation.md +176 -0
  141. package/docs/reference/loops.md +465 -0
  142. package/docs/reference/mcp-platform-constraints.md +59 -0
  143. package/docs/reference/recovery.md +88 -0
  144. package/docs/reference/releases.md +177 -0
  145. package/docs/reference/troubleshooting.md +105 -0
  146. package/docs/reference/workflow-execution-contract.md +998 -0
  147. package/docs/roadmap/README.md +22 -0
  148. package/docs/roadmap/legacy-planning-status.md +103 -0
  149. package/docs/roadmap/now-next-later.md +70 -0
  150. package/docs/roadmap/open-work-inventory.md +389 -0
  151. package/docs/tickets/README.md +39 -0
  152. package/docs/tickets/next-up.md +76 -0
  153. package/docs/workflow-management.md +317 -0
  154. package/docs/workflow-templates.md +423 -0
  155. package/docs/workflow-validation.md +184 -0
  156. package/docs/workflows.md +254 -0
  157. package/package.json +3 -1
  158. package/spec/authoring-spec.json +61 -16
  159. package/workflows/workflow-for-workflows.json +252 -93
  160. package/workflows/workflow-for-workflows.v2.json +188 -77
@@ -0,0 +1,316 @@
1
+ # Architecture Guide
2
+
3
+ > 🏛️ **System architecture and design principles**
4
+
5
+ [![Build](https://img.shields.io/github/actions/workflow/status/EtienneBBeaulac/mcp/ci.yml?branch=main)]()
6
+ [![Spec Version](https://img.shields.io/badge/spec-1.0.0-blue.svg)](specs/)
7
+ [![MCP Compatible](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.org)
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [System Overview](#system-overview)
12
+ 2. [Architecture Layers](#architecture-layers)
13
+ 3. [Component Roles](#component-roles)
14
+ 4. [Data Flow](#data-flow)
15
+ 5. [Key Technical Decisions](#key-technical-decisions)
16
+ 6. [Scalability & Monitoring](#scalability--monitoring)
17
+ 7. [Migration Paths](#migration-paths)
18
+ 8. [References](#references)
19
+
20
+ ---
21
+
22
+ ## System Overview
23
+
24
+ The MVP is fully implemented using **Clean Architecture**. Responsibilities are split into **Domain**, **Application**, and **Infrastructure** layers wired together by a lightweight **dependency-injection container**.
25
+
26
+ ```
27
+ ┌───────────┐ JSON-RPC ┌───────────────┐ Uses ┌─────────────┐
28
+ │ AI Agent │ ───────────▶ │ RPC Adapter │ ─────▶ │ Use Cases │
29
+ └───────────┘ stdin │ (server.ts) │ └─────┬──────┘
30
+ ▼ └───────────────┘ │DTOs
31
+ stdout calls ▼
32
+ ┌───────────────┐ pure logic
33
+ │ Domain │◀───────────
34
+ └───────────────┘ Entities
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Architecture Layers
40
+
41
+ | Layer | Folder | Responsibilities | Depends On |
42
+ |-------|--------|------------------|------------|
43
+ | Domain | `src/domain` | Pure entities & error classes | – |
44
+ | Application | `src/application` | Use-cases, services, validation | Domain |
45
+ | Infrastructure | `src/infrastructure` | Adapters (RPC, storage, caching) | Application / Domain |
46
+
47
+ Cross-cutting concerns (logging, DI) live at the root.
48
+
49
+ ---
50
+
51
+ ## Component Roles
52
+
53
+ ### RPC Server (Infrastructure)
54
+ * File: `src/infrastructure/rpc/server.ts`
55
+ * Exposes JSON-RPC 2.0 over **stdin/stdout**.
56
+ * Delegates each method (`workflow_list`, `workflow_get`, `workflow_next`, `workflow_validate`, `workflow_validate_json`) to the corresponding **use-case**.
57
+ * Applies request-schema validation middleware and maps thrown domain errors to JSON-RPC error objects.
58
+
59
+ ### Use-Cases (Application)
60
+ * Folder: `src/application/use-cases/`
61
+ * Pure functions with no side-effects.
62
+ * Injected with an `IWorkflowStorage` implementation and executed by the server.
63
+ * **Current**: `get-next-step` accepts optional context parameter for conditional step evaluation.
64
+ * **Current**: `validate-workflow-json` provides direct JSON validation without external tool dependencies.
65
+
66
+ ### ValidationEngine (Application)
67
+ * **File**: `src/application/services/validation-engine.ts`
68
+ * **Purpose**: Advanced step output validation with three enhancement types for comprehensive quality assurance.
69
+ * **Architecture**: Dependency-injected service with AJV integration and performance optimizations.
70
+
71
+ #### Core Validation Enhancement Types
72
+
73
+ **1. JSON Schema Validation**
74
+ * **Technology**: AJV (Another JSON Schema Validator) with Draft 7 support
75
+ * **Performance**: Map-based compiled schema caching for sub-millisecond validation
76
+ * **Capabilities**: Full JSON validation (objects, arrays, primitives) with detailed error reporting
77
+ * **Use Cases**: Structured output validation, API response validation, complex data format verification
78
+
79
+ **2. Context-Aware Validation**
80
+ * **Technology**: Integration with `condition-evaluator.ts` for dynamic rule application
81
+ * **Capabilities**: Conditional validation rules based on execution context variables
82
+ * **Operators**: equals, not_equals, gt, gte, lt, lte, and, or, not
83
+ * **Use Cases**: Task-specific validation, user role-based rules, environment-dependent validation
84
+ * **Safety**: Graceful degradation when context variables are missing
85
+
86
+ **3. Logical Composition**
87
+ * **Technology**: Recursive composition evaluation with unlimited nesting depth
88
+ * **Operators**: AND (all must pass), OR (at least one must pass), NOT (must not pass)
89
+ * **Format**: Both array format (backward compatible) and composition object format
90
+ * **Use Cases**: Complex business logic validation, multi-condition requirements, sophisticated validation expressions
91
+
92
+ #### Validation Rule Types
93
+
94
+ ```typescript
95
+ // Basic rule types with comprehensive support
96
+ ValidationRule {
97
+ type: 'contains' | 'regex' | 'length' | 'schema';
98
+ message: string;
99
+ condition?: Condition; // Optional context-aware evaluation
100
+ // Type-specific properties...
101
+ }
102
+
103
+ // Logical composition for complex expressions
104
+ ValidationComposition {
105
+ and?: ValidationCriteria[];
106
+ or?: ValidationCriteria[];
107
+ not?: ValidationCriteria;
108
+ }
109
+ ```
110
+
111
+ #### Performance Architecture
112
+
113
+ * **Schema Compilation Cache**: `Map<string, ValidateFunction>` prevents recompilation overhead
114
+ * **Conditional Evaluation**: Rules with unmet conditions are skipped entirely
115
+ * **Lazy Evaluation**: Composition operators short-circuit when possible (AND stops on first failure, OR stops on first success)
116
+ * **Memory Management**: Efficient validation with minimal allocation during execution
117
+
118
+ #### Error Handling & Debugging
119
+
120
+ * **Structured Error Messages**: Clear, actionable validation failure descriptions
121
+ * **AJV Error Integration**: Detailed JSON Schema validation errors with path information
122
+ * **Validation Context**: Error messages include context about which rule failed and why
123
+ * **Debug Information**: Comprehensive validation results with issues and suggestions
124
+
125
+ #### Integration Patterns
126
+
127
+ * **WorkflowService Integration**: Step output validation via `validateStepOutput()`
128
+ * **Workflow JSON Validation**: Direct JSON validation via `validateWorkflowJson()` use case
129
+ * **Backward Compatibility**: Legacy string-based validation rules still supported
130
+ * **Dependency Injection**: Clean separation from storage and transport concerns
131
+ * **Testing Support**: Extensive test coverage (72 tests) demonstrating all validation patterns
132
+
133
+ #### JSON Validation Use Case
134
+
135
+ The `validate-workflow-json` use case provides comprehensive workflow JSON validation:
136
+
137
+ * **JSON Syntax Validation**: Parses and validates JSON syntax with detailed error messages
138
+ * **Schema Compliance**: Validates against the workflow schema using the same ValidationEngine
139
+ * **Error Enhancement**: Provides actionable suggestions for LLM consumption
140
+ * **Standalone Operation**: No external dependencies or storage requirements
141
+ * **Integration**: Uses existing validation infrastructure without code duplication
142
+
143
+ ### Storage Adapters (Infrastructure)
144
+ * Folder: `src/infrastructure/storage/`
145
+ * Implement the async `IWorkflowStorage` interface.
146
+ * `FileWorkflowStorage` – reads workflow JSON files.
147
+ * `InMemoryWorkflowStorage` – used in tests.
148
+ * `SchemaValidatingWorkflowStorage` – wraps another storage, performing workflow-schema validation.
149
+ * `CachingWorkflowStorage` – TTL cache wrapper.
150
+ * Adapters are composed via the DI container, yielding a single façade to the application layer.
151
+
152
+ ### Dependency Injection Container
153
+ * File: `src/container.ts`
154
+ * Registers storage stack, error handler, and RPC server for production and for tests.
155
+
156
+ ---
157
+
158
+ ## Data Flow
159
+
160
+ 1. **Request** – Agent sends JSON-RPC over stdin.
161
+ 2. **RPC Layer** parses & validates parameters (Ajv).
162
+ 3. **Use-Case** executes core logic, querying storage via injected adapter.
163
+ 4. **WorkflowService** processes step data, including agentRole field handling for agent behavioral guidance.
164
+ 5. **ValidationEngine** – For `workflow_validate` calls, applies advanced validation rules to step output. For `workflow_validate_json` calls, validates JSON syntax and schema compliance.
165
+ 6. **Domain Error**? → mapped to JSON-RPC error.
166
+ 7. **Response** emitted on stdout.
167
+
168
+ ### AgentRole Processing Flow
169
+
170
+ ```
171
+ WorkflowStep → WorkflowService.getNextStep() → {
172
+ Step Selection → Find next eligible step
173
+
174
+ Guidance Construction → {
175
+ AgentRole Present? → Add "## Agent Role Instructions" header + agentRole content
176
+ Guidance Present? → Add "## Step Guidance" section
177
+ Combine with user-facing prompt
178
+ }
179
+
180
+ Response Assembly → {
181
+ step: Original step data (includes agentRole field)
182
+ guidance: { prompt: Enhanced prompt with agent instructions }
183
+ isComplete: Workflow completion status
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### Validation Flow Detail
189
+
190
+ ```
191
+ Step Output → ValidationEngine.validate() → {
192
+ Context Evaluation → Filter applicable rules
193
+
194
+ Criteria Assessment → {
195
+ Array Format: Apply each rule sequentially
196
+ Composition: Recursive logical evaluation (and/or/not)
197
+ }
198
+
199
+ Rule Execution → {
200
+ contains: String inclusion check
201
+ regex: Pattern matching with flags
202
+ length: Min/max constraints
203
+ schema: AJV compilation and validation
204
+ }
205
+
206
+ Result Aggregation → ValidationResult
207
+ }
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Key Technical Decisions
213
+
214
+ * **Clean Architecture** chosen to isolate domain logic from transport/storage concerns and ease future adapter swaps (e.g., WebSocket transport).
215
+ * **TypeScript** with strict null-checks enabled.
216
+ * **Ajv** for high-performance JSON-schema validation (both RPC params & workflow documents).
217
+ * **Advanced ValidationEngine Architecture** – Three-tier validation system (JSON Schema + Context-Aware + Logical Composition) provides comprehensive output quality assurance without sacrificing performance.
218
+ * **Schema Compilation Caching** – Map-based validator caching prevents repeated AJV compilation overhead during high-frequency validation operations.
219
+ * **Context-Aware Validation** – Dynamic rule application based on execution context enables task-specific, user-role-based, and environment-dependent validation patterns.
220
+ * **Backward-Compatible Validation** – Support for both legacy array-based rules and modern composition syntax ensures smooth migration paths.
221
+ * **AgentRole Field Architecture** – Clean separation of agent behavioral instructions from user-facing prompts, processed at the WorkflowService layer with backward compatibility.
222
+ * **Async I/O Only** – storage interface returns `Promise` to support remote stores later.
223
+ * **Thin Adapters** – server & storage wrappers are intentionally small; majority of logic resides in use-cases.
224
+ * **Conditional Step Execution** – Safe expression evaluation enables dynamic workflows that adapt based on context variables like task scope and user expertise.
225
+
226
+ ---
227
+
228
+ ## Scalability & Monitoring
229
+
230
+ * **Horizontal Scaling** – Multiple server instances can run behind a queue; stdin transport can be swapped for HTTP without touching domain code.
231
+ * **Caching** – `CachingWorkflowStorage` reduces disk access; switch to Redis in distributed setups.
232
+ * **Observability** – Structured logging via the error handler + TODO: OTEL traces.
233
+
234
+ ---
235
+
236
+ ## Migration Paths
237
+
238
+ | From… | To (v0.0.1-alpha) | Migration Notes |
239
+ |-------|-----------|-----------------|
240
+ | `src/core/server.ts` JSON-RPC wrapper | `src/infrastructure/rpc/server.ts` | Now a pure adapter, delegates to use-cases. |
241
+ | Modules in `src/tools/` | Removed | Logic moved to application use-cases. |
242
+ | `src/workflow/*.ts` storage impls | `src/infrastructure/storage/*` | Names unchanged; import paths updated. |
243
+ | Ad-hoc validation utilities | `src/application/services/validation-engine.ts` | Advanced ValidationEngine with three enhancement types. |
244
+
245
+ ---
246
+
247
+ ## Documentation Standards & Terminology
248
+
249
+ ### Core Validation Terminology
250
+
251
+ **Standardized Terms** (use consistently across all documentation):
252
+ * **ValidationEngine** – The core validation service class
253
+ * **ValidationRule** – Individual validation criteria (contains, regex, length, schema)
254
+ * **ValidationComposition** – Logical grouping of rules with and/or/not operators
255
+ * **ValidationCriteria** – Union type supporting both rules and compositions
256
+ * **ValidationResult** – Structured output with valid/issues/suggestions
257
+ * **Context-Aware Validation** – Rules that apply conditionally based on execution context
258
+ * **Condition Context** – Variables available for conditional rule evaluation
259
+
260
+ ### Code Example Standards
261
+
262
+ **TypeScript Code Blocks**: Always include proper typing
263
+ ```typescript
264
+ // Good - includes types and context
265
+ const result: ValidationResult = await engine.validate(output, rules, context);
266
+
267
+ // Bad - no types or context
268
+ const result = engine.validate(output, rules);
269
+ ```
270
+
271
+ **JSON Examples**: Always validate against current schema
272
+ ```json
273
+ {
274
+ "validationCriteria": {
275
+ "and": [
276
+ { "type": "contains", "value": "success", "message": "Must contain success" },
277
+ { "type": "length", "min": 10, "message": "Must be detailed" }
278
+ ]
279
+ }
280
+ }
281
+ ```
282
+
283
+ ### Documentation Structure Standards
284
+
285
+ **Section Headers**: Use descriptive, action-oriented titles
286
+ * "Implementing Advanced Validation Rules"
287
+ * "Validation"
288
+
289
+ **Code Comments**: Explain the why, not just the what
290
+ ```typescript
291
+ // Apply conditional rules only when context matches
292
+ if (rule.condition && !evaluateCondition(rule.condition, context)) {
293
+ continue; // Skip rule when condition not met
294
+ }
295
+ ```
296
+
297
+ ### Cross-Reference Standards
298
+
299
+ **File References**: Always use relative paths from current document
300
+ * `../../spec/workflow.schema.json`
301
+ * `../implementation/13-advanced-validation-guide.md`
302
+
303
+ **Validation Examples**: Must demonstrate real-world use cases
304
+ * Task-specific validation scenarios
305
+ * Performance optimization patterns
306
+ * Error handling and debugging approaches
307
+
308
+ ---
309
+
310
+ ## References
311
+
312
+ * [Main README](../../README.md)
313
+ * [Advanced Validation Guide](13-advanced-validation-guide.md)
314
+ * [Simple Workflow Guide](09-simple-workflow-guide.md)
315
+ * [API Specification](../../spec/mcp-api-v1.0.md)
316
+ * [Workflow Schema](../../spec/workflow.schema.json)
@@ -0,0 +1,124 @@
1
+ # Testing Strategy Guide
2
+
3
+ > **Comprehensive testing strategy for the WorkRail System**
4
+
5
+ [![Build](https://img.shields.io/github/actions/workflow/status/EtienneBBeaulac/mcp/ci.yml?branch=main)]()
6
+ [![Coverage](https://img.shields.io/badge/coverage-90%25-green)]()
7
+ [![MCP Compatible](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.org)
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Testing Philosophy](#testing-philosophy)
12
+ 2. [Testing Pyramid](#testing-pyramid)
13
+ 3. [Current Coverage](#current-coverage)
14
+ 4. [Testing Requirements](#testing-requirements)
15
+ 5. [Approaches & Tooling](#approaches--tooling)
16
+ 6. [Quality Gates](#quality-gates)
17
+
18
+ ---
19
+
20
+ ## Testing Philosophy
21
+
22
+ Our goal is to guarantee **high confidence with fast feedback**. Tests must be deterministic, isolated, and easy to maintain.
23
+
24
+ Core principles:
25
+ 1. **Test-Driven Development (TDD)** where practical.
26
+ 2. **Focus on Pure Logic** – Domain & Application layers are unit-tested in isolation.
27
+ 3. **Contract Tests** – RPC layer has schema-driven tests ensuring parameter validation & error mapping.
28
+ 4. **No Sleep()** – async code is awaited, not timed.
29
+ 5. **High Reliability** – flaky tests are fixed or removed immediately.
30
+
31
+ ---
32
+
33
+ ## Testing Pyramid
34
+
35
+ ```
36
+ ┌─────────────┐
37
+ │ E2E Tests │ ← Minimal happy-path CLI / Docker checks
38
+ └─────────────┘
39
+ ┌─────────────┐
40
+ │Integration │ ← RPC ↔ use-cases ↔ storage
41
+ │ Tests │
42
+ └─────────────┘
43
+ ┌─────────────┐
44
+ │ Unit Tests │ ← Pure functions (use-cases, validation, errors)
45
+ └─────────────┘
46
+ ```
47
+
48
+ Target distribution: **60% unit / 30% integration / 10% E2E**.
49
+
50
+ ---
51
+
52
+ ## Current Coverage
53
+
54
+ | Suite | Tests | Status | Notes |
55
+ |-------|-------|--------|-------|
56
+ | Unit Tests | 47 | Passing | covers use-cases, storage adapters, validation, error mapping, CLI |
57
+ | Integration Tests | 22 | Passing | JSON-RPC requests through stdin/stdout mocked in tests |
58
+ | Contract Tests | 12 | Passing | server contract validation |
59
+ | Performance Tests | 7 | Failing | optimization in progress |
60
+ | **Total** | **88** | **81 passing, 7 failing** | comprehensive coverage |
61
+
62
+ ### Test Suite Breakdown
63
+ - **Unit Tests**: 47 tests covering CLI validation, storage adapters, workflow validation, error mapping
64
+ - **Integration Tests**: 22 tests covering server functionality and RPC layer
65
+ - **Contract Tests**: 12 tests ensuring API compliance
66
+ - **Performance Tests**: 7 tests (optimization in progress)
67
+ - **Workflow Validation Tests**: 27 tests covering JSON validation use case and MCP tool integration
68
+
69
+ `npm test` executes all Jest suites in <15 s locally.
70
+
71
+ ---
72
+
73
+ ## Testing Requirements
74
+
75
+ ### Unit
76
+ * Business rules in Application layer.
77
+ * Domain error classes & mapping.
78
+ * Validation schemas (positive & negative cases).
79
+ * CLI command validation and error handling.
80
+ * Workflow JSON validation use case (syntax, schema, error messages).
81
+
82
+ ### Workflow Validation Testing Patterns
83
+ * **JSON Syntax Validation**: Malformed JSON, missing quotes, trailing commas
84
+ * **Schema Compliance**: Required fields, type validation, constraint checking
85
+ * **Error Message Quality**: Actionable suggestions, clear problem descriptions
86
+ * **Edge Cases**: Empty JSON, null values, extremely large workflows
87
+ * **Integration**: MCP tool parameter validation and response format
88
+
89
+ ### Integration
90
+ * RPC server end-to-end through use-cases.
91
+ * Storage composition (cache + schema validate + file).
92
+
93
+ ### Performance
94
+ * Response time assertion (<200 ms) per RPC call.
95
+ * Throughput testing for workflow execution.
96
+
97
+ ### Security & Performance
98
+ * Path-traversal checks in FileStorage.
99
+ * Version field consistency validation.
100
+
101
+ ---
102
+
103
+ ## Approaches & Tooling
104
+
105
+ | Area | Tooling |
106
+ |------|---------|
107
+ | Test runner | **Jest** (ts-jest) |
108
+ | Coverage | `--coverage` produces lcov & badge update CI |
109
+ | Fast mocks | **jest.mock** for DI container overrides |
110
+ | Static analysis | **ESLint**, **TypeScript strict** |
111
+ | CI pipeline | GitHub Actions (`ci.yml`) – lint, test, coverage gate |
112
+
113
+ ---
114
+
115
+ ## Quality Gates
116
+
117
+ 1. **Lint Passes** – `npm run lint` must return 0.
118
+ 2. **Core Tests Pass** – `npm test` unit and integration tests must pass.
119
+ 3. **Coverage ≥ 90%** – enforced in jest config & CI badge.
120
+ 4. **No TODO's** – eslint rule `no-warning-comments` for production code.
121
+
122
+ Performance test failures are allowed during optimization phases but must be addressed before release.
123
+
124
+ These gates block merges via required GitHub checks.