Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(cwd): keep override and reorg repo paths bounded
AkitaOnRails23c6ffce69e2
diff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rsindex b28db18d..aec1c93f 100644--- a/crates/ai-memory-cli/src/commands/serve.rs+++ b/crates/ai-memory-cli/src/commands/serve.rs@@ -297,6 +297,7 @@ pub async fn run(config: &Config, args: ServeArgs) -> Result<()> {data_dir: config.data_dir.clone(),db_path: store.db_path().to_path_buf(),bind: bind.clone(),+ home_dir: config.home_dir.clone(),bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: config.authdiff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rsindex b213dbd9..847db89f 100644--- a/crates/ai-memory-hooks/src/router.rs+++ b/crates/ai-memory-hooks/src/router.rs@@ -436,7 +436,8 @@ async fn resolve_project_ids(.to_string();let (project_name, repo_path) = match (project_override, cwd_norm.as_deref()) {- (Some(p), _) => (p.to_string(), cwd_norm.clone()),+ (Some(p), Some(c)) => (p.to_string(), repo_path_from_cwd(c)),+ (Some(p), None) => (p.to_string(), None),(None, Some(c)) => match derive_project_from_cwd(c, project_strategy) {Some(resolved) => resolved,None => {@@ -493,15 +494,18 @@ async fn resolve_project_ids(// (issue #103). A subdir cwd therefore stores None.ai_memory_consolidate::derive_project_name(path, strat).map(|(name, root)| {let repo_path = root- .or_else(|| {- let repo_root = ai_memory_consolidate::discover_repo_root(path).ok()?;- cwd_is_repo_root(path, &repo_root).then_some(repo_root)- })- .map(|p| p.to_string_lossy().into_owned());+ .map(|p| p.to_string_lossy().into_owned())+ .or_else(|| repo_path_from_cwd(cwd));(name, repo_path)})}+ fn repo_path_from_cwd(cwd: &str) -> Option<String> {+ let path = std::path::Path::new(cwd);+ let repo_root = ai_memory_consolidate::discover_repo_root(path).ok()?;+ cwd_is_repo_root(path, &repo_root).then(|| repo_root.to_string_lossy().into_owned())+ }+fn cwd_is_repo_root(cwd: &std::path::Path, repo_root: &std::path::Path) -> bool {// git2's workdir may carry a trailing separator and resolves symlinks;// canonicalize both before comparing. Fall back to a trailing-slash@@ -1526,6 +1530,55 @@ mod tests {);}+ /// Regression for the explicit project override path of #103: a marker or+ /// query override in a non-git ancestor must not persist that ancestor as a+ /// catch-all `repo_path`.+ #[tokio::test]+ async fn project_override_nongit_ancestor_does_not_become_repo_path_catch_all() {+ let tmp = TempDir::new().unwrap();+ let state = make_state(&tmp).await;++ let home = tmp.path().join("home");+ std::fs::create_dir_all(&home).unwrap();+ let (_ws_h, proj_home_override) = resolve_project_ids(+ &state,+ Some(home.to_str().unwrap()),+ None,+ Some("home-override"),+ ProjectStrategy::Basename,+ &ai_memory_core::ActorKey::default(),+ )+ .await+ .unwrap();++ let app = home.join("projects").join("app");+ init_repo_with_commit(&app);+ let (ws_app, proj_app) = resolve_project_ids(+ &state,+ Some(app.to_str().unwrap()),+ None,+ None,+ ProjectStrategy::Basename,+ &ai_memory_core::ActorKey::default(),+ )+ .await+ .unwrap();++ assert_ne!(+ proj_app, proj_home_override,+ "a non-git override cwd must not capture nested real repos via repo_path prefix"+ );+ assert_eq!(+ state+ .reader+ .find_project(ws_app, "app".to_string())+ .await+ .unwrap(),+ Some(proj_app),+ "nested repo cwd must resolve to its own 'app' project",+ );+ }+/// Under the default `Basename` strategy, the first hook fired from a/// repo *subdirectory* must store its repo_path as the subdir (or NULL),/// never the whole repo root. Storing the repo root would turn the leafdiff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rsindex b178cda6..8ff54778 100644--- a/crates/ai-memory-mcp/src/admin.rs+++ b/crates/ai-memory-mcp/src/admin.rs@@ -95,6 +95,9 @@ pub struct AdminState {pub db_path: PathBuf,/// Server's bind address — informational, surfaced in /admin/status.pub bind: String,+ /// Server home directory resolved once at config load. Used to keep admin+ /// audits consistent with the hook router's cwd-prefix guard.+ pub home_dir: Option<String>,/// Serialises concurrent bootstrap requests. Bootstrap fans out/// into an LLM call + a multi-page wiki write + a git commit;/// running two in parallel would race the `commit_all` git ops and@@ -545,7 +548,11 @@ async fn handle_audit_contamination(}_ => None,};- match state.reader.audit_contamination(scope).await {+ match state+ .reader+ .audit_contamination(scope, state.home_dir.as_deref())+ .await+ {Ok(report) => (StatusCode::OK,Json(serde_json::to_value(&report).unwrap_or_else(|_| serde_json::json!({}))),@@ -1794,7 +1801,7 @@ async fn build_reorg_plan(.unwrap_or_else(|| "unknown".to_string());let proj = state.writer- .get_or_create_project(ws, project_name.clone(), Some(cwd.clone()))+ .get_or_create_project(ws, project_name.clone(), repo_path_from_reorg_cwd(cwd)).await?;cwd_to_proj.insert(cwd.clone(), (ws, proj, project_name));}@@ -1821,6 +1828,20 @@ async fn build_reorg_plan(Ok((plan_entries, writer_plan, distinct_new_projects.len()))}+fn repo_path_from_reorg_cwd(cwd: &str) -> Option<String> {+ let path = std::path::Path::new(cwd);+ let repo_root = ai_memory_consolidate::discover_repo_root(path).ok()?;+ cwd_is_repo_root(path, &repo_root).then(|| repo_root.to_string_lossy().into_owned())+}++fn cwd_is_repo_root(cwd: &std::path::Path, repo_root: &std::path::Path) -> bool {+ if let (Ok(a), Ok(b)) = (std::fs::canonicalize(cwd), std::fs::canonicalize(repo_root)) {+ return a == b;+ }+ let strip = |p: &std::path::Path| p.to_string_lossy().trim_end_matches('/').to_string();+ strip(cwd) == strip(repo_root)+}+async fn handle_reorg(State(state): State<Arc<AdminState>>,Json(req): Json<ReorgRequest>,@@ -4251,6 +4272,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -4292,6 +4314,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -4322,6 +4345,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -5271,6 +5295,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -5377,6 +5402,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -5476,6 +5502,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -5581,6 +5608,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -5665,6 +5693,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: Some(pepper),active_project: ai_memory_core::ActiveProject::new(),@@ -6168,6 +6197,7 @@ mod tests {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_backup.rs b/crates/ai-memory-mcp/tests/admin_backup.rsindex 284b1601..09606441 100644--- a/crates/ai-memory-mcp/tests/admin_backup.rs+++ b/crates/ai-memory-mcp/tests/admin_backup.rs@@ -35,6 +35,7 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_bootstrap.rs b/crates/ai-memory-mcp/tests/admin_bootstrap.rsindex 8c092b07..fa263571 100644--- a/crates/ai-memory-mcp/tests/admin_bootstrap.rs+++ b/crates/ai-memory-mcp/tests/admin_bootstrap.rs@@ -32,6 +32,7 @@ async fn make_admin_state(tmp: &TempDir) -> AdminState {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_move.rs b/crates/ai-memory-mcp/tests/admin_move.rsindex 20457e98..9cfd0028 100644--- a/crates/ai-memory-mcp/tests/admin_move.rs+++ b/crates/ai-memory-mcp/tests/admin_move.rs@@ -48,6 +48,7 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -401,6 +402,7 @@ async fn move_project_carries_source_embedding() {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -683,6 +685,7 @@ async fn true_move_notifies_admission_with_destination_names() {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -735,6 +738,7 @@ async fn make_state_with_embedder(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -886,6 +890,7 @@ fn build_state(store: &Store, tmp: &TempDir) -> AdminState {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -1380,6 +1385,7 @@ async fn true_move_aborts_when_admission_rejects() {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -1473,6 +1479,7 @@ async fn copy_purge_purge_admission_runs_before_db_destruction() {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_phase3.rs b/crates/ai-memory-mcp/tests/admin_phase3.rsindex 96440026..90742cd2 100644--- a/crates/ai-memory-mcp/tests/admin_phase3.rs+++ b/crates/ai-memory-mcp/tests/admin_phase3.rs@@ -43,6 +43,7 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -203,6 +204,28 @@ async fn reorg_live_moves_sessions() {assert!(!body["dry_run"].as_bool().unwrap());}+#[tokio::test]+async fn reorg_does_not_store_nongit_cwd_as_repo_path() {+ let tmp = TempDir::new().unwrap();+ let (state, store) = make_state(&tmp).await;+ seed_sessions_for_reorg(&store).await;++ let resp = post(state, "/admin/reorg", json!({ "dry_run": false })).await;+ assert_eq!(resp.status(), StatusCode::OK);++ let scopes = store.reader.list_all_scopes().await.unwrap();+ for project_name in ["alpha-repo", "beta-repo"] {+ let scope = scopes+ .iter()+ .find(|s| s.workspace_name == "default" && s.project_name == project_name)+ .unwrap_or_else(|| panic!("missing reorg-created project {project_name}"));+ assert_eq!(+ scope.repo_path, None,+ "admin reorg must not turn non-git cwd into catch-all repo_path for {project_name}"+ );+ }+}+#[tokio::test]async fn reorg_live_graveyards_only_default_workspace_pages() {let tmp = TempDir::new().unwrap();diff --git a/crates/ai-memory-mcp/tests/admin_purge.rs b/crates/ai-memory-mcp/tests/admin_purge.rsindex d90ab052..6d771ff3 100644--- a/crates/ai-memory-mcp/tests/admin_purge.rs+++ b/crates/ai-memory-mcp/tests/admin_purge.rs@@ -40,6 +40,7 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {decay_params: DecayParams::default(),data_dir: tmp.path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -346,6 +347,7 @@ async fn purge_project_rejecting_admission_leaves_source_intact() {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -445,6 +447,7 @@ async fn purge_project_idempotent_second_call_is_404() {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_read_page.rs b/crates/ai-memory-mcp/tests/admin_read_page.rsindex d57f1e3b..e8b0f633 100644--- a/crates/ai-memory-mcp/tests/admin_read_page.rs+++ b/crates/ai-memory-mcp/tests/admin_read_page.rs@@ -28,6 +28,7 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_rename.rs b/crates/ai-memory-mcp/tests/admin_rename.rsindex 3e89e903..3c4ca076 100644--- a/crates/ai-memory-mcp/tests/admin_rename.rs+++ b/crates/ai-memory-mcp/tests/admin_rename.rs@@ -34,6 +34,7 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -320,6 +321,7 @@ async fn rename_project_pages_still_searchable() {data_dir: tmp.path().to_path_buf(),db_path: store.db_path().to_path_buf(),bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),@@ -390,6 +392,7 @@ async fn rename_project_after_purge_returns_404_not_silent_200() {data_dir: state.data_dir.clone(),db_path: state.db_path.clone(),bind: state.bind.clone(),+ home_dir: None,bootstrap_lock: state.bootstrap_lock.clone(),token_pepper: None,active_project: state.active_project.clone(),diff --git a/crates/ai-memory-mcp/tests/admin_status_search.rs b/crates/ai-memory-mcp/tests/admin_status_search.rsindex 9007e679..8f23ad67 100644--- a/crates/ai-memory-mcp/tests/admin_status_search.rs+++ b/crates/ai-memory-mcp/tests/admin_status_search.rs@@ -29,6 +29,7 @@ async fn make_admin_state(tmp: &TempDir) -> (AdminState, Store) {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:49374".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-mcp/tests/admin_write_page.rs b/crates/ai-memory-mcp/tests/admin_write_page.rsindex 1b976660..d3b5519f 100644--- a/crates/ai-memory-mcp/tests/admin_write_page.rs+++ b/crates/ai-memory-mcp/tests/admin_write_page.rs@@ -29,6 +29,7 @@ async fn make_state(tmp: &TempDir) -> AdminState {data_dir: tmp.path().to_path_buf(),db_path,bind: "127.0.0.1:0".to_string(),+ home_dir: None,bootstrap_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),token_pepper: None,active_project: ai_memory_core::ActiveProject::new(),diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rsindex 38010f63..eaf20556 100644--- a/crates/ai-memory-store/src/reader.rs+++ b/crates/ai-memory-store/src/reader.rs@@ -3358,8 +3358,10 @@ impl ReaderPool {pub async fn audit_contamination(&self,scope: Option<(WorkspaceId, ProjectId)>,+ home: Option<&str>,) -> StoreResult<ContaminationReport> {let scoped = scope.is_some();+ let home = home.map(str::to_owned);let scope_params: Vec<Value> = match &scope {Some((ws, proj)) => vec![Value::Blob(ws.as_bytes().to_vec()),@@ -3487,6 +3489,9 @@ impl ReaderPool {})?;for r in rows {let (ws_b, proj_b, name, repo_path) = r?;+ if home.as_deref() == Some(repo_path.as_str()) {+ continue;+ }prefixes.push((WorkspaceId::from_slice(&ws_b)?,ProjectId::from_slice(&proj_b)?,@@ -3505,6 +3510,9 @@ impl ReaderPool {})?;for r in rows {let (ws_b, proj_b, name, repo_path) = r?;+ if home.as_deref() == Some(repo_path.as_str()) {+ continue;+ }prefixes.push((WorkspaceId::from_slice(&ws_b)?,ProjectId::from_slice(&proj_b)?,diff --git a/crates/ai-memory-store/tests/audit_contamination.rs b/crates/ai-memory-store/tests/audit_contamination.rsindex f5297521..9d616f8b 100644--- a/crates/ai-memory-store/tests/audit_contamination.rs+++ b/crates/ai-memory-store/tests/audit_contamination.rs@@ -75,7 +75,7 @@ async fn audit_flags_wrong_bucket_session_and_drifted_observation() {let store = Store::open(tmp.path()).unwrap();seed(store.db_path());- let report = store.reader.audit_contamination(None).await.unwrap();+ let report = store.reader.audit_contamination(None, None).await.unwrap();assert_eq!(report.summary.sessions_misbucketed, 1,@@ -134,12 +134,60 @@ async fn audit_clean_db_returns_no_findings() {.unwrap();drop(conn);- let report = store.reader.audit_contamination(None).await.unwrap();+ let report = store.reader.audit_contamination(None, None).await.unwrap();assert_eq!(report.summary.sessions_misbucketed, 0);assert_eq!(report.summary.observations_drifted, 0);assert!(report.findings.is_empty());}+#[tokio::test]+async fn audit_ignores_home_repo_path_when_home_is_provided() {+ let tmp = tempfile::tempdir().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let conn = Connection::open(store.db_path()).unwrap();+ let now = 1_700_000_000_000_i64;+ let (ws, home_proj, app_proj, session) = (id(1), id(2), id(3), id(4));++ conn.execute(+ "INSERT INTO workspaces (id, name, created_at) VALUES (?1, 'w', ?2)",+ params![&ws[..], now],+ )+ .unwrap();+ conn.execute(+ "INSERT INTO projects (id, workspace_id, name, repo_path, created_at) \+ VALUES (?1, ?2, 'home', '/home/tester', ?3)",+ params![&home_proj[..], &ws[..], now],+ )+ .unwrap();+ conn.execute(+ "INSERT INTO projects (id, workspace_id, name, repo_path, created_at) \+ VALUES (?1, ?2, 'app', NULL, ?3)",+ params![&app_proj[..], &ws[..], now],+ )+ .unwrap();+ conn.execute(+ "INSERT INTO sessions (id, workspace_id, project_id, agent_kind, cwd, started_at) \+ VALUES (?1, ?2, ?3, 'claude-code', '/home/tester/projects/app', ?4)",+ params![&session[..], &ws[..], &app_proj[..], now],+ )+ .unwrap();+ drop(conn);++ let without_home = store.reader.audit_contamination(None, None).await.unwrap();+ assert_eq!(+ without_home.summary.sessions_misbucketed, 1,+ "without the home guard, the home repo_path looks like the expected project"+ );++ let with_home = store+ .reader+ .audit_contamination(None, Some("/home/tester"))+ .await+ .unwrap();+ assert_eq!(with_home.summary.sessions_misbucketed, 0);+ assert!(with_home.findings.is_empty());+}+#[tokio::test]async fn audit_scope_restricts_to_landed_bucket() {let tmp = tempfile::tempdir().unwrap();@@ -153,7 +201,7 @@ async fn audit_scope_restricts_to_landed_bucket() {WorkspaceId::from_slice(&ws).unwrap(),ProjectId::from_slice(&a).unwrap(),));- let report = store.reader.audit_contamination(scope).await.unwrap();+ let report = store.reader.audit_contamination(scope, None).await.unwrap();assert_eq!(report.summary.sessions_misbucketed, 1);assert_eq!(report.summary.observations_drifted, 0,