2bbf42b741
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package rag
|
|
|
|
import (
|
|
"code.tczkiot.com/wlw/ai-agent/internal/ai/rag/vectordb"
|
|
"code.tczkiot.com/wlw/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)
|
|
}
|
|
}
|