From b5b8d46f8a88a8d57ab180bd08c35477e4048d9a Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Wed, 12 Aug 2026 00:52:01 +0800 Subject: [PATCH] test(ssh-config): let the second write to an included file be seen as one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `an_alias_added_to_an_included_file_is_seen_without_touching_the_root` failed on every Windows run of this branch and had passed on main by a margin the branch happened to spend elsewhere. The cache keys on mtime, the test writes `conf.d/work` twice back to back, and Windows stamps files from a clock that ticks about every 15ms — so both writes can land on one mtime, and the cache is then correct to say nothing changed. Nothing in the product depends on resolving edits that close: the poll behind this runs at 4Hz and a real edit arrives at human speed. It is the test that is too fast, so the second write now says when it happened rather than sleeping out the tick. --- src/core/ssh_config.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/ssh_config.rs b/src/core/ssh_config.rs index 36756010..c98b452f 100644 --- a/src/core/ssh_config.rs +++ b/src/core/ssh_config.rs @@ -1423,6 +1423,7 @@ mod tests { ); std::fs::write(ssh.join("conf.d/work"), "Host work\n").unwrap(); + edited_just_now(&ssh.join("conf.d/work")); assert!( cache.resolves(&cfg, &root, "work"), "an alias put back in an included file is found again, \ @@ -1430,6 +1431,21 @@ mod tests { ); } + /// Make a write that has just happened look like one, on a filesystem + /// whose clock is coarser than this test is fast. + /// + /// Windows stamps files from a clock that ticks about every 15ms, so two + /// writes as close together as the ones above can share an mtime — and a + /// cache keyed on mtime is then right to say nothing changed. A real edit + /// arrives at human speed, and the poll behind this cache runs at 4Hz, so + /// the collision is an artefact of the test rather than something a user + /// can reach. Stated by hand instead of slept out. + fn edited_just_now(path: &Path) { + let f = std::fs::File::options().write(true).open(path).unwrap(); + let ahead = std::time::SystemTime::now() + std::time::Duration::from_secs(1); + f.set_modified(ahead).unwrap(); + } + fn temp_root(name: &str) -> PathBuf { let dir = std::env::temp_dir().join(format!( "tty7-ssh-config-test-{name}-{}",