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

Function TestKnowledgeAdapter_EndToEnd

cli/knowledge_adapter_test.go:51–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestKnowledgeAdapter_EndToEnd(t *testing.T) {
52 cli := newKnowledgeTestCLI(t)
53 a := &knowledgePluginAdapter{cli: cli}
54
55 list, err := a.List()
56 if err != nil || !strings.Contains(list, "chatcli-docs") {
57 t.Fatalf("List = %q, err %v", list, err)
58 }
59
60 // topK above the cap must be clamped, not rejected.
61 found, err := a.Search("homebrew install", "", 500)
62 if err != nil {
63 t.Fatalf("Search: %v", err)
64 }
65 if !strings.Contains(found, "brew install chatcli") || !strings.Contains(found, "guide/install.md") {
66 t.Errorf("Search must return the cited passage, got:\n%s", found)
67 }
68
69 doc, err := a.Get("guide/install.md", "", 0)
70 if err != nil {
71 t.Fatalf("Get: %v", err)
72 }
73 if !strings.Contains(doc, "# Install") || !strings.Contains(doc, "## Homebrew") {
74 t.Errorf("Get must join the document chunks, got:\n%s", doc)
75 }
76 if strings.Contains(doc, "document continues") {
77 t.Error("small document must not advertise a continuation")
78 }
79 if _, err := a.Get("guide/missing.md", "", 0); err == nil {
80 t.Error("unknown source must error")
81 }
82
83 toc, err := a.TOC("", "api/")
84 if err != nil {
85 t.Fatalf("TOC: %v", err)
86 }
87 if !strings.Contains(toc, "api/auth.md") || strings.Contains(toc, "guide/install.md") {
88 t.Errorf("TOC prefix filter failed:\n%s", toc)
89 }
90
91 block := cli.knowledgeAgentBlock()
92 if !strings.Contains(block, "📚 KNOWLEDGE BASE: chatcli-docs") || !strings.Contains(block, "@knowledge") {
93 t.Errorf("agent block must carry the digest and the tool hint, got:\n%s", block)
94 }
95}
96
97func TestKnowledgeAdapter_WithoutManager(t *testing.T) {
98 cli := &ChatCLI{} // no contextHandler wired

Callers

nothing calls this directly

Calls 8

ListMethod · 0.95
SearchMethod · 0.95
GetMethod · 0.95
TOCMethod · 0.95
newKnowledgeTestCLIFunction · 0.85
ErrorfMethod · 0.80
knowledgeAgentBlockMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected