mise 2026.9.2

Dev tools, env vars, and tasks in one CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
use crate::semver::{chunkify_version, split_version_prefix};
use crate::toolset;
use crate::toolset::{ResolveOptions, ToolRequest, ToolSource, ToolVersion};
use crate::{Result, backend::ABackend, config::Config};
use serde::Serialize;
use std::{
    collections::BTreeSet,
    fmt::{Display, Formatter},
    path::PathBuf,
    sync::Arc,
};
use tabled::Tabled;
use versions::Version;

#[derive(Debug, Serialize, Clone, Tabled, PartialEq, Eq, Hash)]
pub(crate) struct OutdatedInfo {
    pub name: String,
    #[serde(skip)]
    #[tabled(skip)]
    pub tool_request: ToolRequest,
    #[serde(skip)]
    #[tabled(skip)]
    pub tool_version: ToolVersion,
    pub requested: String,
    #[tabled(display("Self::display_current"))]
    pub current: Option<String>,
    #[tabled(display("Self::display_bump"))]
    pub bump: Option<String>,
    pub latest: String,
    /// Where to read about `latest`, when the backend knows.
    ///
    /// JSON only: a release URL is long enough to wreck the table, and the
    /// table is the thing people read at a glance. Omitted rather than null
    /// when the backend does not publish one, so a consumer can ask whether the
    /// key is there instead of whether its value happens to be null.
    #[tabled(skip)]
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub release_url: Option<String>,
    pub source: ToolSource,
}

impl OutdatedInfo {
    pub(crate) fn new(config: &Arc<Config>, tv: ToolVersion, latest: String) -> Result<Self> {
        let t = tv.backend()?;
        let current = Self::current_version(config, &t, &tv)?;
        let oi = Self {
            source: tv.request.source().clone(),
            name: tv.ba().short.to_string(),
            current,
            requested: tv.request.version(),
            tool_request: tv.request.clone(),
            tool_version: tv,
            bump: None,
            latest,
            // Filled in by `resolve`, which is the only path that knows the
            // version was actually reported as outdated. Every other caller
            // builds an `OutdatedInfo` for a version it already has in hand.
            release_url: None,
        };
        Ok(oi)
    }

    fn current_version(
        config: &Arc<Config>,
        backend: &ABackend,
        tv: &ToolVersion,
    ) -> Result<Option<String>> {
        if backend.is_version_installed(config, tv, true) {
            return Ok(Some(tv.version.clone()));
        }
        if matches!(&tv.request, ToolRequest::Version { version, .. } if version == "latest") {
            if tv.request.version() == tv.version {
                // "latest" was not resolved to a concrete version (e.g. plugin not
                // installed yet). Don't try to infer an installed version; the
                // generic path below would treat "latest" as a fuzzy prefix and
                // incorrectly match any installed numeric version.
                return Ok(None);
            }
            // When minimum_release_age causes "latest" to resolve to a version not yet
            // installed on disk, fall back to finding the highest installed version.
            // Otherwise to_remove in `mise up` won't know which old version to uninstall.
            let Some(current) = backend.latest_installed_version(None)? else {
                return Ok(None);
            };
            let current_tv = ToolVersion::new(tv.request.clone(), current);
            if backend.is_version_installed(config, &current_tv, true) {
                return Ok(Some(current_tv.version));
            }
            return Ok(None);
        }

        let query = match &tv.request {
            ToolRequest::Version { version, .. } => Some(version.clone()),
            ToolRequest::Prefix { prefix, .. } => Some(prefix.clone()),
            _ => return Ok(None),
        };
        let Some(current) = backend.latest_installed_version(query)? else {
            return Ok(None);
        };
        let current_tv = ToolVersion::new(tv.request.clone(), current);
        if backend.is_version_installed(config, &current_tv, true) {
            Ok(Some(current_tv.version))
        } else {
            Ok(None)
        }
    }

    pub(crate) async fn resolve(
        config: &Arc<Config>,
        tv: ToolVersion,
        bump: bool,
        opts: &ResolveOptions,
    ) -> eyre::Result<Option<Self>> {
        let t = tv.backend()?;
        // prefix is something like "temurin-" or "corretto-"
        let (prefix, prefix_version) = split_version_prefix(&tv.request.version());
        let use_backend_latest =
            bump || (opts.inactive && tv.request.source() == &ToolSource::Unknown);

        let latest_result = if use_backend_latest {
            let prefix = prefixed_latest_query(&prefix, &prefix_version);
            // For bumps and installed-but-inactive tools (`--no-source`), use backend latest.
            t.latest_version(config, prefix, opts.before_date).await
        } else {
            tv.latest_version_with_opts(config, opts)
                .await
                .map(Option::from)
        };
        let latest = match latest_result {
            Ok(Some(latest)) => latest,
            Ok(None) => {
                warn!("Error getting latest version for {t}: no latest version found");
                return Ok(None);
            }
            Err(e) => {
                warn!("Error getting latest version for {t}: {e:#}");
                return Ok(None);
            }
        };
        let mut oi = Self::new(config, tv, latest)?;
        if opts.inactive && oi.source == ToolSource::Unknown {
            // Installed-but-inactive tools have no config source, so their request
            // is usually pinned to the currently installed version. With --no-source we
            // want to install the discovered latest version instead.
            let backend = oi.tool_request.ba().clone();
            let source = oi.tool_request.source().clone();
            let options = oi.tool_request.options();
            oi.tool_request = ToolRequest::new_with_options(backend, &oi.latest, options, source)?;
        }
        if oi
            .current
            .as_ref()
            .is_some_and(|c| !toolset::is_outdated_version(c, &oi.latest))
        {
            // Check if this is a rolling version (like "nightly") with a new checksum
            let rolling_outdated = t
                .is_rolling_version_outdated(config, &oi.tool_version)
                .await;
            if !rolling_outdated {
                trace!("skipping up-to-date version {}", oi.tool_version);
                return Ok(None);
            }
            trace!(
                "rolling version {} has updates (checksum changed)",
                oi.tool_version.request.version()
            );
        }
        // Asked for after the up-to-date checks above, so a tool that is not
        // going to be reported does not pay for the lookup. It reads the remote
        // listing, which is cached and which resolution has usually just read,
        // so this normally costs no extra request.
        //
        // `oi.latest` rather than the requested version: what is wanted is where
        // to read about the version being offered, not the one already pinned.
        oi.release_url = match t.get_version_info(config, &oi.latest).await {
            Some(info) => info.release_url,
            // A plain `latest` without prereleases does not come from that
            // listing at all — `latest_version` takes the backend's
            // stable-latest shortcut, which can name a release the cached
            // listing has not caught up with. Looking that version up here then
            // finds nothing, and the URL would go missing precisely for the
            // freshest release. The shortcut carries the URL itself, so ask it
            // rather than report nothing.
            None => t
                .latest_stable_version_info(config)
                .await
                .ok()
                .flatten()
                // Only if it is describing the version actually being reported.
                .filter(|info| info.version == oi.latest)
                .and_then(|info| info.release_url),
        };
        if bump {
            let old = oi.tool_version.request.version();
            let old = old.strip_prefix(&prefix).unwrap_or(old.as_str());
            let new = oi.latest.strip_prefix(&prefix).unwrap_or(&oi.latest);
            if let Some(bumped_version) = check_semver_bump(old, new)
                && bumped_version != oi.tool_version.request.version()
            {
                oi.bump = match oi.tool_request.clone() {
                    ToolRequest::Version {
                        version: _version,
                        backend,
                        options,
                        source,
                    } => {
                        oi.tool_request = ToolRequest::Version {
                            backend,
                            options,
                            source,
                            version: format!("{prefix}{bumped_version}"),
                        };
                        Some(oi.tool_request.version())
                    }
                    ToolRequest::Prefix {
                        prefix: _prefix,
                        backend,
                        options,
                        source,
                    } => {
                        oi.tool_request = ToolRequest::Prefix {
                            backend,
                            options,
                            source,
                            prefix: format!("{prefix}{bumped_version}"),
                        };
                        Some(oi.tool_request.version())
                    }
                    _ => {
                        warn!("upgrading non-version tool requests");
                        None
                    }
                }
            }
        }
        Ok(Some(oi))
    }

    fn display_current(current: &Option<String>) -> String {
        if let Some(current) = current {
            current.to_string()
        } else {
            "[MISSING]".to_string()
        }
    }

    fn display_bump(bump: &Option<String>) -> String {
        if let Some(bump) = bump {
            bump.to_string()
        } else {
            "[NONE]".to_string()
        }
    }
}

impl Display for OutdatedInfo {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        write!(f, "{:<20} ", self.name)?;
        if let Some(current) = &self.current {
            write!(f, "{current:<20} ")?;
        } else {
            write!(f, "{:<20} ", "MISSING")?;
        }
        write!(f, "-> {:<10} (", self.latest)?;
        if let Some(bump) = &self.bump {
            write!(f, "bump to {bump} in ")?;
        }
        write!(f, "{})", self.source)
    }
}

pub(crate) fn prefixed_latest_query(prefix: &str, prefix_version: &str) -> Option<String> {
    let prefix = prefix.trim();
    if prefix.is_empty()
        || prefix_version.is_empty()
        || prefix.contains(':')
        // A lone leading v/V is version syntax, not a backend/vendor prefix.
        // Treat it as unprefixed so backends with normalized bare versions like
        // 3.13.1 still resolve their latest release during --bump.
        || matches!(prefix, "v" | "V")
    {
        return None;
    }

    let query_version = chunkify_version(prefix_version)
        .into_iter()
        .next()
        .filter(|version| !version.is_empty())
        .unwrap_or_else(|| prefix_version.to_string());

    Some(format!("{prefix}{query_version}"))
}

/// check if the new version is a bump from the old version and return the new version
/// at the same specificity level as the old version
/// used with `mise outdated --bump` to determine what new semver range to use
/// given old: "20" and new: "21.2.3", return Some("21")
pub(crate) fn check_semver_bump(old: &str, new: &str) -> Option<String> {
    // Preserve known channel names as-is
    const CHANNEL_NAMES: &[&str] = &[
        "latest", "nightly", "stable", "beta", "dev", "canary", "edge", "lts",
    ];
    if CHANNEL_NAMES.iter().any(|&c| c.eq_ignore_ascii_case(old)) {
        return Some(old.to_string());
    }
    if let Some(("prefix", old_)) = old.split_once(':') {
        return check_semver_bump(old_, new);
    }
    let old_chunks = chunkify_version(old);
    let new_chunks = chunkify_version(new);
    // If old has no semver chunks but is non-empty, it's likely a channel name
    // that we didn't recognize - preserve it as-is
    if old_chunks.is_empty() && !old.is_empty() {
        return Some(old.to_string());
    }
    if !old_chunks.is_empty() && !new_chunks.is_empty() {
        if old_chunks.len() > new_chunks.len() {
            warn!(
                "something weird happened with versioning, old: {old:?}, new: {new:?}",
                old = old_chunks,
                new = new_chunks,
            );
        }
        let bump = new_chunks
            .into_iter()
            .take(old_chunks.len())
            .collect::<Vec<_>>();
        if bump == old_chunks {
            None
        } else {
            Some(bump.join(""))
        }
    } else {
        Some(new.to_string())
    }
}

/// Represents a config file update needed when a CLI-specified version doesn't match
/// the current config prefix.
pub(crate) struct ConfigBump {
    pub tool_name: String,
    pub config_path: std::path::PathBuf,
    pub old_version: String,
    pub new_version: String,
    pub new_request: ToolRequest,
}

/// Compute config bumps needed when CLI-specified versions don't match current config prefixes.
/// Returns a list of bumps to apply (or preview in dry-run mode).
pub(crate) fn compute_config_bumps(
    config: &Config,
    tool_versions: &[(&str, &str)], // (tool_short_name, cli_version)
) -> Vec<ConfigBump> {
    let config_paths = config.config_files.keys().cloned().collect();
    compute_config_bumps_for_paths(config, tool_versions, &config_paths)
}

/// Compute config bumps against a bounded set of config paths.
///
/// This lets callers that intentionally target a subset of the loaded config
/// hierarchy avoid updating shadowed parent configs.
pub(crate) fn compute_config_bumps_for_paths(
    config: &Config,
    tool_versions: &[(&str, &str)], // (tool_short_name, cli_version)
    config_paths: &BTreeSet<PathBuf>,
) -> Vec<ConfigBump> {
    let mut bumps = Vec::new();

    for &(tool_name, cli_version) in tool_versions {
        for (path, cf) in config.config_files.iter() {
            if !config_paths.contains(path) {
                continue;
            }
            if crate::config::is_global_config(path) {
                continue;
            }
            let Ok(trs) = cf.to_tool_request_set() else {
                continue;
            };

            // Find the tool by short name in this config file
            let matching = trs.tools.iter().find(|(ba, _)| ba.short == tool_name);
            let Some((_ba, requests)) = matching else {
                continue;
            };
            if requests.len() != 1 {
                continue;
            }

            let current_version = requests[0].version();
            let (prefix, _) = split_version_prefix(&current_version);
            let old = current_version
                .strip_prefix(&prefix)
                .unwrap_or(&current_version);

            if let Some(bumped) = check_semver_bump(old, cli_version)
                && bumped != old
            {
                let new_version = format!("{prefix}{bumped}");
                let new_request = match requests[0].clone() {
                    ToolRequest::Version {
                        version: _,
                        backend,
                        options,
                        source,
                    } => ToolRequest::Version {
                        version: new_version.clone(),
                        backend,
                        options,
                        source,
                    },
                    ToolRequest::Prefix {
                        prefix: _,
                        backend,
                        options,
                        source,
                    } => ToolRequest::Prefix {
                        prefix: format!("{prefix}{bumped}"),
                        backend,
                        options,
                        source,
                    },
                    other => other,
                };
                bumps.push(ConfigBump {
                    tool_name: tool_name.to_string(),
                    config_path: path.clone(),
                    old_version: current_version.to_string(),
                    new_version,
                    new_request,
                });
            }
            break;
        }
    }

    bumps
}

/// Apply config bumps by writing the new versions to their config files.
pub(crate) fn apply_config_bumps(config: &Config, bumps: &[ConfigBump]) -> Result<()> {
    for bump in bumps {
        let Some(cf) = config.config_files.get(&bump.config_path) else {
            continue;
        };
        let Ok(trs) = cf.to_tool_request_set() else {
            continue;
        };
        let Some((ba, _)) = trs.tools.iter().find(|(ba, _)| ba.short == bump.tool_name) else {
            continue;
        };
        cf.replace_versions(ba, vec![bump.new_request.clone()])?;
        cf.save()?;
    }
    Ok(())
}

pub(crate) fn is_outdated_version(current: &str, latest: &str) -> bool {
    if let (Some(c), Some(l)) = (Version::new(current), Version::new(latest)) {
        c.lt(&l)
    } else {
        current != latest
    }
}

#[cfg(test)]
mod tests {
    use pretty_assertions::assert_eq;
    use std::sync::Arc;
    use test_log::test;

    use super::{OutdatedInfo, check_semver_bump, is_outdated_version, prefixed_latest_query};
    use crate::cli::args::{BackendArg, BackendResolution};
    use crate::config::Config;
    use crate::toolset::{ToolRequest, ToolSource, ToolVersion, ToolVersionOptions, install_state};

    #[test]
    fn test_is_outdated_version() {
        assert_eq!(is_outdated_version("1.10.0", "1.12.0"), true);
        assert_eq!(is_outdated_version("1.12.0", "1.10.0"), false);

        assert_eq!(
            is_outdated_version("1.10.0-SNAPSHOT", "1.12.0-SNAPSHOT"),
            true
        );
        assert_eq!(
            is_outdated_version("1.12.0-SNAPSHOT", "1.10.0-SNAPSHOT"),
            false
        );

        assert_eq!(
            is_outdated_version("temurin-17.0.0", "temurin-17.0.1"),
            true
        );
        assert_eq!(
            is_outdated_version("temurin-17.0.1", "temurin-17.0.0"),
            false
        );
    }

    #[test]
    fn test_check_semver_bump() {
        std::assert_eq!(check_semver_bump("20", "20.0.0"), None);
        std::assert_eq!(check_semver_bump("20.0", "20.0.0"), None);
        std::assert_eq!(check_semver_bump("20.0.0", "20.0.0"), None);
        std::assert_eq!(check_semver_bump("20", "21.0.0"), Some("21".to_string()));
        std::assert_eq!(
            check_semver_bump("20.0", "20.1.0"),
            Some("20.1".to_string())
        );
        std::assert_eq!(
            check_semver_bump("20.0.0", "20.0.1"),
            Some("20.0.1".to_string())
        );
        std::assert_eq!(
            check_semver_bump("20.0.1", "20.1"),
            Some("20.1".to_string())
        );
        std::assert_eq!(
            check_semver_bump("2024-09-16", "2024-10-21"),
            Some("2024-10-21".to_string())
        );
        std::assert_eq!(
            check_semver_bump("20.0a1", "20.0a2"),
            Some("20.0a2".to_string())
        );
        std::assert_eq!(check_semver_bump("v20", "v20.0.0"), None);
        std::assert_eq!(check_semver_bump("v20.0", "v20.0.0"), None);
        std::assert_eq!(check_semver_bump("v20.0.0", "v20.0.0"), None);
        std::assert_eq!(check_semver_bump("v20", "v21.0.0"), Some("v21".to_string()));
        std::assert_eq!(
            check_semver_bump("v20.0.0", "v20.0.1"),
            Some("v20.0.1".to_string())
        );
        std::assert_eq!(
            check_semver_bump("latest", "20.0.0"),
            Some("latest".to_string())
        );
        // Channel names like "nightly", "stable", "beta" should be preserved
        std::assert_eq!(
            check_semver_bump("nightly", "0.10.0"),
            Some("nightly".to_string())
        );
        std::assert_eq!(
            check_semver_bump("stable", "0.10.0"),
            Some("stable".to_string())
        );
        std::assert_eq!(
            check_semver_bump("beta", "1.0.0-beta.1"),
            Some("beta".to_string())
        );
    }

    #[test]
    fn test_prefixed_latest_query() {
        assert_eq!(
            prefixed_latest_query("temurin-", "17.0.7+7"),
            Some("temurin-17".to_string())
        );
        assert_eq!(
            prefixed_latest_query("temurin-", "17-ea"),
            Some("temurin-17".to_string())
        );
        assert_eq!(
            prefixed_latest_query("corretto-", "2024-09-16"),
            Some("corretto-2024".to_string())
        );
        assert_eq!(prefixed_latest_query("prefix:1.", "24"), None);
        assert_eq!(prefixed_latest_query("v", "3.13.1"), None);
        assert_eq!(prefixed_latest_query("V", "3.13.1"), None);
        assert_eq!(prefixed_latest_query("", "17.0.7"), None);
        assert_eq!(prefixed_latest_query("temurin-", ""), None);
    }

    #[test]
    fn test_v_prefix_bump_preserves_bare_latest_version() {
        let prefix = "v";
        let old = "v3.12.0";
        let latest = "3.13.1";

        let old = old.strip_prefix(prefix).unwrap_or(old);
        let new = latest.strip_prefix(prefix).unwrap_or(latest);
        let bumped = check_semver_bump(old, new).unwrap();

        assert_eq!(bumped, "3.13.1");
        assert_eq!(format!("{prefix}{bumped}"), "v3.13.1");
    }

    #[tokio::test]
    async fn current_version_uses_installed_version_matching_request() {
        let config = Config::get().await.unwrap();
        let temp_dir = tempfile::tempdir().unwrap();
        let short = "summary-current-test";
        let mut backend = BackendArg::new_raw(
            short.into(),
            Some(format!("asdf:{short}")),
            short.into(),
            Some(ToolVersionOptions::default()),
            BackendResolution::new(true),
        );
        backend.installs_path = temp_dir.path().join("installs").join(short);
        let install_path = backend.installs_path.join("1.25.9");
        std::fs::create_dir_all(&install_path).unwrap();
        install_state::add_tool_version(&backend, &install_path, "1.25.9");

        let request = ToolRequest::new(Arc::new(backend), "1.25", ToolSource::Argument).unwrap();
        let tv = ToolVersion::new(request, "1.25.10".into());
        let info = OutdatedInfo::new(&config, tv, "1.25.10".into()).unwrap();

        assert_eq!(info.current.as_deref(), Some("1.25.9"));
    }

    #[tokio::test]
    async fn current_version_uses_installed_version_matching_prefix_request() {
        let config = Config::get().await.unwrap();
        let temp_dir = tempfile::tempdir().unwrap();
        let short = "summary-current-prefix-test";
        let mut backend = BackendArg::new_raw(
            short.into(),
            Some(format!("asdf:{short}")),
            short.into(),
            Some(ToolVersionOptions::default()),
            BackendResolution::new(true),
        );
        backend.installs_path = temp_dir.path().join("installs").join(short);
        let install_path = backend.installs_path.join("1.25.9");
        std::fs::create_dir_all(&install_path).unwrap();
        install_state::add_tool_version(&backend, &install_path, "1.25.9");

        let request =
            ToolRequest::new(Arc::new(backend), "prefix:1.25", ToolSource::Argument).unwrap();
        let tv = ToolVersion::new(request, "1.25.10".into());
        let info = OutdatedInfo::new(&config, tv, "1.25.10".into()).unwrap();

        assert_eq!(info.current.as_deref(), Some("1.25.9"));
    }

    #[tokio::test]
    async fn current_version_ignores_stale_install_state_matches() {
        let config = Config::get().await.unwrap();
        let temp_dir = tempfile::tempdir().unwrap();
        let short = "summary-current-stale-test";
        let mut backend = BackendArg::new_raw(
            short.into(),
            Some(format!("asdf:{short}")),
            short.into(),
            Some(ToolVersionOptions::default()),
            BackendResolution::new(true),
        );
        backend.installs_path = temp_dir.path().join("installs").join(short);
        let install_path = backend.installs_path.join("1.25.9");
        install_state::add_tool_version(&backend, &install_path, "1.25.9");

        let request = ToolRequest::new(Arc::new(backend), "1.25", ToolSource::Argument).unwrap();
        let tv = ToolVersion::new(request, "1.25.10".into());
        let info = OutdatedInfo::new(&config, tv, "1.25.10".into()).unwrap();

        assert_eq!(info.current, None);
    }

    #[tokio::test]
    async fn current_version_falls_back_to_installed_when_latest_not_installed() {
        let config = Config::get().await.unwrap();
        let temp_dir = tempfile::tempdir().unwrap();
        let short = "summary-current-latest-test";
        let mut backend = BackendArg::new_raw(
            short.into(),
            Some(format!("asdf:{short}")),
            short.into(),
            Some(ToolVersionOptions::default()),
            BackendResolution::new(true),
        );
        backend.installs_path = temp_dir.path().join("installs").join(short);
        let install_path = backend.installs_path.join("1.25.9");
        std::fs::create_dir_all(&install_path).unwrap();
        install_state::add_tool_version(&backend, &install_path, "1.25.9");

        let request = ToolRequest::new(Arc::new(backend), "latest", ToolSource::Argument).unwrap();
        let tv = ToolVersion::new(request, "1.25.10".into());
        let info = OutdatedInfo::new(&config, tv, "1.25.10".into()).unwrap();

        assert_eq!(info.current.as_deref(), Some("1.25.9"));
    }

    #[tokio::test]
    async fn current_version_reports_installed_resolved_latest() {
        let config = Config::get().await.unwrap();
        let temp_dir = tempfile::tempdir().unwrap();
        let short = "summary-current-resolved-latest-test";
        let mut backend = BackendArg::new_raw(
            short.into(),
            Some(format!("asdf:{short}")),
            short.into(),
            Some(ToolVersionOptions::default()),
            BackendResolution::new(true),
        );
        backend.installs_path = temp_dir.path().join("installs").join(short);
        let install_path = backend.installs_path.join("1.25.10");
        std::fs::create_dir_all(&install_path).unwrap();
        install_state::add_tool_version(&backend, &install_path, "1.25.10");

        let request = ToolRequest::new(Arc::new(backend), "latest", ToolSource::Argument).unwrap();
        let tv = ToolVersion::new(request, "1.25.10".into());
        let info = OutdatedInfo::new(&config, tv, "1.25.10".into()).unwrap();

        assert_eq!(info.current.as_deref(), Some("1.25.10"));
    }

    /// Build an `OutdatedInfo` the way the tests above do, for the cases that
    /// only care about how it is rendered.
    async fn outdated_info_for(short: &str) -> OutdatedInfo {
        let config = Config::get().await.unwrap();
        let temp_dir = tempfile::tempdir().unwrap();
        let mut backend = BackendArg::new_raw(
            short.into(),
            Some(format!("asdf:{short}")),
            short.into(),
            Some(ToolVersionOptions::default()),
            BackendResolution::new(true),
        );
        backend.installs_path = temp_dir.path().join("installs").join(short);
        let request = ToolRequest::new(Arc::new(backend), "1.25", ToolSource::Argument).unwrap();
        let tv = ToolVersion::new(request, "1.25.10".into());
        OutdatedInfo::new(&config, tv, "1.25.10".into()).unwrap()
    }

    /// Most backends publish no release URL, and those entries must not gain a
    /// `"release_url": null`. A consumer should be able to ask whether the key
    /// is there rather than whether its value happens to be null.
    #[tokio::test]
    async fn a_missing_release_url_leaves_the_key_out_of_the_json() {
        let info = outdated_info_for("release-url-absent-test").await;

        let json = serde_json::to_string(&info).unwrap();

        assert!(
            !json.contains("release_url"),
            "a tool with no release URL still carried the key: {json}"
        );
    }

    #[tokio::test]
    async fn a_release_url_is_reported_in_the_json() {
        let mut info = outdated_info_for("release-url-present-test").await;
        info.release_url = Some("https://example.invalid/releases/tag/v1.25.10".to_string());

        let json = serde_json::to_string(&info).unwrap();

        assert!(
            json.contains(r#""release_url":"https://example.invalid/releases/tag/v1.25.10""#),
            "the release URL did not reach the json: {json}"
        );
    }

    /// The table is the thing people read at a glance, and a release URL is long
    /// enough to wreck it. `#[tabled(skip)]` keeps it out; this is what notices
    /// if that attribute is dropped.
    #[tokio::test]
    async fn a_release_url_stays_out_of_the_table() {
        let mut info = outdated_info_for("release-url-table-test").await;
        info.release_url = Some("https://example.invalid/releases/tag/v1.25.10".to_string());

        let rendered = tabled::Table::new(vec![info]).to_string();

        assert!(
            !rendered.contains("example.invalid"),
            "the release URL leaked into the table: {rendered}"
        );
        assert!(
            !rendered.contains("release_url"),
            "the table grew a release_url column: {rendered}"
        );
    }
}