From 3066bb2f78229dbc1617cb5c669cc9e643bb6e39 Mon Sep 17 00:00:00 2001 From: Ahmar Ali Date: Mon, 23 Nov 2026 05:43:10 +0500 Subject: [PATCH 1/3] update: explain the manual Windows update instead of failing on Unix paths On Windows the update notice said "run 'proofline update'", but that command could never work there. It looked for the Unix installer folder ($HOME/.local/bin or PROOFLINE_INSTALL_DIR) and a binary called "proofline" without ".exe". So it failed with "set HOME or PROOFLINE_INSTALL_DIR", or with "this binary is outside the installer directory", even when PROOFLINE_INSTALL_DIR was the folder holding proofline.exe. It never showed the manual steps from the README. On Windows, install() now stops before any path check or download. It returns an error that lists the README's steps: close Proofline, download proofline-x86_64-pc-windows-msvc.tar.gz and SHA256SUMS from the latest GitHub release, check the hash with Get-FileHash, extract the archive and replace this binary (its path is printed). The exit status stays non-zero because nothing was updated. The Windows notice now says "'proofline update' shows how to install it". Linux and macOS behave exactly as before. Tests: windows_update_explains_the_manual_steps (tests/update.rs, Windows only, runs the real binary from a README-style folder with and without HOME) fails on main and passes now. windows_notices_point_to_the_manual_steps (src/update/tests.rs, runs on every OS) checks both notice texts and the steps. --- src/update.rs | 30 ++++++++++++++++++++++++++++- src/update/tests.rs | 33 ++++++++++++++++++++++++++++++++ tests/update.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/update.rs b/src/update.rs index d001d62..17d9cf2 100644 --- a/src/update.rs +++ b/src/update.rs @@ -143,7 +143,32 @@ fn suggestion(cache: &Cache, args: &[std::ffi::OsString], interactive: bool) -> .latest .as_ref() .filter(|latest| newer(latest)) - .map(|latest| format!("proofline {latest} is available; run 'proofline update'")) + .map(|latest| notice(latest, cfg!(target_os = "windows"))) +} + +fn notice(latest: &str, windows: bool) -> String { + if windows { + format!("proofline {latest} is available; 'proofline update' shows how to install it") + } else { + format!("proofline {latest} is available; run 'proofline update'") + } +} + +/// The README's verified manual update: self-update cannot replace a Windows +/// binary, and Windows has no Unix installer directory to check. +fn windows_steps(executable: Option<&Path>) -> String { + const ARCHIVE: &str = "proofline-x86_64-pc-windows-msvc.tar.gz"; + let executable = executable.map_or_else( + || "proofline.exe".to_owned(), + |path| path.display().to_string(), + ); + format!( + "'proofline update' cannot replace proofline.exe on Windows; update it by hand:\n \ + 1. Close every running Proofline process.\n \ + 2. Download {ARCHIVE} and SHA256SUMS from https://github.com/prooflinedev/cli/releases/latest\n \ + 3. Run 'Get-FileHash -Algorithm SHA256 {ARCHIVE}' and check that the hash matches the archive's line in SHA256SUMS.\n \ + 4. Run 'tar -xzf {ARCHIVE}' and replace {executable} with the extracted proofline.exe." + ) } fn prepare_check( @@ -422,6 +447,9 @@ fn replace(archive: &[u8], destination: &Path) -> anyhow::Result<()> { /// Updates an official installer location after verifying the pinned archive. pub(crate) async fn install() -> anyhow::Result<()> { + if cfg!(target_os = "windows") { + bail!(windows_steps(std::env::current_exe().ok().as_deref())); + } let (destination, target) = tokio::task::spawn_blocking(|| Ok::<_, anyhow::Error>((destination()?, target()?))) .await??; diff --git a/src/update/tests.rs b/src/update/tests.rs index d7387c5..5e1acb9 100644 --- a/src/update/tests.rs +++ b/src/update/tests.rs @@ -195,6 +195,39 @@ fn notices_are_suppressed_for_machine_and_hook_commands() { assert!(suggestion(&cache, &["status".into()], true).is_some()); } +#[test] +fn windows_notices_point_to_the_manual_steps() { + assert_eq!( + notice("9.0.0", false), + "proofline 9.0.0 is available; run 'proofline update'" + ); + let windows = notice("9.0.0", true); + assert!( + windows.starts_with("proofline 9.0.0 is available;"), + "{windows}" + ); + assert!( + windows.contains("'proofline update' shows how"), + "{windows}" + ); + let steps = windows_steps(Some(Path::new(r"C:\tools\proofline.exe"))); + for expected in [ + "Close every running Proofline process", + "https://github.com/prooflinedev/cli/releases/latest", + "proofline-x86_64-pc-windows-msvc.tar.gz", + "SHA256SUMS", + "Get-FileHash -Algorithm SHA256", + "tar -xzf", + r"C:\tools\proofline.exe", + ] { + assert!( + steps.contains(expected), + "{expected:?} missing from {steps}" + ); + } + assert!(windows_steps(None).contains("proofline.exe")); +} + // This same test executable supplies a real child fixture. All endpoint and // fixture-mode injection lives in cfg(test), never in the customer binary. #[tokio::test] diff --git a/tests/update.rs b/tests/update.rs index 0a165b0..495a60c 100644 --- a/tests/update.rs +++ b/tests/update.rs @@ -51,3 +51,49 @@ fn cached_update_preserves_schema_help_and_source_installation() { b"keep this installed CLI" ); } + +// Windows binaries are installed by hand (README "Windows installation"), so +// `update` must explain those steps instead of failing on Unix installer paths. +#[cfg(windows)] +#[test] +fn windows_update_explains_the_manual_steps() { + let directory = tempfile::tempdir().unwrap(); + let installed = directory.path().join("bin").join("proofline.exe"); + std::fs::create_dir_all(installed.parent().unwrap()).unwrap(); + std::fs::copy(env!("CARGO_BIN_EXE_proofline"), &installed).unwrap(); + let before = std::fs::read(&installed).unwrap(); + for home in [None, Some(directory.path())] { + let mut command = Command::new(&installed); + command + .arg("update") + .env("PROOFLINE_NO_UPDATE_CHECK", "1") + .env("LOCALAPPDATA", directory.path()) + .env_remove("PROOFLINE_INSTALL_DIR") + .env_remove("HOME"); + if let Some(home) = home { + command.env("HOME", home); + } + let update = command.output().unwrap(); + assert!(!update.status.success()); + assert!(update.stdout.is_empty()); + let stderr = String::from_utf8(update.stderr).unwrap(); + for expected in [ + "https://github.com/prooflinedev/cli/releases/latest", + "proofline-x86_64-pc-windows-msvc.tar.gz", + "SHA256SUMS", + "Get-FileHash -Algorithm SHA256", + &installed.display().to_string(), + ] { + assert!( + stderr.contains(expected), + "{expected:?} missing from {stderr}" + ); + } + assert!(!stderr.contains("HOME"), "{stderr}"); + assert!( + !stderr.contains("outside the installer directory"), + "{stderr}" + ); + } + assert_eq!(std::fs::read(&installed).unwrap(), before); +} From 92a28ddeb1751027ddafa1643dbbff63b6c6826a Mon Sep 17 00:00:00 2001 From: Ahmar Ali Date: Mon, 23 Nov 2026 05:48:32 +0500 Subject: [PATCH 2/3] update: pin the Windows steps to the announced version and extract safely Proofline review, round 1: - Extracting with 'tar -xzf' in the current folder could overwrite the installed proofline.exe (and leave it broken if interrupted). The steps now extract into a new 'proofline-new' folder and replace the binary only after that succeeded. - The notice's version comes from https://proofline.sh/cli/latest, which the release workflow publishes before GitHub marks the release as latest, so 'releases/latest' could still be the old version. When the local cache holds the newer version the notice showed, the steps now link to that version's pinned downloads on proofline.sh (the same files the Unix updater verifies). Still no network call. - When the binary's own path can't be read, the steps say how to find it: '(Get-Command proofline).Source'. - Tests: the cached-discovery test now accepts the Windows wording; a new assertion checks that suggestion() picks the platform's wording; the Windows integration test also covers the pinned links and checks for the exact old error instead of any "HOME". --- src/update.rs | 31 ++++++++++++++++++++++++++----- src/update/tests.rs | 37 +++++++++++++++++++++++++++---------- tests/update.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 18 deletions(-) diff --git a/src/update.rs b/src/update.rs index 17d9cf2..affabb1 100644 --- a/src/update.rs +++ b/src/update.rs @@ -156,18 +156,32 @@ fn notice(latest: &str, windows: bool) -> String { /// The README's verified manual update: self-update cannot replace a Windows /// binary, and Windows has no Unix installer directory to check. -fn windows_steps(executable: Option<&Path>) -> String { +/// `latest` is the cached version the notice announced; its pinned downloads +/// exist before GitHub marks that release as the latest one. +fn windows_steps(executable: Option<&Path>, latest: Option<&str>) -> String { const ARCHIVE: &str = "proofline-x86_64-pc-windows-msvc.tar.gz"; + let download = latest.map_or_else( + || { + format!( + "{ARCHIVE} and SHA256SUMS from https://github.com/prooflinedev/cli/releases/latest" + ) + }, + |version| { + let release = format!("{RELEASES}/download/{version}"); + format!("{release}/{ARCHIVE} and {release}/SHA256SUMS") + }, + ); let executable = executable.map_or_else( - || "proofline.exe".to_owned(), + || "the proofline.exe you ran (find it with '(Get-Command proofline).Source')".to_owned(), |path| path.display().to_string(), ); format!( "'proofline update' cannot replace proofline.exe on Windows; update it by hand:\n \ 1. Close every running Proofline process.\n \ - 2. Download {ARCHIVE} and SHA256SUMS from https://github.com/prooflinedev/cli/releases/latest\n \ + 2. Download {download}\n \ 3. Run 'Get-FileHash -Algorithm SHA256 {ARCHIVE}' and check that the hash matches the archive's line in SHA256SUMS.\n \ - 4. Run 'tar -xzf {ARCHIVE}' and replace {executable} with the extracted proofline.exe." + 4. Extract it into a new folder: 'mkdir proofline-new; tar -xzf {ARCHIVE} -C proofline-new'.\n \ + 5. Only if that succeeded, replace {executable} with proofline-new\\proofline.exe." ) } @@ -448,7 +462,14 @@ fn replace(archive: &[u8], destination: &Path) -> anyhow::Result<()> { /// Updates an official installer location after verifying the pinned archive. pub(crate) async fn install() -> anyhow::Result<()> { if cfg!(target_os = "windows") { - bail!(windows_steps(std::env::current_exe().ok().as_deref())); + let latest = cache_path() + .and_then(|path| read_cache(&path).ok()) + .and_then(|cache| cache.latest) + .filter(|latest| newer(latest)); + bail!(windows_steps( + std::env::current_exe().ok().as_deref(), + latest.as_deref() + )); } let (destination, target) = tokio::task::spawn_blocking(|| Ok::<_, anyhow::Error>((destination()?, target()?))) diff --git a/src/update/tests.rs b/src/update/tests.rs index 5e1acb9..1bc7f6a 100644 --- a/src/update/tests.rs +++ b/src/update/tests.rs @@ -210,22 +210,39 @@ fn windows_notices_point_to_the_manual_steps() { windows.contains("'proofline update' shows how"), "{windows}" ); - let steps = windows_steps(Some(Path::new(r"C:\tools\proofline.exe"))); + // `suggestion` itself must pick the wording of the platform it runs on. + let cache = Cache { + checked: now(), + latest: Some("9.0.0".to_owned()), + }; + assert_eq!( + suggestion(&cache, &["status".into()], true).unwrap(), + notice("9.0.0", cfg!(target_os = "windows")) + ); + let steps = windows_steps(Some(Path::new(r"C:\tools\proofline.exe")), Some("9.0.0")); for expected in [ "Close every running Proofline process", - "https://github.com/prooflinedev/cli/releases/latest", - "proofline-x86_64-pc-windows-msvc.tar.gz", - "SHA256SUMS", - "Get-FileHash -Algorithm SHA256", - "tar -xzf", - r"C:\tools\proofline.exe", + "https://proofline.sh/cli/download/9.0.0/proofline-x86_64-pc-windows-msvc.tar.gz", + "https://proofline.sh/cli/download/9.0.0/SHA256SUMS", + "Get-FileHash -Algorithm SHA256 proofline-x86_64-pc-windows-msvc.tar.gz", + "mkdir proofline-new; tar -xzf proofline-x86_64-pc-windows-msvc.tar.gz -C proofline-new", + r"replace C:\tools\proofline.exe with proofline-new\proofline.exe", ] { assert!( steps.contains(expected), "{expected:?} missing from {steps}" ); } - assert!(windows_steps(None).contains("proofline.exe")); + let unknown = windows_steps(None, None); + for expected in [ + "from https://github.com/prooflinedev/cli/releases/latest", + "(Get-Command proofline).Source", + ] { + assert!( + unknown.contains(expected), + "{expected:?} missing from {unknown}" + ); + } } // This same test executable supplies a real child fixture. All endpoint and @@ -327,7 +344,7 @@ async fn detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocat assert!( !String::from_utf8(output.stdout) .unwrap() - .contains("run 'proofline update'") + .contains("proofline 9.0.0 is available;") ); } tokio::time::timeout(Duration::from_secs(5), async { @@ -355,7 +372,7 @@ async fn detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocat assert!( String::from_utf8(output.stdout) .unwrap() - .contains("run 'proofline update'") + .contains(¬ice("9.0.0", cfg!(target_os = "windows"))) ); assert_eq!(received.load(Ordering::SeqCst), 1); server.abort(); diff --git a/tests/update.rs b/tests/update.rs index 495a60c..0d2d2f7 100644 --- a/tests/update.rs +++ b/tests/update.rs @@ -62,7 +62,38 @@ fn windows_update_explains_the_manual_steps() { std::fs::create_dir_all(installed.parent().unwrap()).unwrap(); std::fs::copy(env!("CARGO_BIN_EXE_proofline"), &installed).unwrap(); let before = std::fs::read(&installed).unwrap(); - for home in [None, Some(directory.path())] { + let cache = directory.path().join("proofline").join("update.json"); + std::fs::create_dir_all(cache.parent().unwrap()).unwrap(); + let checked = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs(); + // Without a cached newer version the steps name the GitHub page; with + // one they pin the downloads to the version the notice announced. + for (home, cached, download) in [ + ( + None, + false, + "https://github.com/prooflinedev/cli/releases/latest", + ), + ( + Some(directory.path()), + false, + "https://github.com/prooflinedev/cli/releases/latest", + ), + ( + None, + true, + "https://proofline.sh/cli/download/9.0.0/proofline-x86_64-pc-windows-msvc.tar.gz", + ), + ] { + if cached { + std::fs::write( + &cache, + format!("{{\"checked\":{checked},\"latest\":\"9.0.0\"}}"), + ) + .unwrap(); + } let mut command = Command::new(&installed); command .arg("update") @@ -78,10 +109,11 @@ fn windows_update_explains_the_manual_steps() { assert!(update.stdout.is_empty()); let stderr = String::from_utf8(update.stderr).unwrap(); for expected in [ - "https://github.com/prooflinedev/cli/releases/latest", + download, "proofline-x86_64-pc-windows-msvc.tar.gz", "SHA256SUMS", "Get-FileHash -Algorithm SHA256", + "-C proofline-new", &installed.display().to_string(), ] { assert!( @@ -89,7 +121,10 @@ fn windows_update_explains_the_manual_steps() { "{expected:?} missing from {stderr}" ); } - assert!(!stderr.contains("HOME"), "{stderr}"); + assert!( + !stderr.contains("set HOME or PROOFLINE_INSTALL_DIR"), + "{stderr}" + ); assert!( !stderr.contains("outside the installer directory"), "{stderr}" From af2f6b23f188ad4dec4346366d8342d761b099be Mon Sep 17 00:00:00 2001 From: Ahmar Ali Date: Mon, 23 Nov 2026 05:56:09 +0500 Subject: [PATCH 3/3] update: guard the Windows steps against downgrades and a reused folder Proofline review, round 2: - Without a cached newer version, the steps point to GitHub's latest release, which may not be newer than the running binary. They now print this binary's version and say to stop if the release isn't newer. - In PowerShell, 'mkdir proofline-new; tar ...' runs tar even when mkdir failed because the folder exists, so an older staged copy could be reused. Creating the empty folder is now its own step (pick another name if it exists), before extracting. - The cached-discovery test now rejects any "is available;" notice before the refresh, not only one for 9.0.0. --- src/update.rs | 10 +++++++--- src/update/tests.rs | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/update.rs b/src/update.rs index affabb1..0d8c688 100644 --- a/src/update.rs +++ b/src/update.rs @@ -162,8 +162,11 @@ fn windows_steps(executable: Option<&Path>, latest: Option<&str>) -> String { const ARCHIVE: &str = "proofline-x86_64-pc-windows-msvc.tar.gz"; let download = latest.map_or_else( || { + // No newer version is known, so this may already be the newest one. format!( - "{ARCHIVE} and SHA256SUMS from https://github.com/prooflinedev/cli/releases/latest" + "{ARCHIVE} and SHA256SUMS from https://github.com/prooflinedev/cli/releases/latest \ + (stop if that release is not newer than this proofline {})", + env!("CARGO_PKG_VERSION") ) }, |version| { @@ -180,8 +183,9 @@ fn windows_steps(executable: Option<&Path>, latest: Option<&str>) -> String { 1. Close every running Proofline process.\n \ 2. Download {download}\n \ 3. Run 'Get-FileHash -Algorithm SHA256 {ARCHIVE}' and check that the hash matches the archive's line in SHA256SUMS.\n \ - 4. Extract it into a new folder: 'mkdir proofline-new; tar -xzf {ARCHIVE} -C proofline-new'.\n \ - 5. Only if that succeeded, replace {executable} with proofline-new\\proofline.exe." + 4. Create an empty folder with 'mkdir proofline-new' (choose another name if it already exists).\n \ + 5. Extract into it with 'tar -xzf {ARCHIVE} -C proofline-new'.\n \ + 6. Only if that succeeded, replace {executable} with proofline-new\\proofline.exe." ) } diff --git a/src/update/tests.rs b/src/update/tests.rs index 1bc7f6a..77d0bcb 100644 --- a/src/update/tests.rs +++ b/src/update/tests.rs @@ -225,7 +225,8 @@ fn windows_notices_point_to_the_manual_steps() { "https://proofline.sh/cli/download/9.0.0/proofline-x86_64-pc-windows-msvc.tar.gz", "https://proofline.sh/cli/download/9.0.0/SHA256SUMS", "Get-FileHash -Algorithm SHA256 proofline-x86_64-pc-windows-msvc.tar.gz", - "mkdir proofline-new; tar -xzf proofline-x86_64-pc-windows-msvc.tar.gz -C proofline-new", + "mkdir proofline-new", + "tar -xzf proofline-x86_64-pc-windows-msvc.tar.gz -C proofline-new", r"replace C:\tools\proofline.exe with proofline-new\proofline.exe", ] { assert!( @@ -237,6 +238,7 @@ fn windows_notices_point_to_the_manual_steps() { for expected in [ "from https://github.com/prooflinedev/cli/releases/latest", "(Get-Command proofline).Source", + concat!("not newer than this proofline ", env!("CARGO_PKG_VERSION")), ] { assert!( unknown.contains(expected), @@ -344,7 +346,7 @@ async fn detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocat assert!( !String::from_utf8(output.stdout) .unwrap() - .contains("proofline 9.0.0 is available;") + .contains(" is available;") ); } tokio::time::timeout(Duration::from_secs(5), async {