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

Function TestAdvisorToolReportsLimitReached

coderd/x/chatd/chatadvisor/tool_test.go:312–351  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310}
311
312func TestAdvisorToolReportsLimitReached(t *testing.T) {
313 t.Parallel()
314
315 runtime, err := chatadvisor.NewRuntime(chatadvisor.RuntimeConfig{
316 Model: &chattest.FakeModel{
317 ProviderName: "test-provider",
318 ModelName: "test-model",
319 StreamFn: func(_ context.Context, _ fantasy.Call) (fantasy.StreamResponse, error) {
320 return streamFromParts([]fantasy.StreamPart{
321 {Type: fantasy.StreamPartTypeTextStart, ID: "text-1"},
322 {Type: fantasy.StreamPartTypeTextDelta, ID: "text-1", Delta: "first"},
323 {Type: fantasy.StreamPartTypeTextEnd, ID: "text-1"},
324 {Type: fantasy.StreamPartTypeFinish, FinishReason: fantasy.FinishReasonStop},
325 }), nil
326 },
327 },
328 MaxUsesPerRun: 1,
329 MaxOutputTokens: 64,
330 })
331 require.NoError(t, err)
332
333 tool := chatadvisor.Tool(chatadvisor.ToolOptions{
334 Runtime: runtime,
335 GetConversationSnapshot: func() []fantasy.Message { return nil },
336 })
337
338 first := runAdvisorTool(t, tool, chatadvisor.AdvisorArgs{Question: "first?"})
339 require.False(t, first.IsError)
340
341 second := runAdvisorTool(t, tool, chatadvisor.AdvisorArgs{Question: "second?"})
342 require.False(t, second.IsError)
343
344 var result chatadvisor.AdvisorResult
345 require.NoError(t, json.Unmarshal([]byte(second.Content), &result))
346 require.Equal(t, chatadvisor.ResultTypeLimitReached, result.Type)
347 require.Equal(t, 0, result.RemainingUses)
348 require.Empty(t, result.Advice)
349 require.Empty(t, result.Error)
350 require.Empty(t, result.AdvisorModel)
351}
352
353func TestAdvisorToolReportsEmptyModelOutput(t *testing.T) {
354 t.Parallel()

Callers

nothing calls this directly

Calls 7

NewRuntimeFunction · 0.92
ToolFunction · 0.92
runAdvisorToolFunction · 0.85
streamFromPartsFunction · 0.70
UnmarshalMethod · 0.45
EqualMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected