mod common;
use std::time::Duration;
use axum::http::StatusCode;
use common::*;
use klieo_workflow::test_support::const_subflow;
use klieo_workflow::Registry;
use tower::ServiceExt;
const GENEROUS_TIMEOUT: Duration = Duration::from_secs(5);
const HIGH_CAP: usize = 8;
#[tokio::test]
async fn returns_the_registered_palette() {
let registry = test_registry()
.with_tool("lookup")
.with_subflow("triage", const_subflow("T"));
let router = build_router(registry, GENEROUS_TIMEOUT, HIGH_CAP).await;
let response = router.oneshot(authed_get("/registry")).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = body_json(response).await;
assert_eq!(body["models"], serde_json::json!([TEST_MODEL]));
assert_eq!(body["tools"], serde_json::json!(["lookup"]));
assert_eq!(body["subflows"], serde_json::json!(["triage"]));
}
#[tokio::test]
async fn empty_registry_returns_empty_arrays() {
let router = build_router(Registry::new(), GENEROUS_TIMEOUT, HIGH_CAP).await;
let response = router.oneshot(authed_get("/registry")).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = body_json(response).await;
assert_eq!(body["models"], serde_json::json!([]));
assert_eq!(body["tools"], serde_json::json!([]));
assert_eq!(body["subflows"], serde_json::json!([]));
}
#[tokio::test]
async fn requires_read_scope() {
let router = build_router_with_auth(
run_only_authenticator(),
test_registry(),
GENEROUS_TIMEOUT,
HIGH_CAP,
)
.await;
let response = router.oneshot(authed_get("/registry")).await.unwrap();
assert_eq!(response.status(), StatusCode::FORBIDDEN);
}