Skip to main content

ignition_core/client/
version.rs

1//! Gateway-info model + the minimum-version gate (CORE-08).
2//!
3//! Field names match the **live 8.3.6 gateway** exactly (captured
4//! 2026-08-21, 02-RESEARCH §Status/info + the gateway's own openapi
5//! schema): the version field is `ignitionVersion` — Phase 1's `version`
6//! name failed deserialization against every real gateway, fixed here
7//! with an alias that tolerates any 8.3.x still shipping the old name.
8//! `state`/`uptime` do NOT exist on this payload (running state and
9//! uptime come from `/overview` + `/StatusPing` in 02-02) — the model
10//! stays truthful to what the endpoint returns.
11
12use serde::{Deserialize, Serialize};
13
14/// Minimum gateway version `ign` supports (CORE-08). Appears in the
15/// `gateway_too_old` envelope and its hint.
16pub const MIN_GATEWAY: &str = "8.3.1";
17
18/// `/data/api/v1/gateway-info` response — field names match the gateway.
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20pub struct GatewayInfo {
21    /// Gateway display name, when reported.
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    pub name: Option<String>,
24    /// Redundancy role (`"Independent"` / `"Backup"` / `"Primary"`), when
25    /// reported.
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub redundancy_role: Option<String>,
28    /// Edition (`"standard"` / `"maker"` / …), when reported.
29    #[serde(default, skip_serializing_if = "Option::is_none")]
30    pub edition: Option<String>,
31    /// Version + build revision in one string, e.g.
32    /// `"8.3.6 (b2026042713)"`. Serialized under the gateway-native key
33    /// (`ignitionVersion`, passthrough-shaped `--json` data); the alias
34    /// tolerates any 8.3.x still shipping the Phase-1-era `version` name.
35    #[serde(rename = "ignitionVersion", alias = "version")]
36    pub ignition_version: String,
37    /// JVM version passthrough, when reported.
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub jvm_version: Option<String>,
40    /// License summary, when reported.
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub license: Option<LicenseInfo>,
43    /// The request URL (populated by the client, never serialized) so
44    /// error variants built from this info can carry `endpoint` (CORE-05).
45    #[serde(skip, default)]
46    pub endpoint: Option<String>,
47}
48
49/// License block of gateway-info (`license: {mode, expirationDate, …}`).
50#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
51pub struct LicenseInfo {
52    /// `"Trial"` / `"Licensed"` / …
53    pub mode: String,
54    /// Trial/license expiration, when reported. Serialized under the
55    /// gateway-native key (camelCase, like `ignitionVersion`); the
56    /// snake_case alias tolerates non-gateway shapers. (02-02 found the
57    /// missing rename silently DROPPED the gateway's `expirationDate`
58    /// on parse — the 02-01 fix covered `ignitionVersion` only.)
59    #[serde(
60        rename = "expirationDate",
61        alias = "expiration_date",
62        default,
63        skip_serializing_if = "Option::is_none"
64    )]
65    pub expiration_date: Option<String>,
66}
67
68/// Is `raw` below [`MIN_GATEWAY`]? Suffix- and short-form tolerant;
69/// unparseable → `true` — refuse safely rather than guess (CORE-08).
70///
71/// Note: the comparison target is the plain three-component semver
72/// `8.3.1` — `semver::Version::parse` is strict, so a four-component
73/// literal like `"8.3.1.0"` would NOT parse (the research sketch's
74/// `.0`-appended constant would have made EVERY comparison fail).
75pub fn below_minimum(raw: &str) -> bool {
76    // Gateway versions are dotted triples, sometimes with a "-SNAPSHOT…"
77    // or space suffix — compare the leading numeric part only.
78    let clean = raw.trim().split(['-', ' ']).next().unwrap_or(raw);
79    // Tolerate the short "8.3" form by appending a patch component.
80    let normalized = if clean.matches('.').count() == 1 {
81        format!("{clean}.0")
82    } else {
83        clean.to_string()
84    };
85    match semver::Version::parse(&normalized) {
86        Ok(version) => {
87            version < semver::Version::parse(MIN_GATEWAY).expect("MIN_GATEWAY is valid semver")
88        }
89        Err(_) => true,
90    }
91}
92
93#[cfg(test)]
94mod tests {
95    use super::{GatewayInfo, LicenseInfo, MIN_GATEWAY, below_minimum};
96
97    /// CORE-08 boundary table — every row of the locked comparison matrix,
98    /// including the EXACT live strings captured from 8.3.6 (02-RESEARCH).
99    #[test]
100    fn below_minimum_matrix() {
101        // (raw, expected below minimum?)
102        let cases = [
103            ("8.3.1", false),                   // exactly the minimum
104            ("8.3.2", false),                   // above
105            ("8.3.0", true),                    // one patch below
106            ("8.1.10", true),                   // older minor line
107            ("8.3", true),                      // short form → 8.3.0
108            ("8.3.1-SNAPSHOT.20260801", false), // suffix stripped → equal
109            (" 8.3.2 ", false),                 // surrounding space tolerated
110            ("garbage", true),                  // unparseable → refuse
111            ("", true),                         // empty → refuse
112            ("9.0.0", false),                   // future major
113            // Live-capture rows (8.3.6, b-build suffix in parens).
114            ("8.3.6 (b2026042713)", false), // the exact live string
115            ("8.3.6", false),               // its bare prefix
116        ];
117        for (raw, expected) in cases {
118            assert_eq!(
119                below_minimum(raw),
120                expected,
121                "below_minimum({raw:?}) must be {expected}"
122            );
123        }
124        assert_eq!(MIN_GATEWAY, "8.3.1");
125    }
126
127    /// The live-shape regression at the model level: the field is
128    /// `ignitionVersion` (camelCase from the gateway) and the Phase-1-era
129    /// `version` name still parses via the alias — both must deserialize.
130    #[test]
131    fn gateway_info_parses_live_and_legacy_field_names() {
132        let live = serde_json::json!({
133            "name": "ign-live",
134            "redundancyRole": "Independent",
135            "edition": "standard",
136            "ignitionVersion": "8.3.6 (b2026042713)",
137            "jvmVersion": "17.0.11",
138            "license": {"mode": "Trial", "expirationDate": "2026-08-21"}
139        });
140        let info: GatewayInfo =
141            serde_json::from_value(live).expect("live ignitionVersion shape parses");
142        assert_eq!(info.ignition_version, "8.3.6 (b2026042713)");
143        assert_eq!(info.name.as_deref(), Some("ign-live"));
144        assert_eq!(info.license.as_ref().expect("license").mode, "Trial");
145
146        let legacy = serde_json::json!({"version": "8.3.2"});
147        let info: GatewayInfo =
148            serde_json::from_value(legacy).expect("legacy `version` name still parses (alias)");
149        assert_eq!(info.ignition_version, "8.3.2");
150    }
151
152    /// The `--json` data key is the gateway-native `ignitionVersion`
153    /// (passthrough shape; LOCKED additive field).
154    #[test]
155    fn gateway_info_serializes_under_the_gateway_native_key() {
156        let info = GatewayInfo {
157            name: Some("ign-live-rig".into()),
158            redundancy_role: Some("Independent".into()),
159            edition: Some("standard".into()),
160            ignition_version: "8.3.6 (b2026042713)".into(),
161            jvm_version: None,
162            license: Some(LicenseInfo {
163                mode: "Trial".into(),
164                expiration_date: None,
165            }),
166            endpoint: None,
167        };
168        let json = serde_json::to_value(&info).expect("serialize");
169        assert_eq!(json["ignitionVersion"], "8.3.6 (b2026042713)");
170        assert_eq!(json["name"], "ign-live-rig");
171        assert_eq!(json["license"]["mode"], "Trial");
172        assert!(
173            json.get("endpoint").is_none(),
174            "endpoint is never serialized (CORE-05 skip)"
175        );
176    }
177}