elph 0.0.11

Minimalist AI agent companion for coding
use elph_agent::write_file_if_missing;

use super::InitError;
use super::paths::Paths;

const GITIGNORE: &str = "\
# Auto-generated by Elph agent -- DO NOT REMOVE!!
# The memory.db contains code structure metadata.
*
";

pub fn ensure(paths: &Paths) -> Result<(), InitError> {
    std::fs::create_dir_all(paths.project_elph_dir())?;
    write_file_if_missing(&paths.project_gitignore_path(), GITIGNORE.as_bytes())?;
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::layout::paths::Paths;

    #[test]
    fn writes_project_gitignore() {
        let tmp = tempfile::tempdir().expect("tempdir");
        let project = tmp.path().join("repo");
        let paths = Paths::from_dirs(tmp.path().join("config"), tmp.path().join("data"), project);

        ensure(&paths).expect("ensure project layout");

        let gitignore = paths.project_gitignore_path();
        assert!(gitignore.exists());
        assert_eq!(std::fs::read_to_string(gitignore).expect("read gitignore"), GITIGNORE);
    }
}