Skip to main content

vtcode_desktop_protocol/
update.rs

1//! Cached updater-status DTOs.
2
3use serde::{Deserialize, Serialize};
4
5/// Cached updater status for the desktop client. The service owns update
6/// policy (channel, pin, check interval); this snapshot never triggers
7/// network I/O, it only reports the last cached check.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct UpdateStatusSnapshot {
11    /// Version of the running service binary.
12    pub current_version: String,
13    /// Newest release the service's update cache knows about that is *newer*
14    /// than `current_version`; clients read its notes. Never the running or an
15    /// older release, so a reader row cannot label a back-version "latest".
16    /// Only [`Self::update_available`] means an update is actually offered (a
17    /// dismissed update keeps its notes readable while this stays `true`).
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub latest_version: Option<String>,
20    /// Whether `latest_version` is newer than `current_version` and not dismissed.
21    #[serde(default)]
22    pub update_available: bool,
23    /// HTTPS release page for `latest_version`, when known.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub release_url: Option<String>,
26    /// Parsed `### Highlights` bullets for `latest_version`, taken from the
27    /// cached release notes. Empty when the cache holds notes without a
28    /// Highlights section; clients render a link-only state then.
29    #[serde(default, skip_serializing_if = "Vec::is_empty")]
30    pub release_highlights: Vec<String>,
31    /// Parsed `### Highlights` bullets for the running `current_version`,
32    /// for the post-update "what's new" moment. Empty unless the cache holds
33    /// notes describing exactly the running version.
34    #[serde(default, skip_serializing_if = "Vec::is_empty")]
35    pub current_release_highlights: Vec<String>,
36    /// HTTPS release page for the running version, sent alongside
37    /// `current_release_highlights` so the "what's new" viewer can link out.
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub current_release_url: Option<String>,
40    /// Whether the running version's notes were already announced by any VT
41    /// Code surface. The marker lives in the shared update cache, so notes
42    /// shown by the CLI are not repeated by the desktop app and vice versa.
43    #[serde(default)]
44    pub current_release_seen: bool,
45    /// Release channel the service follows (stable/beta/nightly).
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub channel: Option<String>,
48    /// Whether the configured check interval has elapsed since the last check.
49    #[serde(default)]
50    pub check_due: bool,
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn update_status_snapshot_round_trips_and_older_payloads_decode() {
59        let snapshot = UpdateStatusSnapshot {
60            current_version: "0.180.5".into(),
61            latest_version: Some("0.181.0".into()),
62            update_available: true,
63            release_url: Some("https://github.com/vinhnx/vtcode/releases/tag/v0.181.0".into()),
64            release_highlights: vec!["Faster startup".into(), "New model picker".into()],
65            current_release_highlights: vec!["Older highlight".into()],
66            current_release_url: Some("https://github.com/vinhnx/vtcode/releases/tag/v0.180.5".into()),
67            current_release_seen: true,
68            channel: Some("stable".into()),
69            check_due: false,
70        };
71        let decoded: UpdateStatusSnapshot = serde_json::from_value(serde_json::to_value(&snapshot).unwrap()).unwrap();
72        assert_eq!(decoded, snapshot);
73
74        // Asymmetric fixtures: the post-update shape carries current-version
75        // notes with no update available, and a legacy payload carries only
76        // the running version.
77        let quiet = UpdateStatusSnapshot {
78            current_version: "0.181.0".into(),
79            latest_version: None,
80            update_available: false,
81            release_url: None,
82            release_highlights: Vec::new(),
83            current_release_highlights: vec!["Freshly installed".into()],
84            current_release_url: Some("https://github.com/vinhnx/vtcode/releases/tag/v0.181.0".into()),
85            current_release_seen: false,
86            channel: None,
87            check_due: true,
88        };
89        let decoded_quiet: UpdateStatusSnapshot =
90            serde_json::from_value(serde_json::to_value(&quiet).unwrap()).unwrap();
91        assert_eq!(decoded_quiet, quiet);
92
93        let legacy: UpdateStatusSnapshot =
94            serde_json::from_value(serde_json::json!({ "currentVersion": "0.179.0" })).unwrap();
95        assert_eq!(legacy.current_version, "0.179.0");
96        assert!(legacy.latest_version.is_none());
97        assert!(!legacy.update_available);
98        assert!(legacy.release_url.is_none());
99        assert!(legacy.release_highlights.is_empty());
100        assert!(legacy.current_release_highlights.is_empty());
101        assert!(legacy.current_release_url.is_none());
102        assert!(!legacy.current_release_seen);
103        assert!(legacy.channel.is_none());
104        assert!(!legacy.check_due);
105    }
106}