Files
ai-agent/internal/ai/rag/utils_test.go
T
mlogclub 101577f163 Refactor internal services to use agent-desk package structure
- Updated import paths in multiple service files to reflect the new agent-desk module.
- Added a new configuration file for agent-desk in the Docker setup.
2026-05-31 18:43:48 +08:00

44 lines
1.3 KiB
Go

package rag
import (
"agent-desk/internal/ai/rag/vectordb"
"agent-desk/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)
}
}