cellos-fleet 0.6.0-pre

S3-queue fleet dispatch agent for CellOS — pulls pending cell specs from S3, claims them, hands off to a local cellos-supervisor.
Documentation
//! cellos-fleet — host-resident agent that polls a spec queue and dispatches
//! execution cells to cellos-supervisor.
//!
//! # Binary entrypoint (S24 thin wrapper)
//!
//! The fleet agent's logic lives in the library target ([`cellos_fleet`]); this
//! binary is a thin wrapper that:
//!
//! 1. short-circuits `--version` / `-V` before any env probing,
//! 2. installs the JSON tracing subscriber with the redacted filter (HIGH-B5),
//! 3. builds a [`cellos_fleet::Config`] from the environment, and
//! 4. drives the poll loop via [`cellos_fleet::run`].
//!
//! All queue, claim, dispatch, and configuration behaviour is unchanged — see
//! the [`cellos_fleet`] crate docs for the full queue model, environment
//! variables, and drain semantics.

use anyhow::{Context, Result};
use cellos_fleet::{run, Config};

/// Build SHA stamped at compile time. Prefer `VERGEN_GIT_SHA` (set by a
/// `vergen`-style build script when present); fall back to the `GIT_COMMIT`
/// env var the release pipeline already exports. `unknown` is fine for local
/// dev builds.
const BUILD_SHA: &str = match option_env!("VERGEN_GIT_SHA") {
    Some(s) => s,
    None => match option_env!("GIT_COMMIT") {
        Some(s) => s,
        None => "unknown",
    },
};

#[tokio::main]
async fn main() -> Result<()> {
    // --version / -V: print `<binary> <semver> (<short-sha>)` and exit
    // (no config required, no env probing — safe to run pre-deploy).
    let args: Vec<String> = std::env::args().skip(1).collect();
    if args
        .first()
        .map(|a| a == "--version" || a == "-V")
        .unwrap_or(false)
    {
        let sha_short = if BUILD_SHA.len() > 7 {
            &BUILD_SHA[..7]
        } else {
            BUILD_SHA
        };
        println!("cellos-fleet {} ({})", env!("CARGO_PKG_VERSION"), sha_short);
        return Ok(());
    }

    // HIGH-B5: redacted filter suppresses reqwest/hyper TRACE events
    // carrying bearer tokens (fleet dispatcher uses reqwest's S3 path for
    // the SigV4-signed queue pull — header redaction matters).
    {
        use tracing_subscriber::layer::SubscriberExt;
        use tracing_subscriber::util::SubscriberInitExt;
        use tracing_subscriber::Layer;

        let fmt_layer = tracing_subscriber::fmt::layer()
            .json()
            .with_filter(cellos_core::observability::redacted_filter());

        tracing_subscriber::registry()
            .with(
                tracing_subscriber::EnvFilter::try_from_default_env()
                    .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
            )
            .with(fmt_layer)
            .init();
    }

    let cfg = Config::from_env().context("failed to read configuration")?;
    run(cfg).await
}

#[cfg(test)]
mod tests {
    /// P4-03 smoke: confirm the version format string compiles. The
    /// runtime path is exercised by release tooling and integration tests;
    /// this test exists to catch a typo in the format string at
    /// `cargo test` time.
    #[test]
    fn version_compiles() {
        let _ = format!(
            "cellos-fleet {} ({})",
            env!("CARGO_PKG_VERSION"),
            super::BUILD_SHA
        );
    }
}