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

Function TestHandler_SendPrompt_WithWatcherContext

server/handler_test.go:344–367  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

342}
343
344func TestHandler_SendPrompt_WithWatcherContext(t *testing.T) {
345 logger := zap.NewNop()
346
347 llmClient := &mockLLMClient{}
348 // The enriched prompt should contain the K8s context + user question
349 llmClient.On("SendPrompt", mock.Anything, mock.MatchedBy(func(prompt string) bool {
350 return strings.Contains(prompt, "[K8s] 3 pods ready") && strings.Contains(prompt, "User Question: Is it healthy?")
351 }), []models.Message{}, 0).Return("Yes, all pods are running.", nil)
352 llmClient.On("GetModelName").Return("gpt-4")
353
354 mgr := &mockLLMManager{}
355 mgr.On("GetClient", "openai", "").Return(llmClient, nil)
356
357 handler := NewHandler(mgr, nil, logger, "openai", "")
358 handler.SetWatcherContext(func() string {
359 return "[K8s] 3 pods ready"
360 })
361
362 resp, err := handler.SendPrompt(context.Background(), &pb.SendPromptRequest{
363 Prompt: "Is it healthy?",
364 })
365 assert.NoError(t, err)
366 assert.Equal(t, "Yes, all pods are running.", resp.Response)
367}
368
369func TestHandler_GetServerInfo_WithWatcher(t *testing.T) {
370 logger := zap.NewNop()

Callers

nothing calls this directly

Calls 4

SetWatcherContextMethod · 0.95
SendPromptMethod · 0.95
NewHandlerFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected