@temporalio/core-bridge 1.13.1 → 1.14.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 (422) hide show
  1. package/Cargo.lock +350 -436
  2. package/Cargo.toml +14 -13
  3. package/{sdk-core/fsm/rustfsm_procmacro/LICENSE.txt → LICENSE} +5 -5
  4. package/README.md +0 -1
  5. package/bridge-macros/Cargo.toml +16 -0
  6. package/bridge-macros/src/derive_js_function.rs +126 -0
  7. package/bridge-macros/src/derive_tryfromjs.rs +138 -0
  8. package/bridge-macros/src/derive_tryintojs.rs +151 -0
  9. package/bridge-macros/src/lib.rs +42 -0
  10. package/lib/native.d.ts +23 -9
  11. package/package.json +6 -5
  12. package/releases/aarch64-apple-darwin/index.node +0 -0
  13. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  14. package/releases/x86_64-apple-darwin/index.node +0 -0
  15. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  16. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  17. package/sdk-core/.cargo/config.toml +78 -12
  18. package/sdk-core/.clippy.toml +1 -0
  19. package/sdk-core/.github/workflows/heavy.yml +2 -0
  20. package/sdk-core/.github/workflows/per-pr.yml +90 -21
  21. package/sdk-core/AGENTS.md +17 -19
  22. package/sdk-core/ARCHITECTURE.md +44 -48
  23. package/sdk-core/Cargo.toml +25 -7
  24. package/sdk-core/README.md +16 -15
  25. package/sdk-core/arch_docs/diagrams/TimerMachine_Coverage.puml +14 -0
  26. package/sdk-core/arch_docs/diagrams/deps.svg +102 -0
  27. package/sdk-core/arch_docs/diagrams/initial_event_history.png +0 -0
  28. package/sdk-core/arch_docs/sdks_intro.md +299 -0
  29. package/sdk-core/{client → crates/client}/Cargo.toml +15 -16
  30. package/sdk-core/{client → crates/client}/src/callback_based.rs +1 -2
  31. package/sdk-core/{client → crates/client}/src/lib.rs +594 -457
  32. package/sdk-core/{client → crates/client}/src/metrics.rs +32 -8
  33. package/sdk-core/crates/client/src/proxy.rs +209 -0
  34. package/sdk-core/{client → crates/client}/src/raw.rs +648 -328
  35. package/sdk-core/crates/client/src/replaceable.rs +253 -0
  36. package/sdk-core/crates/client/src/request_extensions.rs +40 -0
  37. package/sdk-core/{client → crates/client}/src/retry.rs +32 -22
  38. package/sdk-core/crates/client/src/worker/mod.rs +1468 -0
  39. package/sdk-core/{client → crates/client}/src/workflow_handle/mod.rs +24 -21
  40. package/sdk-core/{core-api → crates/common}/Cargo.toml +21 -12
  41. package/sdk-core/{sdk-core-protos → crates/common}/build.rs +10 -23
  42. package/sdk-core/crates/common/protos/api_cloud_upstream/VERSION +1 -0
  43. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/account/v1/message.proto +18 -0
  44. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/request_response.proto +38 -11
  45. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto +21 -4
  46. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/operation/v1/message.proto +6 -6
  47. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/sink/v1/message.proto +22 -0
  48. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/create-release.yml +13 -0
  49. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/openapi/openapiv2.json +254 -5
  50. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/openapi/openapiv3.yaml +234 -5
  51. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/common/v1/message.proto +1 -1
  52. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/deployment/v1/message.proto +6 -0
  53. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -2
  54. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -2
  55. package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +30 -6
  56. package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
  57. package/sdk-core/{core-api → crates/common}/src/envconfig.rs +155 -56
  58. package/sdk-core/{core-api → crates/common}/src/errors.rs +8 -1
  59. package/sdk-core/{fsm/rustfsm_trait/src/lib.rs → crates/common/src/fsm_trait.rs} +1 -27
  60. package/sdk-core/{core-api → crates/common}/src/lib.rs +92 -9
  61. package/sdk-core/{test-utils/src → crates/common/src/protos}/canned_histories.rs +5 -5
  62. package/sdk-core/{sdk-core-protos/src → crates/common/src/protos}/history_builder.rs +3 -3
  63. package/sdk-core/{sdk-core-protos/src → crates/common/src/protos}/history_info.rs +2 -2
  64. package/sdk-core/{sdk-core-protos/src/lib.rs → crates/common/src/protos/mod.rs} +43 -26
  65. package/sdk-core/crates/common/src/protos/test_utils.rs +89 -0
  66. package/sdk-core/{sdk-core-protos/src → crates/common/src/protos}/utilities.rs +14 -5
  67. package/sdk-core/{core-api → crates/common}/src/telemetry/metrics.rs +449 -51
  68. package/sdk-core/{core-api → crates/common}/src/telemetry.rs +16 -1
  69. package/sdk-core/{core-api → crates/common}/src/worker.rs +112 -18
  70. package/sdk-core/crates/common/tests/worker_task_types_test.rs +129 -0
  71. package/sdk-core/crates/macros/Cargo.toml +23 -0
  72. package/sdk-core/{fsm/rustfsm_procmacro → crates/macros}/src/lib.rs +12 -12
  73. package/sdk-core/{sdk → crates/sdk}/Cargo.toml +18 -12
  74. package/sdk-core/{sdk → crates/sdk}/src/activity_context.rs +9 -7
  75. package/sdk-core/{sdk → crates/sdk}/src/app_data.rs +1 -1
  76. package/sdk-core/{sdk → crates/sdk}/src/interceptors.rs +2 -5
  77. package/sdk-core/{sdk → crates/sdk}/src/lib.rs +43 -42
  78. package/sdk-core/{sdk → crates/sdk}/src/workflow_context/options.rs +12 -3
  79. package/sdk-core/{sdk → crates/sdk}/src/workflow_context.rs +21 -19
  80. package/sdk-core/{sdk → crates/sdk}/src/workflow_future.rs +2 -2
  81. package/sdk-core/crates/sdk-core/Cargo.toml +222 -0
  82. package/sdk-core/{core/benches/workflow_replay.rs → crates/sdk-core/benches/workflow_replay_bench.rs} +15 -10
  83. package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +32 -0
  84. package/sdk-core/crates/sdk-core/machine_coverage/CancelExternalMachine_Coverage.puml +9 -0
  85. package/sdk-core/crates/sdk-core/machine_coverage/CancelWorkflowMachine_Coverage.puml +6 -0
  86. package/sdk-core/crates/sdk-core/machine_coverage/ChildWorkflowMachine_Coverage.puml +27 -0
  87. package/sdk-core/crates/sdk-core/machine_coverage/CompleteWorkflowMachine_Coverage.puml +6 -0
  88. package/sdk-core/crates/sdk-core/machine_coverage/ContinueAsNewWorkflowMachine_Coverage.puml +6 -0
  89. package/sdk-core/crates/sdk-core/machine_coverage/FailWorkflowMachine_Coverage.puml +6 -0
  90. package/sdk-core/crates/sdk-core/machine_coverage/LocalActivityMachine_Coverage.puml +23 -0
  91. package/sdk-core/crates/sdk-core/machine_coverage/ModifyWorkflowPropertiesMachine_Coverage.puml +5 -0
  92. package/sdk-core/crates/sdk-core/machine_coverage/PatchMachine_Coverage.puml +8 -0
  93. package/sdk-core/crates/sdk-core/machine_coverage/SignalExternalMachine_Coverage.puml +12 -0
  94. package/sdk-core/crates/sdk-core/machine_coverage/TimerMachine_Coverage.puml +13 -0
  95. package/sdk-core/crates/sdk-core/machine_coverage/UpdateMachine_Coverage.puml +19 -0
  96. package/sdk-core/crates/sdk-core/machine_coverage/UpsertSearchAttributesMachine_Coverage.puml +5 -0
  97. package/sdk-core/crates/sdk-core/machine_coverage/WorkflowTaskMachine_Coverage.puml +11 -0
  98. package/sdk-core/{core → crates/sdk-core}/src/abstractions.rs +62 -6
  99. package/sdk-core/crates/sdk-core/src/antithesis.rs +60 -0
  100. package/sdk-core/{core → crates/sdk-core}/src/core_tests/activity_tasks.rs +85 -250
  101. package/sdk-core/{core → crates/sdk-core}/src/core_tests/mod.rs +13 -16
  102. package/sdk-core/{core → crates/sdk-core}/src/core_tests/queries.rs +25 -24
  103. package/sdk-core/{core → crates/sdk-core}/src/core_tests/replay_flag.rs +11 -68
  104. package/sdk-core/{core → crates/sdk-core}/src/core_tests/updates.rs +21 -20
  105. package/sdk-core/{core → crates/sdk-core}/src/core_tests/workers.rs +242 -16
  106. package/sdk-core/{core → crates/sdk-core}/src/core_tests/workflow_cancels.rs +10 -7
  107. package/sdk-core/{core → crates/sdk-core}/src/core_tests/workflow_tasks.rs +150 -326
  108. package/sdk-core/{core → crates/sdk-core}/src/debug_client.rs +1 -1
  109. package/sdk-core/{core → crates/sdk-core}/src/ephemeral_server/mod.rs +18 -6
  110. package/sdk-core/{test-utils → crates/sdk-core}/src/histfetch.rs +9 -4
  111. package/sdk-core/{core → crates/sdk-core}/src/internal_flags.rs +15 -4
  112. package/sdk-core/{core → crates/sdk-core}/src/lib.rs +128 -72
  113. package/sdk-core/{core → crates/sdk-core}/src/pollers/mod.rs +13 -11
  114. package/sdk-core/{core → crates/sdk-core}/src/pollers/poll_buffer.rs +53 -18
  115. package/sdk-core/{core → crates/sdk-core}/src/protosext/mod.rs +14 -6
  116. package/sdk-core/{core → crates/sdk-core}/src/protosext/protocol_messages.rs +5 -12
  117. package/sdk-core/{core → crates/sdk-core}/src/replay/mod.rs +14 -11
  118. package/sdk-core/crates/sdk-core/src/retry_logic.rs +390 -0
  119. package/sdk-core/{core → crates/sdk-core}/src/telemetry/log_export.rs +2 -2
  120. package/sdk-core/{core → crates/sdk-core}/src/telemetry/metrics.rs +80 -33
  121. package/sdk-core/{core → crates/sdk-core}/src/telemetry/mod.rs +12 -6
  122. package/sdk-core/{core → crates/sdk-core}/src/telemetry/otel.rs +1 -1
  123. package/sdk-core/{core → crates/sdk-core}/src/telemetry/prometheus_meter.rs +14 -14
  124. package/sdk-core/{core → crates/sdk-core}/src/telemetry/prometheus_server.rs +2 -2
  125. package/sdk-core/{core/src/test_help/mod.rs → crates/sdk-core/src/test_help/integ_helpers.rs} +284 -329
  126. package/sdk-core/crates/sdk-core/src/test_help/mod.rs +13 -0
  127. package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +220 -0
  128. package/sdk-core/{core → crates/sdk-core}/src/worker/activities/activity_heartbeat_manager.rs +44 -8
  129. package/sdk-core/{core → crates/sdk-core}/src/worker/activities/local_activities.rs +33 -31
  130. package/sdk-core/{core → crates/sdk-core}/src/worker/activities.rs +31 -15
  131. package/sdk-core/{core → crates/sdk-core}/src/worker/client/mocks.rs +28 -15
  132. package/sdk-core/{core → crates/sdk-core}/src/worker/client.rs +275 -145
  133. package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +246 -0
  134. package/sdk-core/crates/sdk-core/src/worker/mod.rs +1462 -0
  135. package/sdk-core/{core → crates/sdk-core}/src/worker/nexus.rs +24 -12
  136. package/sdk-core/{core → crates/sdk-core}/src/worker/slot_provider.rs +18 -10
  137. package/sdk-core/{core → crates/sdk-core}/src/worker/tuner/fixed_size.rs +5 -1
  138. package/sdk-core/{core → crates/sdk-core}/src/worker/tuner/resource_based.rs +453 -57
  139. package/sdk-core/{core → crates/sdk-core}/src/worker/tuner.rs +179 -3
  140. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/driven_workflow.rs +1 -1
  141. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/history_update.rs +5 -267
  142. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/activity_state_machine.rs +147 -90
  143. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/cancel_external_state_machine.rs +8 -91
  144. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/cancel_nexus_op_state_machine.rs +14 -12
  145. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +97 -0
  146. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/child_workflow_state_machine.rs +32 -229
  147. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/complete_workflow_state_machine.rs +13 -8
  148. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +6 -50
  149. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/fail_workflow_state_machine.rs +6 -7
  150. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/local_activity_state_machine.rs +39 -584
  151. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/mod.rs +22 -17
  152. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +4 -74
  153. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/nexus_operation_state_machine.rs +118 -21
  154. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/patch_state_machine.rs +273 -0
  155. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/signal_external_state_machine.rs +9 -151
  156. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/timer_state_machine.rs +27 -132
  157. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/transition_coverage.rs +1 -2
  158. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/update_state_machine.rs +19 -13
  159. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +25 -80
  160. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/workflow_machines/local_acts.rs +1 -1
  161. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/workflow_machines.rs +68 -72
  162. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/machines/workflow_task_state_machine.rs +13 -15
  163. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/managed_run.rs +55 -37
  164. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/mod.rs +171 -61
  165. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/run_cache.rs +10 -7
  166. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/wft_extraction.rs +4 -2
  167. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/wft_poller.rs +15 -4
  168. package/sdk-core/{core → crates/sdk-core}/src/worker/workflow/workflow_stream.rs +38 -19
  169. package/sdk-core/crates/sdk-core/tests/c_bridge_smoke_test.c +10 -0
  170. package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +25 -0
  171. package/sdk-core/crates/sdk-core/tests/common/fake_grpc_server.rs +106 -0
  172. package/sdk-core/crates/sdk-core/tests/common/http_proxy.rs +134 -0
  173. package/sdk-core/{test-utils/src/lib.rs → crates/sdk-core/tests/common/mod.rs} +286 -334
  174. package/sdk-core/{test-utils/src → crates/sdk-core/tests/common}/workflows.rs +6 -4
  175. package/sdk-core/crates/sdk-core/tests/fsm_procmacro.rs +6 -0
  176. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/dupe_transitions_fail.rs +1 -3
  177. package/sdk-core/crates/sdk-core/tests/fsm_trybuild/dupe_transitions_fail.stderr +12 -0
  178. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/dynamic_dest_pass.rs +2 -4
  179. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/forgot_name_fail.rs +1 -3
  180. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/forgot_name_fail.stderr +4 -4
  181. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/handler_arg_pass.rs +2 -4
  182. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/handler_pass.rs +2 -4
  183. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/medium_complex_pass.rs +2 -4
  184. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/no_handle_conversions_require_into_fail.rs +2 -4
  185. package/sdk-core/crates/sdk-core/tests/fsm_trybuild/no_handle_conversions_require_into_fail.stderr +15 -0
  186. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/simple_pass.rs +2 -4
  187. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/struct_event_variant_fail.rs +1 -3
  188. package/sdk-core/crates/sdk-core/tests/fsm_trybuild/struct_event_variant_fail.stderr +5 -0
  189. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/tuple_more_item_event_variant_fail.rs +1 -3
  190. package/sdk-core/crates/sdk-core/tests/fsm_trybuild/tuple_more_item_event_variant_fail.stderr +5 -0
  191. package/sdk-core/{fsm/rustfsm_procmacro/tests/trybuild → crates/sdk-core/tests/fsm_trybuild}/tuple_zero_item_event_variant_fail.rs +1 -3
  192. package/sdk-core/crates/sdk-core/tests/fsm_trybuild/tuple_zero_item_event_variant_fail.stderr +5 -0
  193. package/sdk-core/{tests → crates/sdk-core/tests}/global_metric_tests.rs +22 -22
  194. package/sdk-core/{tests → crates/sdk-core/tests/heavy_tests}/fuzzy_workflow.rs +4 -4
  195. package/sdk-core/{tests → crates/sdk-core/tests}/heavy_tests.rs +25 -14
  196. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/activity_functions.rs +1 -1
  197. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/client_tests.rs +115 -123
  198. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/ephemeral_server_tests.rs +19 -15
  199. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/heartbeat_tests.rs +24 -20
  200. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/metrics_tests.rs +241 -67
  201. package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +273 -0
  202. package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +513 -0
  203. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/queries_tests.rs +13 -11
  204. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/update_tests.rs +47 -29
  205. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/visibility_tests.rs +49 -27
  206. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +1061 -0
  207. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +920 -0
  208. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/worker_versioning_tests.rs +58 -40
  209. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/activities.rs +268 -30
  210. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/appdata_propagation.rs +4 -4
  211. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +155 -0
  212. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +121 -0
  213. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +717 -0
  214. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +109 -0
  215. package/sdk-core/{core/src/core_tests → crates/sdk-core/tests/integ_tests/workflow_tests}/determinism.rs +108 -20
  216. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/eager.rs +10 -5
  217. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +2884 -0
  218. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +119 -0
  219. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/nexus.rs +174 -46
  220. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +740 -0
  221. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/replay.rs +78 -27
  222. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/resets.rs +46 -28
  223. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +294 -0
  224. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/stickyness.rs +9 -8
  225. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +249 -0
  226. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/upsert_search_attrs.rs +72 -7
  227. package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests.rs +97 -33
  228. package/sdk-core/{tests → crates/sdk-core/tests}/main.rs +40 -25
  229. package/sdk-core/{tests → crates/sdk-core/tests}/manual_tests.rs +25 -15
  230. package/sdk-core/{tests → crates/sdk-core/tests}/runner.rs +23 -41
  231. package/sdk-core/{tests → crates/sdk-core/tests}/shared_tests/mod.rs +11 -6
  232. package/sdk-core/{tests → crates/sdk-core/tests}/shared_tests/priority.rs +6 -6
  233. package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +59 -0
  234. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/include/temporal-sdk-core-c-bridge.h +215 -44
  235. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/client.rs +515 -214
  236. package/sdk-core/crates/sdk-core-c-bridge/src/envconfig.rs +314 -0
  237. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/lib.rs +2 -1
  238. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/metric.rs +1 -1
  239. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/random.rs +4 -4
  240. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/runtime.rs +42 -28
  241. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/testing.rs +2 -5
  242. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/tests/context.rs +42 -41
  243. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/tests/mod.rs +38 -34
  244. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/tests/utils.rs +10 -11
  245. package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/src/worker.rs +427 -121
  246. package/sdk-core/docker-cgroup-tests.sh +24 -0
  247. package/sdk-core/{docker → etc/docker}/docker-compose-ci.yaml +9 -9
  248. package/sdk-core/{docker → etc/docker}/docker-compose-telem.yaml +11 -11
  249. package/sdk-core/{docker → etc/docker}/docker-compose.yaml +8 -8
  250. package/sdk-core/{integ-with-otel.sh → etc/integ-with-otel.sh} +1 -1
  251. package/sdk-core/etc/regen-depgraph.sh +2 -2
  252. package/src/client.rs +117 -49
  253. package/src/helpers/callbacks.rs +4 -4
  254. package/src/helpers/errors.rs +7 -1
  255. package/src/helpers/handles.rs +1 -0
  256. package/src/helpers/try_from_js.rs +5 -4
  257. package/src/lib.rs +3 -2
  258. package/src/logs.rs +1 -1
  259. package/src/metrics.rs +6 -3
  260. package/src/runtime.rs +41 -24
  261. package/src/testing.rs +3 -3
  262. package/src/worker.rs +77 -44
  263. package/ts/native.ts +26 -9
  264. package/LICENSE.md +0 -23
  265. package/sdk-core/arch_docs/diagrams/workflow_internals.svg +0 -1
  266. package/sdk-core/client/src/proxy.rs +0 -90
  267. package/sdk-core/client/src/worker_registry/mod.rs +0 -266
  268. package/sdk-core/core/Cargo.toml +0 -146
  269. package/sdk-core/core/src/core_tests/child_workflows.rs +0 -281
  270. package/sdk-core/core/src/core_tests/local_activities.rs +0 -1442
  271. package/sdk-core/core/src/retry_logic.rs +0 -224
  272. package/sdk-core/core/src/worker/heartbeat.rs +0 -231
  273. package/sdk-core/core/src/worker/mod.rs +0 -980
  274. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +0 -165
  275. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +0 -801
  276. package/sdk-core/core-c-bridge/Cargo.toml +0 -51
  277. package/sdk-core/etc/deps.svg +0 -162
  278. package/sdk-core/fsm/Cargo.toml +0 -21
  279. package/sdk-core/fsm/README.md +0 -3
  280. package/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +0 -27
  281. package/sdk-core/fsm/rustfsm_procmacro/tests/progress.rs +0 -8
  282. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.stderr +0 -12
  283. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +0 -15
  284. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.stderr +0 -5
  285. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.stderr +0 -5
  286. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.stderr +0 -5
  287. package/sdk-core/fsm/rustfsm_trait/Cargo.toml +0 -14
  288. package/sdk-core/fsm/rustfsm_trait/LICENSE.txt +0 -21
  289. package/sdk-core/fsm/src/lib.rs +0 -2
  290. package/sdk-core/sdk-core-protos/Cargo.toml +0 -37
  291. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/VERSION +0 -1
  292. package/sdk-core/test-utils/Cargo.toml +0 -38
  293. package/sdk-core/test-utils/src/interceptors.rs +0 -46
  294. package/sdk-core/tests/cloud_tests.rs +0 -23
  295. package/sdk-core/tests/integ_tests/polling_tests.rs +0 -294
  296. package/sdk-core/tests/integ_tests/worker_tests.rs +0 -203
  297. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +0 -74
  298. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +0 -57
  299. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +0 -246
  300. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +0 -65
  301. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +0 -85
  302. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +0 -908
  303. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +0 -51
  304. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +0 -206
  305. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +0 -164
  306. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +0 -123
  307. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/.github/workflows/build.yaml +0 -0
  308. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/.github/workflows/push-to-buf.yml +0 -0
  309. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/CODEOWNERS +0 -0
  310. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/LICENSE +0 -0
  311. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/Makefile +0 -0
  312. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/README.md +0 -0
  313. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/buf.gen.yaml +0 -0
  314. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/buf.lock +0 -0
  315. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/buf.yaml +0 -0
  316. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/connectivityrule/v1/message.proto +0 -0
  317. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/identity/v1/message.proto +0 -0
  318. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/namespace/v1/message.proto +0 -0
  319. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/nexus/v1/message.proto +0 -0
  320. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/region/v1/message.proto +0 -0
  321. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/resource/v1/message.proto +0 -0
  322. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_cloud_upstream/temporal/api/cloud/usage/v1/message.proto +0 -0
  323. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/CODEOWNERS +0 -0
  324. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  325. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/ci.yml +0 -0
  326. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/publish-docs.yml +0 -0
  327. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/push-to-buf.yml +0 -0
  328. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/trigger-api-go-delete-release.yml +0 -0
  329. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/trigger-api-go-publish-release.yml +0 -0
  330. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/.github/workflows/trigger-api-go-update.yml +0 -0
  331. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/LICENSE +0 -0
  332. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/Makefile +0 -0
  333. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/README.md +0 -0
  334. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/api-linter.yaml +0 -0
  335. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/buf.gen.yaml +0 -0
  336. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/buf.lock +0 -0
  337. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/buf.yaml +0 -0
  338. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/api/annotations.proto +0 -0
  339. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/api/http.proto +0 -0
  340. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/any.proto +0 -0
  341. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/descriptor.proto +0 -0
  342. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/duration.proto +0 -0
  343. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/empty.proto +0 -0
  344. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/struct.proto +0 -0
  345. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/timestamp.proto +0 -0
  346. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/google/protobuf/wrappers.proto +0 -0
  347. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/openapi/payload_description.txt +0 -0
  348. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/activity/v1/message.proto +0 -0
  349. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/batch/v1/message.proto +0 -0
  350. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/command/v1/message.proto +0 -0
  351. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -0
  352. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/command_type.proto +0 -0
  353. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/common.proto +0 -0
  354. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/deployment.proto +0 -0
  355. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/event_type.proto +0 -0
  356. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +0 -0
  357. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/namespace.proto +0 -0
  358. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/nexus.proto +0 -0
  359. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/query.proto +0 -0
  360. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/reset.proto +0 -0
  361. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/schedule.proto +0 -0
  362. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -0
  363. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/update.proto +0 -0
  364. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/enums/v1/workflow.proto +0 -0
  365. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/errordetails/v1/message.proto +0 -0
  366. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/export/v1/message.proto +0 -0
  367. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/failure/v1/message.proto +0 -0
  368. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/filter/v1/message.proto +0 -0
  369. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/history/v1/message.proto +0 -0
  370. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/nexus/v1/message.proto +0 -0
  371. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +0 -0
  372. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +0 -0
  373. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/protocol/v1/message.proto +0 -0
  374. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/query/v1/message.proto +0 -0
  375. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/replication/v1/message.proto +0 -0
  376. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/rules/v1/message.proto +0 -0
  377. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/schedule/v1/message.proto +0 -0
  378. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/sdk/v1/enhanced_stack_trace.proto +0 -0
  379. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +0 -0
  380. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/sdk/v1/user_metadata.proto +0 -0
  381. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/sdk/v1/worker_config.proto +0 -0
  382. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto +0 -0
  383. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +0 -0
  384. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/update/v1/message.proto +0 -0
  385. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/version/v1/message.proto +0 -0
  386. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/worker/v1/message.proto +0 -0
  387. /package/sdk-core/{sdk-core-protos → crates/common}/protos/api_upstream/temporal/api/workflow/v1/message.proto +0 -0
  388. /package/sdk-core/{sdk-core-protos → crates/common}/protos/google/rpc/status.proto +0 -0
  389. /package/sdk-core/{sdk-core-protos → crates/common}/protos/grpc/health/v1/health.proto +0 -0
  390. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/activity_result/activity_result.proto +0 -0
  391. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/activity_task/activity_task.proto +0 -0
  392. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +0 -0
  393. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/common/common.proto +0 -0
  394. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/core_interface.proto +0 -0
  395. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/external_data/external_data.proto +0 -0
  396. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/nexus/nexus.proto +0 -0
  397. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +0 -0
  398. /package/sdk-core/{sdk-core-protos → crates/common}/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +0 -0
  399. /package/sdk-core/{sdk-core-protos → crates/common}/protos/testsrv_upstream/Makefile +0 -0
  400. /package/sdk-core/{sdk-core-protos → crates/common}/protos/testsrv_upstream/api-linter.yaml +0 -0
  401. /package/sdk-core/{sdk-core-protos → crates/common}/protos/testsrv_upstream/buf.yaml +0 -0
  402. /package/sdk-core/{sdk-core-protos → crates/common}/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +0 -0
  403. /package/sdk-core/{sdk-core-protos → crates/common}/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +0 -0
  404. /package/sdk-core/{sdk-core-protos/src → crates/common/src/protos}/constants.rs +0 -0
  405. /package/sdk-core/{sdk-core-protos/src → crates/common/src/protos}/task_token.rs +0 -0
  406. /package/sdk-core/{fsm → crates/macros}/LICENSE.txt +0 -0
  407. /package/sdk-core/{core → crates/sdk-core}/src/abstractions/take_cell.rs +0 -0
  408. /package/sdk-core/{core → crates/sdk-core}/src/worker/slot_supplier.rs +0 -0
  409. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/ends_empty_wft_complete.bin +0 -0
  410. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/evict_while_la_running_no_interference-16_history.bin +0 -0
  411. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/evict_while_la_running_no_interference-23_history.bin +0 -0
  412. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/evict_while_la_running_no_interference-85_history.bin +0 -0
  413. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/fail_wf_task.bin +0 -0
  414. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/long_local_activity_with_update-0_history.bin +0 -0
  415. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/long_local_activity_with_update-1_history.bin +0 -0
  416. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/long_local_activity_with_update-2_history.bin +0 -0
  417. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/long_local_activity_with_update-3_history.bin +0 -0
  418. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/old_change_marker_format.bin +0 -0
  419. /package/sdk-core/{histories → crates/sdk-core/tests/histories}/timer_workflow_history.bin +0 -0
  420. /package/sdk-core/{tests → crates/sdk-core/tests}/integ_tests/workflow_tests/priority.rs +0 -0
  421. /package/sdk-core/{core-c-bridge → crates/sdk-core-c-bridge}/build.rs +0 -0
  422. /package/sdk-core/{cargo-tokio-console.sh → etc/cargo-tokio-console.sh} +0 -0
@@ -0,0 +1,740 @@
1
+ use crate::common::{ActivationAssertionsInterceptor, CoreWfStarter, build_fake_sdk};
2
+ use std::{
3
+ collections::{HashSet, VecDeque, hash_map::RandomState},
4
+ sync::{
5
+ Arc,
6
+ atomic::{AtomicBool, Ordering},
7
+ },
8
+ time::Duration,
9
+ };
10
+ use temporalio_client::WorkflowClientTrait;
11
+ use temporalio_common::protos::{
12
+ DEFAULT_WORKFLOW_TYPE, TestHistoryBuilder, VERSION_SEARCH_ATTR_KEY,
13
+ constants::PATCH_MARKER_NAME,
14
+ coresdk::{
15
+ AsJsonPayloadExt, FromJsonPayloadExt,
16
+ common::decode_change_marker_details,
17
+ workflow_activation::{NotifyHasPatch, WorkflowActivationJob, workflow_activation_job},
18
+ },
19
+ temporal::api::{
20
+ command::v1::{
21
+ RecordMarkerCommandAttributes, ScheduleActivityTaskCommandAttributes,
22
+ UpsertWorkflowSearchAttributesCommandAttributes, command::Attributes,
23
+ },
24
+ common::v1::ActivityType,
25
+ enums::v1::{CommandType, EventType, IndexedValueType},
26
+ history::v1::{
27
+ ActivityTaskCompletedEventAttributes, ActivityTaskScheduledEventAttributes,
28
+ ActivityTaskStartedEventAttributes, TimerFiredEventAttributes,
29
+ },
30
+ },
31
+ };
32
+
33
+ use temporalio_common::worker::WorkerTaskTypes;
34
+ use temporalio_sdk::{ActivityOptions, WfContext, WorkflowResult};
35
+ use temporalio_sdk_core::test_help::{CoreInternalFlags, MockPollCfg, ResponseType};
36
+ use tokio::{join, sync::Notify};
37
+ use tokio_stream::StreamExt;
38
+
39
+ const MY_PATCH_ID: &str = "integ_test_change_name";
40
+
41
+ pub(crate) async fn changes_wf(ctx: WfContext) -> WorkflowResult<()> {
42
+ if ctx.patched(MY_PATCH_ID) {
43
+ ctx.timer(Duration::from_millis(100)).await;
44
+ } else {
45
+ ctx.timer(Duration::from_millis(200)).await;
46
+ }
47
+ ctx.timer(Duration::from_millis(200)).await;
48
+ if ctx.patched(MY_PATCH_ID) {
49
+ ctx.timer(Duration::from_millis(100)).await;
50
+ } else {
51
+ ctx.timer(Duration::from_millis(200)).await;
52
+ }
53
+ Ok(().into())
54
+ }
55
+
56
+ #[tokio::test]
57
+ async fn writes_change_markers() {
58
+ let wf_name = "writes_change_markers";
59
+ let mut starter = CoreWfStarter::new(wf_name);
60
+ starter
61
+ .worker_config
62
+ .task_types(WorkerTaskTypes::workflow_only());
63
+ let mut worker = starter.worker().await;
64
+ worker.register_wf(wf_name.to_owned(), changes_wf);
65
+
66
+ starter.start_with_worker(wf_name, &mut worker).await;
67
+ worker.run_until_done().await.unwrap();
68
+ }
69
+
70
+ /// This one simulates a run as if the worker had the "old" code, then it fails at the end as
71
+ /// a cheapo way of being re-run, at which point it runs with change checks and the "new" code.
72
+ static DID_DIE: AtomicBool = AtomicBool::new(false);
73
+
74
+ pub(crate) async fn no_change_then_change_wf(ctx: WfContext) -> WorkflowResult<()> {
75
+ if DID_DIE.load(Ordering::Acquire) {
76
+ assert!(!ctx.patched(MY_PATCH_ID));
77
+ }
78
+ ctx.timer(Duration::from_millis(200)).await;
79
+ ctx.timer(Duration::from_millis(200)).await;
80
+ if DID_DIE.load(Ordering::Acquire) {
81
+ assert!(!ctx.patched(MY_PATCH_ID));
82
+ }
83
+ ctx.timer(Duration::from_millis(200)).await;
84
+
85
+ if !DID_DIE.load(Ordering::Acquire) {
86
+ DID_DIE.store(true, Ordering::Release);
87
+ ctx.force_task_fail(anyhow::anyhow!("i'm ded"));
88
+ }
89
+ Ok(().into())
90
+ }
91
+
92
+ #[tokio::test]
93
+ async fn can_add_change_markers() {
94
+ let wf_name = "can_add_change_markers";
95
+ let mut starter = CoreWfStarter::new(wf_name);
96
+ starter
97
+ .worker_config
98
+ .task_types(WorkerTaskTypes::workflow_only());
99
+ let mut worker = starter.worker().await;
100
+ worker.register_wf(wf_name.to_owned(), no_change_then_change_wf);
101
+
102
+ starter.start_with_worker(wf_name, &mut worker).await;
103
+ worker.run_until_done().await.unwrap();
104
+ }
105
+
106
+ static DID_DIE_2: AtomicBool = AtomicBool::new(false);
107
+
108
+ pub(crate) async fn replay_with_change_marker_wf(ctx: WfContext) -> WorkflowResult<()> {
109
+ assert!(ctx.patched(MY_PATCH_ID));
110
+ ctx.timer(Duration::from_millis(200)).await;
111
+ if !DID_DIE_2.load(Ordering::Acquire) {
112
+ DID_DIE_2.store(true, Ordering::Release);
113
+ ctx.force_task_fail(anyhow::anyhow!("i'm ded"));
114
+ }
115
+ Ok(().into())
116
+ }
117
+
118
+ #[tokio::test]
119
+ async fn replaying_with_patch_marker() {
120
+ let wf_name = "replaying_with_patch_marker";
121
+ let mut starter = CoreWfStarter::new(wf_name);
122
+ starter
123
+ .worker_config
124
+ .task_types(WorkerTaskTypes::workflow_only());
125
+ let mut worker = starter.worker().await;
126
+ worker.register_wf(wf_name.to_owned(), replay_with_change_marker_wf);
127
+
128
+ starter.start_with_worker(wf_name, &mut worker).await;
129
+ worker.run_until_done().await.unwrap();
130
+ }
131
+
132
+ /// Test that the internal patching mechanism works on the second workflow task when replaying.
133
+ /// Used as regression test for a bug that detected that we did not look ahead far enough to find
134
+ /// the next workflow task completion, which the flags are attached to.
135
+ #[tokio::test]
136
+ async fn patched_on_second_workflow_task_is_deterministic() {
137
+ let wf_name = "timer_patched_timer";
138
+ let mut starter = CoreWfStarter::new(wf_name);
139
+ // Disable caching to force replay from beginning
140
+ starter
141
+ .worker_config
142
+ .max_cached_workflows(0_usize)
143
+ .task_types(WorkerTaskTypes::workflow_only());
144
+ let mut worker = starter.worker().await;
145
+ // Include a task failure as well to make sure that works
146
+ static FAIL_ONCE: AtomicBool = AtomicBool::new(true);
147
+ worker.register_wf(wf_name.to_owned(), |ctx: WfContext| async move {
148
+ ctx.timer(Duration::from_millis(1)).await;
149
+ if FAIL_ONCE.load(Ordering::Acquire) {
150
+ FAIL_ONCE.store(false, Ordering::Release);
151
+ panic!("Enchi is hungry!");
152
+ }
153
+ assert!(ctx.patched(MY_PATCH_ID));
154
+ ctx.timer(Duration::from_millis(1)).await;
155
+ Ok(().into())
156
+ });
157
+
158
+ starter.start_with_worker(wf_name, &mut worker).await;
159
+ worker.run_until_done().await.unwrap();
160
+ }
161
+
162
+ #[tokio::test]
163
+ async fn can_remove_deprecated_patch_near_other_patch() {
164
+ let wf_name = "can_add_change_markers";
165
+ let mut starter = CoreWfStarter::new(wf_name);
166
+ starter
167
+ .worker_config
168
+ .task_types(WorkerTaskTypes::workflow_only());
169
+ let mut worker = starter.worker().await;
170
+ let did_die = Arc::new(AtomicBool::new(false));
171
+ worker.register_wf(wf_name.to_owned(), move |ctx: WfContext| {
172
+ let did_die = did_die.clone();
173
+ async move {
174
+ ctx.timer(Duration::from_millis(200)).await;
175
+ if !did_die.load(Ordering::Acquire) {
176
+ assert!(ctx.deprecate_patch("getting-deprecated"));
177
+ assert!(ctx.patched("staying"));
178
+ } else {
179
+ assert!(ctx.patched("staying"));
180
+ }
181
+ ctx.timer(Duration::from_millis(200)).await;
182
+
183
+ if !did_die.load(Ordering::Acquire) {
184
+ did_die.store(true, Ordering::Release);
185
+ ctx.force_task_fail(anyhow::anyhow!("i'm ded"));
186
+ }
187
+ Ok(().into())
188
+ }
189
+ });
190
+
191
+ starter.start_with_worker(wf_name, &mut worker).await;
192
+ worker.run_until_done().await.unwrap();
193
+ }
194
+
195
+ #[tokio::test]
196
+ async fn deprecated_patch_removal() {
197
+ let wf_name = "deprecated_patch_removal";
198
+ let mut starter = CoreWfStarter::new(wf_name);
199
+ starter
200
+ .worker_config
201
+ .task_types(WorkerTaskTypes::workflow_only());
202
+ let mut worker = starter.worker().await;
203
+ let client = starter.get_client().await;
204
+ let wf_id = starter.get_task_queue().to_string();
205
+ let did_die = Arc::new(AtomicBool::new(false));
206
+ let send_sig = Arc::new(Notify::new());
207
+ let send_sig_c = send_sig.clone();
208
+ worker.register_wf(wf_name, move |ctx: WfContext| {
209
+ let did_die = did_die.clone();
210
+ let send_sig_c = send_sig_c.clone();
211
+ async move {
212
+ if !did_die.load(Ordering::Acquire) {
213
+ assert!(ctx.deprecate_patch("getting-deprecated"));
214
+ }
215
+ send_sig_c.notify_one();
216
+ ctx.make_signal_channel("sig").next().await;
217
+
218
+ ctx.timer(Duration::from_millis(1)).await;
219
+
220
+ if !did_die.load(Ordering::Acquire) {
221
+ did_die.store(true, Ordering::Release);
222
+ ctx.force_task_fail(anyhow::anyhow!("i'm ded"));
223
+ }
224
+ Ok(().into())
225
+ }
226
+ });
227
+
228
+ starter.start_with_worker(wf_name, &mut worker).await;
229
+ let sig_fut = async {
230
+ send_sig.notified().await;
231
+ client
232
+ .signal_workflow_execution(wf_id, "".to_string(), "sig".to_string(), None, None)
233
+ .await
234
+ .unwrap()
235
+ };
236
+ let run_fut = async {
237
+ worker.run_until_done().await.unwrap();
238
+ };
239
+ join!(sig_fut, run_fut);
240
+ }
241
+
242
+ #[derive(Eq, PartialEq, Copy, Clone, Debug)]
243
+ enum MarkerType {
244
+ Deprecated,
245
+ NotDeprecated,
246
+ NoMarker,
247
+ }
248
+
249
+ const ONE_SECOND: Duration = Duration::from_secs(1);
250
+
251
+ /// EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
252
+ /// EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
253
+ /// EVENT_TYPE_WORKFLOW_TASK_STARTED
254
+ /// EVENT_TYPE_WORKFLOW_TASK_COMPLETED
255
+ /// EVENT_TYPE_MARKER_RECORDED (depending on marker_type)
256
+ /// EVENT_TYPE_ACTIVITY_TASK_SCHEDULED
257
+ /// EVENT_TYPE_ACTIVITY_TASK_STARTED
258
+ /// EVENT_TYPE_ACTIVITY_TASK_COMPLETED
259
+ /// EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
260
+ /// EVENT_TYPE_WORKFLOW_TASK_STARTED
261
+ /// EVENT_TYPE_WORKFLOW_TASK_COMPLETED
262
+ /// EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED
263
+ fn patch_marker_single_activity(
264
+ marker_type: MarkerType,
265
+ version: usize,
266
+ replay: bool,
267
+ ) -> TestHistoryBuilder {
268
+ let mut t = TestHistoryBuilder::default();
269
+ t.add_by_type(EventType::WorkflowExecutionStarted);
270
+ t.add_full_wf_task();
271
+ t.set_flags_first_wft(
272
+ &[CoreInternalFlags::UpsertSearchAttributeOnPatch as u32],
273
+ &[],
274
+ );
275
+ match marker_type {
276
+ MarkerType::Deprecated => {
277
+ t.add_has_change_marker(MY_PATCH_ID, true);
278
+ t.add_upsert_search_attrs_for_patch(&[MY_PATCH_ID.to_string()]);
279
+ }
280
+ MarkerType::NotDeprecated => {
281
+ t.add_has_change_marker(MY_PATCH_ID, false);
282
+ t.add_upsert_search_attrs_for_patch(&[MY_PATCH_ID.to_string()]);
283
+ }
284
+ MarkerType::NoMarker => {}
285
+ };
286
+
287
+ let activity_id = if replay {
288
+ match (marker_type, version) {
289
+ (_, 1) => "no_change",
290
+ (MarkerType::NotDeprecated, 2) => "had_change",
291
+ (MarkerType::Deprecated, 2) => "had_change",
292
+ (MarkerType::NoMarker, 2) => "no_change",
293
+ (_, 3) => "had_change",
294
+ (_, 4) => "had_change",
295
+ v => panic!("Nonsense marker / version combo {v:?}"),
296
+ }
297
+ } else {
298
+ // If the workflow isn't replaying (we're creating history here for a workflow which
299
+ // wasn't replaying at the time of scheduling the activity, and has done that, and now
300
+ // we're feeding back the history it would have produced) then it always has the change,
301
+ // except in v1.
302
+ if version > 1 {
303
+ "had_change"
304
+ } else {
305
+ "no_change"
306
+ }
307
+ };
308
+
309
+ let scheduled_event_id = t.add(ActivityTaskScheduledEventAttributes {
310
+ activity_id: activity_id.to_string(),
311
+ ..Default::default()
312
+ });
313
+ let started_event_id = t.add(ActivityTaskStartedEventAttributes {
314
+ scheduled_event_id,
315
+ ..Default::default()
316
+ });
317
+ t.add(ActivityTaskCompletedEventAttributes {
318
+ scheduled_event_id,
319
+ started_event_id,
320
+ ..Default::default()
321
+ });
322
+ t.add_full_wf_task();
323
+ t.add_workflow_execution_completed();
324
+ t
325
+ }
326
+
327
+ async fn v1(ctx: &mut WfContext) {
328
+ ctx.activity(ActivityOptions {
329
+ activity_id: Some("no_change".to_owned()),
330
+ ..Default::default()
331
+ })
332
+ .await;
333
+ }
334
+
335
+ async fn v2(ctx: &mut WfContext) -> bool {
336
+ if ctx.patched(MY_PATCH_ID) {
337
+ ctx.activity(ActivityOptions {
338
+ activity_id: Some("had_change".to_owned()),
339
+ ..Default::default()
340
+ })
341
+ .await;
342
+ true
343
+ } else {
344
+ ctx.activity(ActivityOptions {
345
+ activity_id: Some("no_change".to_owned()),
346
+ ..Default::default()
347
+ })
348
+ .await;
349
+ false
350
+ }
351
+ }
352
+
353
+ async fn v3(ctx: &mut WfContext) {
354
+ ctx.deprecate_patch(MY_PATCH_ID);
355
+ ctx.activity(ActivityOptions {
356
+ activity_id: Some("had_change".to_owned()),
357
+ ..Default::default()
358
+ })
359
+ .await;
360
+ }
361
+
362
+ async fn v4(ctx: &mut WfContext) {
363
+ ctx.activity(ActivityOptions {
364
+ activity_id: Some("had_change".to_owned()),
365
+ ..Default::default()
366
+ })
367
+ .await;
368
+ }
369
+
370
+ fn patch_setup(replaying: bool, marker_type: MarkerType, workflow_version: usize) -> MockPollCfg {
371
+ let t = patch_marker_single_activity(marker_type, workflow_version, replaying);
372
+ if replaying {
373
+ MockPollCfg::from_resps(t, [ResponseType::AllHistory])
374
+ } else {
375
+ MockPollCfg::from_hist_builder(t)
376
+ }
377
+ }
378
+
379
+ macro_rules! patch_wf {
380
+ ($workflow_version:ident) => {
381
+ move |mut ctx: WfContext| async move {
382
+ match $workflow_version {
383
+ 1 => {
384
+ v1(&mut ctx).await;
385
+ }
386
+ 2 => {
387
+ v2(&mut ctx).await;
388
+ }
389
+ 3 => {
390
+ v3(&mut ctx).await;
391
+ }
392
+ 4 => {
393
+ v4(&mut ctx).await;
394
+ }
395
+ _ => panic!("Invalid workflow version for test setup"),
396
+ }
397
+ Ok(().into())
398
+ }
399
+ };
400
+ }
401
+
402
+ #[rstest]
403
+ #[case::v1_breaks_on_normal_marker(false, MarkerType::NotDeprecated, 1)]
404
+ #[case::v1_accepts_dep_marker(false, MarkerType::Deprecated, 1)]
405
+ #[case::v1_replay_breaks_on_normal_marker(true, MarkerType::NotDeprecated, 1)]
406
+ #[case::v1_replay_accepts_dep_marker(true, MarkerType::Deprecated, 1)]
407
+ #[case::v4_breaks_on_normal_marker(false, MarkerType::NotDeprecated, 4)]
408
+ #[case::v4_accepts_dep_marker(false, MarkerType::Deprecated, 4)]
409
+ #[case::v4_replay_breaks_on_normal_marker(true, MarkerType::NotDeprecated, 4)]
410
+ #[case::v4_replay_accepts_dep_marker(true, MarkerType::Deprecated, 4)]
411
+ #[tokio::test]
412
+ async fn v1_and_v4_changes(
413
+ #[case] replaying: bool,
414
+ #[case] marker_type: MarkerType,
415
+ #[case] wf_version: usize,
416
+ ) {
417
+ let mut mock_cfg = patch_setup(replaying, marker_type, wf_version);
418
+
419
+ if marker_type != MarkerType::Deprecated {
420
+ // should explode b/c non-dep marker is present
421
+ mock_cfg.num_expected_fails = 1;
422
+ }
423
+
424
+ let mut aai = ActivationAssertionsInterceptor::default();
425
+ aai.skip_one().then(move |a| {
426
+ if marker_type == MarkerType::Deprecated {
427
+ // Activity is resolved
428
+ assert_matches!(
429
+ a.jobs.as_slice(),
430
+ [WorkflowActivationJob {
431
+ variant: Some(workflow_activation_job::Variant::ResolveActivity(_))
432
+ }]
433
+ );
434
+ }
435
+ });
436
+
437
+ if !replaying {
438
+ mock_cfg.completion_asserts_from_expectations(|mut asserts| {
439
+ asserts.then(|wft| {
440
+ assert_eq!(wft.commands.len(), 1);
441
+ assert_eq!(
442
+ wft.commands[0].command_type,
443
+ CommandType::ScheduleActivityTask as i32
444
+ );
445
+ });
446
+ });
447
+ }
448
+
449
+ let mut worker = build_fake_sdk(mock_cfg);
450
+ worker.set_worker_interceptor(aai);
451
+ worker.register_wf(DEFAULT_WORKFLOW_TYPE, patch_wf!(wf_version));
452
+ worker.run().await.unwrap();
453
+ }
454
+
455
+ // Note that the not-replaying and no-marker cases don't make sense and hence are absent
456
+ #[rstest]
457
+ #[case::v2_marker_new_path(false, MarkerType::NotDeprecated, 2)]
458
+ #[case::v2_dep_marker_new_path(false, MarkerType::Deprecated, 2)]
459
+ #[case::v2_replay_no_marker_old_path(true, MarkerType::NoMarker, 2)]
460
+ #[case::v2_replay_marker_new_path(true, MarkerType::NotDeprecated, 2)]
461
+ #[case::v2_replay_dep_marker_new_path(true, MarkerType::Deprecated, 2)]
462
+ #[case::v3_marker_new_path(false, MarkerType::NotDeprecated, 3)]
463
+ #[case::v3_dep_marker_new_path(false, MarkerType::Deprecated, 3)]
464
+ #[case::v3_replay_no_marker_old_path(true, MarkerType::NoMarker, 3)]
465
+ #[case::v3_replay_marker_new_path(true, MarkerType::NotDeprecated, 3)]
466
+ #[case::v3_replay_dep_marker_new_path(true, MarkerType::Deprecated, 3)]
467
+ #[tokio::test]
468
+ async fn v2_and_v3_changes(
469
+ #[case] replaying: bool,
470
+ #[case] marker_type: MarkerType,
471
+ #[case] wf_version: usize,
472
+ ) {
473
+ let mut mock_cfg = patch_setup(replaying, marker_type, wf_version);
474
+
475
+ let mut aai = ActivationAssertionsInterceptor::default();
476
+ aai.then(move |act| {
477
+ // replaying cases should immediately get a resolve change activation when marker is
478
+ // present
479
+ if replaying && marker_type != MarkerType::NoMarker {
480
+ assert_matches!(
481
+ &act.jobs[1],
482
+ WorkflowActivationJob {
483
+ variant: Some(workflow_activation_job::Variant::NotifyHasPatch(
484
+ NotifyHasPatch {
485
+ patch_id,
486
+ }
487
+ ))
488
+ } => patch_id == MY_PATCH_ID
489
+ );
490
+ } else {
491
+ assert_eq!(act.jobs.len(), 1);
492
+ }
493
+ })
494
+ .then(move |act| {
495
+ assert_matches!(
496
+ act.jobs.as_slice(),
497
+ [WorkflowActivationJob {
498
+ variant: Some(workflow_activation_job::Variant::ResolveActivity(_))
499
+ }]
500
+ );
501
+ });
502
+
503
+ if !replaying {
504
+ mock_cfg.completion_asserts_from_expectations(|mut asserts| {
505
+ asserts.then(move |wft| {
506
+ let mut commands = VecDeque::from(wft.commands.clone());
507
+ let expected_num_cmds = if marker_type == MarkerType::NoMarker {
508
+ 2
509
+ } else {
510
+ 3
511
+ };
512
+ assert_eq!(commands.len(), expected_num_cmds);
513
+ let dep_flag_expected = wf_version != 2;
514
+ assert_matches!(
515
+ commands.pop_front().unwrap().attributes.as_ref().unwrap(),
516
+ Attributes::RecordMarkerCommandAttributes(
517
+ RecordMarkerCommandAttributes { marker_name, details,.. })
518
+ if marker_name == PATCH_MARKER_NAME
519
+ && decode_change_marker_details(details).unwrap().1 == dep_flag_expected
520
+ );
521
+ if expected_num_cmds == 3 {
522
+ let mut as_payload = [MY_PATCH_ID].as_json_payload().unwrap();
523
+ as_payload.metadata.insert(
524
+ "type".to_string(),
525
+ IndexedValueType::KeywordList
526
+ .as_str_name()
527
+ .as_bytes()
528
+ .to_vec(),
529
+ );
530
+ assert_matches!(
531
+ commands.pop_front().unwrap().attributes.as_ref().unwrap(),
532
+ Attributes::UpsertWorkflowSearchAttributesCommandAttributes(
533
+ UpsertWorkflowSearchAttributesCommandAttributes
534
+ { search_attributes: Some(attrs) }
535
+ )
536
+ if attrs.indexed_fields.get(VERSION_SEARCH_ATTR_KEY).unwrap()
537
+ == &as_payload
538
+ );
539
+ }
540
+ // The only time the "old" timer should fire is in v2, replaying, without a marker.
541
+ let expected_activity_id =
542
+ if replaying && marker_type == MarkerType::NoMarker && wf_version == 2 {
543
+ "no_change"
544
+ } else {
545
+ "had_change"
546
+ };
547
+ assert_matches!(
548
+ commands.pop_front().unwrap().attributes.as_ref().unwrap(),
549
+ Attributes::ScheduleActivityTaskCommandAttributes(
550
+ ScheduleActivityTaskCommandAttributes { activity_id, .. }
551
+ )
552
+ if activity_id == expected_activity_id
553
+ );
554
+ });
555
+ });
556
+ }
557
+
558
+ let mut worker = build_fake_sdk(mock_cfg);
559
+ worker.set_worker_interceptor(aai);
560
+ worker.register_wf(DEFAULT_WORKFLOW_TYPE, patch_wf!(wf_version));
561
+ worker.run().await.unwrap();
562
+ }
563
+
564
+ #[rstest]
565
+ #[case::has_change_replay(true, true)]
566
+ #[case::no_change_replay(false, true)]
567
+ #[case::has_change_inc(true, false)]
568
+ // The false-false case doesn't make sense, as the incremental cases act as if working against
569
+ // a sticky queue, and it'd be impossible for a worker with the call to get an incremental
570
+ // history that then suddenly doesn't have the marker.
571
+ #[tokio::test]
572
+ async fn same_change_multiple_spots(#[case] have_marker_in_hist: bool, #[case] replay: bool) {
573
+ let mut t = TestHistoryBuilder::default();
574
+ t.add_by_type(EventType::WorkflowExecutionStarted);
575
+ t.add_full_wf_task();
576
+ t.set_flags_first_wft(
577
+ &[CoreInternalFlags::UpsertSearchAttributeOnPatch as u32],
578
+ &[],
579
+ );
580
+ if have_marker_in_hist {
581
+ t.add_has_change_marker(MY_PATCH_ID, false);
582
+ t.add_upsert_search_attrs_for_patch(&[MY_PATCH_ID.to_string()]);
583
+ let scheduled_event_id = t.add(ActivityTaskScheduledEventAttributes {
584
+ activity_id: "1".to_owned(),
585
+ activity_type: Some(ActivityType {
586
+ name: "".to_string(),
587
+ }),
588
+ ..Default::default()
589
+ });
590
+ let started_event_id = t.add(ActivityTaskStartedEventAttributes {
591
+ scheduled_event_id,
592
+ ..Default::default()
593
+ });
594
+ t.add(ActivityTaskCompletedEventAttributes {
595
+ scheduled_event_id,
596
+ started_event_id,
597
+ ..Default::default()
598
+ });
599
+ t.add_full_wf_task();
600
+ let timer_started_event_id = t.add_by_type(EventType::TimerStarted);
601
+ t.add(TimerFiredEventAttributes {
602
+ started_event_id: timer_started_event_id,
603
+ timer_id: "1".to_owned(),
604
+ });
605
+ } else {
606
+ let started_event_id = t.add_by_type(EventType::TimerStarted);
607
+ t.add(TimerFiredEventAttributes {
608
+ started_event_id,
609
+ timer_id: "1".to_owned(),
610
+ });
611
+ t.add_full_wf_task();
612
+ let timer_started_event_id = t.add_by_type(EventType::TimerStarted);
613
+ t.add(TimerFiredEventAttributes {
614
+ started_event_id: timer_started_event_id,
615
+ timer_id: "2".to_owned(),
616
+ });
617
+ }
618
+ t.add_full_wf_task();
619
+
620
+ if have_marker_in_hist {
621
+ let scheduled_event_id = t.add(ActivityTaskScheduledEventAttributes {
622
+ activity_id: "2".to_string(),
623
+ activity_type: Some(ActivityType {
624
+ name: "".to_string(),
625
+ }),
626
+ ..Default::default()
627
+ });
628
+ let started_event_id = t.add(ActivityTaskStartedEventAttributes {
629
+ scheduled_event_id,
630
+ ..Default::default()
631
+ });
632
+ t.add(ActivityTaskCompletedEventAttributes {
633
+ scheduled_event_id,
634
+ started_event_id,
635
+ ..Default::default()
636
+ });
637
+ } else {
638
+ let started_event_id = t.add_by_type(EventType::TimerStarted);
639
+ t.add(TimerFiredEventAttributes {
640
+ started_event_id,
641
+ timer_id: "3".to_owned(),
642
+ });
643
+ }
644
+ t.add_full_wf_task();
645
+ t.add_workflow_execution_completed();
646
+
647
+ let mock_cfg = if replay {
648
+ MockPollCfg::from_resps(t, [ResponseType::AllHistory])
649
+ } else {
650
+ MockPollCfg::from_hist_builder(t)
651
+ };
652
+
653
+ // Errors would appear as nondeterminism problems, so just run it.
654
+ let mut worker = build_fake_sdk(mock_cfg);
655
+ worker.register_wf(DEFAULT_WORKFLOW_TYPE, move |ctx: WfContext| async move {
656
+ if ctx.patched(MY_PATCH_ID) {
657
+ ctx.activity(ActivityOptions::default()).await;
658
+ } else {
659
+ ctx.timer(ONE_SECOND).await;
660
+ }
661
+ ctx.timer(ONE_SECOND).await;
662
+ if ctx.patched(MY_PATCH_ID) {
663
+ ctx.activity(ActivityOptions::default()).await;
664
+ } else {
665
+ ctx.timer(ONE_SECOND).await;
666
+ }
667
+ Ok(().into())
668
+ });
669
+ worker.run().await.unwrap();
670
+ }
671
+
672
+ const SIZE_OVERFLOW_PATCH_AMOUNT: usize = 180;
673
+ #[rstest]
674
+ #[case::happy_path(50)]
675
+ // We start exceeding the 2k size limit at 180 patches with this format
676
+ #[case::size_overflow(SIZE_OVERFLOW_PATCH_AMOUNT)]
677
+ #[tokio::test]
678
+ async fn many_patches_combine_in_search_attrib_update(#[case] num_patches: usize) {
679
+ let mut t = TestHistoryBuilder::default();
680
+ t.add_by_type(EventType::WorkflowExecutionStarted);
681
+ t.add_full_wf_task();
682
+ t.set_flags_first_wft(
683
+ &[CoreInternalFlags::UpsertSearchAttributeOnPatch as u32],
684
+ &[],
685
+ );
686
+ for i in 1..=num_patches {
687
+ let id = format!("patch-{i}");
688
+ t.add_has_change_marker(&id, false);
689
+ if i < SIZE_OVERFLOW_PATCH_AMOUNT {
690
+ t.add_upsert_search_attrs_for_patch(&[id]);
691
+ }
692
+ let timer_started_event_id = t.add_by_type(EventType::TimerStarted);
693
+ t.add(TimerFiredEventAttributes {
694
+ started_event_id: timer_started_event_id,
695
+ timer_id: i.to_string(),
696
+ });
697
+ t.add_full_wf_task();
698
+ }
699
+ t.add_workflow_execution_completed();
700
+
701
+ let mut mock_cfg = MockPollCfg::from_hist_builder(t);
702
+ mock_cfg.completion_asserts_from_expectations(|mut asserts| {
703
+ // Iterate through all activations/responses except the final one with complete workflow
704
+ for i in 2..=num_patches + 1 {
705
+ asserts.then(move |wft| {
706
+ let cmds = &wft.commands;
707
+ if i > SIZE_OVERFLOW_PATCH_AMOUNT {
708
+ assert_eq!(2, cmds.len());
709
+ assert_matches!(cmds[1].command_type(), CommandType::StartTimer);
710
+ } else {
711
+ assert_eq!(3, cmds.len());
712
+ let attrs = assert_matches!(
713
+ cmds[1].attributes.as_ref().unwrap(),
714
+ Attributes::UpsertWorkflowSearchAttributesCommandAttributes(
715
+ UpsertWorkflowSearchAttributesCommandAttributes
716
+ { search_attributes: Some(attrs) }
717
+ ) => attrs
718
+ );
719
+ let expected_patches: HashSet<String, _> =
720
+ (1..i).map(|i| format!("patch-{i}")).collect();
721
+ let deserialized = HashSet::<String, RandomState>::from_json_payload(
722
+ attrs.indexed_fields.get(VERSION_SEARCH_ATTR_KEY).unwrap(),
723
+ )
724
+ .unwrap();
725
+ assert_eq!(deserialized, expected_patches);
726
+ }
727
+ });
728
+ }
729
+ });
730
+
731
+ let mut worker = build_fake_sdk(mock_cfg);
732
+ worker.register_wf(DEFAULT_WORKFLOW_TYPE, move |ctx: WfContext| async move {
733
+ for i in 1..=num_patches {
734
+ let _dontcare = ctx.patched(&format!("patch-{i}"));
735
+ ctx.timer(ONE_SECOND).await;
736
+ }
737
+ Ok(().into())
738
+ });
739
+ worker.run().await.unwrap();
740
+ }