Files
moteva/server/internal/infrastructure/websearch/duckduckgo_test.go
T
root 44406b72db Initial commit: img-infinite-canvas AI design workbench MVP
Moteva-style AI design workbench replica. Home prompt creates a project;
the project page provides an infinite canvas with node drag, zoom/pan,
a design chat panel, history replay, image asset upload, and project
save/regenerate.

- Backend: go-zero, DDD layering, sqlc/pgx, optional PostgreSQL; memory
  or Redis cache; asynq job queue; MinIO/S3/R2/OSS object storage;
  sky-valley/pi agent runtime adapter.
- Frontend: Next.js App Router + Vite artifact build, TypeScript, i18n,
  shadcn/ui components, auth (OTP/Turnstile/Google/WeChat).
- Deploy: Docker Compose and k3s manifests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-07 23:15:37 +08:00

42 lines
1.7 KiB
Go

package websearch
import (
"strings"
"testing"
)
func TestParseDuckDuckGoResults(t *testing.T) {
body := `
<a rel="nofollow" class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com%2Ffashion&amp;rut=abc">Fashion Website Design</a>
<a class="result__snippet" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com%2Ffashion&amp;rut=abc">A <b>fashion</b> ecommerce homepage reference.</a>
<a rel="nofollow" class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.org%2Fhoodie&amp;rut=def">Hoodie Brand System</a>
<a class="result__snippet" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.org%2Fhoodie&amp;rut=def">Brand and hoodie visual language.</a>`
results := parseDuckDuckGoResults(body, 5)
if len(results) != 2 {
t.Fatalf("expected 2 results, got %d", len(results))
}
if results[0].Title != "Fashion Website Design" {
t.Fatalf("unexpected title: %s", results[0].Title)
}
if results[0].URL != "https://example.com/fashion" {
t.Fatalf("unexpected url: %s", results[0].URL)
}
if results[0].Snippet != "A fashion ecommerce homepage reference." {
t.Fatalf("unexpected snippet: %s", results[0].Snippet)
}
}
func TestBuildVisualSearchQueryForLogoReferencesAvoidsMakerTools(t *testing.T) {
query := BuildVisualSearchQuery("Moteva 让设计变简单懂你的设计 Agent,帮我搞定一切设计需求,制作一个 logo")
for _, want := range []string{"AI design agent", "logo 设计稿", "设计思路", "brand identity", "-maker", "-generator", "-template"} {
if !strings.Contains(query, want) {
t.Fatalf("expected query to contain %q, got %q", want, query)
}
}
if strings.Contains(query, "制作一个 logo") {
t.Fatalf("expected query to avoid raw prompt wording, got %q", query)
}
}