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

Function TestAdvisorGating_ExploreSubagent

coderd/x/chatd/chatd_test.go:10234–10307  ·  view source on GitHub ↗

TestAdvisorGating_ExploreSubagent guards the fourth dimension of the advisor eligibility condition: Explore chats (root or subagent) run under allowedExploreToolNames, whose policy does not include advisor, so the runtime must not register the advisor tool or inject the parent guidance block there.

(t *testing.T)

Source from the content-addressed store, hash-verified

10232// !isExploreSubagent guard would leave the other gating tests green
10233// while leaking advisor into explore chats.
10234func TestAdvisorGating_ExploreSubagent(t *testing.T) {
10235 t.Parallel()
10236
10237 db, ps := dbtestutil.NewDB(t)
10238 ctx := testutil.Context(t, testutil.WaitLong)
10239
10240 var toolsMu sync.Mutex
10241 var capturedTools []string
10242 var capturedMessages []chattest.OpenAIMessage
10243
10244 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
10245 if !req.Stream {
10246 return chattest.OpenAINonStreamingResponse("title")
10247 }
10248
10249 names := make([]string, 0, len(req.Tools))
10250 for _, tool := range req.Tools {
10251 names = append(names, tool.Function.Name)
10252 }
10253 toolsMu.Lock()
10254 capturedTools = names
10255 capturedMessages = append([]chattest.OpenAIMessage(nil), req.Messages...)
10256 toolsMu.Unlock()
10257
10258 return chattest.OpenAIStreamingResponse(
10259 chattest.OpenAITextChunks("explore reply")...,
10260 )
10261 })
10262
10263 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
10264 seedAdvisorConfig(ctx, t, db, codersdk.AdvisorConfig{
10265 Enabled: true,
10266 MaxUsesPerRun: 3,
10267 MaxOutputTokens: 16384,
10268 })
10269 server := newActiveTestServer(t, db, ps)
10270
10271 chat, err := server.CreateChat(ctx, chatd.CreateOptions{
10272 OrganizationID: org.ID,
10273 OwnerID: user.ID,
10274 Title: "advisor-explore",
10275 ModelConfigID: model.ID,
10276 ChatMode: database.NullChatMode{
10277 ChatMode: database.ChatModeExplore,
10278 Valid: true,
10279 },
10280 InitialUserContent: []codersdk.ChatMessagePart{
10281 codersdk.ChatMessageText("inspect the codebase"),
10282 },
10283 })
10284 require.NoError(t, err)
10285
10286 require.Eventually(t, func() bool {
10287 got, getErr := db.GetChatByID(ctx, chat.ID)
10288 if getErr != nil {
10289 return false
10290 }
10291 return got.Status == database.ChatStatusWaiting ||

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