Skip to main content

agentmux_launcher/
verify_update.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `agentmux-launcher --verify-update <version> <dir> <file> [installed:<version>] [unreachable:<why>]`
5//!
6//! Used by the root helper of a `.deb` or `.rpm` install (`agentmux-install-update`,
7//! `docs/specs/SPEC_LINUX_PACKAGE_UPGRADE_AND_REPOSITORY_2026_10_24.md` ยง3.2): the
8//! helper fetches the release's envelope, signature and manifest into `<dir>`
9//! (named as `agentmux_common::update_manifest::file_names` names them; a file the
10//! release doesn't have is left out) and asks this to check `<file>` against them with
11//! the key this build pins, the same decision the app makes before it downloads
12//! (`SPEC_SIGNED_UPDATE_CHECKSUMS_2026_10_25.md`). One pinned key and one decision, so
13//! the shell script holds neither.
14//!
15//! With `installed:<version>` it also holds the release to its upgrade floor
16//! (`SPEC_UPGRADE_FLOOR_IN_SIGNED_MANIFEST`): the higher of the floor the verified
17//! manifest signs and this build's own, against the version the helper read from the
18//! package database. The helper runs as root on a caller's word, so it takes the floor
19//! from the manifest it verified and the installed version from the database, never from
20//! the caller; a release whose manifest signs no floor is checked as before.
21//!
22//! Exit status: 0 verified; 10 the release predates signing and has no manifest (the
23//! helper falls back to the checksum GitHub lists, as the app does); 1 refused, with the
24//! message the person reads on stderr.
25
26use std::io::Read;
27use std::path::Path;
28
29use agentmux_common::update_manifest::{
30    decide, file_names, install_first_message, judge_file_and_floor, signed_floor_in_force, version_core, Outcome, SignedFloor, UpdateKey,
31    MAX_ENVELOPE_BYTES, MAX_MANIFEST_BYTES, UPDATE_KEYS,
32};
33use sha2::{Digest, Sha256};
34
35/// Exit status for a release made before signing existed, with no manifest.
36pub const EXIT_UNSIGNED_OLD: i32 = 10;
37
38/// What a check allows.
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum Verdict {
41    /// The signed manifest lists the file with its size and hash.
42    Verified,
43    /// A release from before signing, which has no manifest.
44    UnsignedOld,
45}
46
47/// A file a release publishes, if it was fetched, read with a cap.
48fn read_capped(path: &Path, cap: usize) -> Result<Option<Vec<u8>>, String> {
49    let file = match std::fs::File::open(path) {
50        Ok(f) => f,
51        Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
52        Err(e) => return Err(format!("can't read {}: {e}", path.display())),
53    };
54    let mut body = Vec::new();
55    file.take(cap as u64 + 1).read_to_end(&mut body).map_err(|e| format!("can't read {}: {e}", path.display()))?;
56    if body.len() > cap {
57        return Err(format!("{} is larger than {cap} bytes", path.display()));
58    }
59    Ok(Some(body))
60}
61
62/// The size and SHA-256 of `path`.
63fn size_and_hash(path: &Path) -> Result<(u64, String), String> {
64    let mut file = std::fs::File::open(path).map_err(|e| format!("can't read {}: {e}", path.display()))?;
65    let mut hasher = Sha256::new();
66    let mut size = 0u64;
67    let mut buf = vec![0u8; 1 << 20];
68    loop {
69        let n = file.read(&mut buf).map_err(|e| format!("can't read {}: {e}", path.display()))?;
70        if n == 0 {
71            break;
72        }
73        hasher.update(&buf[..n]);
74        size += n as u64;
75    }
76    Ok((size, agentmux_common::update_manifest::hex(&hasher.finalize())))
77}
78
79/// The upgrade floor of the repository when this build was made (`UPGRADE_FLOOR`): a floor only rises, so no later
80/// release's is lower. The app's check holds the same value.
81const BUILD_FLOOR: &str = include_str!("../../../UPGRADE_FLOOR");
82
83/// [`BUILD_FLOOR`] when it is a version.
84fn build_floor() -> Option<&'static str> {
85    Some(BUILD_FLOOR.trim()).filter(|f| version_core(f).is_some())
86}
87
88/// Check `file` against the signed manifest files in `dir` for `version`, using `keys`.
89/// `unreachable` is the helper's reason when it couldn't fetch them at all. `installed` is the version the
90/// package database says is installed and about to be replaced: given, the release's upgrade floor is enforced.
91pub fn verify(keys: &[UpdateKey], version: &str, dir: &Path, file: &Path, unreachable: Option<&str>) -> Result<Verdict, String> {
92    verify_replacing(keys, build_floor(), version, dir, file, unreachable, None)
93}
94
95/// [`verify`], holding the release to its upgrade floor against `installed` when that is given. `build` is this build's own floor.
96pub fn verify_replacing(
97    keys: &[UpdateKey],
98    build: Option<&str>,
99    version: &str,
100    dir: &Path,
101    file: &Path,
102    unreachable: Option<&str>,
103    installed: Option<&str>,
104) -> Result<Verdict, String> {
105    let tag = format!("v{}", version.trim_start_matches('v'));
106    let name = file.file_name().and_then(|n| n.to_str()).ok_or_else(|| format!("{} has no file name", file.display()))?;
107    let mut signed_floor = SignedFloor::Absent;
108    let outcome = if let Some(why) = unreachable {
109        Outcome::Unreachable(why.to_string())
110    } else {
111        let (envelope_name, signature_name, manifest_name) = file_names(version.trim_start_matches('v'));
112        match read_capped(&dir.join(envelope_name), MAX_ENVELOPE_BYTES)? {
113            // The release has no signed manifest (made before signing).
114            None => Outcome::Unsigned,
115            Some(envelope) => match read_capped(&dir.join(signature_name), MAX_ENVELOPE_BYTES)? {
116                None => Outcome::Failed("the envelope has no signature file".into()),
117                Some(signatures) => match read_capped(&dir.join(manifest_name), MAX_MANIFEST_BYTES)? {
118                    None => Outcome::Failed("the envelope has no manifest".into()),
119                    Some(manifest) => {
120                        let (size, sha256) = size_and_hash(file)?;
121                        let (outcome, floor) = judge_file_and_floor(keys, &tag, Some((&envelope, &String::from_utf8_lossy(&signatures), &manifest)), name, size, &sha256);
122                        signed_floor = floor;
123                        outcome
124                    }
125                },
126            },
127        }
128    };
129    decide(version, &outcome)?;
130    // Only a verified manifest has a floor (`signed_floor` is `Absent` for anything else). The installed version is read by
131    // the helper from the package database; one that can't be read as a version, beside a floor, is refused.
132    if let (Some(installed), Some(floor)) = (installed, signed_floor_in_force(build, &signed_floor)) {
133        let older = match (version_core(installed), version_core(&floor)) {
134            (Some(i), Some(f)) => i < f,
135            _ => true,
136        };
137        if older {
138            return Err(install_first_message(installed, version.trim_start_matches('v'), &floor));
139        }
140    }
141    Ok(if outcome == Outcome::Unsigned { Verdict::UnsignedOld } else { Verdict::Verified })
142}
143
144/// What `--verify-update` was asked: the version, the folder of signed files, the package, and the optional parts.
145#[derive(Debug, PartialEq, Eq)]
146struct Request<'a> {
147    version: &'a str,
148    dir: &'a str,
149    file: &'a str,
150    /// The version the package database says is installed (`installed:<version>`).
151    installed: Option<&'a str>,
152    /// Why the helper could not fetch the signed files (`unreachable:<why>`), in one string.
153    unreachable: Option<String>,
154}
155
156/// Read the words after `--verify-update`. `installed:<version>` comes before the reason, which is one argument whose
157/// words were split apart and are put back together.
158fn parse_request(rest: &[String]) -> Option<Request<'_>> {
159    let (version, dir, file) = (rest.first()?, rest.get(1)?, rest.get(2)?);
160    let (installed, reason_from) = match rest.get(3).and_then(|a| a.strip_prefix("installed:")) {
161        Some(v) => (Some(v), 4),
162        None => (None, 3),
163    };
164    let reason = rest[reason_from..].join(" ");
165    let unreachable = reason.strip_prefix("unreachable:").map(str::to_string);
166    Some(Request { version, dir, file, installed, unreachable })
167}
168
169/// Handle `--verify-update` if it is what was asked, returning the exit status.
170pub fn run_if_requested(args: &[String]) -> Option<i32> {
171    let at = args.iter().position(|a| a == "--verify-update")?;
172    let Some(request) = parse_request(&args[at + 1..]) else {
173        eprintln!("usage: agentmux-launcher --verify-update <version> <dir> <file> [installed:<version>] [unreachable:<why>]");
174        return Some(2);
175    };
176    let result = verify_replacing(
177        UPDATE_KEYS,
178        build_floor(),
179        request.version,
180        Path::new(request.dir),
181        Path::new(request.file),
182        request.unreachable.as_deref(),
183        request.installed,
184    );
185    Some(match result {
186        Ok(Verdict::Verified) => 0,
187        Ok(Verdict::UnsignedOld) => EXIT_UNSIGNED_OLD,
188        Err(message) => {
189            eprintln!("{message}");
190            1
191        }
192    })
193}
194
195#[cfg(test)]
196mod tests {
197    use super::*;
198
199    /// The real v0.60.4 release's signed files, as published (the pinned key `k1` signed them).
200    const ENVELOPE: &str = include_str!("../tests/fixtures/verify_update/AgentMux-0.60.4-envelope.json");
201    const SIGNATURES: &str = include_str!("../tests/fixtures/verify_update/AgentMux-0.60.4-envelope.json.sig");
202    const MANIFEST: &str = include_str!("../tests/fixtures/verify_update/AgentMux-0.60.4-manifest.json");
203
204    fn scratch(name: &str) -> std::path::PathBuf {
205        let dir = std::env::temp_dir().join(format!("verify-update-{name}-{}", std::process::id()));
206        let _ = std::fs::remove_dir_all(&dir);
207        std::fs::create_dir_all(&dir).unwrap();
208        dir
209    }
210
211    fn signed_dir(name: &str) -> std::path::PathBuf {
212        let dir = scratch(name);
213        let (e, s, m) = file_names("0.60.4");
214        std::fs::write(dir.join(e), ENVELOPE).unwrap();
215        std::fs::write(dir.join(s), SIGNATURES).unwrap();
216        std::fs::write(dir.join(m), MANIFEST).unwrap();
217        dir
218    }
219
220    /// A file the real manifest lists, made to have a given content, is not the real one:
221    /// the manifest's own entry is used to build a stand-in only where a test needs it.
222    fn put(dir: &Path, name: &str, body: &[u8]) -> std::path::PathBuf {
223        let p = dir.join(name);
224        std::fs::write(&p, body).unwrap();
225        p
226    }
227
228    #[test]
229    fn the_real_v0_60_4_manifest_verifies_with_the_pinned_key_and_refuses_a_file_that_is_not_listed() {
230        let dir = signed_dir("real");
231        let signed = agentmux_common::update_manifest::verify_release(UPDATE_KEYS, "v0.60.4", ENVELOPE.as_bytes(), SIGNATURES, MANIFEST.as_bytes())
232            .expect("the published v0.60.4 files verify with the pinned key");
233        assert!(signed.file("AgentMux_0.60.4_amd64.deb").is_some());
234        // Not the real package: the manifest lists the name, and the size and hash differ.
235        let fake = put(&dir, "AgentMux_0.60.4_amd64.deb", b"not the real package");
236        assert!(verify(UPDATE_KEYS, "0.60.4", &dir, &fake, None).unwrap_err().contains("doesn't match"));
237        // A name the signed manifest doesn't list: only a verified manifest gets this far.
238        let other = put(&dir, "AgentMux_0.60.4_arm64.deb", b"x");
239        assert!(verify(UPDATE_KEYS, "0.60.4", &dir, &other, None).unwrap_err().contains("no file for this kind of install"));
240    }
241
242    #[test]
243    fn a_missing_envelope_is_unsigned_which_only_a_release_before_0_60_4_may_be() {
244        let dir = scratch("unsigned");
245        let f = put(&dir, "AgentMux_0.60.3_amd64.deb", b"x");
246        assert_eq!(verify(UPDATE_KEYS, "0.60.3", &dir, &f, None), Ok(Verdict::UnsignedOld));
247        let f = put(&dir, "AgentMux_0.60.4_amd64.deb", b"x");
248        assert!(verify(UPDATE_KEYS, "0.60.4", &dir, &f, None).unwrap_err().contains("wasn't signed"));
249        // A version that can't be read is not an old one.
250        assert!(verify(UPDATE_KEYS, "nightly", &dir, &f, None).unwrap_err().contains("wasn't signed"));
251    }
252
253    #[test]
254    fn a_release_that_could_not_be_reached_is_refused_whatever_its_age() {
255        let dir = scratch("unreachable");
256        let f = put(&dir, "AgentMux_0.60.3_amd64.deb", b"x");
257        let e = verify(UPDATE_KEYS, "0.60.3", &dir, &f, Some("GitHub didn't answer")).unwrap_err();
258        assert!(e.contains("Couldn't check the signature of v0.60.3") && e.contains("GitHub didn't answer"), "{e}");
259    }
260
261    #[test]
262    fn a_tampered_manifest_a_missing_signature_and_another_tag_are_refused() {
263        let (e, s, m) = file_names("0.60.4");
264        let dir = signed_dir("tamper");
265        let f = put(&dir, "AgentMux_0.60.4_amd64.deb", b"x");
266        std::fs::write(dir.join(&m), MANIFEST.replace("\"size\"", "\"size \"")).unwrap();
267        assert!(verify(UPDATE_KEYS, "0.60.4", &dir, &f, None).unwrap_err().contains("signature on v0.60.4 doesn't match"));
268        let dir = signed_dir("nosig");
269        std::fs::remove_file(dir.join(&s)).unwrap();
270        let f = put(&dir, "AgentMux_0.60.4_amd64.deb", b"x");
271        assert!(verify(UPDATE_KEYS, "0.60.4", &dir, &f, None).unwrap_err().contains("signature on v0.60.4 doesn't match"));
272        // The envelope of 0.60.4 offered for 0.60.5 under that release's names.
273        let dir = scratch("replay");
274        std::fs::write(dir.join("AgentMux-0.60.5-envelope.json"), ENVELOPE).unwrap();
275        std::fs::write(dir.join("AgentMux-0.60.5-envelope.json.sig"), SIGNATURES).unwrap();
276        std::fs::write(dir.join("AgentMux-0.60.5-manifest.json"), MANIFEST).unwrap();
277        let f = put(&dir, "AgentMux_0.60.5_amd64.deb", b"x");
278        assert!(verify(UPDATE_KEYS, "0.60.5", &dir, &f, None).unwrap_err().contains("signature on v0.60.5 doesn't match"));
279        let _ = e;
280    }
281
282    #[test]
283    fn a_file_the_manifest_lists_with_its_size_and_hash_is_verified() {
284        // A manifest of our own under a throwaway key stands in for "the right file".
285        use agentmux_common::update_manifest::hex;
286        use base64::Engine;
287        use ed25519_dalek::{Signer, SigningKey};
288        let body = b"the package bytes";
289        let sha = hex(&Sha256::digest(body));
290        let manifest = format!(r#"{{"format":1,"version":"0.60.9","tag":"v0.60.9","files":[{{"name":"AgentMux_0.60.9_amd64.deb","size":{},"sha256":"{sha}"}}]}}"#, body.len());
291        let envelope = format!(r#"{{"format":1,"tag":"v0.60.9","manifest_sha256":"{}","created_at":"2026-10-28T12:00:00Z"}}"#, hex(&Sha256::digest(manifest.as_bytes())));
292        let key = SigningKey::from_bytes(&[5; 32]);
293        let sig = format!("k1 {}\n", base64::engine::general_purpose::STANDARD.encode(key.sign(envelope.as_bytes()).to_bytes()));
294        let keys = [UpdateKey { id: "k1", public: key.verifying_key().to_bytes() }];
295        let dir = scratch("good");
296        let (e, s, m) = file_names("0.60.9");
297        std::fs::write(dir.join(e), &envelope).unwrap();
298        std::fs::write(dir.join(s), &sig).unwrap();
299        std::fs::write(dir.join(m), &manifest).unwrap();
300        let f = put(&dir, "AgentMux_0.60.9_amd64.deb", body);
301        assert_eq!(verify(&keys, "0.60.9", &dir, &f, None), Ok(Verdict::Verified));
302        // One byte different, same name: refused.
303        let f = put(&dir, "AgentMux_0.60.9_amd64.deb", b"the package byteZ");
304        assert!(verify(&keys, "0.60.9", &dir, &f, None).is_err());
305        // The throwaway key isn't the one the app pins.
306        assert!(verify(UPDATE_KEYS, "0.60.9", &dir, &f, None).is_err());
307    }
308
309    /// A release of our own under a throwaway key whose manifest signs `upgrade_json` (e.g. `,"upgrade":{"floor":"0.58.0"}`),
310    /// with the package it lists: the keys, the folder and the package's path.
311    fn floor_release(name: &str, upgrade_json: &str) -> ([UpdateKey; 1], std::path::PathBuf, std::path::PathBuf) {
312        use agentmux_common::update_manifest::hex;
313        use base64::Engine;
314        use ed25519_dalek::{Signer, SigningKey};
315        let body = b"the package bytes";
316        let sha = hex(&Sha256::digest(body));
317        let manifest = format!(
318            r#"{{"format":1,"version":"0.60.9","tag":"v0.60.9","files":[{{"name":"AgentMux_0.60.9_amd64.deb","size":{},"sha256":"{sha}"}}]{upgrade_json}}}"#,
319            body.len()
320        );
321        let envelope = format!(r#"{{"format":1,"tag":"v0.60.9","manifest_sha256":"{}","created_at":"2026-10-28T12:00:00Z"}}"#, hex(&Sha256::digest(manifest.as_bytes())));
322        let key = SigningKey::from_bytes(&[5; 32]);
323        let sig = format!("k1 {}\n", base64::engine::general_purpose::STANDARD.encode(key.sign(envelope.as_bytes()).to_bytes()));
324        let dir = scratch(name);
325        let (e, s, m) = file_names("0.60.9");
326        std::fs::write(dir.join(e), &envelope).unwrap();
327        std::fs::write(dir.join(s), &sig).unwrap();
328        std::fs::write(dir.join(m), &manifest).unwrap();
329        let f = put(&dir, "AgentMux_0.60.9_amd64.deb", body);
330        ([UpdateKey { id: "k1", public: key.verifying_key().to_bytes() }], dir, f)
331    }
332
333    #[test]
334    fn a_release_whose_signed_floor_is_above_the_installed_version_is_refused_naming_the_version_to_install_first() {
335        let (keys, dir, f) = floor_release("floor-above", r#","upgrade":{"floor":"0.58.0"}"#);
336        let e = verify_replacing(&keys, Some("0.55.0"), "0.60.9", &dir, &f, None, Some("0.57.3")).unwrap_err();
337        assert_eq!(e, "This AgentMux (0.57.3) is older than 0.60.9 can upgrade from; install 0.58.0 first, then upgrade.");
338        // The app says the same words for the same case.
339        assert_eq!(e, install_first_message("0.57.3", "0.60.9", "0.58.0"));
340    }
341
342    #[test]
343    fn at_or_above_the_signed_floor_the_release_installs_as_before() {
344        let (keys, dir, f) = floor_release("floor-at", r#","upgrade":{"floor":"0.58.0"}"#);
345        for installed in ["0.58.0", "0.58.1", "0.60.8", "0.60.8-1"] {
346            assert_eq!(verify_replacing(&keys, Some("0.55.0"), "0.60.9", &dir, &f, None, Some(installed)), Ok(Verdict::Verified), "{installed}");
347        }
348    }
349
350    #[test]
351    fn the_version_strings_of_real_packages_pass_beside_the_floor_every_release_signs() {
352        // Every release signs a floor today (0.55.0 in 0.60.39's manifest), so every Linux upgrade reaches this check with the
353        // installed package's version as the package database gives it: the control file's `Version` for a .deb, the header's
354        // `%{VERSION}` for an .rpm. These are the strings read out of the published 0.60.39 .deb and .rpm, and the version the
355        // nightly build gives its packages: `--version "$VERSION"` is package.json's version, and a build label only renames
356        // the file (scripts/build-deb-linux.sh, build-rpm-linux.sh), so a nightly's string has the same three numbers.
357        let (keys, dir, f) = floor_release("floor-real", r#","upgrade":{"floor":"0.55.0"}"#);
358        for (what, installed) in [("0.60.39 .deb Version", "0.60.39"), ("0.60.39 .rpm VERSION", "0.60.39"), ("nightly 0.60.38 .deb and .rpm", "0.60.38"), ("the floor itself", "0.55.0")] {
359            assert_eq!(verify_replacing(&keys, Some("0.55.0"), "0.60.9", &dir, &f, None, Some(installed)), Ok(Verdict::Verified), "{what}");
360        }
361        // A version with a package revision or a build suffix reads by its three numbers, as a dpkg or rpm revision would be.
362        for installed in ["0.60.39-1", "0.60.39+nightly"] {
363            assert_eq!(verify_replacing(&keys, Some("0.55.0"), "0.60.9", &dir, &f, None, Some(installed)), Ok(Verdict::Verified), "{installed}");
364        }
365    }
366
367    #[test]
368    fn a_manifest_with_no_usable_floor_is_checked_as_before_whatever_is_installed() {
369        for (name, upgrade) in [("none", ""), ("empty", r#","upgrade":{}"#), ("above", r#","upgrade":{"floor":"0.99.0"}"#), ("junk", r#","upgrade":{"floor":"soon"}"#)] {
370            let (keys, dir, f) = floor_release(&format!("nofloor-{name}"), upgrade);
371            assert_eq!(verify_replacing(&keys, None, "0.60.9", &dir, &f, None, Some("0.1.0")), Ok(Verdict::Verified), "{name}");
372        }
373    }
374
375    #[test]
376    fn the_higher_of_the_signed_floor_and_this_builds_floor_holds_and_a_signed_floor_never_lowers_it() {
377        let (keys, dir, f) = floor_release("floor-build", r#","upgrade":{"floor":"0.55.0"}"#);
378        let e = verify_replacing(&keys, Some("0.59.0"), "0.60.9", &dir, &f, None, Some("0.58.0")).unwrap_err();
379        assert!(e.contains("install 0.59.0 first"), "{e}");
380        assert_eq!(verify_replacing(&keys, Some("0.59.0"), "0.60.9", &dir, &f, None, Some("0.59.0")), Ok(Verdict::Verified));
381    }
382
383    #[test]
384    fn an_installed_version_that_cannot_be_read_is_refused_beside_a_floor_and_ignored_without_one() {
385        let (keys, dir, f) = floor_release("floor-unreadable", r#","upgrade":{"floor":"0.58.0"}"#);
386        assert!(verify_replacing(&keys, None, "0.60.9", &dir, &f, None, Some("nightly")).is_err());
387        assert!(verify_replacing(&keys, None, "0.60.9", &dir, &f, None, Some("")).is_err());
388        let (keys, dir, f) = floor_release("nofloor-unreadable", "");
389        assert_eq!(verify_replacing(&keys, None, "0.60.9", &dir, &f, None, Some("nightly")), Ok(Verdict::Verified));
390    }
391
392    #[test]
393    fn a_floor_is_read_only_from_a_manifest_that_verifies_and_never_asked_for_without_an_installed_version() {
394        // Going back to an older release passes no installed version: the floor is not asked.
395        let (keys, dir, f) = floor_release("floor-goback", r#","upgrade":{"floor":"0.58.0"}"#);
396        assert_eq!(verify_replacing(&keys, None, "0.60.9", &dir, &f, None, None), Ok(Verdict::Verified));
397        // A floor lowered after signing breaks the signature: refused whatever is installed, and nothing is read from it.
398        let manifest = std::fs::read_to_string(dir.join(file_names("0.60.9").2)).unwrap();
399        std::fs::write(dir.join(file_names("0.60.9").2), manifest.replace("0.58.0", "0.10.0")).unwrap();
400        assert!(verify_replacing(&keys, None, "0.60.9", &dir, &f, None, Some("0.57.0")).unwrap_err().contains("signature on v0.60.9 doesn't match"));
401    }
402
403    #[test]
404    fn the_installed_version_is_read_before_the_reason_and_the_reason_keeps_its_words() {
405        let a = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<Vec<_>>();
406        let r = a(&["0.60.9", "/d", "/f", "installed:0.57.3", "unreachable:GitHub", "didn't", "answer"]);
407        let q = parse_request(&r).unwrap();
408        assert_eq!((q.version, q.dir, q.file, q.installed), ("0.60.9", "/d", "/f", Some("0.57.3")));
409        assert_eq!(q.unreachable.as_deref(), Some("GitHub didn't answer"));
410        let r = a(&["0.60.9", "/d", "/f"]);
411        assert_eq!(parse_request(&r).unwrap().installed, None);
412        // The old form, a reason alone, is still read.
413        let r = a(&["0.60.9", "/d", "/f", "unreachable:x"]);
414        let q = parse_request(&r).unwrap();
415        assert_eq!((q.installed, q.unreachable.as_deref()), (None, Some("x")));
416        assert!(parse_request(&a(&["0.60.9", "/d"])).is_none());
417    }
418
419    #[test]
420    fn the_verb_is_found_among_the_arguments_and_a_short_one_is_a_usage_error() {
421        assert_eq!(run_if_requested(&["agentmux-launcher".into()]), None);
422        assert_eq!(run_if_requested(&["agentmux-launcher".into(), "--verify-update".into(), "0.60.4".into()]), Some(2));
423    }
424}