55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package ai
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestFallbackTableAnalysisUnparsedProfile(t *testing.T) {
|
|
result := fallbackTableAnalysis(TableAnalysisInput{
|
|
Topic: "销售分析",
|
|
FileID: "file1",
|
|
FileName: "sales.xlsx",
|
|
FileType: "xlsx",
|
|
FileSize: 5149,
|
|
Profile: TableProfile{Parsed: false, Message: "source file is not available locally"},
|
|
}, Usage{Model: "deepseek-flash"}, "AI 输出格式异常,已使用兜底解读。")
|
|
if result.Title != "销售分析" {
|
|
t.Fatalf("Title=%q, want 销售分析", result.Title)
|
|
}
|
|
if strings.TrimSpace(result.Interpretation) == "" {
|
|
t.Fatal("Interpretation is empty")
|
|
}
|
|
if len(result.Alerts) < 2 {
|
|
t.Fatalf("Alerts len=%d, want at least 2", len(result.Alerts))
|
|
}
|
|
if got := result.Metrics[len(result.Metrics)-1].Value; got != "未解析" {
|
|
t.Fatalf("last metric value=%q, want 未解析", got)
|
|
}
|
|
}
|
|
|
|
func TestFallbackDocumentBuildsDisplayableContent(t *testing.T) {
|
|
result := fallbackDocument(
|
|
"生成一个竞争销售部门副科长职位的演讲稿",
|
|
"竞争销售部门副科长职位演讲稿",
|
|
"meeting_minutes",
|
|
Usage{Model: "deepseek-flash"},
|
|
"AI 输出格式异常,已使用兜底文档。",
|
|
)
|
|
if result.Title != "竞争销售部门副科长职位演讲稿" {
|
|
t.Fatalf("Title=%q, want title hint", result.Title)
|
|
}
|
|
if strings.TrimSpace(result.ContentMarkdown) == "" {
|
|
t.Fatal("ContentMarkdown is empty")
|
|
}
|
|
if !strings.Contains(result.ContentMarkdown, "AI 输出格式异常") {
|
|
t.Fatalf("ContentMarkdown=%q, want fallback reason", result.ContentMarkdown)
|
|
}
|
|
if !strings.Contains(result.ContentPlain, "生成一个竞争销售部门副科长职位的演讲稿") {
|
|
t.Fatalf("ContentPlain=%q, want source text", result.ContentPlain)
|
|
}
|
|
if len(result.Sections) != 3 {
|
|
t.Fatalf("Sections len=%d, want 3", len(result.Sections))
|
|
}
|
|
}
|