cmdx 1.0.1 → 1.1.1

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 (170) hide show
  1. checksums.yaml +4 -4
  2. data/.cursor/prompts/docs.md +9 -0
  3. data/.cursor/prompts/rspec.md +21 -0
  4. data/.cursor/prompts/yardoc.md +13 -0
  5. data/.rubocop.yml +2 -0
  6. data/CHANGELOG.md +29 -3
  7. data/README.md +2 -1
  8. data/docs/ai_prompts.md +269 -195
  9. data/docs/basics/call.md +126 -60
  10. data/docs/basics/chain.md +190 -160
  11. data/docs/basics/context.md +242 -154
  12. data/docs/basics/setup.md +302 -32
  13. data/docs/callbacks.md +382 -119
  14. data/docs/configuration.md +211 -49
  15. data/docs/deprecation.md +245 -0
  16. data/docs/getting_started.md +161 -39
  17. data/docs/internationalization.md +590 -70
  18. data/docs/interruptions/exceptions.md +135 -118
  19. data/docs/interruptions/faults.md +152 -127
  20. data/docs/interruptions/halt.md +134 -80
  21. data/docs/logging.md +183 -120
  22. data/docs/middlewares.md +165 -392
  23. data/docs/outcomes/result.md +140 -112
  24. data/docs/outcomes/states.md +134 -99
  25. data/docs/outcomes/statuses.md +204 -146
  26. data/docs/parameters/coercions.md +251 -289
  27. data/docs/parameters/defaults.md +224 -169
  28. data/docs/parameters/definitions.md +289 -141
  29. data/docs/parameters/namespacing.md +250 -161
  30. data/docs/parameters/validations.md +247 -159
  31. data/docs/testing.md +196 -203
  32. data/docs/workflows.md +146 -101
  33. data/lib/cmdx/.DS_Store +0 -0
  34. data/lib/cmdx/callback.rb +39 -55
  35. data/lib/cmdx/callback_registry.rb +80 -73
  36. data/lib/cmdx/chain.rb +65 -122
  37. data/lib/cmdx/chain_inspector.rb +23 -116
  38. data/lib/cmdx/chain_serializer.rb +34 -146
  39. data/lib/cmdx/coercion.rb +57 -0
  40. data/lib/cmdx/coercion_registry.rb +113 -0
  41. data/lib/cmdx/coercions/array.rb +18 -36
  42. data/lib/cmdx/coercions/big_decimal.rb +21 -33
  43. data/lib/cmdx/coercions/boolean.rb +21 -40
  44. data/lib/cmdx/coercions/complex.rb +18 -31
  45. data/lib/cmdx/coercions/date.rb +20 -39
  46. data/lib/cmdx/coercions/date_time.rb +22 -39
  47. data/lib/cmdx/coercions/float.rb +19 -32
  48. data/lib/cmdx/coercions/hash.rb +22 -41
  49. data/lib/cmdx/coercions/integer.rb +20 -33
  50. data/lib/cmdx/coercions/rational.rb +20 -32
  51. data/lib/cmdx/coercions/string.rb +23 -31
  52. data/lib/cmdx/coercions/time.rb +24 -40
  53. data/lib/cmdx/coercions/virtual.rb +14 -31
  54. data/lib/cmdx/configuration.rb +101 -162
  55. data/lib/cmdx/context.rb +34 -166
  56. data/lib/cmdx/core_ext/hash.rb +42 -67
  57. data/lib/cmdx/core_ext/module.rb +35 -79
  58. data/lib/cmdx/core_ext/object.rb +63 -98
  59. data/lib/cmdx/correlator.rb +59 -154
  60. data/lib/cmdx/error.rb +37 -202
  61. data/lib/cmdx/errors.rb +153 -216
  62. data/lib/cmdx/fault.rb +68 -150
  63. data/lib/cmdx/faults.rb +26 -137
  64. data/lib/cmdx/immutator.rb +22 -110
  65. data/lib/cmdx/lazy_struct.rb +110 -186
  66. data/lib/cmdx/log_formatters/json.rb +14 -40
  67. data/lib/cmdx/log_formatters/key_value.rb +14 -40
  68. data/lib/cmdx/log_formatters/line.rb +14 -48
  69. data/lib/cmdx/log_formatters/logstash.rb +14 -57
  70. data/lib/cmdx/log_formatters/pretty_json.rb +14 -50
  71. data/lib/cmdx/log_formatters/pretty_key_value.rb +13 -46
  72. data/lib/cmdx/log_formatters/pretty_line.rb +16 -54
  73. data/lib/cmdx/log_formatters/raw.rb +19 -49
  74. data/lib/cmdx/logger.rb +22 -79
  75. data/lib/cmdx/logger_ansi.rb +31 -72
  76. data/lib/cmdx/logger_serializer.rb +74 -103
  77. data/lib/cmdx/middleware.rb +56 -60
  78. data/lib/cmdx/middleware_registry.rb +82 -77
  79. data/lib/cmdx/middlewares/correlate.rb +41 -226
  80. data/lib/cmdx/middlewares/timeout.rb +46 -185
  81. data/lib/cmdx/parameter.rb +167 -183
  82. data/lib/cmdx/parameter_evaluator.rb +231 -0
  83. data/lib/cmdx/parameter_inspector.rb +37 -55
  84. data/lib/cmdx/parameter_registry.rb +65 -84
  85. data/lib/cmdx/parameter_serializer.rb +32 -76
  86. data/lib/cmdx/railtie.rb +24 -107
  87. data/lib/cmdx/result.rb +254 -259
  88. data/lib/cmdx/result_ansi.rb +28 -80
  89. data/lib/cmdx/result_inspector.rb +34 -70
  90. data/lib/cmdx/result_logger.rb +23 -77
  91. data/lib/cmdx/result_serializer.rb +59 -125
  92. data/lib/cmdx/rspec/matchers.rb +28 -0
  93. data/lib/cmdx/rspec/result_matchers/be_executed.rb +42 -0
  94. data/lib/cmdx/rspec/result_matchers/be_failed_task.rb +94 -0
  95. data/lib/cmdx/rspec/result_matchers/be_skipped_task.rb +94 -0
  96. data/lib/cmdx/rspec/result_matchers/be_state_matchers.rb +59 -0
  97. data/lib/cmdx/rspec/result_matchers/be_status_matchers.rb +57 -0
  98. data/lib/cmdx/rspec/result_matchers/be_successful_task.rb +87 -0
  99. data/lib/cmdx/rspec/result_matchers/have_bad_outcome.rb +51 -0
  100. data/lib/cmdx/rspec/result_matchers/have_caused_failure.rb +58 -0
  101. data/lib/cmdx/rspec/result_matchers/have_chain_index.rb +59 -0
  102. data/lib/cmdx/rspec/result_matchers/have_context.rb +86 -0
  103. data/lib/cmdx/rspec/result_matchers/have_empty_metadata.rb +54 -0
  104. data/lib/cmdx/rspec/result_matchers/have_good_outcome.rb +52 -0
  105. data/lib/cmdx/rspec/result_matchers/have_metadata.rb +114 -0
  106. data/lib/cmdx/rspec/result_matchers/have_preserved_context.rb +66 -0
  107. data/lib/cmdx/rspec/result_matchers/have_received_thrown_failure.rb +64 -0
  108. data/lib/cmdx/rspec/result_matchers/have_runtime.rb +78 -0
  109. data/lib/cmdx/rspec/result_matchers/have_thrown_failure.rb +76 -0
  110. data/lib/cmdx/rspec/task_matchers/be_well_formed_task.rb +62 -0
  111. data/lib/cmdx/rspec/task_matchers/have_callback.rb +85 -0
  112. data/lib/cmdx/rspec/task_matchers/have_cmd_setting.rb +68 -0
  113. data/lib/cmdx/rspec/task_matchers/have_executed_callbacks.rb +92 -0
  114. data/lib/cmdx/rspec/task_matchers/have_middleware.rb +46 -0
  115. data/lib/cmdx/rspec/task_matchers/have_parameter.rb +181 -0
  116. data/lib/cmdx/task.rb +336 -427
  117. data/lib/cmdx/task_deprecator.rb +52 -0
  118. data/lib/cmdx/task_processor.rb +246 -0
  119. data/lib/cmdx/task_serializer.rb +34 -69
  120. data/lib/cmdx/utils/ansi_color.rb +13 -89
  121. data/lib/cmdx/utils/log_timestamp.rb +13 -42
  122. data/lib/cmdx/utils/monotonic_runtime.rb +11 -63
  123. data/lib/cmdx/utils/name_affix.rb +21 -71
  124. data/lib/cmdx/validator.rb +57 -0
  125. data/lib/cmdx/validator_registry.rb +108 -0
  126. data/lib/cmdx/validators/exclusion.rb +55 -94
  127. data/lib/cmdx/validators/format.rb +31 -85
  128. data/lib/cmdx/validators/inclusion.rb +65 -110
  129. data/lib/cmdx/validators/length.rb +117 -133
  130. data/lib/cmdx/validators/numeric.rb +123 -130
  131. data/lib/cmdx/validators/presence.rb +38 -79
  132. data/lib/cmdx/version.rb +1 -7
  133. data/lib/cmdx/workflow.rb +58 -330
  134. data/lib/cmdx.rb +1 -1
  135. data/lib/generators/cmdx/install_generator.rb +14 -31
  136. data/lib/generators/cmdx/task_generator.rb +39 -55
  137. data/lib/generators/cmdx/templates/install.rb +24 -6
  138. data/lib/generators/cmdx/workflow_generator.rb +41 -66
  139. data/lib/locales/ar.yml +0 -1
  140. data/lib/locales/cs.yml +0 -1
  141. data/lib/locales/da.yml +0 -1
  142. data/lib/locales/de.yml +0 -1
  143. data/lib/locales/el.yml +0 -1
  144. data/lib/locales/en.yml +0 -1
  145. data/lib/locales/es.yml +0 -1
  146. data/lib/locales/fi.yml +0 -1
  147. data/lib/locales/fr.yml +0 -1
  148. data/lib/locales/he.yml +0 -1
  149. data/lib/locales/hi.yml +0 -1
  150. data/lib/locales/it.yml +0 -1
  151. data/lib/locales/ja.yml +0 -1
  152. data/lib/locales/ko.yml +0 -1
  153. data/lib/locales/nl.yml +0 -1
  154. data/lib/locales/no.yml +0 -1
  155. data/lib/locales/pl.yml +0 -1
  156. data/lib/locales/pt.yml +0 -1
  157. data/lib/locales/ru.yml +0 -1
  158. data/lib/locales/sv.yml +0 -1
  159. data/lib/locales/th.yml +0 -1
  160. data/lib/locales/tr.yml +0 -1
  161. data/lib/locales/vi.yml +0 -1
  162. data/lib/locales/zh.yml +0 -1
  163. metadata +36 -8
  164. data/lib/cmdx/parameter_validator.rb +0 -81
  165. data/lib/cmdx/parameter_value.rb +0 -244
  166. data/lib/cmdx/parameters_inspector.rb +0 -72
  167. data/lib/cmdx/parameters_serializer.rb +0 -115
  168. data/lib/cmdx/rspec/result_matchers.rb +0 -917
  169. data/lib/cmdx/rspec/task_matchers.rb +0 -570
  170. data/lib/cmdx/validators/custom.rb +0 -102
data/docs/ai_prompts.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AI Prompt Templates
2
2
 
3
- This guide provides AI prompt templates for building CMDx Task and Workflow objects, helping you leverage AI assistants to generate well-structured, production-ready command objects.
3
+ AI prompt templates provide structured guidance for generating production-ready CMDx Task and Workflow objects. These templates ensure consistent code quality, proper framework usage, and comprehensive testing coverage when working with AI assistants.
4
4
 
5
5
  ## Table of Contents
6
6
 
@@ -9,196 +9,216 @@ This guide provides AI prompt templates for building CMDx Task and Workflow obje
9
9
  - [Task Generation Templates](#task-generation-templates)
10
10
  - [Workflow Generation Templates](#workflow-generation-templates)
11
11
  - [Testing Templates](#testing-templates)
12
- - [Best Practices for AI Prompts](#best-practices-for-ai-prompts)
12
+ - [Error Handling and Edge Cases](#error-handling-and-edge-cases)
13
+ - [Best Practices](#best-practices)
13
14
 
14
15
  ## TLDR
15
16
 
16
- - **Purpose** - Pre-written prompts to help AI assistants generate production-ready CMDx code
17
- - **Templates** - Framework context, task generation, workflow generation, and testing templates
18
- - **Framework context** - Essential CMDx concepts and coding standards for AI understanding
19
- - **Task templates** - Structured prompts for generating tasks with parameters, validations, and tests
20
- - **Workflow templates** - Prompts for orchestrating multi-step business processes
21
- - **Testing templates** - Comprehensive RSpec test generation with CMDx matchers
17
+ > [!NOTE]
18
+ > Pre-written prompts help AI assistants generate well-structured CMDx code with proper validations, error handling, and comprehensive tests.
19
+
20
+ ```ruby
21
+ # Task generation pattern
22
+ "Create a CMDx task that [ACTION] with parameters [PARAMS] and validation [RULES]"
23
+
24
+ # Workflow orchestration pattern
25
+ "Create a CMDx workflow that orchestrates [PROCESS] with steps [TASKS] and error handling [STRATEGY]"
26
+
27
+ # Testing pattern
28
+ "Generate RSpec tests with CMDx matchers for success, failure, and edge cases"
29
+ ```
22
30
 
23
31
  ## Framework Context Template
24
32
 
25
- Use this context in your AI conversations to ensure proper CMDx code generation:
33
+ > [!IMPORTANT]
34
+ > Always include this context when working with AI assistants to ensure proper CMDx code generation and adherence to framework conventions.
26
35
 
27
36
  ```
28
37
  I'm working with CMDx, a Ruby framework for designing and executing business logic within service/command objects.
29
38
 
30
- KEY FRAMEWORK CONCEPTS:
31
- - Tasks inherit from CMDx::Task and implement business logic in a `call` method
32
- - Workflows inherit from CMDx::Workflow and orchestrate multiple tasks
33
- - Parameters are defined with type coercion, validation, and defaults
34
- - Results contain status (success/failed/skipped), state, context, and metadata
35
- - Callbacks execute at specific lifecycle points (before_validation, on_success, etc.)
36
- - Middlewares wrap task execution (authentication, logging, timeouts)
37
- - Chains link multiple tasks together with shared context
39
+ CORE CONCEPTS:
40
+ - Tasks inherit from CMDx::Task with business logic in `call` method
41
+ - Workflows inherit from CMDx::Workflow to orchestrate multiple tasks
42
+ - Parameters support type coercion, validation, defaults, and nesting
43
+ - Results contain status (success/failed/skipped), state, context, metadata
44
+ - Callbacks execute at lifecycle points (before_validation, on_success, etc.)
45
+ - Middlewares wrap execution (authentication, logging, timeouts, correlation)
46
+ - Chains link tasks with shared context and failure propagation
38
47
 
39
48
  CODING STANDARDS:
40
- - Use Ruby 3.4+ syntax and conventions
41
- - Follow snake_case for methods/variables, CamelCase for classes
42
- - Use double quotes for strings
43
- - Include comprehensive YARD documentation
44
- - Write RSpec tests with CMDx custom matchers
45
- - Name tasks as VerbNounTask (e.g., ProcessOrderTask)
46
- - Name workflows as NounVerbWorkflow (e.g., OrderProcessingWorkflow)
49
+ - Ruby 3.4+ syntax and conventions
50
+ - snake_case methods/variables, CamelCase classes
51
+ - Double quotes for strings, proper indentation
52
+ - YARD documentation with @param, @return, @example
53
+ - RSpec tests using CMDx custom matchers
54
+ - Task naming: VerbNounTask (ProcessOrderTask)
55
+ - Workflow naming: NounVerbWorkflow (OrderProcessingWorkflow)
47
56
 
48
- Generate code that is production-ready with proper error handling, validation, and testing.
57
+ REQUIREMENTS:
58
+ - Production-ready code with comprehensive error handling
59
+ - Parameter validation with meaningful error messages
60
+ - Proper context management and metadata usage
61
+ - Full test coverage including edge cases and failure scenarios
49
62
  ```
50
63
 
51
64
  ## Task Generation Templates
52
65
 
66
+ ### Standard Task Template
67
+
53
68
  ```
54
- Create a CMDx task that [SPECIFIC_ACTION] with the following requirements:
69
+ Create a CMDx task that [SPECIFIC_ACTION] with these requirements:
55
70
 
56
71
  PARAMETERS:
57
- - [parameter_name]: [type] - [description] - [required/optional]
58
- - [parameter_name]: [type] - [description] - [validation_rules]
72
+ - [name]: [type] - [description] - [required/optional] - [validation_rules]
73
+ - [name]: [type] - [description] - [default_value] - [constraints]
59
74
 
60
75
  BUSINESS LOGIC:
61
- - [Step 1 description]
62
- - [Step 2 description]
63
- - [Error conditions to handle]
76
+ 1. [Validation step with error conditions]
77
+ 2. [Core processing with success criteria]
78
+ 3. [Side effects and external calls]
79
+ 4. [Context updates and metadata]
64
80
 
65
- CONTEXT UPDATES:
66
- - [What data should be added to context]
67
- - [What side effects should occur]
81
+ ERROR HANDLING:
82
+ - [Specific error condition] [failure response with metadata]
83
+ - [Edge case] [appropriate handling strategy]
68
84
 
69
- TESTING:
70
- - Generate comprehensive RSpec tests using CMDx matchers
71
- - Include success, failure, and edge case scenarios
72
- - Test parameter validation and context updates
85
+ CONTEXT UPDATES:
86
+ - [key]: [description of data added]
87
+ - [key]: [metadata or tracking information]
73
88
 
74
- Please include:
75
- - Proper parameter definitions with validations
76
- - Error handling and metadata
77
- - YARD documentation
78
- - RSpec test file
89
+ OUTPUT:
90
+ - Complete task implementation with YARD docs
91
+ - RSpec test file with success/failure/edge cases
92
+ - Parameter validation tests
93
+ - Integration tests for external dependencies
79
94
  ```
80
95
 
81
- **Example Usage:**
96
+ ### Practical Example
97
+
82
98
  ```
83
- Create a CMDx task that processes user email preferences with the following requirements:
99
+ Create a CMDx task that processes user profile updates with these requirements:
84
100
 
85
101
  PARAMETERS:
86
- - user_id: integer - ID of the user - required, positive
87
- - email_types: array - Types of emails to enable - required, inclusion in ['marketing', 'notifications', 'alerts']
88
- - enabled: boolean - Whether to enable or disable - optional, defaults to true
102
+ - user_id: integer - User identifier - required - positive, exists in database
103
+ - profile_data: hash - Profile information - required - non-empty hash
104
+ - send_notification: boolean - Email update notification - optional - defaults to true
105
+ - audit_reason: string - Reason for update - optional - 3-255 characters when provided
89
106
 
90
107
  BUSINESS LOGIC:
91
- - Validate user exists and is active
92
- - Update user's email preferences in database
93
- - Send confirmation email if preferences changed
94
- - Log preference changes for audit trail
108
+ 1. Validate user exists and is active (error if not found or inactive)
109
+ 2. Sanitize and validate profile data fields (reject invalid formats)
110
+ 3. Update user profile in database (handle transaction failures)
111
+ 4. Send notification email if enabled (log failures, don't fail task)
112
+ 5. Create audit log entry with before/after values
95
113
 
96
- CONTEXT UPDATES:
97
- - Add updated user object to context
98
- - Add preference_changes hash with before/after values
99
- - Add confirmation_sent boolean
114
+ ERROR HANDLING:
115
+ - User not found failed with metadata {error_code: 'USER_NOT_FOUND'}
116
+ - Invalid profile data → failed with metadata {invalid_fields: [...]}
117
+ - Database failure → failed with metadata {error_code: 'DB_ERROR', retryable: true}
100
118
 
101
- TESTING:
102
- - Generate comprehensive RSpec tests using CMDx matchers
103
- - Include success, failure, and edge case scenarios
104
- - Test parameter validation and context updates
119
+ CONTEXT UPDATES:
120
+ - updated_user: User object with new profile data
121
+ - profile_changes: Hash with {field: [old_value, new_value]}
122
+ - notification_sent: Boolean indicating email delivery status
105
123
  ```
106
124
 
107
125
  ## Workflow Generation Templates
108
126
 
127
+ ### Standard Workflow Template
128
+
109
129
  ```
110
- Create a CMDx workflow that orchestrates [BUSINESS_PROCESS] with the following requirements:
130
+ Create a CMDx workflow that orchestrates [BUSINESS_PROCESS] with these requirements:
111
131
 
112
132
  WORKFLOW STEPS:
113
- 1. [Task 1]: [Description and purpose]
114
- 2. [Task 2]: [Description and purpose]
115
- 3. [Task 3]: [Description and purpose]
133
+ 1. [TaskName]: [Purpose and responsibilities]
134
+ 2. [TaskName]: [Dependencies and data requirements]
135
+ 3. [TaskName]: [Conditional execution criteria]
116
136
 
117
- TASK DEPENDENCIES:
118
- - [How tasks share data through context]
119
- - [Which tasks can run in parallel]
120
- - [Sequential requirements]
137
+ DATA FLOW:
138
+ - [Context key]: Flows from [Task A] to [Task B] for [purpose]
139
+ - [Shared state]: Available to [tasks] for [coordination]
121
140
 
122
- ERROR HANDLING:
123
- - [How to handle individual task failures]
124
- - [Rollback requirements]
125
- - [Compensation logic]
141
+ ERROR STRATEGY:
142
+ - [Task failure] [recovery action or compensation]
143
+ - [Critical failure] → [rollback requirements]
144
+ - [Partial failure] → [continuation strategy]
126
145
 
127
146
  CONDITIONAL LOGIC:
128
- - [When to skip certain tasks]
129
- - [Branching based on context]
147
+ - Skip [task] when [condition] is [value]
148
+ - Execute [alternative_task] if [criteria] met
149
+ - Branch execution based on [context_data]
130
150
 
131
- TESTING:
132
- - Generate workflow integration tests
133
- - Test success path and various failure scenarios
134
- - Include individual task unit tests
151
+ OUTPUT:
152
+ - Complete workflow with task orchestration
153
+ - Individual task implementations
154
+ - Integration tests covering success/failure paths
155
+ - Error handling and rollback mechanisms
135
156
  ```
136
157
 
137
- **Example Usage:**
158
+ ### Practical Example
159
+
138
160
  ```
139
- Create a CMDx workflow that orchestrates user onboarding with the following requirements:
161
+ Create a CMDx workflow that orchestrates user account deactivation with these requirements:
140
162
 
141
163
  WORKFLOW STEPS:
142
- 1. ValidateUserDataTask: Validate and sanitize user registration data
143
- 2. CreateUserAccountTask: Create user account in database
144
- 3. SendWelcomeEmailTask: Send personalized welcome email
145
- 4. SetupDefaultPreferencesTask: Configure default user preferences
146
- 5. TrackOnboardingEventTask: Log onboarding completion for analytics
147
-
148
- TASK DEPENDENCIES:
149
- - All tasks run sequentially
150
- - User data flows through context from validation to account creation
151
- - Welcome email uses created user object
152
- - Preferences setup requires user ID
153
- - Analytics tracking happens last with full context
154
-
155
- ERROR HANDLING:
156
- - If account creation fails, don't send email or setup preferences
157
- - If email fails, continue with preferences but log the failure
158
- - If preferences fail, still complete onboarding but flag for followup
164
+ 1. ValidateDeactivationRequestTask: Verify user permissions and business rules
165
+ 2. BackupUserDataTask: Archive user data before deactivation
166
+ 3. DeactivateAccountTask: Update account status and revoke access
167
+ 4. NotifyStakeholdersTask: Send notifications to relevant parties
168
+ 5. UpdateAnalyticsTask: Record deactivation metrics
169
+
170
+ DATA FLOW:
171
+ - user_id: Required input, flows through all tasks
172
+ - deactivation_reason: Used by validation, backup, and analytics
173
+ - backup_reference: Created by backup, used by analytics
174
+ - stakeholder_list: Determined by validation, used by notification
175
+
176
+ ERROR STRATEGY:
177
+ - Validation failure → halt workflow, return validation errors
178
+ - Backup failure critical error, do not proceed with deactivation
179
+ - Account deactivation failure rollback backup, restore previous state
180
+ - Notification failure log error, continue workflow (non-critical)
181
+ - Analytics failure → log error, workflow succeeds (tracking only)
159
182
 
160
183
  CONDITIONAL LOGIC:
161
- - Skip welcome email if user opted out during registration
162
- - Skip analytics if user has privacy settings enabled
163
-
164
- TESTING:
165
- - Generate workflow integration tests
166
- - Test success path and various failure scenarios
167
- - Include individual task unit tests
184
+ - Skip stakeholder notification if user is internal test account
185
+ - Execute priority backup for premium users
186
+ - Send different notifications based on deactivation reason
168
187
  ```
169
188
 
170
189
  ## Testing Templates
171
190
 
172
191
  ### Task Testing Template
173
192
 
193
+ > [!TIP]
194
+ > Use CMDx custom matchers for cleaner, more expressive tests that follow framework conventions.
195
+
174
196
  ```
175
197
  Generate comprehensive RSpec tests for [TASK_NAME] including:
176
198
 
177
- PARAMETER VALIDATION TESTS:
178
- - Test all required parameters
179
- - Test type coercion and validation rules
180
- - Test default values
181
- - Test invalid parameter combinations
182
-
183
- EXECUTION TESTS:
184
- - Test successful execution with various inputs
185
- - Test all error conditions and edge cases
186
- - Test context updates and side effects
187
- - Test metadata and timing information
188
-
189
- INTEGRATION TESTS:
190
- - Test external service interactions
191
- - Test database operations
192
- - Test file system operations (if applicable)
193
-
194
- CALLBACK TESTS:
195
- - Test lifecycle callbacks execute correctly
196
- - Test callback order and context
197
-
198
- Use CMDx custom matchers like:
199
+ PARAMETER VALIDATION:
200
+ - Required parameters missing → proper error messages
201
+ - Type coercion edge cases → successful conversion or clear failures
202
+ - Validation rules → boundary conditions and invalid inputs
203
+ - Default values proper application and override behavior
204
+
205
+ EXECUTION SCENARIOS:
206
+ - Happy path → successful execution with expected context updates
207
+ - Business rule violations appropriate failure states with metadata
208
+ - External service failures → error handling and retry logic
209
+ - Edge cases → boundary conditions and unusual inputs
210
+
211
+ INTEGRATION POINTS:
212
+ - Database operations transaction handling and rollback
213
+ - External APIs → network failures and response validation
214
+ - File system permissions and storage errors
215
+ - Email/messaging → delivery failures and formatting
216
+
217
+ Use CMDx matchers:
199
218
  - expect(result).to be_successful_task
200
- - expect(result).to be_failed_task
201
- - expect(TaskClass).to handle_exceptions_gracefully
219
+ - expect(result).to be_failed_task.with_metadata(hash_including(...))
220
+ - expect(result).to have_context(key: value)
221
+ - expect(TaskClass).to have_parameter(:name).with_type(:integer)
202
222
  ```
203
223
 
204
224
  ### Workflow Testing Template
@@ -206,114 +226,168 @@ Use CMDx custom matchers like:
206
226
  ```
207
227
  Generate comprehensive RSpec tests for [WORKFLOW_NAME] including:
208
228
 
209
- INTEGRATION TESTS:
210
- - Test complete workflow execution
211
- - Test various success scenarios
212
- - Test different failure points
213
- - Test context flow between tasks
229
+ INTEGRATION SCENARIOS:
230
+ - Complete success path → all tasks execute with proper data flow
231
+ - Early failure workflow halts at appropriate point
232
+ - Mid-workflow failure → proper error propagation and cleanup
233
+ - Recovery scenarios compensation and rollback behavior
214
234
 
215
- INDIVIDUAL TASK TESTS:
216
- - Test each task in isolation
217
- - Test task parameter validation
218
- - Test task-specific logic
235
+ TASK COORDINATION:
236
+ - Context passing data flows correctly between tasks
237
+ - Conditional execution tasks skip/execute based on conditions
238
+ - Parallel execution → concurrent tasks complete properly
239
+ - Sequential dependencies → tasks wait for predecessors
219
240
 
220
- CONDITIONAL LOGIC TESTS:
221
- - Test all branching paths
222
- - Test edge cases in decision logic
223
- - Test context preservation across branches
241
+ ERROR PROPAGATION:
242
+ - Individual task failures → workflow response and metadata
243
+ - Critical vs non-critical failures appropriate handling
244
+ - Rollback mechanisms state restoration and cleanup
245
+ - Error aggregation → multiple failure consolidation
224
246
 
225
- ERROR HANDLING TESTS:
226
- - Test failure propagation
227
- - Test recovery mechanisms
228
- - Test compensation logic
247
+ EDGE CASES:
248
+ - Empty context → proper initialization and defaults
249
+ - Malformed inputs → validation and sanitization
250
+ - Resource constraints → timeout and resource management
251
+ - Concurrent execution → race conditions and locking
229
252
  ```
230
253
 
231
- ## Best Practices for AI Prompts
254
+ ## Error Handling and Edge Cases
255
+
256
+ > [!WARNING]
257
+ > Always include comprehensive error handling in your prompts to ensure robust, production-ready code generation.
258
+
259
+ ### Common Error Scenarios
260
+
261
+ ```ruby
262
+ # Parameter validation failures
263
+ expect(result).to be_failed_task
264
+ .with_metadata(
265
+ reason: "user_id is required",
266
+ messages: { user_id: ["can't be blank"] }
267
+ )
268
+
269
+ # Business rule violations
270
+ expect(result).to be_failed_task
271
+ .with_metadata(
272
+ error_code: "INSUFFICIENT_BALANCE",
273
+ retryable: false,
274
+ balance: current_balance,
275
+ required: requested_amount
276
+ )
277
+
278
+ # External service failures
279
+ expect(result).to be_failed_task
280
+ .with_metadata(
281
+ error_code: "SERVICE_UNAVAILABLE",
282
+ retryable: true,
283
+ retry_after: 30,
284
+ service: "payment_processor"
285
+ )
286
+ ```
287
+
288
+ ### Edge Case Coverage
289
+
290
+ Include these scenarios in your prompts:
291
+
292
+ | Scenario | Test Coverage | Expected Behavior |
293
+ |----------|---------------|-------------------|
294
+ | Empty inputs | Nil, empty strings, empty arrays | Validation errors or defaults |
295
+ | Boundary values | Min/max limits, zero, negative | Proper validation and coercion |
296
+ | Malformed data | Invalid JSON, corrupt files | Clear error messages |
297
+ | Resource limits | Memory, timeout, rate limits | Graceful degradation |
298
+ | Concurrent access | Race conditions, locks | Proper synchronization |
299
+
300
+ ## Best Practices
301
+
302
+ ### 1. Specific Requirements
232
303
 
233
- ### 1. Be Specific About Requirements
304
+ > [!NOTE]
305
+ > Provide detailed, actionable requirements rather than vague descriptions to get better code generation.
234
306
 
235
- **Good:**
307
+ **Effective:**
236
308
  ```
237
- Create a task that validates credit card information, including:
238
- - Card number validation with Luhn algorithm
239
- - Expiry date validation (not expired, reasonable future date)
240
- - CVV validation (3-4 digits depending on card type)
241
- - Cardholder name validation (2-50 characters, letters and spaces only)
309
+ Create a task that validates payment information including:
310
+ - Credit card number validation using Luhn algorithm
311
+ - Expiry date validation (not expired, within 10 years)
312
+ - CVV validation (3 digits for Visa/MC, 4 for Amex)
313
+ - Amount validation (positive, max $10,000, 2 decimal places)
314
+ - Return structured validation errors with field-specific messages
242
315
  ```
243
316
 
244
- **Avoid:**
317
+ **Ineffective:**
245
318
  ```
246
- Create a task that validates credit cards
319
+ Create a payment validation task
247
320
  ```
248
321
 
249
- ### 2. Include Context About Data Flow
322
+ ### 2. Complete Context Flow
250
323
 
251
- **Good:**
324
+ **Effective:**
252
325
  ```
253
- The task should receive user_id and payment_amount, validate the payment method,
254
- charge the card, and update the context with:
255
- - transaction_id
256
- - charged_amount
257
- - payment_method_last_four
258
- - charge_timestamp
326
+ Task receives user_id and order_data, validates inventory, processes payment,
327
+ updates order status, and adds to context:
328
+ - order: Order object with updated status
329
+ - payment_reference: Payment processor transaction ID
330
+ - inventory_reserved: Array of reserved item IDs
331
+ - processing_time: Duration in milliseconds
259
332
  ```
260
333
 
261
- **Avoid:**
334
+ **Ineffective:**
262
335
  ```
263
- Process a payment
336
+ Process an order and update context
264
337
  ```
265
338
 
266
- ### 3. Specify Error Conditions
339
+ ### 3. Explicit Error Conditions
267
340
 
268
- **Good:**
341
+ **Effective:**
269
342
  ```
270
- Handle these error conditions:
271
- - Invalid card number → failed result with metadata { error_code: 'INVALID_CARD' }
272
- - Expired card → failed result with metadata { error_code: 'EXPIRED_CARD' }
273
- - Insufficient funds → failed result with metadata { error_code: 'DECLINED', retryable: false }
274
- - Network timeout → failed result with metadata { error_code: 'TIMEOUT', retryable: true }
343
+ Handle these specific errors:
344
+ - Invalid card → failed with {error_code: 'INVALID_CARD', field: 'number'}
345
+ - Expired card → failed with {error_code: 'EXPIRED', retry_date: Date}
346
+ - Declined → failed with {error_code: 'DECLINED', retryable: false}
347
+ - Timeout → failed with {error_code: 'TIMEOUT', retryable: true, delay: 30}
275
348
  ```
276
349
 
277
- **Avoid:**
350
+ **Ineffective:**
278
351
  ```
279
- Handle payment errors
352
+ Handle payment errors appropriately
280
353
  ```
281
354
 
282
- ### 4. Request Complete Examples
355
+ ### 4. Framework-Specific Patterns
283
356
 
284
- **Good:**
357
+ **Effective:**
285
358
  ```
286
- Generate a complete working example including:
287
- - Task class with full implementation
288
- - Parameter definitions with validations
289
- - RSpec test file with success/failure scenarios
290
- - YARD documentation
291
- - Usage examples in comments
359
+ Follow CMDx conventions:
360
+ - Use present tense task names (ProcessPaymentTask, not PaymentProcessor)
361
+ - Include detailed metadata for failures
362
+ - Use callbacks for cross-cutting concerns (audit, logging)
363
+ - Leverage parameter coercion for input flexibility
364
+ - Return rich context updates for downstream tasks
292
365
  ```
293
366
 
294
- **Avoid:**
367
+ **Ineffective:**
295
368
  ```
296
- Show me the basic structure
369
+ Use good Ruby practices
297
370
  ```
298
371
 
299
- ### 5. Specify Framework Patterns
372
+ ### 5. Comprehensive Test Coverage
300
373
 
301
- **Good:**
374
+ **Effective:**
302
375
  ```
303
- Follow CMDx patterns:
304
- - Use present tense verbs in task names (ProcessPaymentTask, not ProcessingPaymentTask)
305
- - Include proper error handling with metadata
306
- - Use callbacks for audit logging
307
- - Return detailed context updates
308
- - Include comprehensive parameter validation
376
+ Generate tests including:
377
+ - All parameter combinations and edge cases
378
+ - Success scenarios with various input types
379
+ - Each failure mode with proper error metadata
380
+ - Integration with external services (mocked)
381
+ - Performance characteristics and timeouts
382
+ - Callback execution and order
309
383
  ```
310
384
 
311
- **Avoid:**
385
+ **Ineffective:**
312
386
  ```
313
- Use best practices
387
+ Include basic tests
314
388
  ```
315
389
 
316
390
  ---
317
391
 
318
- - **Prev:** [Testing](testing.md)
392
+ - **Prev:** [Deprecation](deprecation.md)
319
393
  - **Next:** [Tips and Tricks](tips_and_tricks.md)