Agents for developpement added + frontend add + backend added. Git viewer created + agent and template creator + layout and project creator
185 lines
6.2 KiB
Rust
185 lines
6.2 KiB
Rust
//! L6 tests for the agent DTO (de)serialisation contract: camelCase on the
|
|
//! wire, embedded [`Agent`] shape preserved, `parse_agent_id` error behaviour,
|
|
//! and `From<LaunchAgentOutput>` for [`TerminalSessionDto`].
|
|
|
|
use app_tauri_lib::dto::{
|
|
parse_agent_id, AgentDto, AgentListDto, CreateAgentRequestDto, LaunchAgentRequestDto,
|
|
TerminalSessionDto, UpdateAgentContextRequestDto,
|
|
};
|
|
use application::{CreateAgentOutput, LaunchAgentOutput, ListAgentsOutput};
|
|
use domain::ids::{AgentId, NodeId, ProfileId, SessionId};
|
|
use domain::terminal::{PtySize, SessionKind, SessionStatus, TerminalSession};
|
|
use domain::{Agent, AgentOrigin, ProjectPath};
|
|
use serde_json::json;
|
|
use uuid::Uuid;
|
|
|
|
/// Helper: build a minimal validated [`Agent`].
|
|
fn make_agent(agent_uuid: u128, profile_uuid: u128) -> Agent {
|
|
Agent::new(
|
|
AgentId::from_uuid(Uuid::from_u128(agent_uuid)),
|
|
"My Agent",
|
|
"agents/my-agent.md",
|
|
ProfileId::from_uuid(Uuid::from_u128(profile_uuid)),
|
|
AgentOrigin::Scratch,
|
|
false,
|
|
)
|
|
.expect("valid agent")
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// AgentDto / AgentListDto serialisation
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn agent_dto_serialises_camelcase() {
|
|
let agent = make_agent(1, 2);
|
|
let dto = AgentDto(agent.clone());
|
|
let v = serde_json::to_value(&dto).unwrap();
|
|
|
|
assert_eq!(v["id"], agent.id.to_string());
|
|
assert_eq!(v["name"], "My Agent");
|
|
assert_eq!(v["contextPath"], "agents/my-agent.md", "camelCase key");
|
|
assert_eq!(v["profileId"], ProfileId::from_uuid(Uuid::from_u128(2)).to_string());
|
|
assert_eq!(v["synchronized"], false);
|
|
// origin: tagged `{ "type": "scratch" }`
|
|
assert_eq!(v["origin"]["type"], "scratch");
|
|
// no snake_case leak
|
|
assert!(v.get("context_path").is_none());
|
|
assert!(v.get("profile_id").is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn agent_list_dto_is_transparent_array() {
|
|
let out = ListAgentsOutput {
|
|
agents: vec![make_agent(1, 2), make_agent(3, 4)],
|
|
};
|
|
let dto = AgentListDto::from(out);
|
|
let v = serde_json::to_value(&dto).unwrap();
|
|
let arr = v.as_array().expect("transparent array");
|
|
assert_eq!(arr.len(), 2);
|
|
assert_eq!(arr[0]["name"], "My Agent");
|
|
}
|
|
|
|
#[test]
|
|
fn create_agent_output_maps_to_agent_dto() {
|
|
let agent = make_agent(5, 6);
|
|
let out = CreateAgentOutput { agent: agent.clone() };
|
|
let dto = AgentDto::from(out);
|
|
assert_eq!(dto.0.id, agent.id);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Request DTO deserialisation
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn create_agent_request_deserialises_camelcase() {
|
|
let project_id = Uuid::from_u128(10).to_string();
|
|
let profile_id = Uuid::from_u128(20).to_string();
|
|
let raw = json!({
|
|
"projectId": project_id,
|
|
"name": "Backend Dev",
|
|
"profileId": profile_id,
|
|
"initialContent": "# Hello"
|
|
});
|
|
let dto: CreateAgentRequestDto = serde_json::from_value(raw).unwrap();
|
|
assert_eq!(dto.project_id, project_id);
|
|
assert_eq!(dto.name, "Backend Dev");
|
|
assert_eq!(dto.profile_id, profile_id);
|
|
assert_eq!(dto.initial_content.as_deref(), Some("# Hello"));
|
|
}
|
|
|
|
#[test]
|
|
fn create_agent_request_initial_content_defaults_to_none() {
|
|
let raw = json!({
|
|
"projectId": Uuid::nil().to_string(),
|
|
"name": "Agent",
|
|
"profileId": Uuid::nil().to_string()
|
|
});
|
|
let dto: CreateAgentRequestDto = serde_json::from_value(raw).unwrap();
|
|
assert!(dto.initial_content.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn update_agent_context_request_deserialises_camelcase() {
|
|
let raw = json!({
|
|
"projectId": Uuid::nil().to_string(),
|
|
"agentId": Uuid::nil().to_string(),
|
|
"content": "# Updated"
|
|
});
|
|
let dto: UpdateAgentContextRequestDto = serde_json::from_value(raw).unwrap();
|
|
assert_eq!(dto.content, "# Updated");
|
|
}
|
|
|
|
#[test]
|
|
fn launch_agent_request_deserialises_camelcase() {
|
|
let project_id = Uuid::from_u128(1).to_string();
|
|
let agent_id = Uuid::from_u128(2).to_string();
|
|
let raw = json!({
|
|
"projectId": project_id,
|
|
"agentId": agent_id,
|
|
"rows": 24,
|
|
"cols": 80
|
|
});
|
|
let dto: LaunchAgentRequestDto = serde_json::from_value(raw).unwrap();
|
|
assert_eq!(dto.rows, 24);
|
|
assert_eq!(dto.cols, 80);
|
|
assert_eq!(dto.project_id, project_id);
|
|
assert_eq!(dto.agent_id, agent_id);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// parse_agent_id
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn parse_agent_id_accepts_uuid() {
|
|
let id = Uuid::from_u128(99);
|
|
assert_eq!(
|
|
parse_agent_id(&id.to_string()).unwrap(),
|
|
AgentId::from_uuid(id)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_agent_id_rejects_garbage() {
|
|
let err = parse_agent_id("not-a-uuid").expect_err("garbage rejected");
|
|
assert_eq!(err.code, "INVALID");
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// From<LaunchAgentOutput> for TerminalSessionDto
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn launch_agent_output_maps_to_terminal_session_dto() {
|
|
let session_id = SessionId::from_uuid(Uuid::from_u128(7));
|
|
let node_id = NodeId::from_uuid(Uuid::from_u128(8));
|
|
let agent_id = AgentId::from_uuid(Uuid::from_u128(9));
|
|
let cwd = ProjectPath::new("/tmp/project".to_owned()).expect("valid path");
|
|
let size = PtySize::new(24, 80).unwrap();
|
|
|
|
let mut session = TerminalSession::starting(
|
|
session_id,
|
|
node_id,
|
|
cwd,
|
|
SessionKind::Agent { agent_id },
|
|
size,
|
|
);
|
|
session.status = SessionStatus::Running;
|
|
|
|
let out = LaunchAgentOutput { session };
|
|
let dto = TerminalSessionDto::from(out);
|
|
|
|
assert_eq!(dto.session_id, session_id.to_string());
|
|
assert_eq!(dto.cwd, "/tmp/project");
|
|
assert_eq!(dto.rows, 24);
|
|
assert_eq!(dto.cols, 80);
|
|
|
|
// Also verify camelCase serialisation.
|
|
let v = serde_json::to_value(&dto).unwrap();
|
|
assert_eq!(v["sessionId"], session_id.to_string());
|
|
assert_eq!(v["cwd"], "/tmp/project");
|
|
assert!(v.get("session_id").is_none(), "no snake_case leak");
|
|
}
|