aion-server 0.30.0

Aion workflow server library: HTTP, gRPC, WebSocket, and worker endpoints. Run it with the `aion` binary from the aion-cli crate.
Documentation
use std::path::Path;

use aion_store::{DesiredState, WorkerArtifactRef};

use super::{auto_name, is_auto_name, new_deployment, verb};

type TestResult = Result<(), Box<dyn std::error::Error>>;

fn binary() -> aion_store::DeployedBinaryIdentity {
    aion_store::DeployedBinaryIdentity {
        version: "0.0.0".to_owned(),
        commit: "commit".to_owned(),
        dirty: "false".to_owned(),
        content_hash: "hash".to_owned(),
    }
}

/// The name is DERIVED, and the prefix is what separates this server's records
/// from an operator's. Both directions, because a test on only one of them is
/// satisfied by a predicate that answers the same thing every time.
#[test]
fn the_name_is_derived_and_the_prefix_separates_it_from_an_operators() {
    assert_eq!(auto_name("assistant"), "auto/assistant");
    assert!(is_auto_name("auto/assistant"));
    assert!(!is_auto_name("assistant"));
    assert!(!is_auto_name("my-assistant-worker"));
}

/// 🔴 THE ARGV IS THE LAUNCH, and it carries only the CONNECTION. Every launch
/// setting — harness kind, concurrency, reconnect budget, the agent's own
/// command, its environment — is the document's, and a flag for any of them
/// here would rebuild the drift pair #204 deleted.
#[test]
fn the_argv_carries_the_connection_and_never_a_launch_setting() -> TestResult {
    let argv = verb(
        "assistant",
        Path::new("/srv/.aion/workers/documents/assistant@abc/assistant.awl"),
        "127.0.0.1:50061",
        "default",
    );
    assert_eq!(argv.first().map(String::as_str), Some("worker"));
    assert_eq!(argv.get(1).map(String::as_str), Some("agent"));
    assert_eq!(
        argv.get(2).map(String::as_str),
        Some("/srv/.aion/workers/documents/assistant@abc/assistant.awl")
    );
    for (flag, value) in [
        ("--task-queue", "assistant"),
        ("--liminal-address", "127.0.0.1:50061"),
        ("--identity", "auto/assistant"),
        ("--namespace", "default"),
    ] {
        let at = argv
            .iter()
            .position(|word| word == flag)
            .ok_or_else(|| format!("`{flag}` must be in the argv: {argv:?}"))?;
        assert_eq!(
            argv.get(at.saturating_add(1)).map(String::as_str),
            Some(value)
        );
    }
    for deleted in [
        "--harness",
        "--concurrency",
        "--reconnect-initial-backoff",
        "--norn-binary",
        "--acp-command",
        "--acp-permission",
        "--cwd",
        "--env-pass",
    ] {
        assert!(
            !argv.iter().any(|word| word == deleted),
            "`{deleted}` is a launch setting and belongs in the document: {argv:?}"
        );
    }
    // `--endpoint` is a CLIENT gRPC target and is not what a worker dials.
    assert!(!argv.iter().any(|word| word == "--endpoint"), "{argv:?}");
    Ok(())
}

/// The record wants to RUN. A record minted `Stopped` would be a worker nobody
/// started, which is the exact state this lane exists to end.
#[test]
fn the_minted_record_wants_to_run_and_binds_the_declared_queue() {
    let record = new_deployment(
        "assistant",
        Path::new("/srv/assistant.awl"),
        "127.0.0.1:50061",
        "tenant-a",
        binary(),
    );
    assert_eq!(record.name, "auto/assistant");
    assert_eq!(record.task_queue, "assistant");
    assert_eq!(record.desired, DesiredState::Running);
    assert_eq!(record.node, None);
    assert!(record.namespaces.contains("tenant-a"));
    assert_eq!(record.namespaces.len(), 1);
    let WorkerArtifactRef::Builtin { verb: argv } = &record.artifact;
    assert_eq!(
        argv,
        &verb(
            "assistant",
            Path::new("/srv/assistant.awl"),
            "127.0.0.1:50061",
            "tenant-a"
        )
    );
}

/// A different document is a different argv — which is what makes a redeploy a
/// re-mint the supervisor can act on rather than an invisible no-op.
#[test]
fn a_different_document_path_produces_a_different_argv() {
    let first = verb("q", Path::new("/a/one.awl"), "127.0.0.1:1", "default");
    let second = verb("q", Path::new("/a/two.awl"), "127.0.0.1:1", "default");
    assert_ne!(first, second);
}