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

Function TestAdvisorToolReportsNestedError

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

Source from the content-addressed store, hash-verified

276}
277
278func TestAdvisorToolReportsNestedError(t *testing.T) {
279 t.Parallel()
280
281 runtime, err := chatadvisor.NewRuntime(chatadvisor.RuntimeConfig{
282 Model: &chattest.FakeModel{
283 ProviderName: "test-provider",
284 ModelName: "test-model",
285 StreamFn: func(_ context.Context, _ fantasy.Call) (fantasy.StreamResponse, error) {
286 return nil, xerrors.New("boom")
287 },
288 },
289 MaxUsesPerRun: 1,
290 MaxOutputTokens: 64,
291 })
292 require.NoError(t, err)
293
294 tool := chatadvisor.Tool(chatadvisor.ToolOptions{
295 Runtime: runtime,
296 GetConversationSnapshot: func() []fantasy.Message { return nil },
297 })
298
299 resp := runAdvisorTool(t, tool, chatadvisor.AdvisorArgs{Question: "why?"})
300 require.False(t, resp.IsError)
301
302 var result chatadvisor.AdvisorResult
303 require.NoError(t, json.Unmarshal([]byte(resp.Content), &result))
304 require.Equal(t, chatadvisor.ResultTypeError, result.Type)
305 require.Contains(t, result.Error, "boom")
306 require.Empty(t, result.Advice)
307 require.Empty(t, result.AdvisorModel)
308 // A failed nested run does not consume the per-run quota.
309 require.Equal(t, 1, result.RemainingUses)
310}
311
312func TestAdvisorToolReportsLimitReached(t *testing.T) {
313 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewRuntimeFunction · 0.92
ToolFunction · 0.92
runAdvisorToolFunction · 0.85
NewMethod · 0.65
UnmarshalMethod · 0.45
EqualMethod · 0.45
ContainsMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected