test(remote): a download whose size nobody sent does not invent one

`install_phase_caption` is shared by the switcher's progress bar and the
strip's, precisely so a user watching both is not told two different things —
which also means a wrong caption is wrong in two places at once.

A server that sends no `content-length` gives `total: None`. Rendering that
through the with-total string reads "12 MB / 12 MB" while the transfer is
still running: it claims the download has finished, and the bar beside it
disagrees. Nothing failed when the two arms were swapped.

Held now across all four phases — no fraction when the size is unknown, one
when it is, an upload always knowing its total, and restarting having no
fraction at all.
This commit is contained in:
l0ng-ai
2026-08-23 16:05:23 +08:00
parent 17a2cc070e
commit ddbea208dc
+38
View File
@@ -3309,4 +3309,42 @@ mod tests {
);
});
}
/// A download whose size the server never sent does not invent one.
///
/// `install_phase_caption` is shared by the switcher's bar and the strip's
/// so a user watching both is not told two different things — which makes
/// a wrong caption wrong in two places at once. A `None` total rendered
/// through the with-total string reads "12 MB / 12 MB" while the transfer
/// is still running: it claims the download is finished, and the bar
/// beside it disagrees.
#[test]
fn a_download_with_no_known_total_says_so() {
use crate::daemon::install::InstallPhase;
let unknown = install_phase_caption(InstallPhase::Downloading {
done: 12_000_000,
total: None,
});
assert!(
!unknown.contains('/'),
"a size nobody sent must not appear as a fraction: {unknown}"
);
let known = install_phase_caption(InstallPhase::Downloading {
done: 6_000_000,
total: Some(12_000_000),
});
assert!(
known.contains('/'),
"a size the server did send is shown as a fraction: {known}"
);
assert_ne!(known, unknown, "the two phases do not read the same");
// An upload always knows its total; restarting has no fraction at all.
let copying = install_phase_caption(InstallPhase::Uploading { done: 1, total: 2 });
assert!(copying.contains('/'), "{copying}");
let restarting = install_phase_caption(InstallPhase::Restarting);
assert!(!restarting.contains('/'), "{restarting}");
}
}