use std::env;
use std::fs;
use std::path::{Path, PathBuf};
mod shell_runner;
mod layer0_microkernel;
mod layer1_cpn_vm;
mod layer2_storage;
mod layer3_network;
mod zerofs;
mod polyglot_sla;
pub use layer0_microkernel::*;
pub use layer1_cpn_vm::*;
pub use layer2_storage::*;
pub use layer3_network::*;
pub use zerofs::*;
pub use polyglot_sla::*;
fn path_to_slash_str<P: AsRef<Path>>(p: P) -> String {
p.as_ref().to_string_lossy().replace('\\', "/")
}
pub fn resolve_clm_root() -> PathBuf {
if let Ok(val) = env::var("CLM_ROOT") {
return PathBuf::from(val);
}
if let Ok(curr) = env::current_dir() {
let mut dir = curr;
loop {
if dir.join("computable_knowledge/Concrete/layer5_system/bootstrap/evaluator").is_dir()
|| dir.join("computable_knowledge/Abstract/layer5_system/bootstrap/evaluator").is_dir()
{
return dir;
}
if dir.join("clm/computable_knowledge/Concrete/layer5_system/bootstrap/evaluator").is_dir()
|| dir.join("clm/computable_knowledge/Abstract/layer5_system/bootstrap/evaluator").is_dir()
{
return dir.join("clm");
}
if let Some(parent) = dir.parent() {
dir = parent.to_path_buf();
} else {
break;
}
}
}
env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
}
#[cfg(unix)]
fn create_dir_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> std::io::Result<()> {
std::os::unix::fs::symlink(original, link)
}
#[cfg(windows)]
fn create_dir_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> std::io::Result<()> {
if let Ok(()) = std::os::windows::fs::symlink_dir(&original, &link) {
return Ok(());
}
let status = std::process::Command::new("cmd")
.args(&[
"/c",
"mklink",
"/j",
link.as_ref().to_str().unwrap(),
original.as_ref().to_str().unwrap(),
])
.status()?;
if status.success() {
Ok(())
} else {
Err(std::io::Error::new(std::io::ErrorKind::Other, "Failed to create directory junction"))
}
}
fn setup_isolated_env(suffix: &str) -> (PathBuf, PathBuf) {
let original_clm_root = resolve_clm_root();
let test_dir = original_clm_root.join(format!("data/execution_logs/.tmp/{}", suffix));
let _ = fs::remove_dir_all(&test_dir);
fs::create_dir_all(&test_dir).unwrap();
for dir in &["tools", "types", "computable_knowledge", "tests", "kernel"] {
let _ = create_dir_symlink(original_clm_root.join(dir), test_dir.join(dir));
}
fs::create_dir_all(test_dir.join("db")).unwrap();
fs::create_dir_all(test_dir.join("data/content_memory")).unwrap();
fs::create_dir_all(test_dir.join("data/execution_logs")).unwrap();
let db_dir = test_dir.join("db");
crate::utils::set_env_var("CLM_ROOT", test_dir.to_str().unwrap());
crate::utils::set_env_var("CLM_MEMBROKER_SNAP_DIR", db_dir.to_str().unwrap());
(original_clm_root, test_dir)
}
fn restore_env(original_clm_root: &Path, test_dir: &Path) {
crate::utils::set_env_var("CLM_ROOT", original_clm_root.to_str().unwrap());
let _ = fs::remove_dir_all(test_dir);
}
#[allow(dead_code)]
fn print_stub_pass(suite_name: &str) -> Result<String, String> {
let strict = std::env::var("CLM_STRICT_INTEGRATION")
.map(|v| v.to_lowercase() == "true")
.unwrap_or(false);
if strict {
return Err(format!(
"STUB FAILURE: '{}' is not implemented (CLM_STRICT_INTEGRATION=true)",
suite_name
));
}
println!("======================================================");
println!(" Test Suite: {} (Rust Native — STUB)", suite_name);
println!("======================================================\n");
println!(" STUB: '{}' is not implemented — no tests were run", suite_name);
println!("\n======================================================");
print!(" Results: 0 run, 0 passed (STUB)");
Ok("".to_string())
}