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

Function TestAdvisorGating_PlanMode

coderd/x/chatd/chatd_test.go:10155–10225  ·  view source on GitHub ↗

TestAdvisorGating_PlanMode guards the third dimension of the advisor eligibility condition: plan-mode turns must not register the advisor tool or inject the parent guidance block. Without this test, deleting the !isPlanModeTurn guard would still leave the other two gating tests green even though adv

(t *testing.T)

Source from the content-addressed store, hash-verified

10153// !isPlanModeTurn guard would still leave the other two gating tests green
10154// even though advisor would now leak into plan mode.
10155func TestAdvisorGating_PlanMode(t *testing.T) {
10156 t.Parallel()
10157
10158 db, ps := dbtestutil.NewDB(t)
10159 ctx := testutil.Context(t, testutil.WaitLong)
10160
10161 var toolsMu sync.Mutex
10162 var capturedTools []string
10163 var capturedMessages []chattest.OpenAIMessage
10164
10165 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
10166 if !req.Stream {
10167 return chattest.OpenAINonStreamingResponse("title")
10168 }
10169
10170 names := make([]string, 0, len(req.Tools))
10171 for _, tool := range req.Tools {
10172 names = append(names, tool.Function.Name)
10173 }
10174 toolsMu.Lock()
10175 capturedTools = names
10176 capturedMessages = append([]chattest.OpenAIMessage(nil), req.Messages...)
10177 toolsMu.Unlock()
10178
10179 return chattest.OpenAIStreamingResponse(
10180 chattest.OpenAITextChunks("plan mode reply")...,
10181 )
10182 })
10183
10184 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
10185 seedAdvisorConfig(ctx, t, db, codersdk.AdvisorConfig{
10186 Enabled: true,
10187 MaxUsesPerRun: 3,
10188 MaxOutputTokens: 16384,
10189 })
10190 server := newActiveTestServer(t, db, ps)
10191
10192 chat, err := server.CreateChat(ctx, chatd.CreateOptions{
10193 OrganizationID: org.ID,
10194 OwnerID: user.ID,
10195 Title: "advisor-plan-mode",
10196 ModelConfigID: model.ID,
10197 PlanMode: database.NullChatPlanMode{ChatPlanMode: database.ChatPlanModePlan, Valid: true},
10198 InitialUserContent: []codersdk.ChatMessagePart{
10199 codersdk.ChatMessageText("draft a plan"),
10200 },
10201 })
10202 require.NoError(t, err)
10203
10204 require.Eventually(t, func() bool {
10205 got, getErr := db.GetChatByID(ctx, chat.ID)
10206 if getErr != nil {
10207 return false
10208 }
10209 return got.Status == database.ChatStatusWaiting ||
10210 got.Status == database.ChatStatusError
10211 }, testutil.WaitLong, testutil.IntervalFast)
10212

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