ai_xiaopei
2026-07-25 7445005745523d430a3cd22c3208cce2f383f1ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package index
 
import (
    "path/filepath"
    "testing"
 
    "github.com/aisim/kb-cli/internal/graph"
)
 
func TestStore(t *testing.T) {
    tmpDir := t.TempDir()
    dbPath := filepath.Join(tmpDir, "test.db")
 
    store, err := Open(dbPath)
    if err != nil {
        t.Fatalf("Open failed: %v", err)
    }
    defer store.Close()
 
    // 测试插入节点
    node := &graph.Node{
        Path:    "FAQ/充装类/001-test.md",
        Title:   "测试FAQ",
        Section: "FAQ",
        Tags:    []string{"充装", "智能枪"},
    }
    id, err := store.InsertNode(node)
    if err != nil {
        t.Fatalf("InsertNode failed: %v", err)
    }
    if id == 0 {
        t.Error("InsertNode returned 0 id")
    }
 
    // 测试插入边
    edge := &graph.Edge{
        FromNode: id,
        ToNode:   1000000,
        Relation: "tag",
        Label:    "充装",
    }
    if err := store.InsertEdge(edge); err != nil {
        t.Fatalf("InsertEdge failed: %v", err)
    }
 
    // 测试元信息
    if err := store.SetMeta("git_commit", "abc123"); err != nil {
        t.Fatalf("SetMeta failed: %v", err)
    }
    commit, err := store.GetMeta("git_commit")
    if err != nil {
        t.Fatalf("GetMeta failed: %v", err)
    }
    if commit != "abc123" {
        t.Errorf("commit = %q, want %q", commit, "abc123")
    }
 
    // 测试计数
    count, err := store.NodeCount()
    if err != nil {
        t.Fatalf("NodeCount failed: %v", err)
    }
    if count != 1 {
        t.Errorf("node count = %d, want 1", count)
    }
}