From 46a01d99b5d15120ada95754c9effbdcb576d31e Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Sun, 26 Jul 2026 08:19:23 +0800
Subject: [PATCH] Task 4: add CLI flags for with-content and with-links

---
 internal/index/sqlite_test.go |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/internal/index/sqlite_test.go b/internal/index/sqlite_test.go
index f83b4bb..5ff1d40 100644
--- a/internal/index/sqlite_test.go
+++ b/internal/index/sqlite_test.go
@@ -64,3 +64,70 @@
 		t.Errorf("node count = %d, want 1", count)
 	}
 }
+
+func TestGetNodeLinks(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()
+
+	// 插入测试节点
+	node1 := &graph.Node{
+		Path:    "FAQ/001-测试.md",
+		Title:   "测试文档",
+		Section: "FAQ",
+		Content: "# 测试\n\n内容",
+	}
+	node2 := &graph.Node{
+		Path:    "FAQ/002-相关.md",
+		Title:   "相关文档",
+		Section: "FAQ",
+		Content: "# 相关\n\n内容",
+	}
+
+	id1, err := store.InsertNode(node1)
+	if err != nil {
+		t.Fatalf("InsertNode node1 failed: %v", err)
+	}
+
+	id2, err := store.InsertNode(node2)
+	if err != nil {
+		t.Fatalf("InsertNode node2 failed: %v", err)
+	}
+
+	// 插入 wikilink 边
+	edge := &graph.Edge{
+		FromNode: id1,
+		ToNode:   id2,
+		Relation: "wikilink",
+		Label:    "相关文档",
+	}
+	if err := store.InsertEdge(edge); err != nil {
+		t.Fatalf("InsertEdge failed: %v", err)
+	}
+
+	// 测试获取链接
+	links, err := store.GetNodeLinks(id1)
+	if err != nil {
+		t.Fatalf("GetNodeLinks failed: %v", err)
+	}
+	if len(links) != 1 {
+		t.Errorf("links count = %d, want 1", len(links))
+	}
+	if len(links) > 0 && links[0] != "FAQ/002-相关.md" {
+		t.Errorf("links[0] = %q, want %q", links[0], "FAQ/002-相关.md")
+	}
+
+	// 测试无链接的节点
+	links, err = store.GetNodeLinks(id2)
+	if err != nil {
+		t.Fatalf("GetNodeLinks for node2 failed: %v", err)
+	}
+	if len(links) != 0 {
+		t.Errorf("links count = %d, want 0", len(links))
+	}
+}

--
Gitblit v1.9.1