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
14 changes: 7 additions & 7 deletions pkgs/atlas-search/crates/atlas-core/src/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ impl JsonlFeedbackSink {
&self.dir
}

/// `~/.local/state/atlas-search/feedback` — the same state
/// root as the trace sink and the service config.
/// `~/.local/state/atlas-search/feedback` - the same state
/// root as the trace sink and the service config. Resolved
/// through the crate's home-resolution contract (issues
/// #5640 / #5762): a missing or empty HOME fails loudly
/// naming HOME, never a CWD-relative substitute
/// (issue #13279).
pub fn default_dir() -> PathBuf {
let home = std::env::var_os("HOME")
.filter(|h| !h.is_empty())
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("."));
home.join(".local/state/atlas-search/feedback")
crate::require_home().join(".local/state/atlas-search/feedback")
}
}

Expand Down
49 changes: 49 additions & 0 deletions pkgs/atlas-search/crates/atlas-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,52 @@ pub use trace_stats::{
};
pub use turso::TursoBackend;
pub use types::{BranchQuery, DEFAULT_MODEL, DEFAULT_VEC_TABLE, VectorBackend};

// ------------------------------------------------------------- home ----

/// Home-resolution contract (issues #5640 / #5762): a missing or
/// empty HOME is an error naming HOME, never a substitute
/// directory. Every atlas-core path rooted at the user's home goes
/// through here so the contract cannot drift per call site - the
/// trace and feedback sinks' `default_dir` once fell back to the
/// CWD (issue #13279), landing state files wherever the process
/// happened to run.
pub(crate) fn require_home() -> std::path::PathBuf {
home_from(std::env::var_os("HOME"))
}

fn home_from(home: Option<std::ffi::OsString>) -> std::path::PathBuf {
match home {
Some(home) if !home.is_empty() => std::path::PathBuf::from(home),
_ => panic!(
"HOME is not set or is empty: atlas-core requires a non-empty HOME to resolve its state/config paths (issue #5640)"
),
}
}

#[cfg(test)]
mod home_tests {
use super::home_from;
use std::ffi::OsString;
use std::path::PathBuf;

#[test]
fn home_from_accepts_a_non_empty_home() {
assert_eq!(
home_from(Some(OsString::from("/home/someone"))),
PathBuf::from("/home/someone")
);
}

#[test]
#[should_panic(expected = "HOME is not set or is empty")]
fn home_from_rejects_a_missing_home() {
home_from(None);
}

#[test]
#[should_panic(expected = "HOME is not set or is empty")]
fn home_from_rejects_an_empty_home() {
home_from(Some(OsString::new()));
}
}
13 changes: 6 additions & 7 deletions pkgs/atlas-search/crates/atlas-core/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ impl JsonlTraceSink {
JsonlTraceSink { dir }
}

/// `~/.local/state/atlas-search/traces` — the same state root
/// as the service config and model store.
/// `~/.local/state/atlas-search/traces` - the same state root
/// as the service config and model store. Resolved through
/// the crate's home-resolution contract (issues #5640 /
/// #5762): a missing or empty HOME fails loudly naming HOME,
/// never a CWD-relative substitute (issue #13279).
pub fn default_dir() -> PathBuf {
let home = std::env::var_os("HOME")
.filter(|h| !h.is_empty())
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("."));
home.join(".local/state/atlas-search/traces")
crate::require_home().join(".local/state/atlas-search/traces")
}
}

Expand Down