#[cfg(unix)]
mod unix {
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
fn supervisor_exe() -> PathBuf {
if let Some(p) = std::env::var_os("CARGO_BIN_EXE_cellos_supervisor") {
return PathBuf::from(p);
}
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(|p| p.parent())
.expect("cellos-supervisor crate under workspace root");
let profile = std::env::var("PROFILE").unwrap_or_else(|_| "debug".into());
root.join("target").join(profile).join("cellos-supervisor")
}
#[test]
fn exports_declared_artifact_to_cell_subdir() {
let tmp = tempfile::tempdir().expect("tempdir");
let src = tmp.path().join("artifact.txt");
File::create(&src)
.unwrap()
.write_all(b"exported-by-cellos")
.unwrap();
let export_root = tmp.path().join("export_out");
std::fs::create_dir_all(&export_root).unwrap();
let spec_path = tmp.path().join("spec.json");
let spec = serde_json::json!({
"apiVersion": "cellos.io/v1",
"kind": "ExecutionCell",
"spec": {
"id": "exp-test",
"authority": { "secretRefs": [] },
"lifetime": { "ttlSeconds": 60 },
"export": {
"artifacts": [
{ "name": "artifact.txt", "path": src.to_str().unwrap() }
]
}
}
});
std::fs::write(&spec_path, serde_json::to_string(&spec).unwrap()).unwrap();
let exe = supervisor_exe();
assert!(
exe.is_file(),
"supervisor binary missing at {}",
exe.display()
);
let status = Command::new(exe)
.env("CELL_OS_USE_NOOP_SINK", "1")
.env("CELLOS_CELL_BACKEND", "stub")
.env("CELLOS_EXPORT_DIR", export_root.as_path())
.env("CELLOS_DEPLOYMENT_PROFILE", "portable")
.current_dir(env!("CARGO_MANIFEST_DIR"))
.arg(&spec_path)
.status()
.expect("spawn cellos-supervisor");
assert!(status.success(), "supervisor failed: {status:?}");
let dest = export_root.join("exp-test").join("artifact.txt");
let got = std::fs::read_to_string(&dest).expect("read export");
assert_eq!(got, "exported-by-cellos");
}
}