(t *testing.T)
| 224 | } |
| 225 | |
| 226 | func TestGenerateFromAnthropicMock(t *testing.T) { |
| 227 | t.Parallel() |
| 228 | |
| 229 | tests := []struct { |
| 230 | name string |
| 231 | responseText string |
| 232 | expectedDisplayName string |
| 233 | expectedNamePrefix string |
| 234 | }{ |
| 235 | { |
| 236 | name: "BareJSON", |
| 237 | responseText: `{"display_name": "Fix bug", "task_name": "fix-bug"}`, |
| 238 | expectedDisplayName: "Fix bug", |
| 239 | expectedNamePrefix: "fix-bug-", |
| 240 | }, |
| 241 | { |
| 242 | name: "FencedJSON", |
| 243 | responseText: "```json\n{\"display_name\": \"Debug auth\", \"task_name\": \"debug-auth\"}\n```", |
| 244 | expectedDisplayName: "Debug auth", |
| 245 | expectedNamePrefix: "debug-auth-", |
| 246 | }, |
| 247 | { |
| 248 | name: "FencedNoLanguage", |
| 249 | responseText: "```\n{\"display_name\": \"Setup CI\", \"task_name\": \"setup-ci\"}\n```", |
| 250 | expectedDisplayName: "Setup CI", |
| 251 | expectedNamePrefix: "setup-ci-", |
| 252 | }, |
| 253 | { |
| 254 | name: "FencedJSONWithTrailingText", |
| 255 | responseText: "```json\n{\"display_name\": \"Debug auth\", \"task_name\": \"debug-auth\"}\n```\n\nDone.", |
| 256 | expectedDisplayName: "Debug auth", |
| 257 | expectedNamePrefix: "debug-auth-", |
| 258 | }, |
| 259 | { |
| 260 | name: "BareJSONWithTrailingFence", |
| 261 | responseText: "{\"display_name\": \"Setup CI\", \"task_name\": \"setup-ci\"}\n```", |
| 262 | expectedDisplayName: "Setup CI", |
| 263 | expectedNamePrefix: "setup-ci-", |
| 264 | }, |
| 265 | } |
| 266 | |
| 267 | for _, tc := range tests { |
| 268 | t.Run(tc.name, func(t *testing.T) { |
| 269 | t.Parallel() |
| 270 | |
| 271 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 272 | w.Header().Set("Content-Type", "text/event-stream") |
| 273 | _, _ = w.Write([]byte(fakeAnthropicSSE(t, tc.responseText))) |
| 274 | })) |
| 275 | t.Cleanup(srv.Close) |
| 276 | |
| 277 | ctx := testutil.Context(t, testutil.WaitShort) |
| 278 | |
| 279 | taskName, err := generateFromAnthropic( |
| 280 | ctx, "test prompt", "fake-key", |
| 281 | anthropic.ModelClaudeHaiku4_5, |
| 282 | anthropicoption.WithBaseURL(srv.URL), |
| 283 | ) |
nothing calls this directly
no test coverage detected