MCPcopy Create free account
hub / github.com/coder/coder / TestAnthropicWebSearchRoundTrip

Function TestAnthropicWebSearchRoundTrip

coderd/x/chatd/integration_test.go:74–219  ·  view source on GitHub ↗

TestAnthropicWebSearchRoundTrip is an integration test that verifies provider-executed tool results (web_search) survive the full persist → reconstruct → re-send cycle. It sends a query that triggers Anthropic's web_search server tool, waits for completion, then sends a follow-up message. If the PE

(t *testing.T)

Source from the content-addressed store, hash-verified

72//
73// The test requires ANTHROPIC_TEST_API_KEY to be set.
74func TestAnthropicWebSearchRoundTrip(t *testing.T) {
75 t.Parallel()
76
77 apiKey := os.Getenv("ANTHROPIC_TEST_API_KEY")
78 if apiKey == "" {
79 t.Skip("ANTHROPIC_TEST_API_KEY not set; skipping Anthropic integration test")
80 }
81 baseURL := os.Getenv("ANTHROPIC_BASE_URL")
82
83 ctx := testutil.Context(t, testutil.WaitSuperLong)
84
85 // Stand up a full coderd.
86 deploymentValues := coderdtest.DeploymentValues(t)
87 client := coderdtest.New(t, &coderdtest.Options{
88 DeploymentValues: deploymentValues,
89 })
90 user := coderdtest.CreateFirstUser(t, client)
91 expClient := codersdk.NewExperimentalClient(client)
92
93 provider := createIntegrationAIProvider(
94 ctx, t, expClient, codersdk.AIProviderTypeAnthropic, apiKey, baseURL,
95 )
96
97 // Create a model config that enables web_search.
98 contextLimit := int64(200000)
99 isDefault := true
100 _, err := expClient.CreateChatModelConfig(ctx, codersdk.CreateChatModelConfigRequest{
101 Provider: string(provider.Type),
102 AIProviderID: &provider.ID,
103 Model: "claude-sonnet-4-20250514",
104 ContextLimit: &contextLimit,
105 IsDefault: &isDefault,
106 ModelConfig: &codersdk.ChatModelCallConfig{
107 ProviderOptions: &codersdk.ChatModelProviderOptions{
108 Anthropic: &codersdk.ChatModelAnthropicProviderOptions{
109 WebSearchEnabled: ptr.Ref(true),
110 },
111 },
112 },
113 })
114 require.NoError(t, err)
115
116 // --- Step 1: Send a message that triggers web_search ---
117 t.Log("Creating chat with web search query...")
118 chat, err := expClient.CreateChat(ctx, codersdk.CreateChatRequest{
119 OrganizationID: user.OrganizationID,
120 Content: []codersdk.ChatInputPart{
121 {
122 Type: codersdk.ChatInputPartTypeText,
123 Text: "What is the current weather in San Francisco right now? Use web search to find out.",
124 },
125 },
126 })
127 require.NoError(t, err)
128 t.Logf("Chat created: %s (status=%s)", chat.ID, chat.Status)
129
130 // Stream events until the chat reaches a terminal status.
131 events, closer, err := expClient.StreamChat(ctx, chat.ID, nil)

Callers

nothing calls this directly

Calls 15

CreateChatModelConfigMethod · 0.95
CreateChatMethod · 0.95
StreamChatMethod · 0.95
GetChatMethod · 0.95
GetChatMessagesMethod · 0.95
CreateChatMessageMethod · 0.95
ContextFunction · 0.92
DeploymentValuesFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewExperimentalClientFunction · 0.92
RefFunction · 0.92

Tested by

no test coverage detected