Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-windows-cleanup-test-flake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
harnx: patch
---

Fix a Windows CI flake in the `harnx-mcp-plans` cleanup test. `cleanup_deletes_stale_plan_but_keeps_fresh_plan` relied on millisecond-scale sleeps finer than Windows filesystem timestamp resolution, causing the fresh plan to be deleted too. The test now sets the stale plan's mtime explicitly via `filetime` and uses a generous retention margin, making it deterministic across platforms.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/harnx-mcp-plans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ tower = { workspace = true }
schemars = { workspace = true }
similar = { workspace = true }

[dev-dependencies]
filetime = "0.2"

[[bin]]
name = "harnx-mcp-plans"
path = "src/main.rs"
16 changes: 13 additions & 3 deletions crates/harnx-mcp-plans/src/server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,17 +2025,27 @@ async fn delete_note_wrong_plan_fails() {

#[tokio::test]
async fn cleanup_deletes_stale_plan_but_keeps_fresh_plan() {
use filetime::set_file_mtime;
use std::time::SystemTime;

let dir = temp_test_dir("cleanup-stale-plan");
let stale_plan = dir.join("stale-plan");
let fresh_plan = dir.join("fresh-plan");

// Create stale plan with mtime far in the past
fs::create_dir_all(&stale_plan).unwrap();
fs::write(stale_plan.join("plan.md"), "stale").unwrap();
tokio::time::sleep(Duration::from_millis(25)).await;
let stale_plan_md = stale_plan.join("plan.md");
fs::write(&stale_plan_md, "stale").unwrap();
let stale_time =
filetime::FileTime::from_system_time(SystemTime::now() - Duration::from_secs(3600));
set_file_mtime(&stale_plan_md, stale_time).unwrap();

// Create fresh plan with mtime ~now
fs::create_dir_all(&fresh_plan).unwrap();
fs::write(fresh_plan.join("plan.md"), "fresh").unwrap();

run_cleanup_pass(&dir, Duration::from_millis(10)).await;
// Retention of 60s: stale (hour old) should be deleted, fresh should be kept
run_cleanup_pass(&dir, Duration::from_secs(60)).await;

assert!(!stale_plan.exists(), "stale plan should be deleted");
assert!(fresh_plan.exists(), "fresh plan should be kept");
Expand Down
Loading