98 lines
3.9 KiB
Rust
98 lines
3.9 KiB
Rust
mod common;
|
|
|
|
use axum::http::StatusCode;
|
|
use common::*;
|
|
|
|
// ═══════════════════════════════════════════════════════════════════
|
|
// List templates
|
|
// ═══════════════════════════════════════════════════════════════════
|
|
|
|
#[tokio::test]
|
|
async fn agent_template_list_empty() {
|
|
let (app, _pool) = build_test_app().await;
|
|
let token = register_token(&app, "atlist").await;
|
|
let (status, body) = send(&app, get("/api/v1/agent-templates", &token)).await;
|
|
assert_eq!(status, StatusCode::OK);
|
|
assert!(body.is_array() || body["items"].is_array());
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════════════
|
|
// Full CRUD
|
|
// ═══════════════════════════════════════════════════════════════════
|
|
|
|
#[tokio::test]
|
|
async fn agent_template_crud() {
|
|
let (app, pool) = build_test_app().await;
|
|
let admin = admin_token(&app, &pool, "atadmin").await;
|
|
|
|
// Create
|
|
let (status, body) = send(
|
|
&app,
|
|
post(
|
|
"/api/v1/agent-templates",
|
|
&admin,
|
|
serde_json::json!({
|
|
"name": "Test Agent",
|
|
"description": "A test agent template",
|
|
"category": "general",
|
|
"model": "test-model-v1",
|
|
"system_prompt": "You are a test agent.",
|
|
"tools": ["search", "browser"],
|
|
"capabilities": ["reasoning", "code"],
|
|
"temperature": 0.7,
|
|
"max_tokens": 4096
|
|
}),
|
|
),
|
|
).await;
|
|
if status != StatusCode::OK {
|
|
eprintln!("ERROR create agent template: status={status}, body={body}");
|
|
}
|
|
assert_eq!(status, StatusCode::OK, "create agent template: {body}");
|
|
let tmpl_id = body["id"].as_str().unwrap();
|
|
assert_eq!(body["name"], "Test Agent");
|
|
|
|
// Get
|
|
let (status, body) = send(&app, get(&format!("/api/v1/agent-templates/{tmpl_id}"), &admin)).await;
|
|
assert_eq!(status, StatusCode::OK);
|
|
assert_eq!(body["name"], "Test Agent");
|
|
assert_eq!(body["model"], "test-model-v1");
|
|
|
|
// Update (POST for update)
|
|
let (status, body) = send(
|
|
&app,
|
|
post(
|
|
&format!("/api/v1/agent-templates/{tmpl_id}"),
|
|
&admin,
|
|
serde_json::json!({
|
|
"description": "Updated description",
|
|
"temperature": 0.5
|
|
}),
|
|
),
|
|
).await;
|
|
assert_eq!(status, StatusCode::OK);
|
|
assert_eq!(body["description"], "Updated description");
|
|
|
|
// Archive (DELETE)
|
|
let (status, _) = send(&app, delete(&format!("/api/v1/agent-templates/{tmpl_id}"), &admin)).await;
|
|
assert_eq!(status, StatusCode::OK);
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════════════
|
|
// Permission enforcement
|
|
// ═══════════════════════════════════════════════════════════════════
|
|
|
|
#[tokio::test]
|
|
async fn agent_template_create_forbidden_for_user() {
|
|
let (app, _pool) = build_test_app().await;
|
|
let token = register_token(&app, "atuser").await;
|
|
let (status, _) = send(
|
|
&app,
|
|
post(
|
|
"/api/v1/agent-templates",
|
|
&token,
|
|
serde_json::json!({ "name": "Forbidden" }),
|
|
),
|
|
).await;
|
|
assert_eq!(status, StatusCode::FORBIDDEN);
|
|
}
|