feat: harden search ranking and deduplication
This commit is contained in:
@@ -135,6 +135,57 @@ func TestISphereSearchGroupsToolUsesInjectedDisplayEntities(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestISphereSearchGroupsToolRanksExactAndDeduplicatesDisplayEntities(t *testing.T) {
|
||||
fakeMessages := &fakeReceiveMessagesSource{
|
||||
result: isphere.ReceiveMessagesResult{Messages: []isphere.Message{{
|
||||
ID: "msg-1",
|
||||
ConversationType: "groupchat",
|
||||
SenderID: "target@conference.imopenfire1-lanzhou",
|
||||
ReceiverID: "member@imopenfire1-lanzhou",
|
||||
}}},
|
||||
}
|
||||
fakeDisplay := &fakeDisplayEntitySource{entities: []msglib.DisplayEntity{
|
||||
{EntityType: msglib.EntityTypeGroups, SourceTable: "TD_WorkGroupAuth", JID: "zzz-target@conference.imopenfire1-lanzhou", DisplayName: "ZZZ Target Group", Confidence: 0.8},
|
||||
{EntityType: msglib.EntityTypeGroups, SourceTable: "TD_WorkGroupAuth", JID: "target@conference.imopenfire1-lanzhou", DisplayName: "Target Group", Confidence: 0.9},
|
||||
}}
|
||||
session, cleanup := connectToolsTestSession(t, func(server *mcp.Server) {
|
||||
RegisterISphereGroupToolsWithDisplayEntities(server, fakeMessages, fakeDisplay)
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
callResult, err := session.CallTool(context.Background(), &mcp.CallToolParams{
|
||||
Name: ToolNameSearchGroups,
|
||||
Arguments: map[string]any{"query": "target@conference.imopenfire1-lanzhou", "limit": 10},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("call %s: %v", ToolNameSearchGroups, err)
|
||||
}
|
||||
if callResult.IsError {
|
||||
t.Fatalf("call result is error: %+v", callResult)
|
||||
}
|
||||
|
||||
var decoded struct {
|
||||
Groups []struct {
|
||||
GroupID string `json:"group_id"`
|
||||
Source string `json:"source"`
|
||||
RawRef string `json:"raw_ref"`
|
||||
} `json:"groups"`
|
||||
}
|
||||
payload, _ := json.Marshal(callResult.StructuredContent)
|
||||
if err := json.Unmarshal(payload, &decoded); err != nil {
|
||||
t.Fatalf("decode structured content %s: %v", payload, err)
|
||||
}
|
||||
if len(decoded.Groups) != 2 {
|
||||
t.Fatalf("groups = %+v, want exact and substring only", decoded.Groups)
|
||||
}
|
||||
if decoded.Groups[0].GroupID != "target@conference.imopenfire1-lanzhou" || decoded.Groups[0].Source != "msglib_readonly" || decoded.Groups[0].RawRef != "msglib:TD_WorkGroupAuth" {
|
||||
t.Fatalf("first group should be exact MsgLib match with source metadata, got %+v", decoded.Groups[0])
|
||||
}
|
||||
if decoded.Groups[1].GroupID != "zzz-target@conference.imopenfire1-lanzhou" {
|
||||
t.Fatalf("second group should be substring match, got %+v", decoded.Groups[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestISphereSearchGroupsToolValidatesContractArgs(t *testing.T) {
|
||||
fake := &fakeReceiveMessagesSource{
|
||||
result: isphere.ReceiveMessagesResult{Messages: []isphere.Message{{
|
||||
|
||||
Reference in New Issue
Block a user