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)
| 72 | // |
| 73 | // The test requires ANTHROPIC_TEST_API_KEY to be set. |
| 74 | func 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) |
nothing calls this directly
no test coverage detected