feat: validate contact and group search args

This commit is contained in:
zhaoyilun
2026-07-10 01:38:48 +08:00
parent 95699e05b5
commit b1891dd6cd
10 changed files with 207 additions and 21 deletions

View File

@@ -74,3 +74,50 @@ func TestISphereSearchContactsToolReturnsJIDContacts(t *testing.T) {
t.Fatalf("source queries = %+v, want one unbounded receive query", fake.queries)
}
}
func TestISphereSearchContactsToolValidatesContractArgs(t *testing.T) {
fake := &fakeReceiveMessagesSource{
result: isphere.ReceiveMessagesResult{Messages: []isphere.Message{{
ID: "msg-1",
SenderID: "alice@imopenfire1-lanzhou",
ReceiverID: "bob@imopenfire1-lanzhou",
}}},
}
session, cleanup := connectToolsTestSession(t, func(server *mcp.Server) {
RegisterISphereContactTools(server, fake)
})
defer cleanup()
callResult, err := session.CallTool(context.Background(), &mcp.CallToolParams{
Name: ToolNameSearchContacts,
Arguments: map[string]any{
"query": "alice",
"source_preference": "local_readonly",
"include_inactive": true,
"cursor": "",
"limit": 10,
},
})
if err != nil {
t.Fatalf("call with safe contract args: %v", err)
}
if callResult.IsError {
t.Fatalf("call result is error: %+v", callResult)
}
bridgeResult, err := session.CallTool(context.Background(), &mcp.CallToolParams{
Name: ToolNameSearchContacts,
Arguments: map[string]any{"query": "alice", "source_preference": "bridge"},
})
if err == nil && !bridgeResult.IsError {
t.Fatalf("bridge source_preference was accepted before connector exists")
}
cursorResult, err := session.CallTool(context.Background(), &mcp.CallToolParams{
Name: ToolNameSearchContacts,
Arguments: map[string]any{"query": "alice", "cursor": "next-page"},
})
if err == nil && !cursorResult.IsError {
t.Fatalf("non-empty cursor was accepted before pagination exists")
}
}