Skip to content
Merged
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
85 changes: 85 additions & 0 deletions crates/cortexkit-store-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,43 @@ mod resolver_tests {
#[test]
fn module_store_path_defaults_to_home_local_share() {
let _g = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
#[cfg(windows)]
let appdata = std::env::var_os("APPDATA");
#[cfg(windows)]
let userprofile = std::env::var_os("USERPROFILE");
std::env::remove_var("XDG_DATA_HOME");
#[cfg(windows)]
{
std::env::remove_var("APPDATA");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: On Windows these tests now reach the HOME tier (the new APPDATA/USERPROFILE removal forces it), but they still assert forward-slash paths like "/tmp/home-test/.local/share/...". On Windows the resolver's HOME branch does PathBuf::from(home).join(".local").join("share"), and PathBuf joins use the platform separator \. The crate's own golden fixture pins this: windows_empty_appdata_userprofile_falls_to_homeC:/golden-home\.local\\share. So on Windows module_store_path returns a string containing a backslash-joined .local\share component (e.g. \tmp\home-test\.local\share/cortexkit/...), which never equals the asserted forward-slash string — the asserted changed tests (module_store_path_defaults_to_home_local_share and empty_env_values_count_as_unset) will still fail on Windows CI. The fix needs to assert a Windows-aware expected string (or gate the forward-slash expectation off Windows) to match the golden/daemon contract.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/cortexkit-store-types/src/lib.rs, line 340:

<comment>On Windows these tests now reach the HOME tier (the new APPDATA/USERPROFILE removal forces it), but they still assert forward-slash paths like "/tmp/home-test/.local/share/...". On Windows the resolver's HOME branch does `PathBuf::from(home).join(".local").join("share")`, and PathBuf joins use the platform separator `\`. The crate's own golden fixture pins this: `windows_empty_appdata_userprofile_falls_to_home` → `C:/golden-home\.local\\share`. So on Windows `module_store_path` returns a string containing a backslash-joined `.local\share` component (e.g. `\tmp\home-test\.local\share/cortexkit/...`), which never equals the asserted forward-slash string — the asserted changed tests (`module_store_path_defaults_to_home_local_share` and `empty_env_values_count_as_unset`) will still fail on Windows CI. The fix needs to assert a Windows-aware expected string (or gate the forward-slash expectation off Windows) to match the golden/daemon contract.</comment>

<file context>
@@ -330,9 +330,29 @@ mod resolver_tests {
         std::env::remove_var("XDG_DATA_HOME");
+        #[cfg(windows)]
+        {
+            std::env::remove_var("APPDATA");
+            std::env::remove_var("USERPROFILE");
+        }
</file context>

std::env::remove_var("USERPROFILE");
}
std::env::set_var("HOME", "/tmp/home-test");
let got = module_store_path("astrocyte");
#[cfg(windows)]
{
match appdata {
Some(value) => std::env::set_var("APPDATA", value),
None => std::env::remove_var("APPDATA"),
}
match userprofile {
Some(value) => std::env::set_var("USERPROFILE", value),
None => std::env::remove_var("USERPROFILE"),
}
}
#[cfg(not(windows))]
assert_eq!(
got,
"/tmp/home-test/.local/share/cortexkit/astrocyte/store.db"
);
#[cfg(windows)]
{
// PathBuf joins the data-home tier while module paths retain the
// daemon's forward slashes, so this mixed form is byte-identical.
assert_eq!(
got,
"/tmp/home-test\\.local\\share/cortexkit/astrocyte/store.db"
);
}
}

#[test]
Expand All @@ -360,11 +390,66 @@ mod resolver_tests {
// Mirrors the daemon's non_empty_os_var: an empty XDG_DATA_HOME falls
// through to the next rule rather than resolving an empty data home.
let _g = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
#[cfg(windows)]
let appdata = std::env::var_os("APPDATA");
#[cfg(windows)]
let userprofile = std::env::var_os("USERPROFILE");
std::env::set_var("XDG_DATA_HOME", "");
#[cfg(windows)]
{
std::env::remove_var("APPDATA");
std::env::remove_var("USERPROFILE");
}
std::env::set_var("HOME", "/tmp/home-test");
let got = module_store_path("m");
std::env::remove_var("XDG_DATA_HOME");
#[cfg(windows)]
{
match appdata {
Some(value) => std::env::set_var("APPDATA", value),
None => std::env::remove_var("APPDATA"),
}
match userprofile {
Some(value) => std::env::set_var("USERPROFILE", value),
None => std::env::remove_var("USERPROFILE"),
}
}
#[cfg(not(windows))]
assert_eq!(got, "/tmp/home-test/.local/share/cortexkit/m/store.db");
#[cfg(windows)]
{
// PathBuf joins the data-home tier while module paths retain the
// daemon's forward slashes, so this mixed form is byte-identical.
assert_eq!(got, "/tmp/home-test\\.local\\share/cortexkit/m/store.db");
}
}

#[cfg(windows)]
#[test]
fn module_store_path_prefers_appdata_over_home() {
// APPDATA is a resolver tier only on Windows, so its coverage must be
// platform-gated too.
let _g = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
let xdg_data_home = std::env::var_os("XDG_DATA_HOME");
let appdata = std::env::var_os("APPDATA");
let home = std::env::var_os("HOME");
std::env::remove_var("XDG_DATA_HOME");
std::env::set_var("APPDATA", "C:\\tmp\\appdata-test");
std::env::set_var("HOME", "/tmp/home-test");
let got = module_store_path("astrocyte");
match xdg_data_home {
Some(value) => std::env::set_var("XDG_DATA_HOME", value),
None => std::env::remove_var("XDG_DATA_HOME"),
}
match appdata {
Some(value) => std::env::set_var("APPDATA", value),
None => std::env::remove_var("APPDATA"),
}
match home {
Some(value) => std::env::set_var("HOME", value),
None => std::env::remove_var("HOME"),
}
assert_eq!(got, "C:\\tmp\\appdata-test/cortexkit/astrocyte/store.db");
}

#[test]
Expand Down