(t *testing.T, cfg Config, chatID uuid.UUID, onMessage func())
| 338 | } |
| 339 | |
| 340 | func 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 | |
| 363 | func validatePromptParts(parts []codersdk.ChatInputPart, prompt string) error { |
| 364 | if len(parts) != 1 || parts[0].Type != codersdk.ChatInputPartTypeText || parts[0].Text != prompt { |
no test coverage detected