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

Function TestAdvisorGating_RootChat

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

Source from the content-addressed store, hash-verified

9720}
9721
9722func TestAdvisorGating_RootChat(t *testing.T) {
9723 t.Parallel()
9724
9725 db, ps := dbtestutil.NewDB(t)
9726 ctx := testutil.Context(t, testutil.WaitLong)
9727
9728 var streamedCallCount atomic.Int32
9729 var streamedCallsMu sync.Mutex
9730 var firstCallTools []string
9731 var firstCallMessages []chattest.OpenAIMessage
9732 var secondCallMessages []chattest.OpenAIMessage
9733
9734 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
9735 if !req.Stream {
9736 return chattest.OpenAINonStreamingResponse("title")
9737 }
9738
9739 switch streamedCallCount.Add(1) {
9740 case 1:
9741 names := make([]string, 0, len(req.Tools))
9742 for _, tool := range req.Tools {
9743 names = append(names, tool.Function.Name)
9744 }
9745 streamedCallsMu.Lock()
9746 firstCallTools = names
9747 firstCallMessages = append([]chattest.OpenAIMessage(nil), req.Messages...)
9748 streamedCallsMu.Unlock()
9749
9750 advisorChunk := chattest.OpenAIToolCallChunk(
9751 "advisor",
9752 `{"question":"help me plan"}`,
9753 )
9754 readChunk := chattest.OpenAIToolCallChunk(
9755 "read_file",
9756 `{"path":"/tmp/test.txt"}`,
9757 )
9758 mergedChunk := advisorChunk
9759 readCall := readChunk.Choices[0].ToolCalls[0]
9760 readCall.Index = 1
9761 mergedChunk.Choices[0].ToolCalls = append(
9762 mergedChunk.Choices[0].ToolCalls,
9763 readCall,
9764 )
9765 return chattest.OpenAIStreamingResponse(mergedChunk)
9766 case 2:
9767 streamedCallsMu.Lock()
9768 secondCallMessages = append([]chattest.OpenAIMessage(nil), req.Messages...)
9769 streamedCallsMu.Unlock()
9770 }
9771
9772 return chattest.OpenAIStreamingResponse(
9773 chattest.OpenAITextChunks("done")...,
9774 )
9775 })
9776
9777 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
9778 seedAdvisorConfig(ctx, t, db, codersdk.AdvisorConfig{
9779 Enabled: true,

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected