fix(truncate): Windows test fixes — path components + cfg(unix) on mtime test

CI surfaced two Windows-only failures in `tools::truncate::tests`:

1. `write_spillover_creates_directory_and_writes_file` asserted
   `path.to_string_lossy().contains(".deepseek/tool_outputs")`. On
   Windows the path separator is `\`, so the substring match never
   matched even though the file lived in the correct directory.
   Replace with a `path.components()` walk that checks for the two
   directory names individually — passes on Windows, Linux, and macOS.

2. `prune_older_than_keeps_fresh_files_drops_stale_ones` relied on
   `filetime_set_modified` to backdate a file by 30 days. The helper
   is implemented with `utimensat` on Unix and is a no-op on Windows,
   which means the prune step had no stale file to drop and the
   `assert_eq!(pruned, 1)` always failed. The mtime invariant is
   already covered by Linux + macOS in CI; gate the test on
   `cfg(unix)` rather than ship a no-op Windows variant that can't
   fail meaningfully.

Restores PR #519 CI to green so the v0.8.8 release can land.
This commit is contained in:
Hunter Bown
2026-05-03 08:37:53 -05:00
parent bda30b0fd6
commit 6a2d95ba3d
+16 -1
View File
@@ -337,7 +337,17 @@ mod tests {
let body = fs::read_to_string(&path).unwrap();
assert_eq!(body, "hello world");
// Directory landed under `<HOME>/.deepseek/tool_outputs/`.
assert!(path.to_string_lossy().contains(".deepseek/tool_outputs"));
// Compare components instead of a substring on `to_string_lossy`
// — Windows uses `\` as the separator so a `/` substring match
// would falsely fail there.
let components: Vec<&str> = path
.components()
.filter_map(|c| c.as_os_str().to_str())
.collect();
assert!(
components.contains(&".deepseek") && components.contains(&"tool_outputs"),
"spillover path missing expected `.deepseek/tool_outputs/...` segments: {path:?}"
);
});
}
@@ -412,7 +422,12 @@ mod tests {
});
}
// The mtime backdate uses utimensat (Unix-only). On Windows the
// filetime_set_modified helper is a no-op, so the prune wouldn't see
// any stale files. Gate the whole test on `cfg(unix)` instead of
// testing a no-op path that can't fail meaningfully.
#[test]
#[cfg(unix)]
fn prune_older_than_keeps_fresh_files_drops_stale_ones() {
let _g = setup();
let tmp = tempdir().unwrap();