feat: Implement comprehensive wiki feature for knowledge bases
This commit introduces the complete wiki feature for WeKnora, enabling AI-powered wiki page generation and management. The implementation includes: **Backend Changes:** - Wiki data model: WikiPage type with support for multiple page types (Summary, Entity, Concept, Index, Log) - Database schema: wiki_pages table with full migration support - WikiPageService: CRUD operations and page management - WikiPageRepository: GORM-based persistence layer - Wiki ingest pipeline: Automated generation of wiki pages from knowledge documents * Summary page generation using LLM * Entity and concept extraction in a single LLM call * Synthesis opportunity detection * Index page rebuilding * Log page maintenance - Wiki boost feature: Enhance chat retrieval with wiki context - Wiki linting: Maintenance and validation utilities - Agent wiki tools: Enable agents to query and interact with wiki pages - Wiki prompts: Comprehensive LLM prompt templates for all wiki generation tasks - Language support: Reuse existing middleware language infrastructure for LLM prompts **Frontend Changes:** - Wiki browser UI: View all wiki pages with filtering and search - Wiki API client: Knowledge base wiki management endpoints - Knowledge base editor: Configure wiki settings (language, auto-ingest, synthesis model) - i18n updates: Support for English, Korean, Russian, and Chinese interfaces **Configuration:** - Container DI: Wire up all wiki services - Router: Register wiki API endpoints - Task handling: Support async wiki ingest tasks **Testing:** - Unit tests for wiki page types - Service layer tests - Endpoint tests for wiki operations - Integration tests with LLM mocking **Documentation:** - Language refactoring analysis and guides - Implementation completion reports - Quick reference guides for developers **Key Features:** ✅ LLM-powered wiki page generation from documents ✅ Multi-language support (9+ languages) ✅ Automatic extraction of entities and concepts ✅ Synthesis opportunity detection ✅ Index and log page maintenance ✅ Progressive wiki building across multiple documents ✅ Agent-based wiki interaction ✅ Chat retrieval enhancement with wiki context ✅ Full frontend UI for wiki browsing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestParseOutLinks(t *testing.T) {
|
||||
svc := &wikiPageService{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
content string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "single link",
|
||||
content: "See [[entity/acme-corp]] for details.",
|
||||
want: []string{"entity/acme-corp"},
|
||||
},
|
||||
{
|
||||
name: "multiple links",
|
||||
content: "See [[entity/acme-corp]] and [[concept/rag]] for details.",
|
||||
want: []string{"entity/acme-corp", "concept/rag"},
|
||||
},
|
||||
{
|
||||
name: "duplicate links deduplicated",
|
||||
content: "See [[entity/acme-corp]] and also [[entity/acme-corp]] again.",
|
||||
want: []string{"entity/acme-corp"},
|
||||
},
|
||||
{
|
||||
name: "pipe syntax: title|slug",
|
||||
content: "See [[Acme Corp|entity/acme-corp]] for details.",
|
||||
want: []string{"entity/acme-corp"},
|
||||
},
|
||||
{
|
||||
name: "no links",
|
||||
content: "Just plain text without any links.",
|
||||
want: nil,
|
||||
},
|
||||
{
|
||||
name: "empty content",
|
||||
content: "",
|
||||
want: nil,
|
||||
},
|
||||
{
|
||||
name: "link with spaces normalized",
|
||||
content: "See [[Entity/Acme Corp]] for details.",
|
||||
want: []string{"entity/acme-corp"},
|
||||
},
|
||||
{
|
||||
name: "nested brackets ignored",
|
||||
content: "Not a link: [not [a] link]",
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := svc.parseOutLinks(tt.content)
|
||||
if len(got) != len(tt.want) {
|
||||
t.Errorf("parseOutLinks() = %v (len %d), want %v (len %d)", got, len(got), tt.want, len(tt.want))
|
||||
return
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != tt.want[i] {
|
||||
t.Errorf("parseOutLinks()[%d] = %q, want %q", i, got[i], tt.want[i])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSlug(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{"Entity/Acme Corp", "entity/acme-corp"},
|
||||
{" hello ", "hello"},
|
||||
{"UPPER-CASE", "upper-case"},
|
||||
{"already-ok", "already-ok"},
|
||||
{"", ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
got := normalizeSlug(tt.input)
|
||||
if got != tt.want {
|
||||
t.Errorf("normalizeSlug(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainsString(t *testing.T) {
|
||||
slice := []string{"a", "b", "c"}
|
||||
if !containsString(slice, "b") {
|
||||
t.Error("should contain 'b'")
|
||||
}
|
||||
if containsString(slice, "d") {
|
||||
t.Error("should not contain 'd'")
|
||||
}
|
||||
if containsString(nil, "a") {
|
||||
t.Error("nil slice should not contain anything")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveString(t *testing.T) {
|
||||
slice := types.StringArray{"a", "b", "c", "b"}
|
||||
result := removeString(slice, "b")
|
||||
if len(result) != 2 {
|
||||
t.Errorf("Expected 2 items after removing 'b', got %d: %v", len(result), result)
|
||||
}
|
||||
if result[0] != "a" || result[1] != "c" {
|
||||
t.Errorf("Unexpected result: %v", result)
|
||||
}
|
||||
|
||||
// Remove non-existing
|
||||
result2 := removeString(slice, "z")
|
||||
if len(result2) != 4 {
|
||||
t.Errorf("Expected 4 items (nothing removed), got %d", len(result2))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user