An AI agent built to do Ralph loops - plan mode for planning and ralph mode for implementing.
1use rustagent::llm::{Message, Role};
2
3#[test]
4fn test_tool_message_creation() {
5 let msg = Message::tool_result("call_123", "File contents here");
6 assert_eq!(msg.role, Role::Tool);
7 assert_eq!(msg.tool_call_id, Some("call_123".to_string()));
8 assert_eq!(msg.content, "File contents here");
9}
10
11#[test]
12fn test_user_message_has_no_tool_call_id() {
13 let msg = Message::user("Hello");
14 assert_eq!(msg.role, Role::User);
15 assert!(msg.tool_call_id.is_none());
16}
17
18#[test]
19fn test_assistant_message_constructor() {
20 let msg = Message::assistant("I can help with that");
21 assert_eq!(msg.role, Role::Assistant);
22 assert_eq!(msg.content, "I can help with that");
23 assert!(msg.tool_call_id.is_none());
24}
25
26#[test]
27fn test_system_message_constructor() {
28 let msg = Message::system("You are a helpful assistant");
29 assert_eq!(msg.role, Role::System);
30 assert_eq!(msg.content, "You are a helpful assistant");
31 assert!(msg.tool_call_id.is_none());
32}
33
34#[test]
35fn test_tool_message_serialization() {
36 let msg = Message::tool_result("call_abc", "result data");
37 let json = serde_json::to_value(&msg).unwrap();
38
39 assert_eq!(json["role"], "tool");
40 assert_eq!(json["tool_call_id"], "call_abc");
41 assert_eq!(json["content"], "result data");
42}
43
44#[test]
45fn test_user_message_serialization_skips_none_tool_call_id() {
46 let msg = Message::user("Hello");
47 let json = serde_json::to_value(&msg).unwrap();
48
49 assert_eq!(json["role"], "user");
50 assert_eq!(json["content"], "Hello");
51 // tool_call_id should not be present (skip_serializing_if = "Option::is_none")
52 assert!(json.get("tool_call_id").is_none());
53}