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
55 changes: 55 additions & 0 deletions crates/agentflare-shim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,58 @@ fn main() {
Err(_) => run_real(&tool, filtered_path.as_ref(), &args),
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::fs;

#[test]
fn finds_marker_in_start_dir() {
let tmp = std::env::temp_dir().join(format!("agentflare-shim-test-{}", std::process::id()));
fs::create_dir_all(&tmp).unwrap();
fs::write(tmp.join(PROJECT_MARKER), "").unwrap();
assert!(in_scoped_project(&tmp, None));
let _ = fs::remove_dir_all(&tmp);
}

#[test]
fn finds_marker_in_an_ancestor_dir() {
let tmp =
std::env::temp_dir().join(format!("agentflare-shim-test-anc-{}", std::process::id()));
let sub = tmp.join("a").join("b");
fs::create_dir_all(&sub).unwrap();
fs::write(tmp.join(PROJECT_MARKER), "").unwrap();
assert!(in_scoped_project(&sub, None));
let _ = fs::remove_dir_all(&tmp);
}

#[test]
fn stops_at_home_without_treating_agentflares_own_dir_as_a_project_marker() {
// ~/.agentflare is agentflare's own app-data dir, not a project
// marker -- walking past `home` (inclusive of home itself) must
// never false-positive on it. Regression for the bug the doc
// comment on `in_scoped_project` calls out.
let tmp =
std::env::temp_dir().join(format!("agentflare-shim-test-home-{}", std::process::id()));
let sub = tmp.join("sub");
fs::create_dir_all(&sub).unwrap();
fs::write(tmp.join(PROJECT_MARKER), "").unwrap();
assert!(!in_scoped_project(&sub, Some(&tmp)));
let _ = fs::remove_dir_all(&tmp);
}

#[test]
fn no_marker_anywhere_is_not_scoped() {
// Bound the walk-up with an explicit synthetic `home` one level
// above `tmp`, rather than `None` -- an unbounded walk from a real
// temp dir keeps climbing past this test's control (e.g. up into
// the real machine's actual `~/.agentflare`, giving a false pass/fail
// that has nothing to do with the logic under test).
let tmp =
std::env::temp_dir().join(format!("agentflare-shim-test-none-{}", std::process::id()));
fs::create_dir_all(&tmp).unwrap();
assert!(!in_scoped_project(&tmp, tmp.parent()));
let _ = fs::remove_dir_all(&tmp);
}
}
Loading