Skip to content

Commit 6279bed

Browse files
committed
Various final cleanup
1 parent be6f80b commit 6279bed

12 files changed

Lines changed: 111 additions & 78 deletions

File tree

crates/sdk-core/tests/integ_tests/wasm_workflow_tests.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@ const WASM_WORKFLOW_TYPE: &str = "HelloWorkflow";
1414
#[tokio::test]
1515
async fn wasm_workflow_component_executes() {
1616
let component_path = build_wasm_hello_component().await;
17-
let mut starter = CoreWfStarter::new("wasm_workflow_component_executes");
17+
let component = WasmWorkflowComponent::from_file(WASM_COMPONENT_ID, component_path)
18+
.expect("sample WASM component should be loadable");
19+
run_hello_workflow("wasm_workflow_component_executes", component).await;
20+
}
21+
22+
// Mirrors `wasm_workflow_component_executes` but loads the component bytes into memory and
23+
// registers via `from_bytes`, exercising the dynamic-blob loading path that callers will use
24+
// for runtime-supplied components (e.g. fetched over the network rather than read from disk).
25+
#[tokio::test]
26+
async fn wasm_workflow_component_executes_from_bytes() {
27+
let component_path = build_wasm_hello_component().await;
28+
let bytes = tokio::fs::read(&component_path)
29+
.await
30+
.expect("WASM component file should be readable");
31+
let component = WasmWorkflowComponent::from_bytes(WASM_COMPONENT_ID, bytes)
32+
.expect("WASM component bytes should be loadable");
33+
run_hello_workflow("wasm_workflow_component_executes_from_bytes", component).await;
34+
}
35+
36+
async fn run_hello_workflow(test_name: &'static str, component: WasmWorkflowComponent) {
37+
let mut starter = CoreWfStarter::new(test_name);
1838
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
19-
starter.sdk_config.register_wasm_workflow(
20-
WasmWorkflowComponent::from_file(WASM_COMPONENT_ID, component_path)
21-
.expect("sample WASM component should be loadable"),
22-
);
39+
starter.sdk_config.register_wasm_workflow(component);
2340

2441
let mut worker = starter.worker().await;
2542
let client = starter.get_client().await;

crates/sdk/src/workflow_registry.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ use temporalio_common::{
1010
coresdk::workflow_activation::InitializeWorkflow, temporal::api::common::v1::Payload,
1111
},
1212
};
13-
use temporalio_workflow::runtime::{
13+
use temporalio_workflow::{
1414
BaseWorkflowContext,
15-
entry::WorkflowImplementation,
16-
guest::WorkflowInstance,
17-
host::WorkflowHost,
18-
instance::{GuestWorkflowInstance, instantiate_workflow},
19-
types::WorkflowDefinitionDescriptor,
15+
runtime::{
16+
entry::WorkflowImplementation,
17+
guest::WorkflowInstance,
18+
host::WorkflowHost,
19+
instance::{GuestWorkflowInstance, instantiate_workflow},
20+
types::WorkflowDefinitionDescriptor,
21+
},
2022
};
2123

2224
/// Host-owned execution inputs used to instantiate a single workflow run.

crates/workflow/src/component.rs

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Component-model guest export support for workflow crates.
2-
3-
#![allow(missing_docs)]
4-
2+
//!
3+
//! Everything in this module is internal SDK/component glue.
54
use crate::{
65
BaseWorkflowContext,
76
runtime::{
@@ -74,8 +73,8 @@ impl<T: StaticWorkflowComponent> wit_guest::Guest for ExportedComponent<T> {
7473
initialize_workflow: decode_proto(init.initialize_workflow),
7574
};
7675
let workflow_type = init.initialize_workflow.workflow_type.clone();
77-
let instance = T::instantiate_workflow(&workflow_type, init, host)
78-
.map_err(convert_failure_to_wit_box)?;
76+
let instance =
77+
T::instantiate_workflow(&workflow_type, init, host).map_err(|e| e.encode_to_vec())?;
7978
Ok(wit_guest::WorkflowInstance::new(ExportedWorkflowInstance(
8079
RefCell::new(instance),
8180
)))
@@ -106,20 +105,18 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
106105
wit_types::QueryResponse {
107106
response: response
108107
.result
109-
.map(encode_proto)
110-
.map_err(encode_proto),
108+
.map(|e| e.encode_to_vec())
109+
.map_err(|e| e.encode_to_vec()),
111110
},
112111
)
113112
}
114113
ActivationJobResult::UpdateRejected(failure) => {
115-
wit_types::ActivationJobResult::UpdateRejected(
116-
convert_failure_to_wit_box(failure),
117-
)
114+
wit_types::ActivationJobResult::UpdateRejected(failure.encode_to_vec())
118115
}
119116
})
120117
.collect(),
121118
})
122-
.map_err(convert_failure_to_wit_box)
119+
.map_err(|e| e.encode_to_vec())
123120
}
124121

125122
fn poll_routine(
@@ -140,28 +137,28 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
140137
MainRoutineCompletion::TaskFailed(task_failure) => {
141138
wit_types::MainRoutineCompletion::TaskFailed(
142139
wit_types::TaskFailure {
143-
failure: convert_failure_to_wit_box(task_failure.failure),
140+
failure: task_failure.failure.encode_to_vec(),
144141
force_cause: task_failure.force_cause,
145142
},
146143
)
147144
}
148145
MainRoutineCompletion::Terminal(outcome) => {
149146
wit_types::MainRoutineCompletion::Terminal(match *outcome {
150147
TerminalOutcome::Completed(payload) => {
151-
wit_types::TerminalOutcome::Completed(encode_proto(payload))
148+
wit_types::TerminalOutcome::Completed(
149+
payload.encode_to_vec(),
150+
)
152151
}
153152
TerminalOutcome::Failed(failure) => {
154-
wit_types::TerminalOutcome::Failed(
155-
convert_failure_to_wit_box(failure),
156-
)
153+
wit_types::TerminalOutcome::Failed(failure.encode_to_vec())
157154
}
158155
TerminalOutcome::Cancelled => {
159156
wit_types::TerminalOutcome::Cancelled
160157
}
161158
TerminalOutcome::ContinueAsNew(req) => {
162-
wit_types::TerminalOutcome::ContinueAsNew(encode_proto(
163-
*req,
164-
))
159+
wit_types::TerminalOutcome::ContinueAsNew(
160+
req.encode_to_vec(),
161+
)
165162
}
166163
})
167164
}
@@ -170,9 +167,9 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
170167
RoutineCompletion::Signal(result) => {
171168
wit_types::RoutineCompletion::Signal(match result {
172169
Ok(()) => wit_types::SignalRoutineCompletion::Succeeded,
173-
Err(failure) => wit_types::SignalRoutineCompletion::Failed(
174-
convert_failure_to_wit_box(failure),
175-
),
170+
Err(failure) => {
171+
wit_types::SignalRoutineCompletion::Failed(failure.encode_to_vec())
172+
}
176173
})
177174
}
178175
RoutineCompletion::Update(completion) => {
@@ -183,7 +180,7 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
183180
} => wit_types::UpdateRoutineCompletion::Completed(
184181
wit_types::UpdateRoutineSuccess {
185182
protocol_instance_id,
186-
value: encode_proto(result),
183+
value: result.encode_to_vec(),
187184
},
188185
),
189186
UpdateRoutineCompletion::Rejected {
@@ -192,15 +189,15 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
192189
} => wit_types::UpdateRoutineCompletion::Rejected(
193190
wit_types::UpdateRoutineRejection {
194191
protocol_instance_id,
195-
failure: convert_failure_to_wit_box(failure),
192+
failure: failure.encode_to_vec(),
196193
},
197194
),
198195
})
199196
}
200197
}),
201198
made_progress: result.made_progress,
202199
})
203-
.map_err(convert_failure_to_wit_box)
200+
.map_err(|e| e.encode_to_vec())
204201
}
205202
}
206203

@@ -237,18 +234,10 @@ impl WorkflowHost for ImportedWorkflowHost {
237234
}
238235

239236
fn push_command(&self, command: WorkflowCommand) {
240-
wit_host::push_command(&encode_proto(command));
237+
wit_host::push_command(&command.encode_to_vec());
241238
}
242239
}
243240

244-
fn convert_failure_to_wit_box(failure: WorkflowFailure) -> wit_types::Failure {
245-
encode_proto(*failure)
246-
}
247-
248-
fn encode_proto<M: Message>(message: M) -> Vec<u8> {
249-
message.encode_to_vec()
250-
}
251-
252241
fn decode_proto<M: Message + prost::Name + Default>(bytes: Vec<u8>) -> M {
253242
M::decode(bytes.as_slice()).unwrap_or_else(|err| {
254243
let n = M::NAME;

crates/workflow/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,26 @@ pub mod __private {
1313

1414
#[doc(hidden)]
1515
pub mod component;
16+
#[doc(hidden)]
1617
pub mod runtime;
1718
mod workflow_context;
1819
pub mod workflows;
1920

21+
#[doc(hidden)]
22+
pub use runtime::model::{CancellableID, UnblockEvent};
23+
pub use runtime::model::{TimerResult, WorkflowResult, WorkflowTermination};
24+
#[doc(hidden)]
25+
pub use runtime::{SdkWakeGuard, is_sdk_wake};
26+
pub use workflow_context::{
27+
ActivityCloseTimeouts, ActivityExecutionError, ActivityOptions, BaseWorkflowContext,
28+
CancellableFuture, ChildWorkflowExecutionError, ChildWorkflowOptions, ChildWorkflowSignalError,
29+
ContinueAsNewOptions, ExternalWorkflowHandle, LocalActivityOptions, NexusOperationOptions,
30+
ParentWorkflowInfo, RootWorkflowInfo, Signal, SignalData,
31+
StartChildWorkflowExecutionFailedCause, StartedChildWorkflow, SyncWorkflowContext,
32+
TimerOptions, WorkflowContext, WorkflowContextView,
33+
};
34+
pub use workflows::{join, join_all, select};
35+
2036
#[macro_export]
2137
#[doc(hidden)]
2238
macro_rules! __temporal_select {
@@ -92,17 +108,3 @@ macro_rules! export_workflow_module {
92108
};
93109
};
94110
}
95-
96-
#[doc(hidden)]
97-
pub use runtime::model::{CancellableID, UnblockEvent};
98-
pub use runtime::model::{TimerResult, WorkflowResult, WorkflowTermination};
99-
#[doc(hidden)]
100-
pub use runtime::{SdkWakeGuard, is_sdk_wake};
101-
pub use workflow_context::{
102-
ActivityCloseTimeouts, ActivityExecutionError, ActivityOptions, BaseWorkflowContext,
103-
CancellableFuture, ChildWorkflowExecutionError, ChildWorkflowOptions, ChildWorkflowSignalError,
104-
ContinueAsNewOptions, ExternalWorkflowHandle, LocalActivityOptions, NexusOperationOptions,
105-
ParentWorkflowInfo, RootWorkflowInfo, Signal, SignalData,
106-
StartChildWorkflowExecutionFailedCause, StartedChildWorkflow, SyncWorkflowContext,
107-
TimerOptions, WorkflowContext, WorkflowContextView,
108-
};

crates/workflow/src/runtime/entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub trait ExecutableAsyncUpdate<U: UpdateDefinition>: WorkflowImplementation {
277277
}
278278

279279
/// Deserialize handler input from payloads.
280-
pub fn deserialize_input<I: TemporalDeserializable + 'static>(
280+
pub(crate) fn deserialize_input<I: TemporalDeserializable + 'static>(
281281
payloads: Vec<Payload>,
282282
converter: &PayloadConverter,
283283
) -> Result<I, WorkflowError> {
@@ -289,7 +289,7 @@ pub fn deserialize_input<I: TemporalDeserializable + 'static>(
289289
}
290290

291291
/// Serialize handler output to a payload.
292-
pub fn serialize_output<O: TemporalSerializable + 'static>(
292+
pub(crate) fn serialize_output<O: TemporalSerializable + 'static>(
293293
output: &O,
294294
converter: &PayloadConverter,
295295
) -> Result<Payload, WorkflowError> {
@@ -301,7 +301,7 @@ pub fn serialize_output<O: TemporalSerializable + 'static>(
301301
}
302302

303303
/// Wrap a handler error into WorkflowError.
304-
pub fn wrap_handler_error(e: Box<dyn std::error::Error + Send + Sync>) -> WorkflowError {
304+
pub(crate) fn wrap_handler_error(e: Box<dyn std::error::Error + Send + Sync>) -> WorkflowError {
305305
WorkflowError::Execution(anyhow::anyhow!(e))
306306
}
307307

crates/workflow/src/runtime/guest.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! High-level guest-side runtime traits mirroring the checked-in WIT interface.
22
3-
#![allow(missing_docs)]
4-
53
use crate::runtime::types::{
64
ActivationResult, RoutineId, RoutinePollResult, WorkflowActivation, WorkflowFailure,
75
};

crates/workflow/src/runtime/instance.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
//! Guest-side workflow execution implementation used by native and future WASM hosts.
22
3-
#![allow(missing_docs)]
4-
53
use crate::{
6-
WorkflowContext,
4+
BaseWorkflowContext, WorkflowContext,
75
runtime::{
8-
BaseWorkflowContext,
96
entry::{WorkflowError, WorkflowImplementation},
107
guest::WorkflowInstance,
118
model::{TimerResult, UnblockEvent, WorkflowResult, WorkflowTermination},

crates/workflow/src/runtime/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Unstable runtime-facing APIs for workflow hosts and future WASM integrations.
22
//!
33
//! These modules collect the parts of the workflow crate that are intended for SDK/runtime glue
4-
//! rather than normal workflow authors. The long-term target for this namespace is the WIT surface
5-
//! checked in under `crates/workflow/wit/`.
4+
//! rather than normal workflow authors.
65
76
use std::{
87
cell::Cell,
@@ -18,8 +17,6 @@ pub mod instance;
1817
pub mod model;
1918
pub mod types;
2019

21-
pub use crate::workflow_context::{BaseWorkflowContext, WorkflowContextView};
22-
2320
thread_local! {
2421
static SDK_WAKE_DEPTH: Cell<u32> = const { Cell::new(0) };
2522
}

crates/workflow/src/runtime/model.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Runtime protocol and execution model types shared by workflow code and native hosts.
22
3-
#![allow(missing_docs)]
4-
53
use crate::{
64
runtime::types::ContinueAsNewRequest,
75
workflow_context::{

crates/workflow/src/runtime/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Shared runtime model types mirroring the checked-in WIT interface.
2-
3-
#![allow(missing_docs)]
2+
//!
3+
//! All items here are SDK/runtime glue.
44
55
use temporalio_common_wasm::protos::{
66
coresdk::{

0 commit comments

Comments
 (0)