Skip to main content

apm_core/wrapper/builtin/
mock_happy.rs

1use crate::config::resolve_outcome;
2use super::{load_transitions_with_outcomes, is_impl_mode, happy_script, write_and_spawn_script};
3use crate::wrapper::{Wrapper, WrapperContext};
4
5pub struct MockHappyWrapper;
6
7impl Wrapper for MockHappyWrapper {
8    fn spawn(&self, ctx: &WrapperContext) -> anyhow::Result<std::process::Child> {
9        let transitions = load_transitions_with_outcomes(ctx)?;
10        let success: Vec<_> = transitions.iter()
11            .filter(|(t, s)| resolve_outcome(t, s) == "success")
12            .collect();
13        match success.len() {
14            0 => anyhow::bail!(
15                "mock-happy: no success-outcome transition from state '{}'",
16                ctx.current_state
17            ),
18            1 => {},
19            n => anyhow::bail!(
20                "mock-happy: {} success-outcome transitions found from state '{}'; expected exactly 1",
21                n, ctx.current_state
22            ),
23        }
24        let target = success[0].0.to.clone();
25        let impl_mode = is_impl_mode(&transitions);
26        let script = happy_script(&ctx.ticket_id, &target, impl_mode);
27        write_and_spawn_script("happy", &script, ctx)
28    }
29}