ontology-docs 0.3.1

A standalone, searchable Ontology documentation and agent-skills demo.
use serde_json::Value;
use std::process::Command;
#[test]
fn embedded_demo_discovers_queries_images_and_skills_without_runtime_files() {
    let exe = env!("CARGO_BIN_EXE_ontology-docs");
    let dir = tempfile::tempdir().unwrap();
    for args in [
        &[][..],
        &["search", "encryption"][..],
        &["images"][..],
        &["skills", "list"][..],
    ] {
        let result = Command::new(exe)
            .args(args)
            .current_dir(dir.path())
            .output()
            .unwrap();
        assert!(result.status.success());
        assert!(result.stderr.is_empty());
        let value: Value = serde_json::from_slice(&result.stdout).unwrap();
        assert_eq!(value["ok"], true);
    }
    let output = dir.path().join("export");
    let result = Command::new(exe)
        .args([
            "skills",
            "export",
            "ontology-authoring",
            "--output",
            output.to_str().unwrap(),
        ])
        .output()
        .unwrap();
    assert!(result.status.success());
    assert!(output.join("ontology-authoring/SKILL.md").is_file());
}
#[test]
fn next_calls_advance_documents_and_keep_opened_child_scope() {
    let exe = env!("CARGO_BIN_EXE_ontology-docs");
    let call = |args: &[&str]| {
        let result = Command::new(exe).args(args).output().unwrap();
        assert!(
            result.status.success(),
            "{}",
            String::from_utf8_lossy(&result.stderr)
        );
        serde_json::from_slice::<Value>(&result.stdout).unwrap()
    };
    let read = call(&["read", "usage"]);
    assert!(
        read["next"]
            .as_array()
            .unwrap()
            .iter()
            .any(|v| v["argv"][1] == "links")
    );
    assert!(
        !read["next"]
            .as_array()
            .unwrap()
            .iter()
            .any(|v| v["argv"][1] == "read" && v["argv"][2] == "usage")
    );
    let open = call(&["open", "nested-example"]);
    let argv = open["next"][0]["argv"].as_array().unwrap();
    assert!(
        argv.windows(2)
            .any(|v| v[0] == "--package-path" && v[1] == "nested-example")
    );
    let result = Command::new(exe)
        .args(argv.iter().skip(1).map(|v| v.as_str().unwrap()))
        .output()
        .unwrap();
    assert!(result.status.success());
    let value: Value = serde_json::from_slice(&result.stdout).unwrap();
    assert!(
        value["data"]["objects"]
            .as_array()
            .unwrap()
            .iter()
            .any(|v| v["id"] == "document:usage" && v["title"] == "Nested usage")
    );
}