MCPcopy Create free account
hub / github.com/diillson/chatcli / TestBuildKnowledgeGraph

Function TestBuildKnowledgeGraph

cli/knowledge_graph_test.go:13–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestBuildKnowledgeGraph(t *testing.T) {
14 cli := newTestCLIWithMemory(t)
15 m := cli.memoryStore.Manager()
16
17 // A project, a fact that belongs to it and wikilinks it, and a topic that
18 // links the fact — all relationships the stores already record.
19 m.Projects.Upsert(map[string]string{"name": "chatcli", "path": "/repo/chatcli", "description": "the cli"})
20 m.Facts.AddFactWithSource("uses OAuth2 PKCE for [[chatcli]]", "architecture", []string{"auth"}, "/repo/chatcli")
21 facts := m.Facts.GetAll()
22 if len(facts) == 0 {
23 t.Fatal("fact was not stored")
24 }
25 fid := facts[0].ID
26 m.Topics.Record([]string{"authentication"})
27 m.Topics.LinkFact("authentication", fid)
28
29 g := cli.buildKnowledgeGraph()
30
31 for _, id := range []string{"project:chatcli", "topic:authentication", "fact:" + fid, "tag:auth"} {
32 if _, ok := g.Node(id); !ok {
33 t.Fatalf("expected node %q in graph", id)
34 }
35 }
36
37 // topic → fact edge (from LinkFact).
38 if nb := g.Neighbors("topic:authentication"); len(nb) == 0 || nb[0].ID != "fact:"+fid {
39 t.Fatalf("topic→fact edge missing: %+v", nb)
40 }
41
42 // fact → project edge (source project AND the [[chatcli]] wikilink).
43 foundProj := false
44 for _, nb := range g.Neighbors("fact:" + fid) {
45 if nb.ID == "project:chatcli" {
46 foundProj = true
47 }
48 }
49 if !foundProj {
50 t.Fatal("fact→project edge missing")
51 }
52
53 // @memory map / neighbors formatting (graph folded into @memory).
54 if idx, _ := cli.graphMapText(); !strings.Contains(idx, "Knowledge graph:") {
55 t.Fatalf("map card malformed: %q", idx)
56 }
57 out, _ := cli.graphNeighborsText("authentication") // free-text resolves to topic:authentication
58 if !strings.Contains(out, "Local graph") || !strings.Contains(out, "OAuth2") {
59 t.Fatalf("neighbors output malformed:\n%s", out)
60 }
61}
62
63func TestGraphHelpers(t *testing.T) {
64 if graphSlug(" Auth Flow ") != "auth flow" {

Callers

nothing calls this directly

Calls 12

newTestCLIWithMemoryFunction · 0.85
ManagerMethod · 0.80
AddFactWithSourceMethod · 0.80
LinkFactMethod · 0.80
buildKnowledgeGraphMethod · 0.80
NodeMethod · 0.80
NeighborsMethod · 0.80
graphMapTextMethod · 0.80
graphNeighborsTextMethod · 0.80
UpsertMethod · 0.45
GetAllMethod · 0.45
RecordMethod · 0.45

Tested by

no test coverage detected