Files
ai-agent/internal/ai/rag/utils_test.go
T
mlogclub 5d7c10aeab refactor: rename agent widget references to AI agent for consistency
- Updated runtime configuration to use __CS_AI_AGENT_WIDGET_CONFIG__ instead of __CS_AGENT_WIDGET_CONFIG__.
- Changed message types in support host bridge from "cs-agent" to "cs-ai-agent".
- Minified SDK script updated to reflect new AI agent naming conventions.
- Adjusted scrollbar styles in main.scss to use .cs-ai-agent-scrollbar instead of .cs-agent-scrollbar.
2026-05-30 21:19:36 +08:00

44 lines
1.3 KiB
Go

package rag
import (
"cs-ai-agent/internal/ai/rag/vectordb"
"cs-ai-agent/internal/pkg/enums"
"testing"
)
func TestExtractPlainTextFromHTMLSeparatesBlockContent(t *testing.T) {
got := ExtractPlainTextFromHTML("<div>Hello</div><div>World</div><p>Again</p>")
want := "Hello World Again"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}
func TestExtractPlainTextMarkdownUsesGoldmark(t *testing.T) {
got := ExtractPlainText("# Title\n\n- one\n- two", enums.KnowledgeDocumentContentTypeMarkdown)
want := "Title one two"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}
func TestChunkPayloadFromMapSupportsTypedConversion(t *testing.T) {
got := vectordb.ChunkPayloadFromMap(map[string]any{
"knowledge_base_id": "1",
"document_id": "123",
"document_title": "Doc",
"chunk_no": "2",
"chunk_type": "text",
"section_path": "A > B",
"title": "hello",
"content": "world",
"provider": "structured",
})
if got.KnowledgeBaseID != 1 || got.DocumentID != 123 || got.ChunkNo != 2 {
t.Fatalf("unexpected numeric conversion result: %+v", got)
}
if got.DocumentTitle != "Doc" || got.SectionPath != "A > B" || got.Provider != "structured" {
t.Fatalf("unexpected string conversion result: %+v", got)
}
}