feat: wire explicit msglib receive source
This commit is contained in:
@@ -67,6 +67,12 @@ type receiveDisplaySummary struct {
|
||||
ConversationDisplayPopulated bool
|
||||
}
|
||||
|
||||
type msgLibReceiveSummary struct {
|
||||
MessageCount int
|
||||
Sources []string
|
||||
BodyValuesPresent bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
@@ -97,6 +103,9 @@ func main() {
|
||||
if contacts.FirstID == "" || contacts.FirstDisplayName == "" { fail("contacts", fmt.Errorf("contact display fixture unavailable")) }
|
||||
if groups.FirstID == "" || groups.FirstDisplayName == "" { fail("groups", fmt.Errorf("group display fixture unavailable")) }
|
||||
|
||||
dbReceive := verifyMsgLibReceive(ctx, session)
|
||||
if dbReceive.MessageCount == 0 { fail("msglib_receive", fmt.Errorf("explicit msglib_readonly receive returned no messages")) }
|
||||
|
||||
receiveDisplay := verifyReceiveDisplay(ctx, contacts, groups)
|
||||
if receiveDisplay.MessageCount == 0 { fail("receive_display", fmt.Errorf("receive message fixture returned no messages")) }
|
||||
if !receiveDisplay.SenderNamePopulated { fail("receive_display", fmt.Errorf("sender display was not populated")) }
|
||||
@@ -109,11 +118,16 @@ func main() {
|
||||
"contact_sources": contacts.Sources,
|
||||
"group_count": groups.Count,
|
||||
"group_sources": groups.Sources,
|
||||
"db_receive_smoke": true,
|
||||
"db_receive_message_count": dbReceive.MessageCount,
|
||||
"db_receive_sources": dbReceive.Sources,
|
||||
"db_receive_body_values_present": dbReceive.BodyValuesPresent,
|
||||
"receive_display_smoke": true,
|
||||
"receive_message_count": receiveDisplay.MessageCount,
|
||||
"receive_sender_name_populated": receiveDisplay.SenderNamePopulated,
|
||||
"receive_conversation_display_populated": receiveDisplay.ConversationDisplayPopulated,
|
||||
"printed_entity_values": false,
|
||||
"message_body_values_printed": false,
|
||||
"message_bodies_returned": false,
|
||||
"file_paths_returned": false,
|
||||
"raw_rows_returned": false,
|
||||
@@ -164,6 +178,41 @@ func callSearch(ctx context.Context, session *mcp.ClientSession, tool string, fi
|
||||
return out
|
||||
}
|
||||
|
||||
func verifyMsgLibReceive(ctx context.Context, session *mcp.ClientSession) msgLibReceiveSummary {
|
||||
result, err := session.CallTool(ctx, &mcp.CallToolParams{Name: "isphere_receive_messages", Arguments: map[string]any{
|
||||
"source_preference": "msglib_readonly",
|
||||
"preview": true,
|
||||
"cursor": "",
|
||||
"include_attachment_metadata": false,
|
||||
"limit": 5,
|
||||
}})
|
||||
if err != nil { fail("msglib_receive_call", err) }
|
||||
if result.IsError { fail("msglib_receive_call", fmt.Errorf("tool returned isError=true")) }
|
||||
payload, _ := json.Marshal(result.StructuredContent)
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(payload, &decoded); err != nil { fail("msglib_receive_decode", err) }
|
||||
messages, ok := decoded["messages"].([]any)
|
||||
if !ok { fail("msglib_receive_shape", fmt.Errorf("messages missing or not array")) }
|
||||
sourceSet := map[string]bool{}
|
||||
out := msgLibReceiveSummary{MessageCount: len(messages)}
|
||||
for _, value := range messages {
|
||||
message, ok := value.(map[string]any)
|
||||
if !ok { continue }
|
||||
rawRef, _ := message["raw_ref"].(string)
|
||||
if strings.HasPrefix(rawRef, "msglib:") { sourceSet[rawRef] = true }
|
||||
text, _ := message["text"].(string)
|
||||
contentText, _ := message["content_text"].(string)
|
||||
if strings.TrimSpace(text) != "" || strings.TrimSpace(contentText) != "" {
|
||||
out.BodyValuesPresent = true
|
||||
}
|
||||
}
|
||||
sources := make([]string, 0, len(sourceSet))
|
||||
for source := range sourceSet { sources = append(sources, source) }
|
||||
sort.Strings(sources)
|
||||
out.Sources = sources
|
||||
return out
|
||||
}
|
||||
|
||||
func verifyReceiveDisplay(ctx context.Context, contact summary, group summary) receiveDisplaySummary {
|
||||
groupPlaintext := packetFixturePlaintext("c33-group-display-fixture", group.FirstID+"/imp_pc_4.1.2.6842", contact.FirstID, "groupchat", "redacted-group-body")
|
||||
directPlaintext := packetFixturePlaintext("c33-contact-display-fixture", contact.FirstID+"/imp_pc_4.1.2.6842", "receiver-redacted@imopenfire1-lanzhou", "chat", "redacted-contact-body")
|
||||
@@ -318,6 +367,9 @@ func fail(step string, err error) {
|
||||
Assert-True ($json.printed_entity_values -eq $false) "harness must not print entity values"
|
||||
Assert-True ($json.contact_count -gt 0) "contact_count should be > 0"
|
||||
Assert-True ($json.group_count -gt 0) "group_count should be > 0"
|
||||
Assert-True (($json.PSObject.Properties.Name -contains "db_receive_smoke") -and $json.db_receive_smoke -eq $true) "db receive smoke should be true"
|
||||
Assert-True (($json.PSObject.Properties.Name -contains "db_receive_message_count") -and $json.db_receive_message_count -gt 0) "db_receive_message_count should be > 0"
|
||||
Assert-True (($json.PSObject.Properties.Name -contains "message_body_values_printed") -and $json.message_body_values_printed -eq $false) "message body values must not be printed"
|
||||
Assert-True (($json.PSObject.Properties.Name -contains "receive_display_smoke") -and $json.receive_display_smoke -eq $true) "receive display smoke should be true"
|
||||
Assert-True (($json.PSObject.Properties.Name -contains "receive_sender_name_populated") -and $json.receive_sender_name_populated -eq $true) "receive sender_name should be populated"
|
||||
Assert-True (($json.PSObject.Properties.Name -contains "receive_conversation_display_populated") -and $json.receive_conversation_display_populated -eq $true) "receive conversation.display_name should be populated"
|
||||
|
||||
Reference in New Issue
Block a user