greentic_deployer/env_packs/local_process/
mod.rs1pub mod credentials;
21pub mod deployer;
22
23use greentic_deploy_spec::CapabilitySlot;
24use semver::VersionReq;
25
26use super::slot::EnvPackHandler;
27use crate::tool_check::ToolCheck;
28
29pub use credentials::LocalProcessCredentials;
30
31#[derive(Debug, Default)]
33pub struct LocalProcessDeployerHandler {
34 creds: LocalProcessCredentials,
35}
36
37impl LocalProcessDeployerHandler {
38 pub const DESCRIPTOR_PATH: &'static str = "greentic.deployer.local-process";
42
43 pub const VERSION_REQ: &'static str = "^0.1.0";
48
49 pub fn new() -> Self {
50 Self::default()
51 }
52
53 pub fn with_port_range(range: std::ops::RangeInclusive<u16>) -> Self {
58 Self {
59 creds: LocalProcessCredentials::with_port_range(range),
60 }
61 }
62}
63
64impl EnvPackHandler for LocalProcessDeployerHandler {
65 fn slot(&self) -> CapabilitySlot {
66 CapabilitySlot::Deployer
67 }
68
69 fn descriptor_path(&self) -> &str {
70 Self::DESCRIPTOR_PATH
71 }
72
73 fn supported_versions(&self) -> VersionReq {
74 Self::VERSION_REQ
75 .parse()
76 .expect("local-process version-req is valid (guarded by tests)")
77 }
78
79 fn preflight(&self) -> Vec<ToolCheck> {
80 Vec::new()
84 }
85
86 fn deployer_credentials(&self) -> Option<&dyn crate::credentials::DeployerCredentials> {
87 Some(&self.creds)
88 }
89
90 fn wizard_qaspec_yaml(&self) -> Option<&'static str> {
91 Some(include_str!("wizard.qaspec.yaml"))
92 }
93
94 fn as_deployer(&self) -> Option<&dyn crate::env_packs::deployer::Deployer> {
95 Some(self)
96 }
97}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102 use crate::defaults::LOCAL_DEPLOYER_PACK;
103 use greentic_deploy_spec::PackDescriptor;
104
105 #[test]
106 fn handler_serves_deployer_slot_with_local_process_path() {
107 let h = LocalProcessDeployerHandler::default();
108 assert_eq!(h.slot(), CapabilitySlot::Deployer);
109 assert_eq!(h.descriptor_path(), "greentic.deployer.local-process");
110 let _ = h.supported_versions();
112 }
113
114 #[test]
115 fn version_req_accepts_default_local_binding_descriptor() {
116 let h = LocalProcessDeployerHandler::default();
117 let pd = PackDescriptor::try_new(LOCAL_DEPLOYER_PACK).expect("descriptor parses");
118 assert!(
119 h.supported_versions().matches(&pd.version().0),
120 "version req {} must accept the default {} binding's version",
121 h.supported_versions(),
122 LOCAL_DEPLOYER_PACK
123 );
124 }
125
126 #[test]
127 fn exposes_credentials_contract() {
128 let h = LocalProcessDeployerHandler::default();
129 let creds = h
130 .deployer_credentials()
131 .expect("local-process handler must expose credentials");
132 let caps = creds.required_capabilities();
134 assert_eq!(caps.len(), 2);
135 }
136
137 #[test]
142 fn wizard_qaspec_yaml_id_matches_canonical() {
143 let yaml = LocalProcessDeployerHandler::default()
144 .wizard_qaspec_yaml()
145 .expect("local-process handler ships a wizard QASpec");
146 let spec: qa_spec::FormSpec =
147 serde_yaml_bw::from_str(yaml).expect("wizard.qaspec.yaml parses as FormSpec");
148 assert_eq!(spec.id, "greentic.deployer.local-process.wizard");
149 }
150}