(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func 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 | |
| 97 | func TestKnowledgeAdapter_WithoutManager(t *testing.T) { |
| 98 | cli := &ChatCLI{} // no contextHandler wired |
nothing calls this directly
no test coverage detected