Files
xinmi/internal/infrastructure/web_search/test_errors_test.go
T
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

103 lines
3.0 KiB
Go

package web_search
import (
"strings"
"testing"
"github.com/Tencent/WeKnora/internal/types"
)
func TestEmptyTestResultsError_SearxngWithUnresponsiveEngines(t *testing.T) {
provider := &SearxngProvider{
lastUnresponsive: [][]string{
{"google", "timeout"},
{"bing", "blocked"},
},
}
err := EmptyTestResultsError(string(types.WebSearchProviderTypeSearxng), provider)
if err == nil {
t.Fatal("expected error")
}
msg := err.Error()
if !strings.Contains(msg, "searxng returned 0 results") {
t.Fatalf("unexpected message: %q", msg)
}
if !strings.Contains(msg, "google (timeout)") || !strings.Contains(msg, "bing (blocked)") {
t.Fatalf("expected unresponsive engine details, got: %q", msg)
}
}
func TestEmptyTestResultsError_SearxngWithoutDiagnostics(t *testing.T) {
provider := &SearxngProvider{}
err := EmptyTestResultsError(string(types.WebSearchProviderTypeSearxng), provider)
if err == nil {
t.Fatal("expected error")
}
msg := err.Error()
if !strings.Contains(msg, "JSON format is enabled in settings.yml") {
t.Fatalf("unexpected message: %q", msg)
}
if strings.Contains(msg, "API key") {
t.Fatalf("searxng message must not mention API key: %q", msg)
}
}
func TestEmptyTestResultsError_DuckDuckGo(t *testing.T) {
err := EmptyTestResultsError(string(types.WebSearchProviderTypeDuckDuckGo), nil)
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "duckduckgo returned 0 results") {
t.Fatalf("unexpected message: %q", err.Error())
}
}
func TestEmptyTestResultsError_Keenable(t *testing.T) {
err := EmptyTestResultsError(string(types.WebSearchProviderTypeKeenable), nil)
if err == nil {
t.Fatal("expected error")
}
msg := err.Error()
if !strings.Contains(msg, "keenable returned 0 results") {
t.Fatalf("unexpected message: %q", msg)
}
if !strings.Contains(msg, "rate-limited") {
t.Fatalf("keenable message should hint at the keyless rate limit: %q", msg)
}
}
func TestEmptyTestResultsError_Exa(t *testing.T) {
err := EmptyTestResultsError(string(types.WebSearchProviderTypeExa), nil)
if err == nil {
t.Fatal("expected error")
}
msg := err.Error()
if !strings.Contains(msg, "exa returned 0 results") {
t.Fatalf("unexpected message: %q", msg)
}
if !strings.Contains(msg, "API key") || !strings.Contains(msg, "quota") || !strings.Contains(msg, "proxy") {
t.Fatalf("exa message should include actionable connection checks: %q", msg)
}
}
func TestEmptyTestResultsError_APIKeyProviders(t *testing.T) {
err := EmptyTestResultsError(string(types.WebSearchProviderTypeBing), nil)
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "API key") {
t.Fatalf("bing message should mention API key: %q", err.Error())
}
}
func TestFormatUnresponsiveEngines(t *testing.T) {
got := formatUnresponsiveEngines([][]string{
{"google", "timeout"},
{"wikipedia"},
})
want := "unresponsive engines: google (timeout), wikipedia"
if got != want {
t.Fatalf("formatUnresponsiveEngines() = %q, want %q", got, want)
}
}