Add helper functions and factory to pika-cloud lifecycle module
Intent: Provide a single source of truth for constructing, encoding, and decoding RuntimeTerminalResult values so that every producer and consumer uses the same contract instead of hand-rolling JSON serialization with ad-hoc structs.
Affected files: crates/pika-cloud/src/lifecycle.rs, crates/pika-cloud/src/lib.rs
@@ -94,6 +94,41 @@ pub struct LifecycleTerminalResult {
+impl LifecycleTerminalStatus {
+ pub fn from_exit_code(exit_code: i32) -> Self {
+ if exit_code == 0 {
+ Self::Completed
+ } else {
+ Self::Failed
+ }
+ }
+}
+
+pub fn runtime_terminal_result_for_exit_code(
+ exit_code: i32,
+ finished_at: impl Into<String>,
+ message: impl Into<String>,
+) -> RuntimeTerminalResult {
+pub fn encode_runtime_terminal_result_pretty(
+ result: &RuntimeTerminalResult,
+) -> serde_json::Result<Vec<u8>> {
+pub fn decode_runtime_terminal_result(bytes: &[u8]) -> serde_json::Result<RuntimeTerminalResult> {
@@ -11,7 +11,8 @@ pub use lifecycle::{
+ RuntimeStatusSnapshot, RuntimeTerminalResult, decode_runtime_terminal_result,
+ encode_runtime_terminal_result_pretty, runtime_terminal_result_for_exit_code,
Three new public helpers are added to crates/pika-cloud/src/lifecycle.rs:
runtime_terminal_result_for_exit_code– Factory that builds aRuntimeTerminalResultfrom an exit code, timestamp, and message. It maps exit code 0 →Completed, anything else →Failed, and always stampsschema_version: LIFECYCLE_SCHEMA_VERSION.encode_runtime_terminal_result_pretty– Thin wrapper aroundserde_json::to_vec_prettyfor consistent pretty-printed encoding.decode_runtime_terminal_result– Thin wrapper aroundserde_json::from_slicethat deserializes bytes into the canonical struct.
LifecycleTerminalStatus also gains a from_exit_code method, which the factory delegates to.
All three helpers, plus the RuntimeTerminalResult type itself, are re-exported from crates/pika-cloud/src/lib.rs so downstream crates can import them from the crate root.