(t *testing.T)
| 8603 | } |
| 8604 | |
| 8605 | func TestManualTitleEndpointsPassCallerAPIKeyToAIGateway(t *testing.T) { |
| 8606 | t.Parallel() |
| 8607 | |
| 8608 | for _, tt := range []struct { |
| 8609 | name string |
| 8610 | call func(context.Context, *codersdk.ExperimentalClient, uuid.UUID) error |
| 8611 | }{ |
| 8612 | { |
| 8613 | name: "RegenerateChatTitle", |
| 8614 | call: func(ctx context.Context, client *codersdk.ExperimentalClient, chatID uuid.UUID) error { |
| 8615 | _, err := client.RegenerateChatTitle(ctx, chatID) |
| 8616 | return err |
| 8617 | }, |
| 8618 | }, |
| 8619 | { |
| 8620 | name: "ProposeChatTitle", |
| 8621 | call: func(ctx context.Context, client *codersdk.ExperimentalClient, chatID uuid.UUID) error { |
| 8622 | _, err := client.ProposeChatTitle(ctx, chatID) |
| 8623 | return err |
| 8624 | }, |
| 8625 | }, |
| 8626 | } { |
| 8627 | t.Run(tt.name, func(t *testing.T) { |
| 8628 | t.Parallel() |
| 8629 | |
| 8630 | ctx := testutil.Context(t, testutil.WaitLong) |
| 8631 | values := chatDeploymentValues(t) |
| 8632 | require.NoError(t, values.AI.BridgeConfig.Enabled.Set("true")) |
| 8633 | require.NoError(t, values.AI.Chat.AIGatewayRoutingEnabled.Set("true")) |
| 8634 | client, db, api := newChatClientWithAPIAndDatabase(t, func(opts *coderdtest.Options) { |
| 8635 | opts.DeploymentValues = values |
| 8636 | }) |
| 8637 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 8638 | modelConfig := createAdditionalChatModelConfig(t, client, "openai", "gpt-4.1") |
| 8639 | wantAPIKeyID := strings.Split(client.SessionToken(), "-")[0] |
| 8640 | wantTitle := "Fallback title" |
| 8641 | seenAPIKeyID := make(chan string, 1) |
| 8642 | stub := &stubTransportFactory{ |
| 8643 | handler: http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 8644 | apiKeyID, _ := aibridge.DelegatedAPIKeyIDFromContext(r.Context()) |
| 8645 | seenAPIKeyID <- apiKeyID |
| 8646 | rw.Header().Set("Content-Type", "application/json") |
| 8647 | text := strconv.Quote(`{"title":"` + wantTitle + `"}`) |
| 8648 | _, _ = io.WriteString(rw, `{"id":"resp_test","object":"response","created_at":0,"status":"completed","model":"gpt-4.1","output":[{"id":"msg_test","type":"message","role":"assistant","content":[{"type":"output_text","text":`+text+`}]}],"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}}`) |
| 8649 | }), |
| 8650 | calls: make(chan callRecord, 1), |
| 8651 | } |
| 8652 | var factory aibridge.TransportFactory = stub |
| 8653 | api.AIBridgeTransportFactory.Store(&factory) |
| 8654 | require.NoError(t, client.UpdateChatModelOverride(ctx, codersdk.ChatModelOverrideContextTitleGeneration, codersdk.UpdateChatModelOverrideRequest{ |
| 8655 | ModelConfigID: modelConfig.ID.String(), |
| 8656 | })) |
| 8657 | |
| 8658 | chat := dbgen.Chat(t, db, database.Chat{ |
| 8659 | OrganizationID: firstUser.OrganizationID, |
| 8660 | OwnerID: firstUser.UserID, |
| 8661 | LastModelConfigID: modelConfig.ID, |
| 8662 | Title: "initial title", |
nothing calls this directly
no test coverage detected