MCPcopy Index your code
hub / github.com/coder/coder / TestAdvisorGating_Disabled

Function TestAdvisorGating_Disabled

coderd/x/chatd/chatd_test.go:9651–9720  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9649}
9650
9651func TestAdvisorGating_Disabled(t *testing.T) {
9652 t.Parallel()
9653
9654 db, ps := dbtestutil.NewDB(t)
9655 ctx := testutil.Context(t, testutil.WaitLong)
9656
9657 var toolsMu sync.Mutex
9658 var capturedTools []string
9659 var capturedMessages []chattest.OpenAIMessage
9660
9661 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
9662 if !req.Stream {
9663 return chattest.OpenAINonStreamingResponse("title")
9664 }
9665
9666 names := make([]string, 0, len(req.Tools))
9667 for _, tool := range req.Tools {
9668 names = append(names, tool.Function.Name)
9669 }
9670 toolsMu.Lock()
9671 capturedTools = names
9672 capturedMessages = append([]chattest.OpenAIMessage(nil), req.Messages...)
9673 toolsMu.Unlock()
9674
9675 return chattest.OpenAIStreamingResponse(
9676 chattest.OpenAITextChunks("advisor is not available")...,
9677 )
9678 })
9679
9680 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
9681 seedAdvisorConfig(ctx, t, db, codersdk.AdvisorConfig{
9682 Enabled: false,
9683 MaxUsesPerRun: 3,
9684 MaxOutputTokens: 16384,
9685 })
9686 server := newActiveTestServer(t, db, ps)
9687
9688 chat, err := server.CreateChat(ctx, chatd.CreateOptions{
9689 OrganizationID: org.ID,
9690 OwnerID: user.ID,
9691 Title: "advisor-disabled",
9692 ModelConfigID: model.ID,
9693 InitialUserContent: []codersdk.ChatMessagePart{
9694 codersdk.ChatMessageText("hello"),
9695 },
9696 })
9697 require.NoError(t, err)
9698
9699 require.Eventually(t, func() bool {
9700 got, getErr := db.GetChatByID(ctx, chat.ID)
9701 if getErr != nil {
9702 return false
9703 }
9704 return got.Status == database.ChatStatusWaiting ||
9705 got.Status == database.ChatStatusError
9706 }, testutil.WaitLong, testutil.IntervalFast)
9707
9708 toolsMu.Lock()

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
ContextFunction · 0.92
NewOpenAIFunction · 0.92
OpenAIStreamingResponseFunction · 0.92
OpenAITextChunksFunction · 0.92
ChatMessageTextFunction · 0.92
seedAdvisorConfigFunction · 0.85
newActiveTestServerFunction · 0.85
NotEmptyMethod · 0.80
CreateChatMethod · 0.65

Tested by

no test coverage detected