#![allow(dead_code)]
use std::io;
use std::path::Path;
const BOOTLOADER_CONTENT: &str = "\
# CLAUDE.md
> Bootloader — loads the omne kernel.
Read `.omne/MANIFEST.md` and follow its boot sequence.
";
pub fn create_volume_dirs(root: &Path) -> io::Result<()> {
let omne = root.join(".omne");
std::fs::create_dir_all(omne.join("cfg"))?;
std::fs::create_dir_all(omne.join("log"))?;
Ok(())
}
pub fn write_bootloader(root: &Path) -> io::Result<()> {
std::fs::write(root.join("CLAUDE.md"), BOOTLOADER_CONTENT)
}
pub fn write_manifest(root: &Path, content: &str) -> io::Result<()> {
std::fs::write(root.join(".omne").join("MANIFEST.md"), content)
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;
#[test]
fn creates_omne_dir() {
let tmp = TempDir::new().unwrap();
create_volume_dirs(tmp.path()).unwrap();
assert!(tmp.path().join(".omne").is_dir());
}
#[test]
fn creates_cfg_dir() {
let tmp = TempDir::new().unwrap();
create_volume_dirs(tmp.path()).unwrap();
assert!(tmp.path().join(".omne").join("cfg").is_dir());
}
#[test]
fn creates_log_dir() {
let tmp = TempDir::new().unwrap();
create_volume_dirs(tmp.path()).unwrap();
assert!(tmp.path().join(".omne").join("log").is_dir());
}
#[test]
fn idempotent() {
let tmp = TempDir::new().unwrap();
create_volume_dirs(tmp.path()).unwrap();
create_volume_dirs(tmp.path()).unwrap();
assert!(tmp.path().join(".omne").is_dir());
}
#[test]
fn creates_claude_md() {
let tmp = TempDir::new().unwrap();
write_bootloader(tmp.path()).unwrap();
assert!(tmp.path().join("CLAUDE.md").is_file());
}
#[test]
fn bootloader_references_manifest() {
let tmp = TempDir::new().unwrap();
write_bootloader(tmp.path()).unwrap();
let content = std::fs::read_to_string(tmp.path().join("CLAUDE.md")).unwrap();
assert!(content.contains(".omne/MANIFEST.md"));
}
#[test]
fn writes_manifest_file() {
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join(".omne")).unwrap();
write_manifest(tmp.path(), "test content").unwrap();
let path = tmp.path().join(".omne").join("MANIFEST.md");
assert!(path.is_file());
assert_eq!(std::fs::read_to_string(path).unwrap(), "test content");
}
}