Repository navigation
Windows: don't make scripts wait for the background update check #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1443801
836ab70
ac50182
a301ee2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,7 +92,7 @@ fn installer_directory_and_bounded_cache() { | |
| ) | ||
| .unwrap(); | ||
| // A fresh cached result schedules no child, and survives the next invocation. | ||
| prepare_check(&cache, &["--json".into()], true, || { | ||
| prepare_check(&cache, &["--json".into()], true, true, || { | ||
| anyhow::bail!("a fresh cache must not launch discovery") | ||
| }) | ||
| .unwrap(); | ||
|
|
@@ -101,6 +101,41 @@ fn installer_directory_and_bounded_cache() { | |
| assert!(read_cache(&cache).is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn windows_detaches_only_when_both_output_streams_are_consoles() { | ||
| // `$o = proofline ...` pipes stdout while stderr stays on the console. | ||
| assert!(!detachable(true, false, true)); | ||
| assert!(!detachable(true, true, false)); | ||
| assert!(!detachable(true, false, false)); | ||
| assert!(detachable(true, true, true)); | ||
| for (stdout, stderr) in [(false, false), (false, true), (true, false), (true, true)] { | ||
| assert!(detachable(false, stdout, stderr)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn an_invocation_that_cannot_detach_leaves_discovery_to_the_next_one() { | ||
| let directory = tempfile::tempdir().unwrap(); | ||
| let cache = directory.path().join("update.json"); | ||
|
prooflinedev[bot] marked this conversation as resolved.
Resolved
Comment on lines
+116
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · Deferral test misses due checks with a stale cache The deferral test passes A redirected run could launch discovery and refresh Seed a valid cache older than a day and assert that a non-detachable call neither launches discovery nor changes DetailsThe subprocess fixtures also start with empty caches; the integration test with a populated cache initializes it with the current timestamp, so the freshness check still prevents discovery under this regression. Also at:
|
||
| // `prepare_check` ignores launch errors, so only a panic proves no launch. | ||
| let notice = prepare_check(&cache, &["status".into()], false, false, || { | ||
| unreachable!("an invocation that cannot detach must not launch discovery") | ||
| }) | ||
| .unwrap(); | ||
| assert!(notice.is_none()); | ||
| // No attempt is recorded, so the next invocation that can detach still checks. | ||
| assert!(read_cache(&cache).is_err()); | ||
| let mut launched = false; | ||
| // Only `detach` decides: a redirected (non-interactive) run still checks. | ||
| prepare_check(&cache, &["status".into()], false, true, || { | ||
| launched = true; | ||
| Ok(()) | ||
| }) | ||
| .unwrap(); | ||
| assert!(launched); | ||
| assert!(read_cache(&cache).is_ok()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn discovery_rejects_bad_bounded_and_offline_responses() { | ||
| use axum::{Router, routing::get}; | ||
|
|
@@ -229,7 +264,10 @@ async fn detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocat | |
| .env(CACHE, &path) | ||
| .env(ADDRESS, address); | ||
| let notice = tokio::task::spawn_blocking(move || { | ||
| prepare_check(&path, &["status".into()], true, || spawn_check(worker)) | ||
| // Output is piped to the test, as under `$(...)` or a CI runner. | ||
| prepare_check(&path, &["status".into()], true, may_detach(), || { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · Captured-output test misses a broken Windows CLI detach gate The fixture calls The test still passes if the CLI always allows discovery, leaving redirected Windows callers vulnerable to waiting for the checker. Run the actual CLI with captured output and an empty update cache, then assert that no discovery attempt is recorded.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accepted. Added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marked fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still present at
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping this as is. This unit test calls prepare_check directly on purpose: it checks one rule ("only detach decides") and has to inject a fake launcher, which on_invocation cannot do. The gap this finding was about (nothing exercised the real on_invocation path) is covered by captured_windows_invocation_leaves_discovery_to_a_console_run in tests/update.rs, which runs the real binary. I checked it: with on_invocation changed on purpose to always allow the helper, that test fails (and the run takes 2.1 s, the bug itself).
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dismiss There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dismissed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dismissed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · The Windows fixture misses single-stream redirection regressions The fixture pipes both streams, so its Windows assertions still pass if Discovery could launch with one Windows output stream redirected without failing the test. Test both mixed terminal states and assert that neither permits discovery.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accepted, good catch: the common real case is mixed.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marked fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marked fixed. |
||
| spawn_check(worker) | ||
|
Comment on lines
266
to
+269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · The Windows fixture can miss a discovery launch The fixture checks for HTTP requests after the invocation exits, not whether its launcher ran. An unintended detached worker can pass the test if it records no attempt and hasn't reached the server when the counter is sampled. Record a synchronous marker in the fixture's launch callback and assert it was never called. |
||
| }) | ||
| }) | ||
| .await | ||
| .unwrap() | ||
|
|
@@ -297,6 +335,14 @@ async fn detached_discovery_is_serialized_and_notices_arrive_on_the_next_invocat | |
| .contains("run 'proofline update'") | ||
| ); | ||
| } | ||
| if cfg!(windows) { | ||
| // A Windows child would hold the piped output open, so these | ||
| // invocations neither start discovery nor record an attempt. | ||
| assert_eq!(received.load(Ordering::SeqCst), 0); | ||
| assert!(read_cache(&cache).is_err()); | ||
| server.abort(); | ||
| return; | ||
| } | ||
| tokio::time::timeout(Duration::from_secs(5), async { | ||
| while received.load(Ordering::SeqCst) == 0 { | ||
| tokio::time::sleep(Duration::from_millis(10)).await; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,25 @@ | |
| use std::process::Command; | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
|
||
| /// A Windows discovery child would inherit the captured output pipe and keep | ||
| /// the reader waiting, so a captured run with no cache records no attempt. | ||
| #[cfg(windows)] | ||
| #[test] | ||
| fn captured_windows_invocation_leaves_discovery_to_a_console_run() { | ||
| let directory = tempfile::tempdir().unwrap(); | ||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · CLI test misses discovery being disabled for every invocation The captured Windows test still passes if Background discovery could stop on all CLI invocations without this test failing. Add a real CLI test that starts with no cache, allows detachment, and asserts that an attempt is recorded. DetailsThe lock assertion catches skipping the scheduler, not passing the wrong policy. The helper tests and subprocess fixture bypass the production call site, and the other CLI test seeds a fresh cache. A person dismissed this finding earlier. It is posted again because it cites new evidence: |
||
| // `output()` pipes stdout and stderr, as `$(...)` or a CI step does. | ||
| let version = Command::new(env!("CARGO_BIN_EXE_proofline")) | ||
| .arg("--version") | ||
| .env_remove("PROOFLINE_NO_UPDATE_CHECK") | ||
| .env("LOCALAPPDATA", directory.path()) | ||
| .output() | ||
| .unwrap(); | ||
| assert!(version.status.success()); | ||
| // The lock proves the decision ran; the missing cache proves it said no. | ||
| assert!(directory.path().join("proofline/update.lock").exists()); | ||
| assert!(!directory.path().join("proofline/update.json").exists()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · Windows capture test passes even if version skips the updater The Windows test checks only that The test would miss a regression that bypasses the detach decision entirely. Also assert that
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accepted. "No update.json" alone cannot tell "decided not to start the helper" from "never decided", so the test now also asserts that update.lock exists (the lock is created before the decision). I checked it: with on_invocation made to skip --version on purpose, the old test passed and the new assertion fails; restored, it passes. Fixed in ac50182.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marked fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marked fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still present at
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping this as is: it is already covered. The test now asserts that update.lock exists, and main.rs calls update::on_invocation() before Cli::try_parse() (src/main.rs:13), so before clap handles --version and exits. I checked it: with on_invocation made to skip --version on purpose, the test fails on the update.lock assertion; restored, it passes.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dismiss There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dismissed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dismissed.
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning · Captured Windows test misses discovery being disabled for console runs The Windows CLI test only exercises piped output. If Due update checks could stop running for eligible console invocations without failing this test. Add a Windows console-backed CLI case that starts without a cache and asserts that A person dismissed this finding earlier. It is posted again because it cites new evidence: |
||
| } | ||
|
|
||
| #[test] | ||
| fn cached_update_preserves_schema_help_and_source_installation() { | ||
| let directory = tempfile::tempdir().unwrap(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning · Update docs omit Windows deferral when either output stream is redirected
The
on_invocationcomment says discovery continues in a child, but this change defers even due checks on Windows when either output stream is not a terminal.Readers may expect a redirected invocation to start a check that it actually skips.
Document that due checks run in a child only when detachment is allowed, and that Windows requires both output streams to be terminals.
View finding in Proofline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepted. The on_invocation comment now says a due check runs in a child only when may_detach allows it, and that on Windows both stdout and stderr must be consoles, so a redirected run leaves the check to a later one. Fixed in a301ee2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked fixed.