From 6b0490cc01c59616ebe13e81589d6d258835f81e Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 6 Dec 2026 10:30:17 +0800 Subject: [PATCH] test: make the Copilot home and Python rearrange tests pass on Windows (#8321) The Copilot home test built an absolute path from /home/test, which has no drive on Windows; it now uses a temp directory. The rearrange test rewrote the file with same-length text inside one mtime tick, which the background scan skips; it now moves the mtime forward. --- crates/ide-agent/src/native/copilot/tests.rs | 4 +++- crates/ide-host/src/ops/doc/tests.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/ide-agent/src/native/copilot/tests.rs b/crates/ide-agent/src/native/copilot/tests.rs index 1ddd1fd70c..7fb164354c 100644 --- a/crates/ide-agent/src/native/copilot/tests.rs +++ b/crates/ide-agent/src/native/copilot/tests.rs @@ -117,7 +117,9 @@ fn sample_price_units() -> Value { #[test] fn resolves_copilot_home_from_agent_env_or_user_home() { - let home = std::path::Path::new("/home/test"); + // Absolute on every platform: `/home/test` has no drive on Windows. + let home_dir = std::env::temp_dir().join("copilot-home-test"); + let home = home_dir.as_path(); assert_eq!( super::config_dir(&[("COPILOT_HOME".into(), "/custom/copilot".into())], Some(home)).as_deref(), Some(std::path::Path::new("/custom/copilot")) diff --git a/crates/ide-host/src/ops/doc/tests.rs b/crates/ide-host/src/ops/doc/tests.rs index 1b861cc091..d6d6e9b86f 100644 --- a/crates/ide-host/src/ops/doc/tests.rs +++ b/crates/ide-host/src/ops/doc/tests.rs @@ -338,10 +338,17 @@ async fn rearrange_returns_utf16_edits_that_put_methods_in_order() { "class Board:\n def __init__(self):\n self.名前 = 1 # 初始化\n\n def 移动(self):\n return '→'\n" ); // Already in order, or broken: nothing to do. - std::fs::write(&path, rearranged.text()).unwrap(); + // The reordered text has the original's length: move the mtime, or a scan that lands in the + // same timestamp tick (common on Windows) keeps the old buffer. + let write_later = |text: &str, secs: u64| { + std::fs::write(&path, text).unwrap(); + let file = std::fs::File::options().write(true).open(&path).unwrap(); + file.set_modified(std::time::SystemTime::now() + std::time::Duration::from_secs(secs)).unwrap(); + }; + write_later(&rearranged.text(), 2); f.sync().await; assert!(doc_rearrange(&f.host, "main", doc).await.unwrap().is_empty()); - std::fs::write(&path, "class A:\n def b(self\n def __init__(self): ...\n").unwrap(); + write_later("class A:\n def b(self\n def __init__(self): ...\n", 4); f.sync().await; assert!(doc_rearrange(&f.host, "main", doc).await.unwrap().is_empty()); }