From cb72759b568baf34281bd15f821ac9834c17bbb9 Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Thu, 03 Sep 2026 14:24:29 +0800
Subject: [PATCH] merge: 合并 origin/master schema v2 重构(RWR/增量对账/explore),保留 tag/entity 实验于 experiment 分支 + 本地 expandPath 修复与 draft list 过滤

---
 internal/graph/builder_test.go |   67 +++++++++++++++++++--------------
 1 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/internal/graph/builder_test.go b/internal/graph/builder_test.go
index a966c86..afd95de 100644
--- a/internal/graph/builder_test.go
+++ b/internal/graph/builder_test.go
@@ -1,12 +1,46 @@
 package graph
 
 import (
-	"strings"
 	"testing"
 
 	"github.com/aisim/kb-cli/internal/vault"
 )
 
+func TestBuildGraphProvenance(t *testing.T) {
+	files := []*vault.FileMeta{
+		{Path: "FAQ/001-补气失败.md", Title: "补气失败", Wikilinks: []string{"红绿闪", "不存在的链接"}},
+		{Path: "FAQ/002-红绿闪.md", Title: "红绿闪"},
+		{Path: "知识/003-称重原理详解.md", Title: "称重原理详解"}, // "称重原理" 是 "称重原理详解" 的子串 → fuzzy
+	}
+	files[0].Wikilinks = append(files[0].Wikilinks, "称重原理")
+
+	g, unresolved := BuildGraph(files)
+
+	// exact: 标题精确匹配
+	var exact, fuzzy int
+	for _, e := range g.Edges {
+		if e.Relation != "wikilink" {
+			continue
+		}
+		switch e.Provenance {
+		case "exact":
+			exact++
+		case "fuzzy":
+			fuzzy++
+		}
+	}
+	if exact != 1 || fuzzy != 1 {
+		t.Errorf("provenance 分布: exact=%d fuzzy=%d (want 1/1)", exact, fuzzy)
+	}
+	// 悬空链接
+	if len(unresolved) != 1 || unresolved[0].LinkText != "不存在的链接" {
+		t.Errorf("unresolved: %+v", unresolved)
+	}
+	if unresolved[0].NameTail != "不存在的链接" {
+		t.Errorf("name_tail: %s", unresolved[0].NameTail)
+	}
+}
+
 func TestBuildGraph(t *testing.T) {
 	files := []*vault.FileMeta{
 		{
@@ -29,35 +63,10 @@
 		},
 	}
 
-	g := BuildGraph(files)
+	g, _ := BuildGraph(files)
 
-	// 2 个文件节点 + 2 个 tag 虚拟节点(充装、智能枪)+ 1 个 entity 虚拟节点
-	if len(g.Nodes) != 5 {
-		t.Errorf("node count = %d, want 5", len(g.Nodes))
-	}
-
-	// 验证虚拟节点 path 命名空间与 NodeType
-	tagCount, entityCount, fileCount := 0, 0, 0
-	for _, n := range g.Nodes {
-		switch n.NodeType {
-		case "tag":
-			tagCount++
-			if !strings.HasPrefix(n.Path, "tag:") {
-				t.Errorf("tag node path = %q, want prefix tag:", n.Path)
-			}
-		case "entity":
-			entityCount++
-			if !strings.HasPrefix(n.Path, "entity:") {
-				t.Errorf("entity node path = %q, want prefix entity:", n.Path)
-			}
-		case "file":
-			fileCount++
-		default:
-			t.Errorf("unexpected node_type %q for %s", n.NodeType, n.Path)
-		}
-	}
-	if tagCount != 2 || entityCount != 1 || fileCount != 2 {
-		t.Errorf("file/tag/entity = %d/%d/%d, want 2/2/1", fileCount, tagCount, entityCount)
+	if len(g.Nodes) != 2 {
+		t.Errorf("node count = %d, want 2", len(g.Nodes))
 	}
 
 	// 应该有 3 条边:2条 tag + 1条 entity

--
Gitblit v1.10.0