use pretty_assertions::assert_eq;
use super::*;
#[cfg(unix)]
#[test]
fn harness_pin_follows_the_canonical_server() {
let install = tempfile::tempdir().unwrap();
let server = install.path().join(ANTIGRAVITY_PROGRAM);
std::fs::write(&server, "").unwrap();
let links = tempfile::tempdir().unwrap();
let link = links.path().join(ANTIGRAVITY_PROGRAM);
std::os::unix::fs::symlink(&server, &link).unwrap();
assert_eq!(harness_env(Some(&link), None), vec![]);
std::fs::write(install.path().join(HARNESS_FILE), "").unwrap();
let harness = std::fs::canonicalize(install.path())
.unwrap()
.join(HARNESS_FILE);
assert_eq!(
harness_env(Some(&link), None),
vec![(OsString::from(HARNESS_PATH_ENV), harness.into_os_string())]
);
assert_eq!(
harness_env(Some(&link), Some(OsString::from("/custom/harness"))),
vec![]
);
}
#[cfg(target_os = "linux")]
#[test]
fn harness_pin_resolves_a_descriptor_backed_server() {
use std::os::fd::AsRawFd as _;
let install = tempfile::tempdir().unwrap();
let server = install.path().join(ANTIGRAVITY_PROGRAM);
std::fs::write(&server, "").unwrap();
std::fs::write(install.path().join(HARNESS_FILE), "").unwrap();
let handle = std::fs::File::open(&server).unwrap();
let descriptor = PathBuf::from(format!("/proc/self/fd/{}", handle.as_raw_fd()));
let harness = std::fs::canonicalize(install.path())
.unwrap()
.join(HARNESS_FILE);
assert_eq!(
harness_env(Some(&descriptor), None),
vec![(OsString::from(HARNESS_PATH_ENV), harness.into_os_string())]
);
}
#[test]
fn harness_location_checks_the_override_path() {
let install = tempfile::tempdir().unwrap();
let server = install.path().join(ANTIGRAVITY_PROGRAM);
std::fs::write(&server, "").unwrap();
std::fs::write(install.path().join(HARNESS_FILE), "").unwrap();
let beside = std::fs::canonicalize(install.path())
.unwrap()
.join(HARNESS_FILE);
let custom = tempfile::tempdir().unwrap();
let present = custom.path().join(HARNESS_FILE);
std::fs::write(&present, "").unwrap();
let dangling = custom.path().join("typo");
let cases = [
(
Some(present.clone().into_os_string()),
HarnessLocation::Override(present),
),
(
Some(dangling.clone().into_os_string()),
HarnessLocation::OverrideMissing(dangling),
),
(Some(OsString::new()), HarnessLocation::Beside(beside)),
];
for (existing, expected) in cases {
assert_eq!(
harness_location(&server, existing.clone()),
expected,
"{existing:?}"
);
}
}