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

Function newKnowledgeTestCLI

cli/knowledge_adapter_test.go:22–49  ·  view source on GitHub ↗

newKnowledgeTestCLI builds a minimal ChatCLI whose context manager lives under a throwaway HOME, with one knowledge base created from a docs-flatten JSONL corpus and attached to the default session.

(t *testing.T)

Source from the content-addressed store, hash-verified

20// under a throwaway HOME, with one knowledge base created from a docs-flatten
21// JSONL corpus and attached to the default session.
22func newKnowledgeTestCLI(t *testing.T) *ChatCLI {
23 t.Helper()
24 t.Setenv("HOME", t.TempDir())
25
26 handler, err := NewContextHandler(zap.NewNop())
27 if err != nil {
28 t.Fatalf("NewContextHandler: %v", err)
29 }
30 handler.GetManager().AttachEmbeddingProvider(embedding.NewNull())
31
32 corpus := filepath.Join(t.TempDir(), "docs.jsonl")
33 lines := strings.Join([]string{
34 `{"id":"guide/install.md#0001","source":"guide/install.md","content":"# Install\nHow to install the CLI."}`,
35 `{"id":"guide/install.md#0002","source":"guide/install.md","content":"## Homebrew\nbrew install chatcli"}`,
36 `{"id":"api/auth.md#0001","source":"api/auth.md","content":"# Auth\noauth login bearer token flows"}`,
37 }, "\n")
38 if err := os.WriteFile(corpus, []byte(lines), 0o600); err != nil {
39 t.Fatal(err)
40 }
41 fc, err := handler.GetManager().CreateContext(context.Background(), "chatcli-docs", "test corpus", []string{corpus}, "knowledge", nil, false)
42 if err != nil {
43 t.Fatalf("CreateContext: %v", err)
44 }
45 if err := handler.GetManager().AttachContext("default", fc.ID, 1); err != nil {
46 t.Fatalf("AttachContext: %v", err)
47 }
48 return &ChatCLI{contextHandler: handler, logger: zap.NewNop()}
49}
50
51func TestKnowledgeAdapter_EndToEnd(t *testing.T) {
52 cli := newKnowledgeTestCLI(t)

Calls 6

GetManagerMethod · 0.95
NewNullFunction · 0.92
NewContextHandlerFunction · 0.85
CreateContextMethod · 0.80
AttachContextMethod · 0.80

Tested by

no test coverage detected