My agentic slop goes here. Not intended for anyone else!
1(** Test the Incoming message codec *) 2 3open Claude 4 5let test_decode_user_message () = 6 let json_str = {|{"type":"user","content":"Hello"}|} in 7 match Jsont_bytesrw.decode_string' Incoming.jsont json_str with 8 | Ok (Incoming.Message (Message.User _)) -> 9 print_endline "✓ Decoded user message successfully" 10 | Ok _ -> 11 print_endline "✗ Wrong message type decoded" 12 | Error err -> 13 Printf.printf "✗ Failed to decode user message: %s\n" (Jsont.Error.to_string err) 14 15let test_decode_assistant_message () = 16 let json_str = {|{"type":"assistant","model":"claude-sonnet-4","content":[{"type":"text","text":"Hi"}]}|} in 17 match Jsont_bytesrw.decode_string' Incoming.jsont json_str with 18 | Ok (Incoming.Message (Message.Assistant _)) -> 19 print_endline "✓ Decoded assistant message successfully" 20 | Ok _ -> 21 print_endline "✗ Wrong message type decoded" 22 | Error err -> 23 Printf.printf "✗ Failed to decode assistant message: %s\n" (Jsont.Error.to_string err) 24 25let test_decode_system_message () = 26 let json_str = {|{"type":"system","subtype":"init","data":{"session_id":"test-123"}}|} in 27 match Jsont_bytesrw.decode_string' Incoming.jsont json_str with 28 | Ok (Incoming.Message (Message.System _)) -> 29 print_endline "✓ Decoded system message successfully" 30 | Ok _ -> 31 print_endline "✗ Wrong message type decoded" 32 | Error err -> 33 Printf.printf "✗ Failed to decode system message: %s\n" (Jsont.Error.to_string err) 34 35let test_decode_control_response () = 36 let json_str = {|{"type":"control_response","response":{"subtype":"success","request_id":"test-req-1"}}|} in 37 match Jsont_bytesrw.decode_string' Incoming.jsont json_str with 38 | Ok (Incoming.Control_response resp) -> 39 (match resp.response with 40 | Sdk_control.Response.Success s -> 41 if s.request_id = "test-req-1" then 42 print_endline "✓ Decoded control response successfully" 43 else 44 Printf.printf "✗ Wrong request_id: %s\n" s.request_id 45 | Sdk_control.Response.Error _ -> 46 print_endline "✗ Got error response instead of success") 47 | Ok _ -> 48 print_endline "✗ Wrong message type decoded" 49 | Error err -> 50 Printf.printf "✗ Failed to decode control response: %s\n" (Jsont.Error.to_string err) 51 52let test_decode_control_response_error () = 53 let json_str = {|{"type":"control_response","response":{"subtype":"error","request_id":"test-req-2","error":"Something went wrong"}}|} in 54 match Jsont_bytesrw.decode_string' Incoming.jsont json_str with 55 | Ok (Incoming.Control_response resp) -> 56 (match resp.response with 57 | Sdk_control.Response.Error e -> 58 if e.request_id = "test-req-2" && e.error = "Something went wrong" then 59 print_endline "✓ Decoded control error response successfully" 60 else 61 Printf.printf "✗ Wrong error content\n" 62 | Sdk_control.Response.Success _ -> 63 print_endline "✗ Got success response instead of error") 64 | Ok _ -> 65 print_endline "✗ Wrong message type decoded" 66 | Error err -> 67 Printf.printf "✗ Failed to decode control error response: %s\n" (Jsont.Error.to_string err) 68 69let () = 70 print_endline "Testing Incoming message codec..."; 71 print_endline ""; 72 test_decode_user_message (); 73 test_decode_assistant_message (); 74 test_decode_system_message (); 75 test_decode_control_response (); 76 test_decode_control_response_error (); 77 print_endline ""; 78 print_endline "All tests completed!"