@temporalio/core-bridge 1.5.2 → 1.7.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 (194) hide show
  1. package/Cargo.lock +304 -112
  2. package/lib/index.d.ts +8 -6
  3. package/lib/index.js.map +1 -1
  4. package/package.json +9 -4
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.buildkite/docker/Dockerfile +2 -2
  11. package/sdk-core/.buildkite/docker/docker-compose.yaml +1 -1
  12. package/sdk-core/.buildkite/pipeline.yml +2 -4
  13. package/sdk-core/.cargo/config.toml +5 -2
  14. package/sdk-core/.github/workflows/heavy.yml +29 -0
  15. package/sdk-core/Cargo.toml +1 -1
  16. package/sdk-core/README.md +20 -10
  17. package/sdk-core/client/src/lib.rs +215 -39
  18. package/sdk-core/client/src/metrics.rs +17 -8
  19. package/sdk-core/client/src/raw.rs +4 -4
  20. package/sdk-core/client/src/retry.rs +32 -20
  21. package/sdk-core/core/Cargo.toml +25 -12
  22. package/sdk-core/core/src/abstractions/take_cell.rs +28 -0
  23. package/sdk-core/core/src/abstractions.rs +204 -14
  24. package/sdk-core/core/src/core_tests/activity_tasks.rs +143 -50
  25. package/sdk-core/core/src/core_tests/child_workflows.rs +6 -5
  26. package/sdk-core/core/src/core_tests/determinism.rs +165 -2
  27. package/sdk-core/core/src/core_tests/local_activities.rs +431 -43
  28. package/sdk-core/core/src/core_tests/queries.rs +34 -16
  29. package/sdk-core/core/src/core_tests/workers.rs +8 -5
  30. package/sdk-core/core/src/core_tests/workflow_tasks.rs +588 -55
  31. package/sdk-core/core/src/ephemeral_server/mod.rs +113 -12
  32. package/sdk-core/core/src/internal_flags.rs +155 -0
  33. package/sdk-core/core/src/lib.rs +16 -9
  34. package/sdk-core/core/src/protosext/mod.rs +1 -1
  35. package/sdk-core/core/src/replay/mod.rs +16 -27
  36. package/sdk-core/core/src/telemetry/log_export.rs +1 -1
  37. package/sdk-core/core/src/telemetry/metrics.rs +69 -35
  38. package/sdk-core/core/src/telemetry/mod.rs +60 -21
  39. package/sdk-core/core/src/telemetry/prometheus_server.rs +19 -13
  40. package/sdk-core/core/src/test_help/mod.rs +73 -14
  41. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +119 -160
  42. package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  43. package/sdk-core/core/src/worker/activities/local_activities.rs +379 -129
  44. package/sdk-core/core/src/worker/activities.rs +350 -175
  45. package/sdk-core/core/src/worker/client/mocks.rs +22 -2
  46. package/sdk-core/core/src/worker/client.rs +18 -2
  47. package/sdk-core/core/src/worker/mod.rs +183 -64
  48. package/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
  49. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +3 -5
  50. package/sdk-core/core/src/worker/workflow/history_update.rs +916 -277
  51. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +216 -183
  52. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +9 -12
  53. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +7 -9
  54. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +160 -87
  55. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +13 -14
  56. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -9
  57. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +14 -17
  58. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +242 -110
  59. package/sdk-core/core/src/worker/workflow/machines/mod.rs +27 -19
  60. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +9 -11
  61. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +321 -206
  62. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +13 -18
  63. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +20 -29
  64. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +2 -2
  65. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +257 -51
  66. package/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
  67. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +310 -150
  68. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +17 -20
  69. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +31 -15
  70. package/sdk-core/core/src/worker/workflow/managed_run.rs +1052 -380
  71. package/sdk-core/core/src/worker/workflow/mod.rs +598 -390
  72. package/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
  73. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +137 -0
  74. package/sdk-core/core/src/worker/workflow/wft_poller.rs +1 -4
  75. package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
  76. package/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
  77. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +469 -718
  78. package/sdk-core/core-api/Cargo.toml +2 -1
  79. package/sdk-core/core-api/src/errors.rs +1 -34
  80. package/sdk-core/core-api/src/lib.rs +19 -9
  81. package/sdk-core/core-api/src/telemetry.rs +4 -6
  82. package/sdk-core/core-api/src/worker.rs +19 -1
  83. package/sdk-core/etc/deps.svg +115 -140
  84. package/sdk-core/etc/regen-depgraph.sh +5 -0
  85. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +86 -61
  86. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +29 -71
  87. package/sdk-core/histories/ends_empty_wft_complete.bin +0 -0
  88. package/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
  89. package/sdk-core/histories/old_change_marker_format.bin +0 -0
  90. package/sdk-core/protos/api_upstream/.github/CODEOWNERS +2 -1
  91. package/sdk-core/protos/api_upstream/Makefile +6 -6
  92. package/sdk-core/protos/api_upstream/build/go.mod +7 -0
  93. package/sdk-core/protos/api_upstream/build/go.sum +5 -0
  94. package/sdk-core/protos/api_upstream/build/tools.go +29 -0
  95. package/sdk-core/protos/api_upstream/go.mod +6 -0
  96. package/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +9 -2
  97. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +7 -26
  98. package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
  99. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  100. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +3 -7
  101. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  102. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +8 -8
  103. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +25 -2
  104. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  105. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  106. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  107. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  108. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  109. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
  110. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  111. package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  112. package/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  113. package/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  114. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +49 -26
  115. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
  116. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +5 -2
  117. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -2
  118. package/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
  119. package/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  120. package/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  121. package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
  122. package/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  123. package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -2
  124. package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
  125. package/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  126. package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +2 -2
  127. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -28
  128. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +4 -4
  129. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +7 -8
  130. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +10 -7
  131. package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +19 -30
  132. package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  133. package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  134. package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +8 -0
  135. package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +67 -60
  136. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +85 -84
  137. package/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +9 -3
  138. package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  139. package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  140. package/sdk-core/sdk/Cargo.toml +5 -4
  141. package/sdk-core/sdk/src/lib.rs +108 -26
  142. package/sdk-core/sdk/src/workflow_context/options.rs +7 -1
  143. package/sdk-core/sdk/src/workflow_context.rs +24 -17
  144. package/sdk-core/sdk/src/workflow_future.rs +16 -15
  145. package/sdk-core/sdk-core-protos/Cargo.toml +5 -2
  146. package/sdk-core/sdk-core-protos/build.rs +36 -2
  147. package/sdk-core/sdk-core-protos/src/history_builder.rs +138 -106
  148. package/sdk-core/sdk-core-protos/src/history_info.rs +10 -1
  149. package/sdk-core/sdk-core-protos/src/lib.rs +272 -87
  150. package/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
  151. package/sdk-core/test-utils/Cargo.toml +3 -1
  152. package/sdk-core/test-utils/src/canned_histories.rs +106 -296
  153. package/sdk-core/test-utils/src/histfetch.rs +1 -1
  154. package/sdk-core/test-utils/src/lib.rs +82 -23
  155. package/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
  156. package/sdk-core/test-utils/src/workflows.rs +29 -0
  157. package/sdk-core/tests/fuzzy_workflow.rs +130 -0
  158. package/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
  159. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  160. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
  161. package/sdk-core/tests/integ_tests/metrics_tests.rs +218 -16
  162. package/sdk-core/tests/integ_tests/polling_tests.rs +4 -47
  163. package/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
  164. package/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
  165. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +161 -72
  166. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  167. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
  168. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +80 -3
  169. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
  170. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
  171. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +94 -200
  172. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +2 -4
  173. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +34 -28
  174. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +76 -7
  175. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  176. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
  177. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
  178. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
  179. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +7 -8
  180. package/sdk-core/tests/integ_tests/workflow_tests.rs +13 -14
  181. package/sdk-core/tests/main.rs +3 -13
  182. package/sdk-core/tests/runner.rs +75 -36
  183. package/sdk-core/tests/wf_input_replay.rs +32 -0
  184. package/src/conversions.rs +14 -8
  185. package/src/runtime.rs +9 -8
  186. package/ts/index.ts +8 -6
  187. package/sdk-core/bridge-ffi/Cargo.toml +0 -24
  188. package/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  189. package/sdk-core/bridge-ffi/build.rs +0 -25
  190. package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -224
  191. package/sdk-core/bridge-ffi/src/lib.rs +0 -746
  192. package/sdk-core/bridge-ffi/src/wrappers.rs +0 -221
  193. package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  194. package/sdk-core/sdk/src/conversions.rs +0 -8
@@ -4,6 +4,10 @@ use super::{
4
4
  workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
5
5
  OnEventWrapper, WFMachinesAdapter, WFMachinesError,
6
6
  };
7
+ use crate::{
8
+ internal_flags::CoreInternalFlags,
9
+ worker::workflow::{machines::HistEventData, InternalFlagsRef},
10
+ };
7
11
  use rustfsm::{fsm, MachineError, StateMachine, TransitionResult};
8
12
  use std::convert::{TryFrom, TryInto};
9
13
  use temporal_sdk_core_protos::{
@@ -16,10 +20,7 @@ use temporal_sdk_core_protos::{
16
20
  command::v1::{command, Command, RequestCancelActivityTaskCommandAttributes},
17
21
  common::v1::{ActivityType, Payload, Payloads},
18
22
  enums::v1::{CommandType, EventType, RetryState},
19
- failure::v1::{
20
- self as failure, failure::FailureInfo, ActivityFailureInfo, CanceledFailureInfo,
21
- Failure,
22
- },
23
+ failure::v1::{failure::FailureInfo, ActivityFailureInfo, CanceledFailureInfo, Failure},
23
24
  history::v1::{
24
25
  history_event, ActivityTaskCanceledEventAttributes,
25
26
  ActivityTaskCompletedEventAttributes, ActivityTaskFailedEventAttributes,
@@ -37,7 +38,7 @@ fsm! {
37
38
  Created --(Schedule, on_schedule)--> ScheduleCommandCreated;
38
39
 
39
40
  ScheduleCommandCreated --(CommandScheduleActivityTask) --> ScheduleCommandCreated;
40
- ScheduleCommandCreated --(ActivityTaskScheduled(i64),
41
+ ScheduleCommandCreated --(ActivityTaskScheduled(ActTaskScheduledData),
41
42
  shared on_activity_task_scheduled) --> ScheduledEventRecorded;
42
43
  ScheduleCommandCreated --(Cancel, shared on_canceled) --> Canceled;
43
44
 
@@ -45,7 +46,7 @@ fsm! {
45
46
  ScheduledEventRecorded --(ActivityTaskTimedOut(ActivityTaskTimedOutEventAttributes),
46
47
  shared on_task_timed_out) --> TimedOut;
47
48
  ScheduledEventRecorded --(Cancel, shared on_canceled) --> ScheduledActivityCancelCommandCreated;
48
- ScheduledEventRecorded --(Abandon, shared on_abandoned) --> Canceled;
49
+ ScheduledEventRecorded --(Abandon, on_abandoned) --> Canceled;
49
50
 
50
51
  Started --(ActivityTaskCompleted(ActivityTaskCompletedEventAttributes),
51
52
  on_activity_task_completed) --> Completed;
@@ -54,7 +55,7 @@ fsm! {
54
55
  Started --(ActivityTaskTimedOut(ActivityTaskTimedOutEventAttributes),
55
56
  shared on_activity_task_timed_out) --> TimedOut;
56
57
  Started --(Cancel, shared on_canceled) --> StartedActivityCancelCommandCreated;
57
- Started --(Abandon, shared on_abandoned) --> Canceled;
58
+ Started --(Abandon, on_abandoned) --> Canceled;
58
59
 
59
60
  ScheduledActivityCancelCommandCreated --(CommandRequestCancelActivityTask) --> ScheduledActivityCancelCommandCreated;
60
61
  ScheduledActivityCancelCommandCreated --(ActivityTaskCancelRequested) --> ScheduledActivityCancelEventRecorded;
@@ -89,39 +90,46 @@ pub(super) enum ActivityMachineCommand {
89
90
  #[display(fmt = "Fail")]
90
91
  Fail(Failure),
91
92
  #[display(fmt = "Cancel")]
92
- Cancel(Option<Payloads>),
93
+ Cancel(Option<ActivityTaskCanceledEventAttributes>),
93
94
  #[display(fmt = "RequestCancellation")]
94
95
  RequestCancellation(Command),
95
96
  }
96
97
 
97
- /// Creates a new activity state machine and a command to schedule it on the server.
98
- pub(super) fn new_activity(attribs: ScheduleActivity) -> NewMachineWithCommand {
99
- let (activity, add_cmd) = ActivityMachine::new_scheduled(attribs);
100
- NewMachineWithCommand {
101
- command: add_cmd,
102
- machine: activity.into(),
103
- }
98
+ pub(super) struct ActTaskScheduledData {
99
+ event_id: i64,
100
+ act_type: String,
101
+ act_id: String,
102
+ last_task_in_history: bool,
104
103
  }
105
104
 
106
105
  impl ActivityMachine {
107
106
  /// Create a new activity and immediately schedule it.
108
- fn new_scheduled(attribs: ScheduleActivity) -> (Self, Command) {
109
- let mut s = Self {
110
- state: Created {}.into(),
111
- shared_state: SharedState {
112
- cancellation_type: ActivityCancellationType::from_i32(attribs.cancellation_type)
107
+ pub(super) fn new_scheduled(
108
+ attrs: ScheduleActivity,
109
+ internal_flags: InternalFlagsRef,
110
+ ) -> NewMachineWithCommand {
111
+ let mut s = Self::from_parts(
112
+ Created {}.into(),
113
+ SharedState {
114
+ cancellation_type: ActivityCancellationType::from_i32(attrs.cancellation_type)
113
115
  .unwrap(),
114
- attrs: attribs,
115
- ..Default::default()
116
+ attrs,
117
+ internal_flags,
118
+ scheduled_event_id: 0,
119
+ started_event_id: 0,
120
+ cancelled_before_sent: false,
116
121
  },
117
- };
122
+ );
118
123
  OnEventWrapper::on_event_mut(&mut s, ActivityMachineEvents::Schedule)
119
124
  .expect("Scheduling activities doesn't fail");
120
- let cmd = Command {
125
+ let command = Command {
121
126
  command_type: CommandType::ScheduleActivityTask as i32,
122
127
  attributes: Some(s.shared_state().attrs.clone().into()),
123
128
  };
124
- (s, cmd)
129
+ NewMachineWithCommand {
130
+ command,
131
+ machine: s.into(),
132
+ }
125
133
  }
126
134
 
127
135
  fn machine_responses_from_cancel_request(&self, cancel_cmd: Command) -> Vec<MachineResponse> {
@@ -136,45 +144,46 @@ impl ActivityMachine {
136
144
  r
137
145
  }
138
146
 
139
- fn create_cancelation_resolve(&self, details: Option<Payload>) -> ResolveActivity {
147
+ fn create_cancelation_resolve(
148
+ &self,
149
+ attrs: Option<ActivityTaskCanceledEventAttributes>,
150
+ ) -> ResolveActivity {
151
+ let attrs = attrs.unwrap_or_default();
140
152
  ResolveActivity {
141
153
  seq: self.shared_state.attrs.seq,
142
154
  result: Some(ActivityResolution {
143
155
  status: Some(activity_resolution::Status::Cancelled(Cancellation {
144
- failure: Some(Failure {
145
- message: "Activity cancelled".to_string(),
146
- cause: Some(Box::from(Failure {
147
- failure_info: Some(FailureInfo::CanceledFailureInfo(
148
- CanceledFailureInfo {
149
- details: details.map(Into::into),
150
- },
151
- )),
152
- ..Default::default()
153
- })),
154
- failure_info: Some(FailureInfo::ActivityFailureInfo(ActivityFailureInfo {
155
- scheduled_event_id: self.shared_state.scheduled_event_id,
156
- started_event_id: self.shared_state.started_event_id,
157
- activity_type: Some(ActivityType {
158
- name: self.shared_state.attrs.activity_type.clone(),
159
- }),
160
- activity_id: self.shared_state.attrs.activity_id.clone(),
161
- retry_state: RetryState::CancelRequested as i32,
162
- ..Default::default()
163
- })),
164
- ..Default::default()
165
- }),
156
+ failure: Some(new_cancel_failure(&self.shared_state, attrs)),
166
157
  })),
167
158
  }),
168
159
  }
169
160
  }
170
161
  }
171
162
 
172
- impl TryFrom<HistoryEvent> for ActivityMachineEvents {
163
+ impl TryFrom<HistEventData> for ActivityMachineEvents {
173
164
  type Error = WFMachinesError;
174
165
 
175
- fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
166
+ fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
167
+ let last_task_in_history = e.current_task_is_last_in_history;
168
+ let e = e.event;
176
169
  Ok(match e.event_type() {
177
- EventType::ActivityTaskScheduled => Self::ActivityTaskScheduled(e.event_id),
170
+ EventType::ActivityTaskScheduled => {
171
+ if let Some(history_event::Attributes::ActivityTaskScheduledEventAttributes(
172
+ attrs,
173
+ )) = e.attributes
174
+ {
175
+ Self::ActivityTaskScheduled(ActTaskScheduledData {
176
+ event_id: e.event_id,
177
+ act_id: attrs.activity_id,
178
+ act_type: attrs.activity_type.unwrap_or_default().name,
179
+ last_task_in_history,
180
+ })
181
+ } else {
182
+ return Err(WFMachinesError::Fatal(format!(
183
+ "Activity scheduled attributes were unset: {e}"
184
+ )));
185
+ }
186
+ }
178
187
  EventType::ActivityTaskStarted => Self::ActivityTaskStarted(e.event_id),
179
188
  EventType::ActivityTaskCompleted => {
180
189
  if let Some(history_event::Attributes::ActivityTaskCompletedEventAttributes(
@@ -184,8 +193,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
184
193
  Self::ActivityTaskCompleted(attrs)
185
194
  } else {
186
195
  return Err(WFMachinesError::Fatal(format!(
187
- "Activity completion attributes were unset: {}",
188
- e
196
+ "Activity completion attributes were unset: {e}"
189
197
  )));
190
198
  }
191
199
  }
@@ -196,8 +204,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
196
204
  Self::ActivityTaskFailed(attrs)
197
205
  } else {
198
206
  return Err(WFMachinesError::Fatal(format!(
199
- "Activity failure attributes were unset: {}",
200
- e
207
+ "Activity failure attributes were unset: {e}"
201
208
  )));
202
209
  }
203
210
  }
@@ -208,8 +215,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
208
215
  Self::ActivityTaskTimedOut(attrs)
209
216
  } else {
210
217
  return Err(WFMachinesError::Fatal(format!(
211
- "Activity timeout attributes were unset: {}",
212
- e
218
+ "Activity timeout attributes were unset: {e}"
213
219
  )));
214
220
  }
215
221
  }
@@ -221,15 +227,13 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
221
227
  Self::ActivityTaskCanceled(attrs)
222
228
  } else {
223
229
  return Err(WFMachinesError::Fatal(format!(
224
- "Activity cancellation attributes were unset: {}",
225
- e
230
+ "Activity cancellation attributes were unset: {e}"
226
231
  )));
227
232
  }
228
233
  }
229
234
  _ => {
230
235
  return Err(WFMachinesError::Nondeterminism(format!(
231
- "Activity machine does not handle this event: {}",
232
- e
236
+ "Activity machine does not handle this event: {e}"
233
237
  )))
234
238
  }
235
239
  })
@@ -268,10 +272,8 @@ impl WFMachinesAdapter for ActivityMachine {
268
272
  ActivityMachineCommand::RequestCancellation(c) => {
269
273
  self.machine_responses_from_cancel_request(c)
270
274
  }
271
- ActivityMachineCommand::Cancel(details) => {
272
- vec![self
273
- .create_cancelation_resolve(convert_payloads(event_info, details)?)
274
- .into()]
275
+ ActivityMachineCommand::Cancel(attrs) => {
276
+ vec![self.create_cancelation_resolve(attrs).into()]
275
277
  }
276
278
  })
277
279
  }
@@ -330,16 +332,9 @@ impl Cancellable for ActivityMachine {
330
332
  self.machine_responses_from_cancel_request(cmd)
331
333
  }
332
334
  ActivityMachineCommand::Cancel(details) => {
333
- vec![self
334
- .create_cancelation_resolve(
335
- details
336
- .map(TryInto::try_into)
337
- .transpose()
338
- .unwrap_or_default(),
339
- )
340
- .into()]
335
+ vec![self.create_cancelation_resolve(details).into()]
341
336
  }
342
- x => panic!("Invalid cancel event response {:?}", x),
337
+ x => panic!("Invalid cancel event response {x:?}"),
343
338
  })
344
339
  .collect();
345
340
  Ok(res)
@@ -350,13 +345,14 @@ impl Cancellable for ActivityMachine {
350
345
  }
351
346
  }
352
347
 
353
- #[derive(Default, Clone)]
348
+ #[derive(Clone)]
354
349
  pub(super) struct SharedState {
355
350
  scheduled_event_id: i64,
356
351
  started_event_id: i64,
357
352
  attrs: ScheduleActivity,
358
353
  cancellation_type: ActivityCancellationType,
359
354
  cancelled_before_sent: bool,
355
+ internal_flags: InternalFlagsRef,
360
356
  }
361
357
 
362
358
  #[derive(Default, Clone)]
@@ -375,28 +371,37 @@ pub(super) struct ScheduleCommandCreated {}
375
371
  impl ScheduleCommandCreated {
376
372
  pub(super) fn on_activity_task_scheduled(
377
373
  self,
378
- dat: SharedState,
379
- scheduled_event_id: i64,
374
+ dat: &mut SharedState,
375
+ sched_dat: ActTaskScheduledData,
380
376
  ) -> ActivityMachineTransition<ScheduledEventRecorded> {
381
- ActivityMachineTransition::ok_shared(
382
- vec![],
383
- ScheduledEventRecorded::default(),
384
- SharedState {
385
- scheduled_event_id,
386
- ..dat
387
- },
388
- )
377
+ if dat.internal_flags.borrow_mut().try_use(
378
+ CoreInternalFlags::IdAndTypeDeterminismChecks,
379
+ sched_dat.last_task_in_history,
380
+ ) {
381
+ if sched_dat.act_id != dat.attrs.activity_id {
382
+ return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
383
+ "Activity id of scheduled event '{}' does not \
384
+ match activity id of activity command '{}'",
385
+ sched_dat.act_id, dat.attrs.activity_id
386
+ )));
387
+ }
388
+ if sched_dat.act_type != dat.attrs.activity_type {
389
+ return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
390
+ "Activity type of scheduled event '{}' does not \
391
+ match activity type of activity command '{}'",
392
+ sched_dat.act_type, dat.attrs.activity_type
393
+ )));
394
+ }
395
+ }
396
+ dat.scheduled_event_id = sched_dat.event_id;
397
+ ActivityMachineTransition::default()
389
398
  }
390
- pub(super) fn on_canceled(self, dat: SharedState) -> ActivityMachineTransition<Canceled> {
391
- let canceled_state = SharedState {
392
- cancelled_before_sent: true,
393
- ..dat
394
- };
399
+
400
+ pub(super) fn on_canceled(self, dat: &mut SharedState) -> ActivityMachineTransition<Canceled> {
401
+ dat.cancelled_before_sent = true;
395
402
  match dat.cancellation_type {
396
- ActivityCancellationType::Abandon => {
397
- ActivityMachineTransition::ok_shared(vec![], Canceled::default(), canceled_state)
398
- }
399
- _ => notify_lang_activity_cancelled(canceled_state, None),
403
+ ActivityCancellationType::Abandon => ActivityMachineTransition::default(),
404
+ _ => notify_lang_activity_cancelled(None),
400
405
  }
401
406
  }
402
407
  }
@@ -407,21 +412,15 @@ pub(super) struct ScheduledEventRecorded {}
407
412
  impl ScheduledEventRecorded {
408
413
  pub(super) fn on_task_started(
409
414
  self,
410
- dat: SharedState,
415
+ dat: &mut SharedState,
411
416
  started_event_id: i64,
412
417
  ) -> ActivityMachineTransition<Started> {
413
- ActivityMachineTransition::ok_shared(
414
- vec![],
415
- Started::default(),
416
- SharedState {
417
- started_event_id,
418
- ..dat
419
- },
420
- )
418
+ dat.started_event_id = started_event_id;
419
+ ActivityMachineTransition::default()
421
420
  }
422
421
  pub(super) fn on_task_timed_out(
423
422
  self,
424
- dat: SharedState,
423
+ dat: &mut SharedState,
425
424
  attrs: ActivityTaskTimedOutEventAttributes,
426
425
  ) -> ActivityMachineTransition<TimedOut> {
427
426
  notify_lang_activity_timed_out(dat, attrs)
@@ -429,15 +428,15 @@ impl ScheduledEventRecorded {
429
428
 
430
429
  pub(super) fn on_canceled(
431
430
  self,
432
- dat: SharedState,
431
+ dat: &mut SharedState,
433
432
  ) -> ActivityMachineTransition<ScheduledActivityCancelCommandCreated> {
434
433
  create_request_cancel_activity_task_command(
435
434
  dat,
436
435
  ScheduledActivityCancelCommandCreated::default(),
437
436
  )
438
437
  }
439
- pub(super) fn on_abandoned(self, dat: SharedState) -> ActivityMachineTransition<Canceled> {
440
- notify_lang_activity_cancelled(dat, None)
438
+ pub(super) fn on_abandoned(self) -> ActivityMachineTransition<Canceled> {
439
+ notify_lang_activity_cancelled(None)
441
440
  }
442
441
  }
443
442
 
@@ -456,7 +455,7 @@ impl Started {
456
455
  }
457
456
  pub(super) fn on_activity_task_failed(
458
457
  self,
459
- dat: SharedState,
458
+ dat: &mut SharedState,
460
459
  attrs: ActivityTaskFailedEventAttributes,
461
460
  ) -> ActivityMachineTransition<Failed> {
462
461
  ActivityMachineTransition::ok(
@@ -467,7 +466,7 @@ impl Started {
467
466
 
468
467
  pub(super) fn on_activity_task_timed_out(
469
468
  self,
470
- dat: SharedState,
469
+ dat: &mut SharedState,
471
470
  attrs: ActivityTaskTimedOutEventAttributes,
472
471
  ) -> ActivityMachineTransition<TimedOut> {
473
472
  notify_lang_activity_timed_out(dat, attrs)
@@ -475,15 +474,15 @@ impl Started {
475
474
 
476
475
  pub(super) fn on_canceled(
477
476
  self,
478
- dat: SharedState,
477
+ dat: &mut SharedState,
479
478
  ) -> ActivityMachineTransition<StartedActivityCancelCommandCreated> {
480
479
  create_request_cancel_activity_task_command(
481
480
  dat,
482
481
  StartedActivityCancelCommandCreated::default(),
483
482
  )
484
483
  }
485
- pub(super) fn on_abandoned(self, dat: SharedState) -> ActivityMachineTransition<Canceled> {
486
- notify_lang_activity_cancelled(dat, None)
484
+ pub(super) fn on_abandoned(self) -> ActivityMachineTransition<Canceled> {
485
+ notify_lang_activity_cancelled(None)
487
486
  }
488
487
  }
489
488
 
@@ -496,15 +495,15 @@ pub(super) struct ScheduledActivityCancelEventRecorded {}
496
495
  impl ScheduledActivityCancelEventRecorded {
497
496
  pub(super) fn on_activity_task_canceled(
498
497
  self,
499
- dat: SharedState,
498
+ dat: &mut SharedState,
500
499
  attrs: ActivityTaskCanceledEventAttributes,
501
500
  ) -> ActivityMachineTransition<Canceled> {
502
- notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_cancelled(dat, Some(attrs)))
501
+ notify_if_not_already_cancelled(dat, |_| notify_lang_activity_cancelled(Some(attrs)))
503
502
  }
504
503
 
505
504
  pub(super) fn on_activity_task_timed_out(
506
505
  self,
507
- dat: SharedState,
506
+ dat: &mut SharedState,
508
507
  attrs: ActivityTaskTimedOutEventAttributes,
509
508
  ) -> ActivityMachineTransition<TimedOut> {
510
509
  notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_timed_out(dat, attrs))
@@ -526,7 +525,7 @@ pub(super) struct StartedActivityCancelEventRecorded {}
526
525
  impl StartedActivityCancelEventRecorded {
527
526
  pub(super) fn on_activity_task_completed(
528
527
  self,
529
- dat: SharedState,
528
+ dat: &mut SharedState,
530
529
  attrs: ActivityTaskCompletedEventAttributes,
531
530
  ) -> ActivityMachineTransition<Completed> {
532
531
  notify_if_not_already_cancelled(dat, |_| {
@@ -535,7 +534,7 @@ impl StartedActivityCancelEventRecorded {
535
534
  }
536
535
  pub(super) fn on_activity_task_failed(
537
536
  self,
538
- dat: SharedState,
537
+ dat: &mut SharedState,
539
538
  attrs: ActivityTaskFailedEventAttributes,
540
539
  ) -> ActivityMachineTransition<Failed> {
541
540
  notify_if_not_already_cancelled(dat, |dat| {
@@ -544,23 +543,23 @@ impl StartedActivityCancelEventRecorded {
544
543
  }
545
544
  pub(super) fn on_activity_task_timed_out(
546
545
  self,
547
- dat: SharedState,
546
+ dat: &mut SharedState,
548
547
  attrs: ActivityTaskTimedOutEventAttributes,
549
548
  ) -> ActivityMachineTransition<TimedOut> {
550
549
  notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_timed_out(dat, attrs))
551
550
  }
552
551
  pub(super) fn on_activity_task_canceled(
553
552
  self,
554
- dat: SharedState,
553
+ dat: &mut SharedState,
555
554
  attrs: ActivityTaskCanceledEventAttributes,
556
555
  ) -> ActivityMachineTransition<Canceled> {
557
- notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_cancelled(dat, Some(attrs)))
556
+ notify_if_not_already_cancelled(dat, |_| notify_lang_activity_cancelled(Some(attrs)))
558
557
  }
559
558
  }
560
559
 
561
560
  fn notify_if_not_already_cancelled<S>(
562
- dat: SharedState,
563
- notifier: impl FnOnce(SharedState) -> ActivityMachineTransition<S>,
561
+ dat: &mut SharedState,
562
+ notifier: impl FnOnce(&mut SharedState) -> ActivityMachineTransition<S>,
564
563
  ) -> ActivityMachineTransition<S>
565
564
  where
566
565
  S: Into<ActivityMachineState> + Default,
@@ -639,7 +638,7 @@ pub(super) struct Canceled {}
639
638
  impl Canceled {
640
639
  pub(super) fn on_activity_task_started(
641
640
  self,
642
- dat: SharedState,
641
+ dat: &mut SharedState,
643
642
  seq_num: i64,
644
643
  ) -> ActivityMachineTransition<Canceled> {
645
644
  // Abandoned activities might start anyway. Ignore the result.
@@ -648,14 +647,13 @@ impl Canceled {
648
647
  } else {
649
648
  TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
650
649
  "Non-Abandon cancel mode activities cannot be started after being cancelled. \
651
- Seq: {:?}",
652
- seq_num
650
+ Seq: {seq_num:?}"
653
651
  )))
654
652
  }
655
653
  }
656
654
  pub(super) fn on_activity_task_completed(
657
655
  self,
658
- dat: SharedState,
656
+ dat: &mut SharedState,
659
657
  attrs: ActivityTaskCompletedEventAttributes,
660
658
  ) -> ActivityMachineTransition<Canceled> {
661
659
  // Abandoned activities might complete anyway. Ignore the result.
@@ -663,15 +661,14 @@ impl Canceled {
663
661
  TransitionResult::default()
664
662
  } else {
665
663
  TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
666
- "Non-Abandon cancel mode activities cannot be completed after being cancelled: {:?}",
667
- attrs
664
+ "Non-Abandon cancel mode activities cannot be completed after being cancelled: {attrs:?}"
668
665
  )))
669
666
  }
670
667
  }
671
668
  }
672
669
 
673
670
  fn create_request_cancel_activity_task_command<S>(
674
- dat: SharedState,
671
+ dat: &mut SharedState,
675
672
  next_state: S,
676
673
  ) -> ActivityMachineTransition<S>
677
674
  where
@@ -696,81 +693,102 @@ where
696
693
  /// Notifies lang side that activity has timed out by sending a failure with timeout error as a cause.
697
694
  /// State machine will transition into the TimedOut state.
698
695
  fn notify_lang_activity_timed_out(
699
- dat: SharedState,
696
+ dat: &SharedState,
700
697
  attrs: ActivityTaskTimedOutEventAttributes,
701
698
  ) -> TransitionResult<ActivityMachine, TimedOut> {
702
- ActivityMachineTransition::ok_shared(
703
- vec![ActivityMachineCommand::Fail(new_timeout_failure(
704
- &dat, attrs,
705
- ))],
706
- TimedOut::default(),
707
- dat,
708
- )
699
+ ActivityMachineTransition::commands(vec![ActivityMachineCommand::Fail(new_timeout_failure(
700
+ dat, attrs,
701
+ ))])
709
702
  }
710
703
 
711
- /// Notifies lang side that activity has been cancelled by sending a failure with cancelled failure
712
- /// as a cause. Optional cancelled_event, if passed, is used to supply event IDs. State machine will
713
- /// transition into the `next_state` provided as a parameter.
704
+ /// Returns the transition to indicate activity has been cancelled by sending a failure with
705
+ /// cancelled failure as a cause. Optional cancelled_event, if passed, is used to supply event IDs.
714
706
  fn notify_lang_activity_cancelled(
715
- dat: SharedState,
716
707
  canceled_event: Option<ActivityTaskCanceledEventAttributes>,
717
708
  ) -> ActivityMachineTransition<Canceled> {
718
- ActivityMachineTransition::ok_shared(
719
- vec![ActivityMachineCommand::Cancel(
720
- canceled_event.and_then(|e| e.details),
721
- )],
722
- Canceled::default(),
723
- dat,
724
- )
709
+ ActivityMachineTransition::commands(vec![ActivityMachineCommand::Cancel(canceled_event)])
725
710
  }
726
711
 
727
- fn new_failure(dat: SharedState, attrs: ActivityTaskFailedEventAttributes) -> Failure {
712
+ fn new_failure(dat: &SharedState, attrs: ActivityTaskFailedEventAttributes) -> Failure {
713
+ let rs = attrs.retry_state();
728
714
  Failure {
729
715
  message: "Activity task failed".to_owned(),
730
716
  cause: attrs.failure.map(Box::new),
731
- failure_info: Some(FailureInfo::ActivityFailureInfo(
732
- failure::ActivityFailureInfo {
733
- identity: attrs.identity,
734
- activity_type: Some(ActivityType {
735
- name: dat.attrs.activity_type,
736
- }),
737
- activity_id: dat.attrs.activity_id,
738
- retry_state: attrs.retry_state,
739
- started_event_id: attrs.started_event_id,
740
- scheduled_event_id: attrs.scheduled_event_id,
741
- },
717
+ failure_info: Some(activity_fail_info(
718
+ dat.attrs.activity_type.clone(),
719
+ dat.attrs.activity_id.clone(),
720
+ Some(attrs.identity),
721
+ rs,
722
+ attrs.started_event_id,
723
+ attrs.scheduled_event_id,
742
724
  )),
743
725
  ..Default::default()
744
726
  }
745
727
  }
746
728
 
747
729
  fn new_timeout_failure(dat: &SharedState, attrs: ActivityTaskTimedOutEventAttributes) -> Failure {
748
- let failure_info = ActivityFailureInfo {
749
- activity_id: dat.attrs.activity_id.to_string(),
750
- activity_type: Some(ActivityType {
751
- name: dat.attrs.activity_type.to_string(),
752
- }),
753
- scheduled_event_id: attrs.scheduled_event_id,
754
- started_event_id: attrs.started_event_id,
755
- retry_state: attrs.retry_state,
756
- ..Default::default()
757
- };
730
+ let rs = attrs.retry_state();
758
731
  Failure {
759
732
  message: "Activity task timed out".to_string(),
760
733
  cause: attrs.failure.map(Box::new),
761
- failure_info: Some(FailureInfo::ActivityFailureInfo(failure_info)),
734
+ failure_info: Some(activity_fail_info(
735
+ dat.attrs.activity_type.clone(),
736
+ dat.attrs.activity_id.clone(),
737
+ None,
738
+ rs,
739
+ attrs.started_event_id,
740
+ attrs.scheduled_event_id,
741
+ )),
762
742
  ..Default::default()
763
743
  }
764
744
  }
765
745
 
746
+ fn new_cancel_failure(dat: &SharedState, attrs: ActivityTaskCanceledEventAttributes) -> Failure {
747
+ Failure {
748
+ message: "Activity cancelled".to_string(),
749
+ cause: Some(Box::from(Failure {
750
+ failure_info: Some(FailureInfo::CanceledFailureInfo(CanceledFailureInfo {
751
+ details: attrs.details.map(Into::into),
752
+ })),
753
+ ..Default::default()
754
+ })),
755
+ failure_info: Some(activity_fail_info(
756
+ dat.attrs.activity_type.clone(),
757
+ dat.attrs.activity_id.clone(),
758
+ Some(attrs.identity),
759
+ RetryState::CancelRequested,
760
+ attrs.started_event_id,
761
+ attrs.scheduled_event_id,
762
+ )),
763
+ ..Default::default()
764
+ }
765
+ }
766
+
767
+ pub fn activity_fail_info(
768
+ act_type: String,
769
+ act_id: String,
770
+ identity: Option<String>,
771
+ retry_state: RetryState,
772
+ started_event_id: i64,
773
+ scheduled_event_id: i64,
774
+ ) -> FailureInfo {
775
+ FailureInfo::ActivityFailureInfo(ActivityFailureInfo {
776
+ identity: identity.unwrap_or_default(),
777
+ activity_type: Some(ActivityType { name: act_type }),
778
+ activity_id: act_id,
779
+ retry_state: retry_state as i32,
780
+ started_event_id,
781
+ scheduled_event_id,
782
+ })
783
+ }
784
+
766
785
  fn convert_payloads(
767
786
  event_info: Option<EventInfo>,
768
787
  result: Option<Payloads>,
769
788
  ) -> Result<Option<Payload>, WFMachinesError> {
770
789
  result.map(TryInto::try_into).transpose().map_err(|pe| {
771
790
  WFMachinesError::Fatal(format!(
772
- "Not exactly one payload in activity result ({}) for event: {:?}",
773
- pe, event_info
791
+ "Not exactly one payload in activity result ({pe}) for event: {event_info:?}"
774
792
  ))
775
793
  })
776
794
  }
@@ -779,15 +797,17 @@ fn convert_payloads(
779
797
  mod test {
780
798
  use super::*;
781
799
  use crate::{
782
- replay::TestHistoryBuilder, test_help::canned_histories, worker::workflow::ManagedWFFunc,
800
+ internal_flags::InternalFlags, replay::TestHistoryBuilder, test_help::canned_histories,
801
+ worker::workflow::ManagedWFFunc,
783
802
  };
784
803
  use rstest::{fixture, rstest};
785
- use std::mem::discriminant;
804
+ use std::{cell::RefCell, mem::discriminant, rc::Rc};
786
805
  use temporal_sdk::{
787
806
  ActivityOptions, CancellableFuture, WfContext, WorkflowFunction, WorkflowResult,
788
807
  };
789
- use temporal_sdk_core_protos::coresdk::workflow_activation::{
790
- workflow_activation_job, WorkflowActivationJob,
808
+ use temporal_sdk_core_protos::{
809
+ coresdk::workflow_activation::{workflow_activation_job, WorkflowActivationJob},
810
+ DEFAULT_ACTIVITY_TYPE,
791
811
  };
792
812
 
793
813
  #[fixture]
@@ -807,7 +827,13 @@ mod test {
807
827
  }
808
828
 
809
829
  async fn activity_wf(command_sink: WfContext) -> WorkflowResult<()> {
810
- command_sink.activity(ActivityOptions::default()).await;
830
+ command_sink
831
+ .activity(ActivityOptions {
832
+ activity_id: Some("activity-id-1".to_string()),
833
+ activity_type: DEFAULT_ACTIVITY_TYPE.to_string(),
834
+ ..Default::default()
835
+ })
836
+ .await;
811
837
  Ok(().into())
812
838
  }
813
839
 
@@ -895,13 +921,20 @@ mod test {
895
921
  TimedOut {}.into(),
896
922
  Completed {}.into(),
897
923
  ] {
898
- let mut s = ActivityMachine {
899
- state: state.clone(),
900
- shared_state: Default::default(),
901
- };
924
+ let mut s = ActivityMachine::from_parts(
925
+ state.clone(),
926
+ SharedState {
927
+ scheduled_event_id: 0,
928
+ started_event_id: 0,
929
+ attrs: Default::default(),
930
+ cancellation_type: Default::default(),
931
+ cancelled_before_sent: false,
932
+ internal_flags: Rc::new(RefCell::new(InternalFlags::new(&Default::default()))),
933
+ },
934
+ );
902
935
  let cmds = s.cancel().unwrap();
903
936
  assert_eq!(cmds.len(), 0);
904
- assert_eq!(discriminant(&state), discriminant(&s.state));
937
+ assert_eq!(discriminant(&state), discriminant(s.state()));
905
938
  }
906
939
  }
907
940
  }