neosian 3.0.2

The state layer for LLM agents, as one static binary: the record, memory and the state process
//! The one server a child's private configuration registers (X7b).

use super::super::adapter::Agent;
use super::*;

fn server(tools: Option<Vec<&'static str>>) -> ChildServer {
    ChildServer {
        command: "/opt/neosian".to_string(),
        args: vec![
            "mcp".into(),
            "--root".into(),
            "/s".into(),
            "--mount".into(),
            "scope=u,path=user,ro".into(),
        ],
        env: vec![("NEOSIAN_HARNESS_CHILD".into(), "1".into())],
        tools,
    }
}

#[test]
fn vibe_registers_one_server_and_allows_only_the_read_tools_in_read_only() {
    let text = vibe_config(&server(Some(vec!["search_memory", "memory"]))).unwrap();
    let config: toml::Table = toml::from_str(&text).unwrap();
    let servers = config["mcp_servers"].as_array().unwrap();
    assert_eq!(servers.len(), 1);
    let entry = servers[0].as_table().unwrap();
    assert_eq!(entry["name"].as_str(), Some("neosian"));
    assert_eq!(entry["command"].as_str(), Some("/opt/neosian"));
    assert_eq!(entry["env"]["NEOSIAN_HARNESS_CHILD"].as_str(), Some("1"));
    let tools = config["tools"].as_table().unwrap();
    let mut names: Vec<&String> = tools.keys().collect();
    names.sort();
    assert_eq!(names, ["neosian_memory", "neosian_search_memory"]);
    assert!(
        tools
            .values()
            .all(|t| t["permission"].as_str() == Some("always"))
    );
    let writing: toml::Table = toml::from_str(&vibe_config(&server(None)).unwrap()).unwrap();
    assert!(
        writing.get("tools").is_none(),
        "write mode leaves approval to --auto-approve"
    );
}

#[test]
fn nothing_is_written_without_a_server() {
    let dir = std::env::temp_dir().join(format!("neosian-x7b-{}", uuid::Uuid::new_v4().simple()));
    std::fs::create_dir(&dir).unwrap();
    register(Agent::Vibe, &dir, None).unwrap();
    assert!(!dir.join("config.toml").exists());
    register(Agent::Vibe, &dir, Some(&server(None))).unwrap();
    assert!(dir.join("config.toml").is_file());
    std::fs::remove_dir_all(&dir).unwrap();
}