TestAdvisorHappyPath_RootChat walks the advisor tool end-to-end: parent calls advisor alone, the nested advisor call produces text, and the structured result flows back into the parent conversation. The exclusive-policy test above only proves the rejection path; this test covers the glue from chatd
(t *testing.T)
| 9856 | // covers the glue from chatd wiring -> chatadvisor.Tool -> Runtime.Run -> |
| 9857 | // nested model call -> structured result back to the outer model. |
| 9858 | func TestAdvisorHappyPath_RootChat(t *testing.T) { |
| 9859 | t.Parallel() |
| 9860 | |
| 9861 | db, ps := dbtestutil.NewDB(t) |
| 9862 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9863 | |
| 9864 | const advisorReply = "break the problem into smaller pieces first" |
| 9865 | advisorDeltas := []string{"break the problem ", "into smaller pieces first"} |
| 9866 | |
| 9867 | var ( |
| 9868 | streamedCallCount atomic.Int32 |
| 9869 | streamedCallsMu sync.Mutex |
| 9870 | advisorCallSeen atomic.Bool |
| 9871 | advisorMessages []chattest.OpenAIMessage |
| 9872 | finalCallMessages []chattest.OpenAIMessage |
| 9873 | ) |
| 9874 | |
| 9875 | openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 9876 | if !req.Stream { |
| 9877 | return chattest.OpenAINonStreamingResponse("title") |
| 9878 | } |
| 9879 | |
| 9880 | switch streamedCallCount.Add(1) { |
| 9881 | case 1: |
| 9882 | // Parent turn 1: call advisor solo. |
| 9883 | return chattest.OpenAIStreamingResponse(chattest.OpenAIToolCallChunk( |
| 9884 | "advisor", |
| 9885 | `{"question":"how should I approach this refactor?"}`, |
| 9886 | )) |
| 9887 | case 2: |
| 9888 | // Nested advisor turn. The nested call has no tools because |
| 9889 | // chatadvisor.RunAdvisor runs with MaxSteps=1 and no tool |
| 9890 | // set. |
| 9891 | require.Empty(t, req.Tools, |
| 9892 | "advisor's nested call must run without tools") |
| 9893 | streamedCallsMu.Lock() |
| 9894 | advisorMessages = append([]chattest.OpenAIMessage(nil), req.Messages...) |
| 9895 | streamedCallsMu.Unlock() |
| 9896 | advisorCallSeen.Store(true) |
| 9897 | return chattest.OpenAIStreamingResponse( |
| 9898 | chattest.OpenAITextChunks(advisorDeltas...)..., |
| 9899 | ) |
| 9900 | default: |
| 9901 | // Parent turn 2: observe the advisor tool result and close |
| 9902 | // out with a final text reply. |
| 9903 | streamedCallsMu.Lock() |
| 9904 | finalCallMessages = append([]chattest.OpenAIMessage(nil), req.Messages...) |
| 9905 | streamedCallsMu.Unlock() |
| 9906 | return chattest.OpenAIStreamingResponse( |
| 9907 | chattest.OpenAITextChunks("acknowledged")..., |
| 9908 | ) |
| 9909 | } |
| 9910 | }) |
| 9911 | |
| 9912 | user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL) |
| 9913 | seedAdvisorConfig(ctx, t, db, codersdk.AdvisorConfig{ |
| 9914 | Enabled: true, |
| 9915 | MaxUsesPerRun: 3, |
nothing calls this directly
no test coverage detected