4f4f063200
- drop brand_time_buckets and sparkline/coverage UI; dashboard now returns a single day - compute mention rate from total actual samples instead of averaging per-platform rates - canonicalize ai_platform_id across services and aggregate platform-overview snapshots - strip mojibake and non-answer noise from callback payloads and question detail answers - keep Kimi citations panel-only; still store raw search_results for audit - render linked [n] inline citations for qwen/yuanbao answers with scroll-to-source behavior - restrict立即采集 to today's business date with a clear i18n hint - refresh content-citations into an ant-design table with truncation and hover styling Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
103 lines
2.8 KiB
Go
103 lines
2.8 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildMonitoringRawPayloadKimiExcludesSearchResultsFromCitationInputs(t *testing.T) {
|
|
citationTitle := "真实引用文章"
|
|
searchTitle := "搜索网页结果"
|
|
|
|
req := MonitoringTaskResultRequest{
|
|
Status: "succeeded",
|
|
Citations: []MonitoringSourceItem{
|
|
{
|
|
URL: "https://example.com/citation",
|
|
Title: &citationTitle,
|
|
},
|
|
},
|
|
SearchResults: []MonitoringSourceItem{
|
|
{
|
|
URL: "https://example.com/search",
|
|
Title: &searchTitle,
|
|
},
|
|
},
|
|
}
|
|
|
|
rawPayload, sourceInputs := buildMonitoringRawPayload("kimi", req)
|
|
if len(sourceInputs) != 1 {
|
|
t.Fatalf("buildMonitoringRawPayload() sourceInputs len = %d, want 1", len(sourceInputs))
|
|
}
|
|
for _, item := range sourceInputs {
|
|
if item.URL != "https://example.com/citation" {
|
|
t.Fatalf("buildMonitoringRawPayload() source url = %q, want citation url", item.URL)
|
|
}
|
|
}
|
|
|
|
var payload map[string]interface{}
|
|
if err := json.Unmarshal(rawPayload, &payload); err != nil {
|
|
t.Fatalf("json.Unmarshal(rawPayload) error = %v", err)
|
|
}
|
|
if got := len(extractMonitoringSourceItems(payload["search_results"])); got != 1 {
|
|
t.Fatalf("stored search_results len = %d, want 1", got)
|
|
}
|
|
}
|
|
|
|
func TestBuildMonitoringRawPayloadQwenIncludesSearchResultsInCitationInputs(t *testing.T) {
|
|
searchTitle := "搜索网页结果"
|
|
|
|
req := MonitoringTaskResultRequest{
|
|
Status: "succeeded",
|
|
SearchResults: []MonitoringSourceItem{
|
|
{
|
|
URL: "https://example.com/search",
|
|
Title: &searchTitle,
|
|
},
|
|
},
|
|
}
|
|
|
|
_, sourceInputs := buildMonitoringRawPayload("qwen", req)
|
|
if len(sourceInputs) != 1 {
|
|
t.Fatalf("buildMonitoringRawPayload() sourceInputs len = %d, want 1", len(sourceInputs))
|
|
}
|
|
for _, item := range sourceInputs {
|
|
if item.URL != "https://example.com/search" {
|
|
t.Fatalf("buildMonitoringRawPayload() source url = %q, want search url", item.URL)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExtractMonitoringInlineCitationsFromRawResponseKimi(t *testing.T) {
|
|
raw := []byte(`{
|
|
"inline_citation_candidates": [
|
|
{
|
|
"url": "https://example.com/a#ref",
|
|
"title": "文章 A",
|
|
"site_name": "示例站点"
|
|
},
|
|
{
|
|
"url": "https://example.com/a#other",
|
|
"title": "文章 A",
|
|
"site_name": "示例站点"
|
|
},
|
|
{
|
|
"url": "https://example.com/b",
|
|
"title": "文章 B",
|
|
"site_name": "另一个站点"
|
|
}
|
|
]
|
|
}`)
|
|
|
|
items := extractMonitoringInlineCitationsFromRawResponse(raw, "kimi")
|
|
if len(items) != 2 {
|
|
t.Fatalf("extractMonitoringInlineCitationsFromRawResponse() len = %d, want 2", len(items))
|
|
}
|
|
if items[0].URL != "https://example.com/a" {
|
|
t.Fatalf("extractMonitoringInlineCitationsFromRawResponse() first url = %q, want https://example.com/a", items[0].URL)
|
|
}
|
|
if items[1].URL != "https://example.com/b" {
|
|
t.Fatalf("extractMonitoringInlineCitationsFromRawResponse() second url = %q, want https://example.com/b", items[1].URL)
|
|
}
|
|
}
|