feat: align receive messages response contract

This commit is contained in:
zhaoyilun
2026-07-10 01:16:47 +08:00
parent 87a787ee1b
commit bbffa2189d
7 changed files with 258 additions and 23 deletions

View File

@@ -18,7 +18,7 @@ func TestISphereReceiveMessagesToolReturnsSourceMessages(t *testing.T) {
ConversationType: "chat",
SenderID: "sender@imopenfire1-lanzhou",
ReceiverID: "receiver@imopenfire1-lanzhou",
Text: "redacted",
Text: "redacted-report.docx",
Timestamp: "1783423807000",
Subject: "FILE_TRANSFER_CANCEL",
ReceiptID: "receipt-1",
@@ -55,18 +55,46 @@ func TestISphereReceiveMessagesToolReturnsSourceMessages(t *testing.T) {
}
var decoded struct {
Messages []struct {
ID string `json:"id"`
OK bool `json:"ok"`
NextCursor *string `json:"next_cursor"`
Conversation *struct {
ConversationID string `json:"conversation_id"`
ConversationType string `json:"conversation_type"`
SenderID string `json:"sender_id"`
ReceiverID string `json:"receiver_id"`
Text string `json:"text"`
Timestamp string `json:"timestamp"`
Subject string `json:"subject"`
ReceiptID string `json:"receipt_id"`
Read bool `json:"read"`
DisplayName string `json:"display_name"`
} `json:"conversation"`
Messages []struct {
ID string `json:"id"`
MessageID string `json:"message_id"`
ConversationID string `json:"conversation_id"`
ConversationType string `json:"conversation_type"`
SenderID string `json:"sender_id"`
SenderName *string `json:"sender_name"`
ReceiverID string `json:"receiver_id"`
Text string `json:"text"`
ContentType string `json:"content_type"`
ContentText string `json:"content_text"`
Attachments []struct {
FileID string `json:"file_id"`
FileName string `json:"file_name"`
DownloadRef any `json:"download_ref"`
} `json:"attachments"`
Timestamp string `json:"timestamp"`
CreatedAt *string `json:"created_at"`
ReceivedAt any `json:"received_at"`
Subject string `json:"subject"`
ReceiptID string `json:"receipt_id"`
Read bool `json:"read"`
Source string `json:"source"`
RawRef string `json:"raw_ref"`
} `json:"messages"`
Audit struct {
Tool string `json:"tool"`
Source string `json:"source"`
ExecutionMode string `json:"execution_mode"`
Result string `json:"result"`
StartedAt string `json:"started_at"`
FinishedAt string `json:"finished_at"`
} `json:"audit"`
}
payload, err := json.Marshal(callResult.StructuredContent)
if err != nil {
@@ -78,19 +106,40 @@ func TestISphereReceiveMessagesToolReturnsSourceMessages(t *testing.T) {
if len(decoded.Messages) != 1 {
t.Fatalf("messages = %+v, want one", decoded.Messages)
}
if !decoded.OK || decoded.NextCursor != nil {
t.Fatalf("ok/next_cursor = %v/%v", decoded.OK, decoded.NextCursor)
}
if decoded.Conversation == nil {
t.Fatalf("conversation missing")
}
if decoded.Conversation.ConversationID != "sender@imopenfire1-lanzhou|receiver@imopenfire1-lanzhou" || decoded.Conversation.DisplayName == "" {
t.Fatalf("unexpected conversation: %+v", decoded.Conversation)
}
msg := decoded.Messages[0]
if msg.ID != "msg-1" || msg.Text != "redacted" || msg.Subject != "FILE_TRANSFER_CANCEL" {
if msg.ID != "msg-1" || msg.MessageID != "msg-1" || msg.Text != "redacted-report.docx" || msg.ContentText != "redacted-report.docx" || msg.Subject != "FILE_TRANSFER_CANCEL" {
t.Fatalf("unexpected message content: %+v", msg)
}
if msg.ContentType != "file" {
t.Fatalf("content_type = %q, want file", msg.ContentType)
}
if len(msg.Attachments) != 1 || msg.Attachments[0].FileID != "msg-1:redacted-report.docx" || msg.Attachments[0].FileName != "redacted-report.docx" || msg.Attachments[0].DownloadRef != nil {
t.Fatalf("attachments = %+v", msg.Attachments)
}
if msg.ConversationID != "sender@imopenfire1-lanzhou|receiver@imopenfire1-lanzhou" {
t.Fatalf("conversation_id = %q", msg.ConversationID)
}
if msg.SenderID != "sender@imopenfire1-lanzhou" || msg.ReceiverID != "receiver@imopenfire1-lanzhou" {
t.Fatalf("sender/receiver = %q/%q", msg.SenderID, msg.ReceiverID)
}
if msg.Timestamp != "1783423807000" || msg.ReceiptID != "receipt-1" || !msg.Read {
if msg.Timestamp != "1783423807000" || msg.CreatedAt == nil || *msg.CreatedAt != "2026-07-07T11:30:07Z" || msg.ReceiptID != "receipt-1" || !msg.Read {
t.Fatalf("metadata = %+v", msg)
}
if msg.SenderName != nil || msg.ReceivedAt != nil || msg.Source != "local_readonly" || msg.RawRef != "packetlog_message" {
t.Fatalf("contract metadata = %+v", msg)
}
if decoded.Audit.Tool != ToolNameReceiveMessages || decoded.Audit.Source != "local_readonly" || decoded.Audit.ExecutionMode != "read" || decoded.Audit.Result != "ok" || decoded.Audit.StartedAt == "" || decoded.Audit.FinishedAt == "" {
t.Fatalf("unexpected audit: %+v", decoded.Audit)
}
}
type fakeReceiveMessagesSource struct {