feat: add msglib bounded message listing

This commit is contained in:
zhaoyilun
2026-07-10 08:54:11 +08:00
parent c0287fa2e6
commit 44d27879f6
8 changed files with 922 additions and 17 deletions

View File

@@ -81,6 +81,46 @@ func TestMessageSourcesPassesConfiguredPathsAndDecodesMetadata(t *testing.T) {
}
}
func TestListMessagesPassesBoundedArgsAndDecodesNormalizedMessages(t *testing.T) {
cfg := Config{
SQLiteDLLPath: `C:\fixture\System.Data.SQLite.dll`,
DBPath: `C:\fixture\MsgLib.db`,
Password: "123",
}
client := newFakeClient(t, "list_messages_ok", cfg)
got, err := client.ListMessages(context.Background(), ListMessagesOptions{
ConversationType: "direct",
Query: "redacted",
Since: "2026-07-10T00:00:00Z",
Limit: 99,
IncludeBody: false,
IncludeAttachmentMetadata: true,
})
if err != nil {
t.Fatalf("ListMessages returned error: %v", err)
}
if !got.ReadOnly || got.MessageBodyValuesReturned || got.RawRowsReturned || got.FilePathsReturned {
t.Fatalf("unexpected safety flags: %+v", got)
}
if strings.Join(got.SourceTables, ",") != "tblPersonMsg" {
t.Fatalf("SourceTables = %#v", got.SourceTables)
}
if len(got.Messages) != 1 {
t.Fatalf("len(Messages) = %d, want 1", len(got.Messages))
}
msg := got.Messages[0]
if msg.MessageID != "msg-redacted-1" || msg.ConversationType != "direct" || msg.RawRef != "msglib:tblPersonMsg" {
t.Fatalf("unexpected message identity: %+v", msg)
}
if msg.ContentText != "" || msg.Text != "" {
t.Fatalf("content should be omitted when include_body=false: %+v", msg)
}
if len(msg.Attachments) != 1 || msg.Attachments[0].FileName != "redacted.docx" || msg.Attachments[0].DownloadRef != "" {
t.Fatalf("unexpected attachments: %+v", msg.Attachments)
}
}
func TestDisplayEntitiesPassesBoundedArgsAndDecodesMetadata(t *testing.T) {
cfg := Config{
SQLiteDLLPath: `C:\fixture\System.Data.SQLite.dll`,
@@ -307,6 +347,49 @@ func fakeSidecarMain() int {
"error": nil,
"warnings": []any{},
})
case "list_messages":
args, _ := req["args"].(map[string]any)
if args["sqlite_dll_path"] != `C:\fixture\System.Data.SQLite.dll` || args["db_path"] != `C:\fixture\MsgLib.db` || args["password"] != "123" || args["conversation_type"] != "direct" || args["query"] != "redacted" || args["since"] != "2026-07-10T00:00:00Z" || args["limit"] != float64(50) || args["include_body"] != false || args["include_attachment_metadata"] != true {
fmt.Fprintf(os.Stderr, "bad list_messages args: %#v\n", args)
return 2
}
return writeFakeResponse(map[string]any{
"protocol": Protocol,
"request_id": requestID,
"op": op,
"ok": true,
"data": map[string]any{
"read_only": true,
"message_body_values_returned": false,
"raw_rows_returned": false,
"file_paths_returned": false,
"source_tables": []any{"tblPersonMsg"},
"messages": []any{
map[string]any{
"message_id": "msg-redacted-1",
"id": "msg-redacted-1",
"conversation_id": "contact-redacted",
"conversation_type": "direct",
"sender_id": "sender-redacted",
"sender_name": "Sender Redacted",
"receiver_id": "receiver-redacted",
"text": "",
"content_text": "",
"content_type": "file",
"timestamp": "2026-07-10T00:01:02Z",
"created_at": "2026-07-10T00:01:02Z",
"read": true,
"source": "local_readonly",
"raw_ref": "msglib:tblPersonMsg",
"attachments": []any{
map[string]any{"file_id": "msg-redacted-1:redacted.docx", "file_name": "redacted.docx", "size_bytes": float64(1234), "download_ref": ""},
},
},
},
},
"error": nil,
"warnings": []any{},
})
case "display_entities":
args, _ := req["args"].(map[string]any)
if args["sqlite_dll_path"] != `C:\fixture\System.Data.SQLite.dll` || args["db_path"] != `C:\fixture\MsgLib.db` || args["password"] != "123" || args["entity_type"] != "contacts" || args["query"] != "alice" || args["limit"] != float64(2) {