groundswell 0.0.1 → 0.0.2

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 (242) hide show
  1. package/.claude/commands/subtask-planning/prp-base-create.md +120 -0
  2. package/.claude/commands/subtask-planning/prp-base-execute.md +65 -0
  3. package/.claude/commands/task-breakdown.md +94 -0
  4. package/.claude/system_prompts/task-breakdown.md +1 -0
  5. package/CHANGELOG.md +188 -0
  6. package/PRD.md +543 -0
  7. package/README.md +99 -5
  8. package/examples/README.md +15 -1
  9. package/examples/examples/11-reparenting-workflows.ts +269 -0
  10. package/examples/index.ts +4 -0
  11. package/package-lock.json +2398 -0
  12. package/package.json +3 -1
  13. package/plan/001_d3bb02af4886/TEST_RESULTS.md +259 -0
  14. package/plan/001_d3bb02af4886/bug_fix_tasks.json +484 -0
  15. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S1/PRP.md +488 -0
  16. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S2/PRP.md +581 -0
  17. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S3/PRP.md +687 -0
  18. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S1/PRP.md +492 -0
  19. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/PRP.md +932 -0
  20. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/concurrent_error_testing_patterns.md +1109 -0
  21. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/vitest_concurrent_testing.md +802 -0
  22. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/workflow_engine_test_references.md +603 -0
  23. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S1/PRP.md +564 -0
  24. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S3/PRP.md +518 -0
  25. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S4/PRP.md +1252 -0
  26. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/PRP.md +364 -0
  27. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/CODEBASE_INVENTORY.md +114 -0
  28. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/DECORATOR_DOCUMENTATION_PATTERNS.md +205 -0
  29. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/PRD_LOCATION_ANALYSIS.md +199 -0
  30. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/ULTRATHINK_PRP_PLAN.md +134 -0
  31. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S1/PRP.md +495 -0
  32. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S1/research/console_error_inventory.md +435 -0
  33. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S2/PRP.md +506 -0
  34. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S3/PRP.md +612 -0
  35. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T2S2/PRP.md +558 -0
  36. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T2S2/research/external_research.md +788 -0
  37. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T3S2/PRP.md +460 -0
  38. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T3S3/PRP.md +454 -0
  39. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/PRP.md +520 -0
  40. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/RECOMMENDATION.md +417 -0
  41. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/research/external_workflow_engines_research.md +760 -0
  42. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/research/security_implications_analysis.md +245 -0
  43. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S2/PRP.md +792 -0
  44. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S1/PRP.md +535 -0
  45. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S1/TEST_EXECUTION_REPORT.md +190 -0
  46. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/PRP.md +654 -0
  47. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/TEST_FIX_REPORT.md +227 -0
  48. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/KEY_FINDINGS.md +345 -0
  49. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/QUICK_REFERENCE.md +193 -0
  50. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/test_maintenance_research.md +1323 -0
  51. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S1/BREAKING_CHANGES_AUDIT.md +1011 -0
  52. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S1/PRP.md +927 -0
  53. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S2/PRP.md +505 -0
  54. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/architecture/logger_child_signature_analysis.md +401 -0
  55. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/child_implementation_research.md +142 -0
  56. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/test_patterns_research.md +112 -0
  57. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/vitest_patterns_research.md +159 -0
  58. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/PRP.md +549 -0
  59. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/VERIFICATION_REPORT.md +368 -0
  60. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/edge_case_analysis.md +172 -0
  61. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/usage_inventory.md +175 -0
  62. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T1S2/PRP.md +696 -0
  63. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T1S4/PRP.md +860 -0
  64. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/PRP.md +1066 -0
  65. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/01-testing-aggregated-errors.md +1103 -0
  66. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/01_typescript_error_aggregation_patterns.md +789 -0
  67. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/02-error-merge-strategy-testing-guide.md +1098 -0
  68. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/02_aggregate_error_patterns.md +1037 -0
  69. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/03-promise-allsettled-testing-patterns.md +916 -0
  70. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/03_error_merging_strategies.md +1045 -0
  71. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/04_github_stackoverflow_examples.md +890 -0
  72. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/05_comprehensive_summary.md +822 -0
  73. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/INDEX.md +668 -0
  74. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/QUICK_REFERENCE.md +706 -0
  75. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/README.md +265 -0
  76. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/RESEARCH_REPORT.md +655 -0
  77. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S4/research/vitest_testing_patterns.md +1103 -0
  78. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T3S2/PRP.md +426 -0
  79. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/PRP.md +506 -0
  80. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/QUICK_REFERENCE.md +114 -0
  81. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/RESEARCH_SUMMARY.md +316 -0
  82. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/vitest_observer_error_logging_best_practices.md +754 -0
  83. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S3/PRP.md +612 -0
  84. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/PRP.md +719 -0
  85. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/README.md +215 -0
  86. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/analysis.md +765 -0
  87. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S3/PRP.md +718 -0
  88. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/DECISION.md +149 -0
  89. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/PRP.md +470 -0
  90. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/ULTRATHINK_PLAN.md +332 -0
  91. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/codebase_workflow_name_analysis.md +167 -0
  92. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/external_best_practices.md +265 -0
  93. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/validation_patterns.md +273 -0
  94. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T4S1/workflow_engine_ancestry_api_research.md +760 -0
  95. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T4S3-PRP.md +434 -0
  96. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S1/PRP.md +717 -0
  97. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/PRP.md +472 -0
  98. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/VALIDATION_REPORT.md +125 -0
  99. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/research/ULTRATHINK_PRP_PLAN.md +301 -0
  100. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/error-logging-best-practices.md +1170 -0
  101. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/research_typescript_partial_and_overloads.md +940 -0
  102. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/vitest-quick-reference.md +151 -0
  103. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/vitest-research.md +650 -0
  104. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/prd_snapshot.md +259 -0
  105. package/plan/001_d3bb02af4886/bugfix/P1M1T1S1/PRP.md +457 -0
  106. package/plan/001_d3bb02af4886/bugfix/RESEARCH_SUMMARY.md +346 -0
  107. package/plan/001_d3bb02af4886/bugfix/architecture/codebase_structure.md +311 -0
  108. package/plan/001_d3bb02af4886/bugfix/architecture/concurrent_execution_best_practices.md +1565 -0
  109. package/plan/001_d3bb02af4886/bugfix/architecture/error_handling_patterns.md +288 -0
  110. package/plan/001_d3bb02af4886/bugfix/architecture/promise_all_analysis.md +741 -0
  111. package/plan/001_d3bb02af4886/docs/PRP/P1M1T1S4-functional-workflow-error-state-capture-test.md +652 -0
  112. package/plan/001_d3bb02af4886/docs/PRP/PRP.md +527 -0
  113. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S1-PRP.md +415 -0
  114. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S2-PRP.md +378 -0
  115. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S4-PRP.md +713 -0
  116. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M2T1S4-PRP.md +370 -0
  117. package/plan/001_d3bb02af4886/docs/PRP_P1M3T1S3.md +499 -0
  118. package/plan/001_d3bb02af4886/docs/TEST_RESULTS.md +230 -0
  119. package/plan/001_d3bb02af4886/docs/bugfix/ANALYSIS_PRD_VS_IMPLEMENTATION.md +1134 -0
  120. package/plan/001_d3bb02af4886/docs/bugfix/GAP_ANALYSIS_SUMMARY.md +179 -0
  121. package/plan/001_d3bb02af4886/docs/bugfix/P1M4T2S1/PRP.md +629 -0
  122. package/plan/001_d3bb02af4886/docs/bugfix/P1M4T2S1/validation-report.md +214 -0
  123. package/plan/001_d3bb02af4886/docs/bugfix/PRP_P1M4T2S3.md +629 -0
  124. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_PRP.md +529 -0
  125. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_QUICK_REFERENCE.md +142 -0
  126. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_README.md +304 -0
  127. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_TEST_RESULTS.md +558 -0
  128. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_VALIDATION_SUMMARY.md +256 -0
  129. package/plan/001_d3bb02af4886/docs/bugfix/system_context.md +346 -0
  130. package/plan/001_d3bb02af4886/docs/bugfix-architecture/bug_analysis.md +415 -0
  131. package/plan/001_d3bb02af4886/docs/bugfix-architecture/implementation_patterns.md +489 -0
  132. package/plan/001_d3bb02af4886/docs/bugfix-architecture/system_context.md +218 -0
  133. package/plan/001_d3bb02af4886/docs/bugfix_INITIATION_SUMMARY.md +380 -0
  134. package/plan/001_d3bb02af4886/docs/research/CYCLE_DETECTION_PATTERNS.md +1923 -0
  135. package/plan/001_d3bb02af4886/docs/research/CYCLE_DETECTION_QUICK_REF.md +319 -0
  136. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/codebase-context.md +115 -0
  137. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/cycle-detection-algorithms.md +134 -0
  138. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/test-patterns.md +153 -0
  139. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/workflow-class.md +132 -0
  140. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/DECORATOR_DOCUMENTATION_BEST_PRACTICES.md +716 -0
  141. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/DECORATOR_DOCUMENTATION_QUICK_REF.md +186 -0
  142. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/GROUNDSWELL_DECORATOR_EXAMPLES.md +604 -0
  143. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/INDEX.md +213 -0
  144. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/codebase_structure.md +30 -0
  145. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/existing_test_pattern.md +56 -0
  146. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/getRootObservers_implementation.md +53 -0
  147. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/test_conventions.md +49 -0
  148. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/PRP.md +958 -0
  149. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/QUICK_REFERENCE.md +339 -0
  150. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/README.md +305 -0
  151. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/SUMMARY.md +433 -0
  152. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/bidirectional-tree-consistency-testing.md +1574 -0
  153. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/test-pattern-examples.md +1014 -0
  154. package/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_QUICK_REF.md +376 -0
  155. package/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_RESEARCH.md +1507 -0
  156. package/plan/001_d3bb02af4886/docs/research/bugfix_typescript_patterns.md +949 -0
  157. package/plan/001_d3bb02af4886/docs/research/error-testing-research.md +619 -0
  158. package/plan/001_d3bb02af4886/docs/research/error_handling_patterns.md +723 -0
  159. package/plan/{research → 001_d3bb02af4886/docs/research/general}/introspection-security-guide.md +56 -0
  160. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/PRP_TEMPLATE.md +460 -0
  161. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/QUICK_REFERENCE.md +324 -0
  162. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/README.md +175 -0
  163. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/RESEARCH_REPORT.md +499 -0
  164. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/SUMMARY.md +163 -0
  165. package/plan/bugfix/BUG_FIX_SUMMARY.md +961 -0
  166. package/src/__tests__/adversarial/attachChild-performance.test.ts +216 -0
  167. package/src/__tests__/adversarial/circular-reference.test.ts +101 -0
  168. package/src/__tests__/adversarial/complex-circular-reference.test.ts +139 -0
  169. package/src/__tests__/adversarial/concurrent-task-failures.test.ts +571 -0
  170. package/src/__tests__/adversarial/deep-analysis.test.ts +729 -0
  171. package/src/__tests__/adversarial/deep-hierarchy-stress.test.ts +213 -0
  172. package/src/__tests__/adversarial/e2e-prd-validation.test.ts +448 -0
  173. package/src/__tests__/adversarial/edge-case.test.ts +703 -0
  174. package/src/__tests__/adversarial/error-merge-strategy.test.ts +760 -0
  175. package/src/__tests__/adversarial/incremental-performance.test.ts +140 -0
  176. package/src/__tests__/adversarial/node-map-update-benchmarks.test.ts +457 -0
  177. package/src/__tests__/adversarial/observer-propagation.test.ts +487 -0
  178. package/src/__tests__/adversarial/parent-validation.test.ts +143 -0
  179. package/src/__tests__/adversarial/prd-12-2-compliance.test.ts +611 -0
  180. package/src/__tests__/adversarial/prd-compliance.test.ts +731 -0
  181. package/src/__tests__/compatibility/backward-compatibility.test.ts +1572 -0
  182. package/src/__tests__/helpers/index.ts +18 -0
  183. package/src/__tests__/helpers/tree-verification.ts +257 -0
  184. package/src/__tests__/integration/bidirectional-consistency.test.ts +847 -0
  185. package/src/__tests__/integration/observer-logging.test.ts +643 -0
  186. package/src/__tests__/integration/tree-mirroring.test.ts +37 -0
  187. package/src/__tests__/integration/workflow-reparenting.test.ts +303 -0
  188. package/src/__tests__/unit/context.test.ts +79 -0
  189. package/src/__tests__/unit/logger.test.ts +293 -0
  190. package/src/__tests__/unit/observable.test.ts +321 -0
  191. package/src/__tests__/unit/tree-debugger-incremental.test.ts +170 -0
  192. package/src/__tests__/unit/utils/workflow-error-utils.test.ts +209 -0
  193. package/src/__tests__/unit/workflow-detachChild.test.ts +100 -0
  194. package/src/__tests__/unit/workflow-emitEvent-childDetached.test.ts +153 -0
  195. package/src/__tests__/unit/workflow-isDescendantOf.test.ts +180 -0
  196. package/src/__tests__/unit/workflow.test.ts +277 -1
  197. package/src/core/agent.ts +21 -1
  198. package/src/core/logger.ts +27 -2
  199. package/src/core/workflow-context.ts +6 -4
  200. package/src/core/workflow.ts +252 -14
  201. package/src/debugger/tree-debugger.ts +52 -7
  202. package/src/decorators/task.ts +65 -2
  203. package/src/index.ts +4 -2
  204. package/src/types/decorators.ts +8 -1
  205. package/src/types/events.ts +1 -0
  206. package/src/utils/index.ts +1 -0
  207. package/src/utils/observable.ts +32 -3
  208. package/src/utils/workflow-error-utils.ts +56 -0
  209. package/tsconfig.json +1 -1
  210. package/llms_full.txt +0 -5890
  211. package/tasks.json +0 -0
  212. /package/plan/{backlog.json → 001_d3bb02af4886/backlog.json} +0 -0
  213. /package/plan/{P1P2/PRP.md → 001_d3bb02af4886/docs/PRP/P1P2-PRP.md} +0 -0
  214. /package/plan/{P3P4/PRP.md → 001_d3bb02af4886/docs/PRP/P3P4-PRP.md} +0 -0
  215. /package/plan/{P4P5/PRP.md → 001_d3bb02af4886/docs/PRP/P4P5-PRP.md} +0 -0
  216. /package/plan/{architecture → 001_d3bb02af4886/docs/architecture}/external_deps.md +0 -0
  217. /package/plan/{architecture → 001_d3bb02af4886/docs/architecture}/system_context.md +0 -0
  218. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_BEST_PRACTICES.md +0 -0
  219. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_CODE_PATTERNS.md +0 -0
  220. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_INTEGRATION_GUIDE.md +0 -0
  221. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_RESEARCH_INDEX.md +0 -0
  222. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/REFLECTION_INDEX.md +0 -0
  223. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/REFLECTION_RESEARCH_REPORT.md +0 -0
  224. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/RESEARCH_SUMMARY.md +0 -0
  225. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/anthropic-sdk.md +0 -0
  226. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/async-local-storage.md +0 -0
  227. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-code-patterns.md +0 -0
  228. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-decision-matrix.md +0 -0
  229. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-implementation-guide.md +0 -0
  230. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-integration-guide.md +0 -0
  231. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-patterns.md +0 -0
  232. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-quick-reference.md +0 -0
  233. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/zod-schema.md +0 -0
  234. /package/plan/{P3P4/research → 001_d3bb02af4886/docs/research/P3P4}/caching-lru.md +0 -0
  235. /package/plan/{P3P4/research → 001_d3bb02af4886/docs/research/P3P4}/introspection-tools.md +0 -0
  236. /package/plan/{P3P4/research → 001_d3bb02af4886/docs/research/P3P4}/reflection-patterns.md +0 -0
  237. /package/plan/{P4P5/research → 001_d3bb02af4886/docs/research/P4P5}/RESEARCH_SUMMARY.md +0 -0
  238. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/INTROSPECTION_RESEARCH_SUMMARY.md +0 -0
  239. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/README-INTROSPECTION.md +0 -0
  240. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/agent-introspection-patterns.md +0 -0
  241. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/introspection-tool-examples.md +0 -0
  242. /package/{PRPs/PRDs/001-hierarchical-workflow-engine.md → plan/001_d3bb02af4886/prd_snapshot.md} +0 -0
@@ -0,0 +1,916 @@
1
+ # Promise.allSettled Testing Patterns for Workflow Engines
2
+
3
+ **Research Date:** 2026-01-12
4
+ **Task:** P1.M2.T2.S2 - Research Promise.allSettled error scenarios
5
+ **Related Implementation:** `/home/dustin/projects/groundswell/src/decorators/task.ts` (lines 111-122)
6
+
7
+ ## Overview
8
+
9
+ Promise.allSettled is crucial for workflow engines because it ensures all concurrent workflows complete execution, even when some fail. This document provides comprehensive testing patterns for Promise.allSettled in the context of hierarchical workflow orchestration.
10
+
11
+ ## Table of Contents
12
+ 1. [Promise.allSettled Basics](#promiseallsettled-basics)
13
+ 2. [Testing Patterns](#testing-patterns)
14
+ 3. [Workflow-Specific Scenarios](#workflow-specific-scenarios)
15
+ 4. [Error Collection Strategies](#error-collection-strategies)
16
+ 5. [Performance & Concurrency](#performance--concurrency)
17
+ 6. [Edge Cases](#edge-cases)
18
+ 7. [Code Examples](#code-examples)
19
+
20
+ ---
21
+
22
+ ## Promise.allSettled Basics
23
+
24
+ ### What is Promise.allSettled?
25
+
26
+ ```typescript
27
+ // Promise.allSettled waits for ALL promises to settle
28
+ // regardless of whether they fulfill or reject
29
+
30
+ const promises = [
31
+ Promise.resolve('success'),
32
+ Promise.reject(new Error('failure')),
33
+ Promise.resolve('another success'),
34
+ ];
35
+
36
+ const results = await Promise.allSettled(promises);
37
+
38
+ // Result structure:
39
+ // [
40
+ // { status: 'fulfilled', value: 'success' },
41
+ // { status: 'rejected', reason: Error: failure },
42
+ // { status: 'fulfilled', value: 'another success' },
43
+ // ]
44
+ ```
45
+
46
+ ### Type Guards for Results
47
+
48
+ ```typescript
49
+ /**
50
+ * Type guard for rejected results
51
+ */
52
+ function isRejected(result: PromiseSettledResult<unknown>): result is PromiseRejectedResult {
53
+ return result.status === 'rejected';
54
+ }
55
+
56
+ /**
57
+ * Type guard for fulfilled results
58
+ */
59
+ function isFulfilled<T>(result: PromiseSettledResult<T>): result is PromiseFulfilledResult<T> {
60
+ return result.status === 'fulfilled';
61
+ }
62
+
63
+ /**
64
+ * Extract errors from allSettled results
65
+ */
66
+ function extractErrors(results: PromiseSettledResult<unknown>[]): unknown[] {
67
+ return results
68
+ .filter(isRejected)
69
+ .map(r => r.reason);
70
+ }
71
+
72
+ /**
73
+ * Extract values from allSettled results
74
+ */
75
+ function extractValues<T>(results: PromiseSettledResult<T>[]): T[] {
76
+ return results
77
+ .filter(isFulfilled)
78
+ .map(r => r.value);
79
+ }
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Testing Patterns
85
+
86
+ ### Pattern 1: Basic Error Collection
87
+
88
+ ```typescript
89
+ describe('Promise.allSettled - Basic Error Collection', () => {
90
+ it('should collect all errors from rejected promises', async () => {
91
+ // ARRANGE: Create promises with mixed results
92
+ const promises = [
93
+ Promise.reject(new Error('Error 1')),
94
+ Promise.reject(new Error('Error 2')),
95
+ Promise.resolve('success'),
96
+ Promise.reject(new Error('Error 3')),
97
+ ];
98
+
99
+ // ACT: Wait for all to settle
100
+ const results = await Promise.allSettled(promises);
101
+
102
+ // ASSERT: Filter and verify errors
103
+ const rejected = results.filter(
104
+ (r): r is PromiseRejectedResult => r.status === 'rejected'
105
+ );
106
+
107
+ expect(rejected).toHaveLength(3);
108
+ expect(rejected[0].reason.message).toBe('Error 1');
109
+ expect(rejected[1].reason.message).toBe('Error 2');
110
+ expect(rejected[2].reason.message).toBe('Error 3');
111
+
112
+ // ASSERT: Verify fulfilled promises
113
+ const fulfilled = results.filter(
114
+ (r): r is PromiseFulfilledResult<unknown> => r.status === 'fulfilled'
115
+ );
116
+
117
+ expect(fulfilled).toHaveLength(1);
118
+ expect(fulfilled[0].value).toBe('success');
119
+ });
120
+ });
121
+ ```
122
+
123
+ ### Pattern 2: All Promises Rejected
124
+
125
+ ```typescript
126
+ describe('Promise.allSettled - All Rejected', () => {
127
+ it('should handle all promises rejected', async () => {
128
+ // ARRANGE: All promises will reject
129
+ const promises = [
130
+ Promise.reject(new Error('Error A')),
131
+ Promise.reject(new Error('Error B')),
132
+ Promise.reject(new Error('Error C')),
133
+ ];
134
+
135
+ // ACT
136
+ const results = await Promise.allSettled(promises);
137
+
138
+ // ASSERT: All results are rejected
139
+ expect(results).toHaveLength(3);
140
+ results.forEach(result => {
141
+ expect(result.status).toBe('rejected');
142
+ if (result.status === 'rejected') {
143
+ expect(result.reason).toBeInstanceOf(Error);
144
+ }
145
+ });
146
+
147
+ // ASSERT: Extract all errors
148
+ const errors = results
149
+ .filter((r): r is PromiseRejectedResult => r.status === 'rejected')
150
+ .map(r => r.reason);
151
+
152
+ expect(errors).toHaveLength(3);
153
+ expect(errors.map(e => e.message)).toEqual(['Error A', 'Error B', 'Error C']);
154
+ });
155
+ });
156
+ ```
157
+
158
+ ### Pattern 3: All Promises Fulfilled
159
+
160
+ ```typescript
161
+ describe('Promise.allSettled - All Fulfilled', () => {
162
+ it('should handle all promises fulfilled', async () => {
163
+ // ARRANGE: All promises will resolve
164
+ const promises = [
165
+ Promise.resolve('Result 1'),
166
+ Promise.resolve('Result 2'),
167
+ Promise.resolve('Result 3'),
168
+ ];
169
+
170
+ // ACT
171
+ const results = await Promise.allSettled(promises);
172
+
173
+ // ASSERT: All results are fulfilled
174
+ expect(results).toHaveLength(3);
175
+ results.forEach(result => {
176
+ expect(result.status).toBe('fulfilled');
177
+ if (result.status === 'fulfilled') {
178
+ expect(result.value).toBeDefined();
179
+ }
180
+ });
181
+
182
+ // ASSERT: Extract all values
183
+ const values = results
184
+ .filter((r): r is PromiseFulfilledResult<string> => r.status === 'fulfilled')
185
+ .map(r => r.value);
186
+
187
+ expect(values).toEqual(['Result 1', 'Result 2', 'Result 3']);
188
+ });
189
+ });
190
+ ```
191
+
192
+ ### Pattern 4: Empty Array
193
+
194
+ ```typescript
195
+ describe('Promise.allSettled - Empty Array', () => {
196
+ it('should handle empty promise array', async () => {
197
+ // ARRANGE: Empty array
198
+ const promises: Promise<unknown>[] = [];
199
+
200
+ // ACT
201
+ const results = await Promise.allSettled(promises);
202
+
203
+ // ASSERT: Returns empty array
204
+ expect(results).toEqual([]);
205
+ });
206
+ });
207
+ ```
208
+
209
+ ---
210
+
211
+ ## Workflow-Specific Scenarios
212
+
213
+ ### Scenario 1: Concurrent Workflow Execution
214
+
215
+ ```typescript
216
+ describe('Concurrent Workflow Execution', () => {
217
+ it('should execute all workflows even when some fail', async () => {
218
+ // ARRANGE: Track execution
219
+ const executedWorkflows = new Set<string>();
220
+
221
+ class ChildWorkflow extends Workflow {
222
+ async run() {
223
+ executedWorkflows.add(this.id);
224
+ throw new Error(`${this.id} failed`);
225
+ }
226
+ }
227
+
228
+ class ParentWorkflow extends Workflow {
229
+ @Task({ concurrent: true })
230
+ async spawnChildren() {
231
+ return [
232
+ new ChildWorkflow('child-1', this),
233
+ new ChildWorkflow('child-2', this),
234
+ new ChildWorkflow('child-3', this),
235
+ ];
236
+ }
237
+
238
+ async run() {
239
+ try {
240
+ await this.spawnChildren();
241
+ } catch (err) {
242
+ // Expected - error thrown after all complete
243
+ }
244
+ }
245
+ }
246
+
247
+ const parent = new ParentWorkflow('parent');
248
+
249
+ // ACT: Run parent workflow
250
+ await parent.run();
251
+
252
+ // ASSERT: All workflows executed (Promise.allSettled completed all)
253
+ expect(executedWorkflows.size).toBe(3);
254
+ expect(executedWorkflows.has('child-1')).toBe(true);
255
+ expect(executedWorkflows.has('child-2')).toBe(true);
256
+ expect(executedWorkflows.has('child-3')).toBe(true);
257
+ });
258
+ });
259
+ ```
260
+
261
+ ### Scenario 2: Mixed Success/Failure
262
+
263
+ ```typescript
264
+ describe('Mixed Success/Failure Scenarios', () => {
265
+ it('should complete successful workflows despite failures', async () => {
266
+ // ARRANGE: Create workflows with mixed outcomes
267
+ const successfulWorkflows = new Set<string>();
268
+ const failedWorkflows = new Set<string>();
269
+
270
+ class MixedOutcomeWorkflow extends Workflow {
271
+ private shouldFail: boolean;
272
+
273
+ constructor(id: string, parent: Workflow, shouldFail: boolean) {
274
+ super(id, parent);
275
+ this.shouldFail = shouldFail;
276
+ }
277
+
278
+ async run() {
279
+ if (this.shouldFail) {
280
+ failedWorkflows.add(this.id);
281
+ throw new Error(`${this.id} failed`);
282
+ } else {
283
+ successfulWorkflows.add(this.id);
284
+ return `${this.id} succeeded`;
285
+ }
286
+ }
287
+ }
288
+
289
+ class ParentWorkflow extends Workflow {
290
+ @Task({ concurrent: true })
291
+ async spawnChildren() {
292
+ return [
293
+ new MixedOutcomeWorkflow('success-1', this, false),
294
+ new MixedOutcomeWorkflow('fail-1', this, true),
295
+ new MixedOutcomeWorkflow('success-2', this, false),
296
+ new MixedOutcomeWorkflow('fail-2', this, true),
297
+ new MixedOutcomeWorkflow('success-3', this, false),
298
+ ];
299
+ }
300
+
301
+ async run() {
302
+ try {
303
+ await this.spawnChildren();
304
+ } catch (err) {
305
+ // Expected
306
+ }
307
+ }
308
+ }
309
+
310
+ const parent = new ParentWorkflow('parent');
311
+
312
+ // ACT
313
+ await parent.run();
314
+
315
+ // ASSERT: All workflows executed
316
+ expect(successfulWorkflows.size).toBe(3);
317
+ expect(failedWorkflows.size).toBe(2);
318
+
319
+ // ASSERT: Verify specific workflows
320
+ expect(successfulWorkflows.has('success-1')).toBe(true);
321
+ expect(successfulWorkflows.has('success-2')).toBe(true);
322
+ expect(successfulWorkflows.has('success-3')).toBe(true);
323
+ expect(failedWorkflows.has('fail-1')).toBe(true);
324
+ expect(failedWorkflows.has('fail-2')).toBe(true);
325
+ });
326
+ });
327
+ ```
328
+
329
+ ### Scenario 3: No Orphaned Workflows
330
+
331
+ ```typescript
332
+ describe('Orphan Prevention', () => {
333
+ it('should not leave orphaned workflows', async () => {
334
+ // ARRANGE: Track all promise completions
335
+ const completions = new Map<string, 'success' | 'failure'>();
336
+
337
+ class TrackedWorkflow extends Workflow {
338
+ private shouldFail: boolean;
339
+
340
+ constructor(id: string, parent: Workflow, shouldFail: boolean) {
341
+ super(id, parent);
342
+ this.shouldFail = shouldFail;
343
+ }
344
+
345
+ async run() {
346
+ // Track completion regardless of outcome
347
+ return this.runInternal()
348
+ .then(
349
+ () => completions.set(this.id, 'success'),
350
+ () => completions.set(this.id, 'failure')
351
+ );
352
+ }
353
+
354
+ async runInternal() {
355
+ if (this.shouldFail) {
356
+ throw new Error(`${this.id} failed`);
357
+ }
358
+ return `${this.id} succeeded`;
359
+ }
360
+ }
361
+
362
+ class ParentWorkflow extends Workflow {
363
+ @Task({ concurrent: true })
364
+ async spawnChildren() {
365
+ const children = [
366
+ new TrackedWorkflow('workflow-1', this, false),
367
+ new TrackedWorkflow('workflow-2', this, true),
368
+ new TrackedWorkflow('workflow-3', this, false),
369
+ ];
370
+
371
+ // Manually track each child's completion
372
+ children.forEach(child => {
373
+ child.run().catch(() => {}); // Don't let errors propagate
374
+ });
375
+
376
+ return children;
377
+ }
378
+
379
+ async run() {
380
+ try {
381
+ await this.spawnChildren();
382
+ } catch (err) {
383
+ // Expected
384
+ }
385
+ }
386
+ }
387
+
388
+ const parent = new ParentWorkflow('parent');
389
+
390
+ // ACT: Run with timeout to detect hanging promises
391
+ const timeoutPromise = new Promise((_, reject) =>
392
+ setTimeout(() => reject(new Error('Timeout: workflows hung')), 5000)
393
+ );
394
+
395
+ await Promise.race([parent.run(), timeoutPromise]);
396
+
397
+ // ASSERT: All workflows accounted for (no orphans)
398
+ expect(completions.size).toBe(3);
399
+ expect(completions.get('workflow-1')).toBe('success');
400
+ expect(completions.get('workflow-2')).toBe('failure');
401
+ expect(completions.get('workflow-3')).toBe('success');
402
+ });
403
+ });
404
+ ```
405
+
406
+ ---
407
+
408
+ ## Error Collection Strategies
409
+
410
+ ### Strategy 1: First Error Wins (Backward Compatible)
411
+
412
+ ```typescript
413
+ describe('Error Collection - First Error Wins', () => {
414
+ it('should throw first error when no merge strategy', async () => {
415
+ // ARRANGE: Create parent without error merge strategy
416
+ class ParentWorkflow extends Workflow {
417
+ @Task({ concurrent: true }) // No errorMergeStrategy
418
+ async spawnChildren() {
419
+ return [
420
+ createFailingWorkflow(this, 'First', 'First error'),
421
+ createFailingWorkflow(this, 'Second', 'Second error'),
422
+ createFailingWorkflow(this, 'Third', 'Third error'),
423
+ ];
424
+ }
425
+
426
+ async run() {
427
+ try {
428
+ await this.spawnChildren();
429
+ } catch (err) {
430
+ return err;
431
+ }
432
+ }
433
+ }
434
+
435
+ const parent = new ParentWorkflow('parent');
436
+
437
+ // ACT
438
+ const result = await parent.run();
439
+
440
+ // ASSERT: Only first error thrown
441
+ expect(result.message).toContain('First error');
442
+ expect(result.message).not.toContain('Second error');
443
+ expect(result.message).not.toContain('Third error');
444
+ });
445
+ });
446
+ ```
447
+
448
+ ### Strategy 2: Collect All Errors
449
+
450
+ ```typescript
451
+ describe('Error Collection - Collect All', () => {
452
+ it('should collect all errors when merge strategy enabled', async () => {
453
+ // ARRANGE: Create parent with error merge strategy
454
+ class ParentWorkflow extends Workflow {
455
+ @Task({
456
+ concurrent: true,
457
+ errorMergeStrategy: { enabled: true }
458
+ })
459
+ async spawnChildren() {
460
+ return [
461
+ createFailingWorkflow(this, 'Alpha', 'Alpha error'),
462
+ createFailingWorkflow(this, 'Beta', 'Beta error'),
463
+ createFailingWorkflow(this, 'Gamma', 'Gamma error'),
464
+ ];
465
+ }
466
+
467
+ async run() {
468
+ try {
469
+ await this.spawnChildren();
470
+ } catch (err) {
471
+ return err;
472
+ }
473
+ }
474
+ }
475
+
476
+ const parent = new ParentWorkflow('parent');
477
+
478
+ // ACT
479
+ const result = await parent.run();
480
+
481
+ // ASSERT: All errors collected
482
+ expect(result.message).toContain('3 concurrent errors');
483
+ expect(result.message).toContain('Alpha error');
484
+ expect(result.message).toContain('Beta error');
485
+ expect(result.message).toContain('Gamma error');
486
+ });
487
+ });
488
+ ```
489
+
490
+ ### Strategy 3: Custom Error Filter
491
+
492
+ ```typescript
493
+ describe('Error Collection - Custom Filter', () => {
494
+ it('should filter errors by type', async () => {
495
+ // ARRANGE: Define custom error filter
496
+ const isRetryableError = (error: Error) => {
497
+ return error.message.includes('timeout') ||
498
+ error.message.includes('network');
499
+ };
500
+
501
+ class CustomFilterWorkflow extends Workflow {
502
+ @Task({
503
+ concurrent: true,
504
+ errorMergeStrategy: {
505
+ enabled: true,
506
+ combine: (errors) => {
507
+ // Filter to only retryable errors
508
+ const retryable = errors.filter(e =>
509
+ isRetryableError(e.original as Error)
510
+ );
511
+
512
+ return {
513
+ message: `${retryable.length} retryable errors`,
514
+ original: retryable,
515
+ workflowId: 'filtered',
516
+ state: {} as any,
517
+ logs: retryable.flatMap(e => e.logs),
518
+ };
519
+ }
520
+ }
521
+ })
522
+ async spawnChildren() {
523
+ return [
524
+ createFailingWorkflow(this, 'A', 'network timeout'),
525
+ createFailingWorkflow(this, 'B', 'validation failed'),
526
+ createFailingWorkflow(this, 'C', 'network error'),
527
+ ];
528
+ }
529
+
530
+ async run() {
531
+ try {
532
+ await this.spawnChildren();
533
+ } catch (err) {
534
+ return err;
535
+ }
536
+ }
537
+ }
538
+
539
+ const workflow = new CustomFilterWorkflow('test');
540
+
541
+ // ACT
542
+ const result = await workflow.run();
543
+
544
+ // ASSERT: Only retryable errors included
545
+ expect(result.message).toContain('2 retryable errors');
546
+ expect(result.original).toHaveLength(2);
547
+ });
548
+ });
549
+ ```
550
+
551
+ ---
552
+
553
+ ## Performance & Concurrency
554
+
555
+ ### Performance Testing
556
+
557
+ ```typescript
558
+ describe('Promise.allSettled Performance', () => {
559
+ it('should complete large batches quickly', async () => {
560
+ // ARRANGE: Create 100 concurrent workflows
561
+ const workflowCount = 100;
562
+
563
+ class PerformanceWorkflow extends Workflow {
564
+ @Task({ concurrent: true })
565
+ async spawnManyChildren() {
566
+ return Array.from({ length: workflowCount }, (_, i) =>
567
+ createChildWorkflow(this, `child-${i}`, false)
568
+ );
569
+ }
570
+
571
+ async run() {
572
+ const startTime = performance.now();
573
+ try {
574
+ await this.spawnManyChildren();
575
+ } catch (err) {
576
+ // Expected
577
+ }
578
+ const duration = performance.now() - startTime;
579
+ return duration;
580
+ }
581
+ }
582
+
583
+ const workflow = new PerformanceWorkflow('perf-test');
584
+
585
+ // ACT
586
+ const duration = await workflow.run();
587
+
588
+ // ASSERT: Should complete in reasonable time
589
+ expect(duration).toBeLessThan(5000); // 5 seconds max
590
+ });
591
+
592
+ it('should handle concurrent execution correctly', async () => {
593
+ // ARRANGE: Track execution order
594
+ const executionOrder: string[] = [];
595
+
596
+ class ConcurrentWorkflow extends Workflow {
597
+ @Task({ concurrent: true })
598
+ async spawnChildren() {
599
+ const children = Array.from({ length: 5 }, (_, i) =>
600
+ createChildWorkflow(this, `child-${i}`, false)
601
+ );
602
+
603
+ // Add tracking
604
+ children.forEach(child => {
605
+ child.run().then(() => {
606
+ executionOrder.push(child.id);
607
+ });
608
+ });
609
+
610
+ return children;
611
+ }
612
+
613
+ async run() {
614
+ try {
615
+ await this.spawnChildren();
616
+ } catch (err) {
617
+ // Expected
618
+ }
619
+ }
620
+ }
621
+
622
+ const workflow = new ConcurrentWorkflow('concurrent-test');
623
+
624
+ // ACT
625
+ await workflow.run();
626
+
627
+ // ASSERT: All workflows executed
628
+ expect(executionOrder).toHaveLength(5);
629
+ });
630
+ });
631
+ ```
632
+
633
+ ### Concurrency Verification
634
+
635
+ ```typescript
636
+ describe('Concurrency Verification', () => {
637
+ it('should execute workflows concurrently', async () => {
638
+ // ARRANGE: Track start times
639
+ const startTimes = new Map<string, number>();
640
+
641
+ class TimedWorkflow extends Workflow {
642
+ async run() {
643
+ startTimes.set(this.id, Date.now());
644
+ await new Promise(resolve => setTimeout(resolve, 100));
645
+ return this.id;
646
+ }
647
+ }
648
+
649
+ class ParentWorkflow extends Workflow {
650
+ @Task({ concurrent: true })
651
+ async spawnChildren() {
652
+ return [
653
+ new TimedWorkflow('child-1', this),
654
+ new TimedWorkflow('child-2', this),
655
+ new TimedWorkflow('child-3', this),
656
+ ];
657
+ }
658
+
659
+ async run() {
660
+ try {
661
+ await this.spawnChildren();
662
+ } catch (err) {
663
+ // Expected
664
+ }
665
+ }
666
+ }
667
+
668
+ const parent = new ParentWorkflow('parent');
669
+
670
+ // ACT
671
+ const startTime = Date.now();
672
+ await parent.run();
673
+ const totalTime = Date.now() - startTime;
674
+
675
+ // ASSERT: Concurrent execution (total time < sequential time)
676
+ expect(totalTime).toBeLessThan(250); // Should be ~100ms, not 300ms sequential
677
+
678
+ // ASSERT: All started around same time
679
+ const times = Array.from(startTimes.values());
680
+ const maxDiff = Math.max(...times) - Math.min(...times);
681
+ expect(maxDiff).toBeLessThan(50); // All started within 50ms
682
+ });
683
+ });
684
+ ```
685
+
686
+ ---
687
+
688
+ ## Edge Cases
689
+
690
+ ### Edge Case 1: Single Workflow
691
+
692
+ ```typescript
693
+ describe('Edge Case - Single Workflow', () => {
694
+ it('should handle single workflow correctly', async () => {
695
+ // ARRANGE: Only one child workflow
696
+ class ParentWorkflow extends Workflow {
697
+ @Task({ concurrent: true })
698
+ async spawnChild() {
699
+ return [createFailingWorkflow(this, 'OnlyChild', 'Single error')];
700
+ }
701
+
702
+ async run() {
703
+ try {
704
+ await this.spawnChild();
705
+ } catch (err) {
706
+ return err;
707
+ }
708
+ }
709
+ }
710
+
711
+ const parent = new ParentWorkflow('parent');
712
+
713
+ // ACT
714
+ const result = await parent.run();
715
+
716
+ // ASSERT: Error handled correctly
717
+ expect(result.message).toContain('Single error');
718
+ expect(parent.children).toHaveLength(1);
719
+ });
720
+ });
721
+ ```
722
+
723
+ ### Edge Case 2: Very Long Error Messages
724
+
725
+ ```typescript
726
+ describe('Edge Case - Long Error Messages', () => {
727
+ it('should handle very long error messages', async () => {
728
+ // ARRANGE: Create error with 1000 character message
729
+ const longMessage = 'X'.repeat(1000);
730
+
731
+ class ParentWorkflow extends Workflow {
732
+ @Task({
733
+ concurrent: true,
734
+ errorMergeStrategy: { enabled: true }
735
+ })
736
+ async spawnChildren() {
737
+ return [
738
+ createFailingWorkflow(this, 'Long', longMessage),
739
+ createFailingWorkflow(this, 'Short', 'Short error'),
740
+ ];
741
+ }
742
+
743
+ async run() {
744
+ try {
745
+ await this.spawnChildren();
746
+ } catch (err) {
747
+ return err;
748
+ }
749
+ }
750
+ }
751
+
752
+ const parent = new ParentWorkflow('parent');
753
+
754
+ // ACT
755
+ const result = await parent.run();
756
+
757
+ // ASSERT: Long message preserved
758
+ expect(result.message).toContain(longMessage);
759
+ expect(result.message).toContain('Short error');
760
+ });
761
+ });
762
+ ```
763
+
764
+ ### Edge Case 3: Rapid Sequential Tasks
765
+
766
+ ```typescript
767
+ describe('Edge Case - Rapid Sequential Tasks', () => {
768
+ it('should handle rapid sequential task execution', async () => {
769
+ // ARRANGE: Execute same task multiple times rapidly
770
+ class RapidWorkflow extends Workflow {
771
+ @Task({ concurrent: true })
772
+ async spawnChildren() {
773
+ return [
774
+ createFailingWorkflow(this, 'A', 'Error A'),
775
+ createFailingWorkflow(this, 'B', 'Error B'),
776
+ ];
777
+ }
778
+
779
+ async run() {
780
+ try {
781
+ await this.spawnChildren();
782
+ } catch (err) {
783
+ // Expected
784
+ }
785
+ }
786
+ }
787
+
788
+ const workflow = new RapidWorkflow('rapid');
789
+
790
+ // ACT: Run multiple times sequentially
791
+ for (let i = 0; i < 10; i++) {
792
+ await workflow.run().catch(() => {});
793
+ }
794
+
795
+ // ASSERT: No memory leaks or hanging promises
796
+ // (Would need memory profiling tools in real scenario)
797
+ });
798
+ });
799
+ ```
800
+
801
+ ---
802
+
803
+ ## Code Examples
804
+
805
+ ### Complete Test Suite Template
806
+
807
+ ```typescript
808
+ // File: src/__tests__/unit/promise-allsettled-patterns.test.ts
809
+ import { describe, it, expect } from 'vitest';
810
+ import { Workflow, Task } from '../../index.js';
811
+
812
+ describe('Promise.allSettled Testing Patterns', () => {
813
+ describe('Basic error collection', () => {
814
+ it('should collect all errors from concurrent failures');
815
+ it('should preserve error messages and context');
816
+ it('should handle mixed success/failure scenarios');
817
+ });
818
+
819
+ describe('Workflow execution', () => {
820
+ it('should complete all workflows despite failures');
821
+ it('should not orphan any workflows');
822
+ it('should execute workflows concurrently');
823
+ });
824
+
825
+ describe('Error handling', () => {
826
+ it('should throw first error when no merge strategy');
827
+ it('should merge errors when strategy enabled');
828
+ it('should use custom merger when provided');
829
+ });
830
+
831
+ describe('Edge cases', () => {
832
+ it('should handle single workflow');
833
+ it('should handle empty workflow array');
834
+ it('should handle very long error messages');
835
+ it('should handle rapid sequential execution');
836
+ });
837
+
838
+ describe('Performance', () => {
839
+ it('should complete large batches quickly');
840
+ it('should execute workflows concurrently not sequentially');
841
+ });
842
+ });
843
+ ```
844
+
845
+ ### Helper Functions
846
+
847
+ ```typescript
848
+ /**
849
+ * Create a child workflow for testing
850
+ */
851
+ function createChildWorkflow(
852
+ parent: Workflow,
853
+ name: string,
854
+ shouldFail: boolean
855
+ ): Workflow {
856
+ return new (class extends Workflow {
857
+ constructor(n: string, p: Workflow) {
858
+ super(n, p);
859
+ }
860
+
861
+ async run() {
862
+ if (shouldFail) {
863
+ throw new Error(`${name} failed`);
864
+ }
865
+ return `${name} succeeded`;
866
+ }
867
+ })(name, parent);
868
+ }
869
+
870
+ /**
871
+ * Create a failing workflow
872
+ */
873
+ function createFailingWorkflow(
874
+ parent: Workflow,
875
+ name: string,
876
+ errorMessage: string
877
+ ): Workflow {
878
+ return new (class extends Workflow {
879
+ async run() {
880
+ throw new Error(errorMessage);
881
+ }
882
+ })(name, parent);
883
+ }
884
+
885
+ /**
886
+ * Setup event observer for testing
887
+ */
888
+ function setupEventObserver(workflow: Workflow): WorkflowEvent[] {
889
+ const events: WorkflowEvent[] = [];
890
+
891
+ workflow.addObserver({
892
+ onLog: () => {},
893
+ onEvent: (e) => events.push(e),
894
+ onStateUpdated: () => {},
895
+ onTreeChanged: () => {},
896
+ });
897
+
898
+ return events;
899
+ }
900
+ ```
901
+
902
+ ---
903
+
904
+ ## Summary
905
+
906
+ This document provides comprehensive testing patterns for Promise.allSettled in workflow engines:
907
+
908
+ 1. **Basics:** Understanding Promise.allSettled behavior and type guards
909
+ 2. **Testing Patterns:** Basic, all-rejected, all-fulfilled, and empty array scenarios
910
+ 3. **Workflow Scenarios:** Concurrent execution, mixed outcomes, orphan prevention
911
+ 4. **Error Collection:** First-error, collect-all, and custom filter strategies
912
+ 5. **Performance:** Testing large batches and concurrency verification
913
+ 6. **Edge Cases:** Single workflow, long messages, rapid execution
914
+ 7. **Code Examples:** Complete test templates and helper functions
915
+
916
+ These patterns can be directly applied to test the Promise.allSettled implementation in `/home/dustin/projects/groundswell/src/decorators/task.ts`.