@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -50,3 +51,38 @@ func TestLoadRequiresSourceMetadata(t *testing.T) {
|
||||
t.Fatal("expected missing source to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadMissingDirectoryReturnsHelpfulError(t *testing.T) {
|
||||
missing := filepath.Join(t.TempDir(), "does-not-exist")
|
||||
_, err := Load(context.Background(), missing, t.TempDir(), nil, false, []string{"internal-kb"})
|
||||
if err == nil {
|
||||
t.Fatal("expected missing knowledge directory to fail")
|
||||
}
|
||||
if got := err.Error(); !strings.Contains(got, "read knowledge directory") || !strings.Contains(got, missing) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilStoreHelpersDoNotPanic(t *testing.T) {
|
||||
var s *Store
|
||||
if got := s.Count(); got != 0 {
|
||||
t.Fatalf("Count()=%d, want 0", got)
|
||||
}
|
||||
if _, ok := s.ByID("KB1"); ok {
|
||||
t.Fatal("nil store unexpectedly returned a document")
|
||||
}
|
||||
if _, err := s.Search(context.Background(), "vpn", 1); err == nil {
|
||||
t.Fatal("expected Search on nil store to return an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRAGRequiresEmbedderWhenDocumentsExist(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
doc := `{"id":"I1","title":"VPN intern","text":"gateway vpn","answer":"x","source":"internal-kb","language":"de-DE","communication_style":"formal"}`
|
||||
if err := os.WriteFile(filepath.Join(dir, "internal.json"), []byte(doc), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Load(context.Background(), dir, t.TempDir(), nil, true, []string{"internal-kb"}); err == nil {
|
||||
t.Fatal("expected RAG without embedder to fail")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user