TestAdvisorGating_ChildChat guards the second dimension of the advisor eligibility condition: even with advisor enabled, a chat whose ParentChatID is set must not register the advisor tool or receive the advisor guidance block. Without this coverage, a refactor that removes or weakens the !chat.Pare
(t *testing.T)
| 10062 | // ParentChatID, exercising the same gating path with no subagent tooling |
| 10063 | // in the way. |
| 10064 | func TestAdvisorGating_ChildChat(t *testing.T) { |
| 10065 | t.Parallel() |
| 10066 | |
| 10067 | db, ps := dbtestutil.NewDB(t) |
| 10068 | ctx := testutil.Context(t, testutil.WaitLong) |
| 10069 | |
| 10070 | var toolsMu sync.Mutex |
| 10071 | var capturedTools []string |
| 10072 | var capturedMessages []chattest.OpenAIMessage |
| 10073 | |
| 10074 | openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 10075 | if !req.Stream { |
| 10076 | return chattest.OpenAINonStreamingResponse("title") |
| 10077 | } |
| 10078 | |
| 10079 | names := make([]string, 0, len(req.Tools)) |
| 10080 | for _, tool := range req.Tools { |
| 10081 | names = append(names, tool.Function.Name) |
| 10082 | } |
| 10083 | toolsMu.Lock() |
| 10084 | capturedTools = names |
| 10085 | capturedMessages = append([]chattest.OpenAIMessage(nil), req.Messages...) |
| 10086 | toolsMu.Unlock() |
| 10087 | |
| 10088 | return chattest.OpenAIStreamingResponse( |
| 10089 | chattest.OpenAITextChunks("done")..., |
| 10090 | ) |
| 10091 | }) |
| 10092 | |
| 10093 | user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL) |
| 10094 | seedAdvisorConfig(ctx, t, db, codersdk.AdvisorConfig{ |
| 10095 | Enabled: true, |
| 10096 | MaxUsesPerRun: 3, |
| 10097 | MaxOutputTokens: 16384, |
| 10098 | }) |
| 10099 | |
| 10100 | // Seed the parent chat directly in the database so the test server |
| 10101 | // never executes the root turn. That keeps this test focused on the |
| 10102 | // child-chat gating path without depending on subagent wiring. |
| 10103 | parent := dbgen.Chat(t, db, database.Chat{ |
| 10104 | OrganizationID: org.ID, |
| 10105 | OwnerID: user.ID, |
| 10106 | Status: database.ChatStatusWaiting, |
| 10107 | ClientType: database.ChatClientTypeUi, |
| 10108 | LastModelConfigID: model.ID, |
| 10109 | Title: "advisor-root-parent", |
| 10110 | }) |
| 10111 | |
| 10112 | server := newActiveTestServer(t, db, ps) |
| 10113 | |
| 10114 | childChat, err := server.CreateChat(ctx, chatd.CreateOptions{ |
| 10115 | OrganizationID: org.ID, |
| 10116 | OwnerID: user.ID, |
| 10117 | Title: "advisor-child", |
| 10118 | ModelConfigID: model.ID, |
| 10119 | ParentChatID: uuid.NullUUID{UUID: parent.ID, Valid: true}, |
| 10120 | RootChatID: uuid.NullUUID{UUID: parent.ID, Valid: true}, |
| 10121 | InitialUserContent: []codersdk.ChatMessagePart{ |
nothing calls this directly
no test coverage detected