From 09c2a03cefa687832257d3b816da50db3cfcc0f2 Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Sat, 25 Jul 2026 23:48:11 +0800
Subject: [PATCH] feat: 实现输出格式化

---
 internal/graph/builder_test.go |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/internal/graph/builder_test.go b/internal/graph/builder_test.go
new file mode 100644
index 0000000..8b66be5
--- /dev/null
+++ b/internal/graph/builder_test.go
@@ -0,0 +1,54 @@
+package graph
+
+import (
+	"testing"
+
+	"github.com/aisim/kb-cli/internal/vault"
+)
+
+func TestBuildGraph(t *testing.T) {
+	files := []*vault.FileMeta{
+		{
+			Path:      "FAQ/充装类/001-test.md",
+			Title:     "测试FAQ",
+			Section:   "FAQ",
+			Tags:      []string{"充装", "智能枪"},
+			Entities:  []string{"YSP-35.5"},
+			Wikilinks: []string{},
+			Content:   "测试内容",
+		},
+		{
+			Path:      "知识/002-配置.md",
+			Title:     "充装规格配置",
+			Section:   "知识",
+			Tags:      []string{"充装"},
+			Entities:  []string{},
+			Wikilinks: []string{},
+			Content:   "配置内容",
+		},
+	}
+
+	g := BuildGraph(files)
+
+	if len(g.Nodes) != 2 {
+		t.Errorf("node count = %d, want 2", len(g.Nodes))
+	}
+
+	// 应该有 3 条边:2条 tag + 1条 entity
+	tagEdges := 0
+	entityEdges := 0
+	for _, e := range g.Edges {
+		if e.Relation == "tag" {
+			tagEdges++
+		}
+		if e.Relation == "entity" {
+			entityEdges++
+		}
+	}
+	if tagEdges != 3 { // 充装 + 智能枪 + 充装(第二个文件)
+		t.Errorf("tag edges = %d, want 3", tagEdges)
+	}
+	if entityEdges != 1 {
+		t.Errorf("entity edges = %d, want 1", entityEdges)
+	}
+}

--
Gitblit v1.9.1