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)
| 20 | // under a throwaway HOME, with one knowledge base created from a docs-flatten |
| 21 | // JSONL corpus and attached to the default session. |
| 22 | func 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 | |
| 51 | func TestKnowledgeAdapter_EndToEnd(t *testing.T) { |
| 52 | cli := newKnowledgeTestCLI(t) |
no test coverage detected