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

Function TestAdvisorToolSuccess

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

Source from the content-addressed store, hash-verified

16)
17
18func TestAdvisorToolSuccess(t *testing.T) {
19 t.Parallel()
20
21 runtime, err := chatadvisor.NewRuntime(chatadvisor.RuntimeConfig{
22 Model: &chattest.FakeModel{
23 ProviderName: "test-provider",
24 ModelName: "test-model",
25 StreamFn: func(_ context.Context, _ fantasy.Call) (fantasy.StreamResponse, error) {
26 return streamFromParts([]fantasy.StreamPart{
27 {Type: fantasy.StreamPartTypeTextStart, ID: "text-1"},
28 {Type: fantasy.StreamPartTypeTextDelta, ID: "text-1", Delta: "Use the smaller diff."},
29 {Type: fantasy.StreamPartTypeTextEnd, ID: "text-1"},
30 {Type: fantasy.StreamPartTypeFinish, FinishReason: fantasy.FinishReasonStop},
31 }), nil
32 },
33 },
34 MaxUsesPerRun: 2,
35 MaxOutputTokens: 128,
36 })
37 require.NoError(t, err)
38
39 tool := chatadvisor.Tool(chatadvisor.ToolOptions{
40 Runtime: runtime,
41 GetConversationSnapshot: func() []fantasy.Message {
42 return []fantasy.Message{{
43 Role: fantasy.MessageRoleUser,
44 Content: []fantasy.MessagePart{
45 fantasy.TextPart{Text: "We need a safe fix."},
46 },
47 }}
48 },
49 })
50
51 resp := runAdvisorTool(t, tool, chatadvisor.AdvisorArgs{Question: "What's the safest next step?"})
52 require.False(t, resp.IsError)
53
54 var result chatadvisor.AdvisorResult
55 require.NoError(t, json.Unmarshal([]byte(resp.Content), &result))
56 require.Equal(t, chatadvisor.ResultTypeAdvice, result.Type)
57 require.Equal(t, "Use the smaller diff.", result.Advice)
58 require.Equal(t, "test-provider/test-model", result.AdvisorModel)
59 require.Equal(t, 1, result.RemainingUses)
60}
61
62func TestAdvisorToolPublishesAdviceDeltasWithToolCallID(t *testing.T) {
63 t.Parallel()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected