MCPcopy Create free account
hub / github.com/coder/coder / newTestRunnerWithChatMessage

Function newTestRunnerWithChatMessage

scaletest/chat/run_internal_test.go:340–361  ·  view source on GitHub ↗
(t *testing.T, cfg Config, chatID uuid.UUID, onMessage func())

Source from the content-addressed store, hash-verified

338}
339
340func newTestRunnerWithChatMessage(t *testing.T, cfg Config, chatID uuid.UUID, onMessage func()) *Runner {
341 t.Helper()
342
343 client := newFakeChatClient(t)
344 client.createChatMessageFunc = func(ctx context.Context, gotChatID uuid.UUID, req codersdk.CreateChatMessageRequest) (codersdk.CreateChatMessageResponse, error) {
345 if gotChatID != chatID {
346 return codersdk.CreateChatMessageResponse{}, xerrors.Errorf("unexpected chat message ID: %s", gotChatID)
347 }
348 if err := validatePromptParts(req.Content, cfg.Prompt); err != nil {
349 return codersdk.CreateChatMessageResponse{}, err
350 }
351 if req.ModelConfigID == nil || *req.ModelConfigID != cfg.ModelConfigID {
352 return codersdk.CreateChatMessageResponse{}, xerrors.Errorf("unexpected chat message model config ID: %v", req.ModelConfigID)
353 }
354
355 if onMessage != nil {
356 onMessage()
357 }
358 return codersdk.CreateChatMessageResponse{Queued: true}, nil
359 }
360 return &Runner{client: client, cfg: cfg}
361}
362
363func validatePromptParts(parts []codersdk.ChatInputPart, prompt string) error {
364 if len(parts) != 1 || parts[0].Type != codersdk.ChatInputPartTypeText || parts[0].Text != prompt {

Callers 1

Calls 4

newFakeChatClientFunction · 0.85
validatePromptPartsFunction · 0.85
HelperMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected