From ddbea208dcd1ef80739773dd19586eed6c7d51a0 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sun, 23 Aug 2026 16:05:23 +0800 Subject: [PATCH] test(remote): a download whose size nobody sent does not invent one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- src/ui/remote_workspace.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/ui/remote_workspace.rs b/src/ui/remote_workspace.rs index d224dc24..c02a348e 100644 --- a/src/ui/remote_workspace.rs +++ b/src/ui/remote_workspace.rs @@ -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}"); + } }