Skip to main content

omne_cli/
scaffold.rs

1//! Volume directory scaffolding.
2//!
3//! Creates the `.omne/` directory structure, writes the `CLAUDE.md`
4//! bootloader, and writes the stamped `MANIFEST.md`. All operations
5//! are idempotent — `create_dir_all` does not error on existing dirs.
6
7// Items below are first used when Unit 8a wires this module into
8// `init::run`. Until then, only the inline test module uses them.
9#![allow(dead_code)]
10
11use std::io;
12use std::path::Path;
13
14/// Bootloader content written to `CLAUDE.md` at the volume root.
15const BOOTLOADER_CONTENT: &str = "\
16# CLAUDE.md
17
18> Bootloader — loads the omne kernel.
19
20Read `.omne/MANIFEST.md` and follow its boot sequence.
21";
22
23/// Create the `.omne/` directory structure with `cfg/` and `log/`.
24pub fn create_volume_dirs(root: &Path) -> io::Result<()> {
25    let omne = root.join(".omne");
26    std::fs::create_dir_all(omne.join("cfg"))?;
27    std::fs::create_dir_all(omne.join("log"))?;
28    Ok(())
29}
30
31/// Write the `CLAUDE.md` bootloader to the volume root.
32pub fn write_bootloader(root: &Path) -> io::Result<()> {
33    std::fs::write(root.join("CLAUDE.md"), BOOTLOADER_CONTENT)
34}
35
36/// Write stamped manifest content to `.omne/MANIFEST.md`.
37pub fn write_manifest(root: &Path, content: &str) -> io::Result<()> {
38    std::fs::write(root.join(".omne").join("MANIFEST.md"), content)
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44    use tempfile::TempDir;
45
46    // -- create_volume_dirs --
47
48    #[test]
49    fn creates_omne_dir() {
50        let tmp = TempDir::new().unwrap();
51        create_volume_dirs(tmp.path()).unwrap();
52        assert!(tmp.path().join(".omne").is_dir());
53    }
54
55    #[test]
56    fn creates_cfg_dir() {
57        let tmp = TempDir::new().unwrap();
58        create_volume_dirs(tmp.path()).unwrap();
59        assert!(tmp.path().join(".omne").join("cfg").is_dir());
60    }
61
62    #[test]
63    fn creates_log_dir() {
64        let tmp = TempDir::new().unwrap();
65        create_volume_dirs(tmp.path()).unwrap();
66        assert!(tmp.path().join(".omne").join("log").is_dir());
67    }
68
69    #[test]
70    fn idempotent() {
71        let tmp = TempDir::new().unwrap();
72        create_volume_dirs(tmp.path()).unwrap();
73        create_volume_dirs(tmp.path()).unwrap();
74        assert!(tmp.path().join(".omne").is_dir());
75    }
76
77    // -- write_bootloader --
78
79    #[test]
80    fn creates_claude_md() {
81        let tmp = TempDir::new().unwrap();
82        write_bootloader(tmp.path()).unwrap();
83        assert!(tmp.path().join("CLAUDE.md").is_file());
84    }
85
86    #[test]
87    fn bootloader_references_manifest() {
88        let tmp = TempDir::new().unwrap();
89        write_bootloader(tmp.path()).unwrap();
90        let content = std::fs::read_to_string(tmp.path().join("CLAUDE.md")).unwrap();
91        assert!(content.contains(".omne/MANIFEST.md"));
92    }
93
94    // -- write_manifest --
95
96    #[test]
97    fn writes_manifest_file() {
98        let tmp = TempDir::new().unwrap();
99        std::fs::create_dir_all(tmp.path().join(".omne")).unwrap();
100        write_manifest(tmp.path(), "test content").unwrap();
101        let path = tmp.path().join(".omne").join("MANIFEST.md");
102        assert!(path.is_file());
103        assert_eq!(std::fs::read_to_string(path).unwrap(), "test content");
104    }
105}