Files
HomeAgent/internal/plugins/webui/graph_source_test.go
JianFeeeee 4e70b8d5d8 refactor(module): 核心仓 Go module 路径改为 github.com/JianFeeeee/HologramAgent
批 1,不含 SDK 仓与目录改名。

- go.mod 第 1 行 module 路径
- 366 个 .go 文件的完整前缀 github.com/JianFeeeee/HomeAgent 机械替换
  (857 处,仅完整前缀;展示名/注释里的 HomeAgent 字样留给批 5)
- 未改:third_party 目录名、SDK 自身 go.mod module、go.mod replace 目标、
  homed/waiter 可执行名、.hmap 后缀
2026-10-21 12:17:19 +08:00

47 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package webui
import (
"encoding/json"
"testing"
"github.com/JianFeeeee/HologramAgent/internal/memory"
)
// 星图数据源必须来自块体系(memory_blocks),而不是停写的旧表 entities。
//
// 判据:真实图谱里 memory_blocks 远多于 entities,且块侧仍在增长。
// 这里用合成数据钉住「有块时节点数 == 块数」,防未来又切回 nodes。
func TestGraphDataExposesBlocksForStarmap(t *testing.T) {
// 模拟后端 GraphData 的返回:旧表 1 个节点,块表 3 个块 + 2 条边
data := map[string]interface{}{
"nodes": []map[string]interface{}{{"id": int64(1), "name": "旧表实体", "type": "Concept"}},
"edges": []map[string]interface{}{},
"memory_blocks": []memory.MemoryBlock{
{ID: "blk_src_a", Modality: memory.BlockText, Text: "张三喜欢咖啡", Source: "sentence"},
{ID: "blk_ent_b", Modality: memory.BlockText, Text: "张三", Source: "triple", SemanticType: "Person"},
{ID: "blk_ent_c", Modality: memory.BlockText, Text: "咖啡", Source: "triple"},
},
"memory_block_edges": []memory.MemoryBlockEdge{
{ID: 1, SourceKind: "block", SourceID: "blk_src_a", TargetKind: "block", TargetID: "blk_ent_b", Type: "contains"},
{ID: 2, SourceKind: "block", SourceID: "blk_src_a", TargetKind: "block", TargetID: "blk_ent_c", Type: "contains"},
},
}
out := graphDataForVisual(data)
// 前端读的是 memory_blocks 字段
blocks, ok := out["memory_blocks"]
if !ok {
t.Fatal("GraphData 必须下发 memory_blocks(前端星图的真实数据源)")
}
raw, _ := json.Marshal(blocks)
var got []graphBlockView
if err := json.Unmarshal(raw, &got); err != nil {
t.Fatal(err)
}
if len(got) != 3 {
t.Fatalf("memory_blocks 应下发 3 个,实际 %d", len(got))
}
if _, hasNodes := out["nodes"]; !hasNodes {
t.Fatal("旧 nodes 字段应保留(向后兼容),只是前端不再依赖它")
}
}