(t *testing.T)
| 6896 | } |
| 6897 | |
| 6898 | func TestComputerUseSubagentToolsAndModel(t *testing.T) { |
| 6899 | t.Parallel() |
| 6900 | |
| 6901 | db, ps := dbtestutil.NewDB(t) |
| 6902 | ctx := testutil.Context(t, testutil.WaitLong) |
| 6903 | |
| 6904 | computerUseModelProvider, computerUseModelName, ok := chattool.DefaultComputerUseModel(chattool.ComputerUseProviderAnthropic) |
| 6905 | require.True(t, ok) |
| 6906 | require.Equal(t, chattool.ComputerUseProviderAnthropic, computerUseModelProvider) |
| 6907 | |
| 6908 | // Track tools and model from the Anthropic LLM calls (the |
| 6909 | // computer use child chat). We use a raw HTTP handler because |
| 6910 | // the chattest AnthropicRequest struct does not capture tools. |
| 6911 | type anthropicCall struct { |
| 6912 | Model string |
| 6913 | Tools []string |
| 6914 | Stream bool |
| 6915 | } |
| 6916 | var anthropicMu sync.Mutex |
| 6917 | var anthropicCalls []anthropicCall |
| 6918 | |
| 6919 | anthropicSrv := httptest.NewServer(http.HandlerFunc( |
| 6920 | func(w http.ResponseWriter, r *http.Request) { |
| 6921 | body, err := io.ReadAll(r.Body) |
| 6922 | if err != nil { |
| 6923 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 6924 | return |
| 6925 | } |
| 6926 | |
| 6927 | var req struct { |
| 6928 | Model string `json:"model"` |
| 6929 | Stream bool `json:"stream"` |
| 6930 | Tools []struct { |
| 6931 | Name string `json:"name"` |
| 6932 | } `json:"tools"` |
| 6933 | } |
| 6934 | if err := json.Unmarshal(body, &req); err != nil { |
| 6935 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 6936 | return |
| 6937 | } |
| 6938 | |
| 6939 | names := make([]string, len(req.Tools)) |
| 6940 | for i, tool := range req.Tools { |
| 6941 | names[i] = tool.Name |
| 6942 | } |
| 6943 | anthropicMu.Lock() |
| 6944 | anthropicCalls = append(anthropicCalls, anthropicCall{ |
| 6945 | Model: req.Model, |
| 6946 | Tools: names, |
| 6947 | Stream: req.Stream, |
| 6948 | }) |
| 6949 | anthropicMu.Unlock() |
| 6950 | |
| 6951 | if !req.Stream { |
| 6952 | w.Header().Set("Content-Type", "application/json") |
| 6953 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 6954 | "id": "msg-test", |
| 6955 | "type": "message", |
nothing calls this directly
no test coverage detected