feat: register isphere contact search tool
This commit is contained in:
@@ -7,7 +7,8 @@ $expectedTools = @(
|
||||
"win_helper_self_check",
|
||||
"win_helper_scan_windows",
|
||||
"win_helper_dump_uia",
|
||||
"isphere_receive_messages"
|
||||
"isphere_receive_messages",
|
||||
"isphere_search_contacts"
|
||||
)
|
||||
|
||||
$tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("isphere-go-mcp-verify-" + [guid]::NewGuid().ToString("N"))
|
||||
@@ -79,9 +80,10 @@ var expectedTools = []string{
|
||||
"win_helper_scan_windows",
|
||||
"win_helper_dump_uia",
|
||||
"isphere_receive_messages",
|
||||
"isphere_search_contacts",
|
||||
}
|
||||
|
||||
var forbiddenTerms = []string{"send", "search", "file", "login", "conversation", "upload", "download", "autologin"}
|
||||
var forbiddenTerms = []string{"send", "file", "login", "conversation", "upload", "download", "autologin"}
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
@@ -134,7 +136,7 @@ func main() {
|
||||
sort.Strings(toolNames)
|
||||
want := append([]string(nil), expectedTools...)
|
||||
sort.Strings(want)
|
||||
if len(toolNames) != 5 || !reflect.DeepEqual(toolNames, want) {
|
||||
if len(toolNames) != 6 || !reflect.DeepEqual(toolNames, want) {
|
||||
fail("tools/list", fmt.Errorf("tool names = %#v, want %#v", toolNames, want))
|
||||
}
|
||||
|
||||
@@ -184,7 +186,8 @@ func main() {
|
||||
if len(messagesValue) != 0 {
|
||||
fail("tools/call isphere_receive_messages", fmt.Errorf("default empty source returned %d messages, want 0", len(messagesValue)))
|
||||
}
|
||||
configuredReceiveCount := verifyConfiguredReceiveSource(ctx)
|
||||
defaultContactCount := verifySearchContacts(ctx, session, "sender", "tools/call isphere_search_contacts default", 0)
|
||||
configuredReceiveCount, configuredContactCount := verifyConfiguredReceiveSource(ctx)
|
||||
|
||||
result := map[string]any{
|
||||
"ok": true,
|
||||
@@ -194,7 +197,9 @@ func main() {
|
||||
"tools": toolNames,
|
||||
"helper_name": helperName,
|
||||
"receive_message_count": len(messagesValue),
|
||||
"contact_count": defaultContactCount,
|
||||
"configured_receive_message_count": configuredReceiveCount,
|
||||
"configured_contact_count": configuredContactCount,
|
||||
"packet_log_file_configured": os.Getenv("ISPHERE_PACKET_LOG_FILE") != "",
|
||||
"real_isphere_login_required": false,
|
||||
"python_runtime_required": false,
|
||||
@@ -205,7 +210,7 @@ func main() {
|
||||
}
|
||||
|
||||
|
||||
func verifyConfiguredReceiveSource(ctx context.Context) int {
|
||||
func verifyConfiguredReceiveSource(ctx context.Context) (int, int) {
|
||||
plaintext := "--------------------------------------------------------------------------------------------------------------------------------------------\n" +
|
||||
"2026/7/7 15:30:07\n" +
|
||||
"<message id=\"msg-fixture-1\" from=\"sender@imopenfire1-lanzhou/imp_pc_4.1.2.6842\" to=\"receiver@imopenfire1-lanzhou\" type=\"chat\">\n" +
|
||||
@@ -302,7 +307,43 @@ func verifyConfiguredReceiveSource(ctx context.Context) int {
|
||||
if message["conversation_id"] != "sender@imopenfire1-lanzhou|receiver@imopenfire1-lanzhou" {
|
||||
fail("fixture/assert", fmt.Errorf("conversation_id = %#v", message["conversation_id"]))
|
||||
}
|
||||
return len(messagesValue)
|
||||
contactCount := verifySearchContacts(ctx, session, "sender", "fixture/call isphere_search_contacts", 1)
|
||||
return len(messagesValue), contactCount
|
||||
}
|
||||
|
||||
func verifySearchContacts(ctx context.Context, session *mcp.ClientSession, query string, step string, wantCount int) int {
|
||||
callResult, err := session.CallTool(ctx, &mcp.CallToolParams{Name: "isphere_search_contacts", Arguments: map[string]any{"query": query, "limit": 5}})
|
||||
if err != nil {
|
||||
fail(step, err)
|
||||
}
|
||||
if callResult.IsError {
|
||||
fail(step, fmt.Errorf("tool returned isError=true: %#v", callResult.Content))
|
||||
}
|
||||
var contactsPayload map[string]any
|
||||
encoded, _ := json.Marshal(callResult.StructuredContent)
|
||||
if err := json.Unmarshal(encoded, &contactsPayload); err != nil {
|
||||
fail(step, fmt.Errorf("decode structuredContent %s: %w", encoded, err))
|
||||
}
|
||||
if contactsPayload["ok"] != true {
|
||||
fail(step, fmt.Errorf("ok = %#v, want true", contactsPayload["ok"]))
|
||||
}
|
||||
contactsValue, ok := contactsPayload["contacts"].([]any)
|
||||
if !ok {
|
||||
fail(step, fmt.Errorf("contacts missing or not array: %s", encoded))
|
||||
}
|
||||
if len(contactsValue) != wantCount {
|
||||
fail(step, fmt.Errorf("contacts count = %d, want %d: %s", len(contactsValue), wantCount, encoded))
|
||||
}
|
||||
if wantCount > 0 {
|
||||
contact, ok := contactsValue[0].(map[string]any)
|
||||
if !ok {
|
||||
fail(step, fmt.Errorf("contact was not object: %#v", contactsValue[0]))
|
||||
}
|
||||
if contact["contact_id"] != "sender@imopenfire1-lanzhou" || contact["source"] != "local_readonly" {
|
||||
fail(step, fmt.Errorf("unexpected contact: %#v", contact))
|
||||
}
|
||||
}
|
||||
return len(contactsValue)
|
||||
}
|
||||
|
||||
func encryptPacketLogLineForHarness(plaintext string) (string, error) {
|
||||
@@ -353,9 +394,11 @@ func fail(step string, err error) {
|
||||
|
||||
Assert-True ($script:harnessJson.ok -eq $true) "SDK harness did not return ok=true"
|
||||
Assert-True ($script:harnessJson.helper_name -eq "ISphereWinHelper") "SDK harness helper_name mismatch: $($script:harnessJson.helper_name)"
|
||||
Assert-True ($script:harnessJson.tool_count -eq 5) "SDK harness tool_count mismatch: $($script:harnessJson.tool_count)"
|
||||
Assert-True ($script:harnessJson.tool_count -eq 6) "SDK harness tool_count mismatch: $($script:harnessJson.tool_count)"
|
||||
Assert-True ($script:harnessJson.receive_message_count -eq 0) "SDK harness receive_message_count mismatch: $($script:harnessJson.receive_message_count)"
|
||||
Assert-True ($script:harnessJson.contact_count -eq 0) "SDK harness contact_count mismatch: $($script:harnessJson.contact_count)"
|
||||
Assert-True ($script:harnessJson.configured_receive_message_count -eq 1) "SDK harness configured_receive_message_count mismatch: $($script:harnessJson.configured_receive_message_count)"
|
||||
Assert-True ($script:harnessJson.configured_contact_count -eq 1) "SDK harness configured_contact_count mismatch: $($script:harnessJson.configured_contact_count)"
|
||||
|
||||
[ordered]@{
|
||||
ok = $true
|
||||
@@ -365,7 +408,9 @@ func fail(step string, err error) {
|
||||
tool_count = $script:harnessJson.tool_count
|
||||
tools = $script:harnessJson.tools
|
||||
receive_message_count = $script:harnessJson.receive_message_count
|
||||
contact_count = $script:harnessJson.contact_count
|
||||
configured_receive_message_count = $script:harnessJson.configured_receive_message_count
|
||||
configured_contact_count = $script:harnessJson.configured_contact_count
|
||||
packet_log_file_configured = $script:harnessJson.packet_log_file_configured
|
||||
python_runtime_required = $false
|
||||
real_isphere_login_required = $false
|
||||
|
||||
Reference in New Issue
Block a user