Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test: respect local tool availability in integration fixtures

Paulo Vitor Martinsccb6c3c9e1dc
diff --git a/crates/ai-memory-cli/tests/suite/packaging.rs b/crates/ai-memory-cli/tests/suite/packaging.rs
index b5d44ac2..6a11686f 100644
--- a/crates/ai-memory-cli/tests/suite/packaging.rs
+++ b/crates/ai-memory-cli/tests/suite/packaging.rs
@@ -1313,14 +1313,49 @@ fn skip_pre_push_tests<T>(reason: &str) -> Option<T> {
fn resolve_in_path(path: &std::ffi::OsStr, tool: &str) -> Option<PathBuf> {
std::env::split_paths(path).find_map(|dir| {
let bare = dir.join(tool);
- if bare.is_file() {
+ if is_executable_candidate(&bare) {
return Some(bare);
}
let exe = dir.join(format!("{tool}.exe"));
- exe.is_file().then_some(exe)
+ is_executable_candidate(&exe).then_some(exe)
})
}
+#[cfg(any(unix, windows))]
+fn is_executable_candidate(path: &Path) -> bool {
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt as _;
+ std::fs::metadata(path)
+ .is_ok_and(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
+ }
+ #[cfg(windows)]
+ {
+ path.is_file()
+ }
+}
+
+#[test]
+#[cfg(unix)]
+fn pre_push_fixture_path_skips_non_executable_shadows() {
+ use std::os::unix::fs::PermissionsExt as _;
+
+ let temp = tempfile::TempDir::new().unwrap();
+ let shadow_dir = temp.path().join("shadow");
+ let executable_dir = temp.path().join("executable");
+ std::fs::create_dir(&shadow_dir).unwrap();
+ std::fs::create_dir(&executable_dir).unwrap();
+ let shadow = shadow_dir.join("env");
+ std::fs::write(&shadow, "not executable").unwrap();
+ std::fs::set_permissions(&shadow, std::fs::Permissions::from_mode(0o644)).unwrap();
+ let executable = executable_dir.join("env");
+ std::fs::write(&executable, "#!/bin/sh\nexit 0\n").unwrap();
+ std::fs::set_permissions(&executable, std::fs::Permissions::from_mode(0o755)).unwrap();
+ let path = std::env::join_paths([shadow_dir.as_os_str(), executable_dir.as_os_str()]).unwrap();
+
+ assert_eq!(resolve_in_path(&path, "env"), Some(executable));
+}
+
/// macOS hands back `/var/folders/...` while Git reports `/private/var/...`.
/// Windows canonicalization yields a `\\?\` verbatim path that Git Bash cannot
/// use, so leave it alone there.
@@ -1390,7 +1425,7 @@ fn fixture_path(bin: &Path) -> Option<std::ffi::OsString> {
let Some(real) = dirs
.iter()
.map(|dir| dir.join(tool))
- .find(|candidate| candidate.is_file())
+ .find(|candidate| is_executable_candidate(candidate))
else {
return skip_pre_push_tests(&format!("{tool} was not found on PATH"));
};
diff --git a/crates/ai-memory-cli/tests/suite/yolo_ai_jail.rs b/crates/ai-memory-cli/tests/suite/yolo_ai_jail.rs
index 43ce97e4..648a03ad 100644
--- a/crates/ai-memory-cli/tests/suite/yolo_ai_jail.rs
+++ b/crates/ai-memory-cli/tests/suite/yolo_ai_jail.rs
@@ -111,10 +111,13 @@ fn real_dry_run(
eprintln!("skipping: ai-jail is not usable here (absent, no sandbox backend, or Windows)");
return None;
};
+ let support = ai_jail_support(&ai_jail).expect("ai-jail --help");
+ if !support.supports("network") {
+ eprintln!("skipping: installed ai-jail does not support the required --network flag");
+ return None;
+ }
let exe = std::env::current_exe().expect("test binary path");
- let no_save_config = ai_jail_support(&ai_jail)
- .expect("ai-jail --help")
- .supports("no-save-config");
+ let no_save_config = support.supports("no-save-config");
let argv = build_ai_jail_invocation(
&exe,
forwarded,