chore: 提交所有工作进度 — SaaS 后端增强、Admin UI、桌面端集成
包含大量 SaaS 平台改进、Admin 管理后台更新、桌面端集成完善、 文档同步、测试文件重构等内容。为 QA 测试准备干净工作树。
This commit is contained in:
97
crates/zclaw-saas/tests/agent_template_test.rs
Normal file
97
crates/zclaw-saas/tests/agent_template_test.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user