aion-server 0.31.0

Aion workflow server library: HTTP, gRPC, WebSocket, and worker endpoints. Run it with the `aion` binary from the aion-cli crate.
Documentation
//! The pin that keeps the grounding embeds honest.
//!
//! `grounding-embed/` exists because an `include_str!` escaping the crate root
//! cannot be packaged (the same necessity as `aion-awl`'s `guide-embed/`). Two
//! files is a packaging necessity, not two truths: each embed is pinned
//! byte-identical to its authored original under `docs/assistant/grounding/`,
//! and the fix for a red here is to copy the authored document over the embed.

use std::path::{Path, PathBuf};

use crate::assistant::grounding;

fn repo_path(relative: &str) -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("../..")
        .join(relative)
}

/// Every embedded grounding document matches its authored original, byte for
/// byte — including `AWL-REFERENCE.md`, whose embed lives in `aion-awl` and is
/// re-checked here against the same authored file so THIS crate's pack cannot
/// drift even if that crate's own gate is not run.
#[test]
fn every_grounding_embed_matches_its_authored_original() -> Result<(), String> {
    for (name, embedded) in grounding::documents() {
        let authored_path = repo_path(&format!("docs/assistant/grounding/{name}"));
        let authored = std::fs::read_to_string(&authored_path)
            .map_err(|error| format!("cannot read {}: {error}", authored_path.display()))?;
        if embedded != authored {
            return Err(format!(
                "the embedded grounding copy of {name} has drifted from \
                 docs/assistant/grounding/{name}; sync it with: \
                 cp docs/assistant/grounding/{name} \
                 crates/aion-server/grounding-embed/{name}"
            ));
        }
    }
    Ok(())
}

/// The pack writes every declared document, rewrites a stale one, and holds
/// the directory owner-only.
#[test]
fn materialize_rewrites_every_document_owner_only() -> Result<(), String> {
    let root = tempfile::tempdir().map_err(|error| error.to_string())?;
    let dir = root.path().join("grounding");
    // A stale file from an older binary, to be overwritten.
    std::fs::create_dir_all(&dir).map_err(|error| error.to_string())?;
    std::fs::write(dir.join("AWL-REFERENCE.md"), "an older binary's truth")
        .map_err(|error| error.to_string())?;

    grounding::materialize(&dir)?;

    for (name, content) in grounding::documents() {
        let written = std::fs::read_to_string(dir.join(name))
            .map_err(|error| format!("{name} was not written: {error}"))?;
        if written != content {
            return Err(format!("{name} on disk does not match the embed"));
        }
    }
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt as _;
        let mode = std::fs::metadata(&dir)
            .map_err(|error| error.to_string())?
            .permissions()
            .mode();
        if mode & 0o077 != 0 {
            return Err(format!(
                "the grounding directory is not owner-only: {mode:o}"
            ));
        }
    }
    Ok(())
}