Skip to main content

golem_schema/schema/tool/
process_exit_status.rs

1// Copyright 2024-2026 Golem Cloud
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/// A completed command's shell-visible status, distinct from a failure to execute the tool.
16#[derive(
17    Debug,
18    Clone,
19    Copy,
20    PartialEq,
21    Eq,
22    golem_schema_derive::IntoSchema,
23    golem_schema_derive::FromSchema,
24)]
25#[schema(named = "golem.tool.ProcessExitStatus")]
26#[cfg_attr(
27    feature = "guest",
28    derive(
29        golem_schema_derive::WireSchema,
30        golem_schema_derive::IntoWire,
31        golem_schema_derive::FromWire
32    )
33)]
34pub struct ProcessExitStatus {
35    pub exit_code: u8,
36}
37
38#[cfg(test)]
39mod tests {
40    use super::ProcessExitStatus;
41    use crate::{FromSchema, IntoSchema, SchemaType, SchemaValue, try_into_schema_graph};
42    use test_r::test;
43
44    #[test]
45    fn process_exit_status_has_the_cross_language_named_contract() {
46        let graph = try_into_schema_graph::<ProcessExitStatus>().unwrap();
47        assert_eq!(
48            graph.root,
49            SchemaType::ref_to("golem.tool.ProcessExitStatus".into())
50        );
51        let SchemaType::Record { fields, .. } = graph.resolve_ref(&graph.root).unwrap() else {
52            panic!("process status must be a record");
53        };
54        assert_eq!(fields.len(), 1);
55        assert_eq!(fields[0].name, "exit_code");
56        assert_eq!(fields[0].body, SchemaType::u8());
57        for code in [0, 7, 255] {
58            let status = ProcessExitStatus { exit_code: code };
59            let value = SchemaValue::Record {
60                fields: vec![SchemaValue::U8(code)],
61            };
62            assert_eq!(status.to_value(), value);
63            assert_eq!(ProcessExitStatus::from_value(&value).unwrap(), status);
64        }
65    }
66}