Files
glpi-neural-brain/internal/ingest/knowledge_test.go
groot e94fb23f0c
All checks were successful
release-tag / release-image (push) Successful in 1m36s
Update 2+3
2026-08-04 12:07:45 +02:00

75 lines
2.4 KiB
Go

package ingest
import (
"os"
"path/filepath"
"testing"
"github.com/local/glpi-neural-brain/internal/graph"
)
func TestKnowledgeScannerIncludesAIThinkStaging(t *testing.T) {
root := t.TempDir()
prod := filepath.Join(root, "knowledge")
stage := filepath.Join(root, "staging")
if err := os.MkdirAll(prod, 0755); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(stage, 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(prod, "vpn.json"), []byte(`{"id":"KB-VPN","title":"VPN","text":"Gateway","categories":["Netzwerk"],"keywords":["VPN"],"source":"internal-kb"}`), 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(stage, "think.json"), []byte(`{"id":"KB-AI-1","title":"VPN Zusammenhang","text":"Synthese","categories":["AI-THINK"],"keywords":["VPN"],"source":"Neural Brain","ai_think":{"subtype":"knowledge_synthesis","generation_depth":2,"source_node_ids":["a","b","c"]}}`), 0644); err != nil {
t.Fatal(err)
}
g, _ := graph.Open(filepath.Join(root, "data"))
s := KnowledgeScanner{Graph: g, ProductionDirs: []string{prod}, StagingDirs: []string{stage}}
if _, err := s.Scan(); err != nil {
t.Fatal(err)
}
snap := g.Snapshot()
var prodOK, thinkOK bool
for _, n := range snap.Nodes {
if n.ExternalID == "KB-VPN" && n.Status == "production" {
prodOK = true
}
if n.ExternalID == "KB-AI-1" && n.Kind == "ai-think" && n.Status == "staging" {
thinkOK = true
if n.Metadata["subtype"] != "knowledge_synthesis" || n.Metadata["generation_depth"].(float64) != 2 {
t.Fatalf("AI synthesis metadata missing: %#v", n.Metadata)
}
}
}
if !prodOK || !thinkOK {
t.Fatalf("missing nodes: prod=%v think=%v", prodOK, thinkOK)
}
}
func TestKnowledgeScannerSkipsUnchangedGraphReplacement(t *testing.T) {
root := t.TempDir()
prod := filepath.Join(root, "prod")
if err := os.MkdirAll(prod, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(prod, "one.json"), []byte(`{"id":"KB-ONE","title":"One","text":"Same","categories":["Test"]}`), 0o644); err != nil {
t.Fatal(err)
}
g, err := graph.Open(filepath.Join(root, "data"))
if err != nil {
t.Fatal(err)
}
scanner := KnowledgeScanner{Graph: g, ProductionDirs: []string{prod}}
if _, err := scanner.Scan(); err != nil {
t.Fatal(err)
}
v1 := g.Version()
if _, err := scanner.Scan(); err != nil {
t.Fatal(err)
}
if v2 := g.Version(); v2 != v1 {
t.Fatalf("unchanged scan changed graph version: %d -> %d", v1, v2)
}
}