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

Function TestGenerateFromAnthropic

coderd/taskname/taskname_internal_test.go:293–341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

291}
292
293func TestGenerateFromAnthropic(t *testing.T) {
294 t.Parallel()
295
296 apiKey := getAnthropicAPIKeyFromEnv()
297 if apiKey == "" {
298 t.Skip("Skipping test as ANTHROPIC_API_KEY not set")
299 }
300
301 tests := []struct {
302 name string
303 prompt string
304 }{
305 {
306 name: "SimplePrompt",
307 prompt: "Create a finance planning app",
308 },
309 {
310 name: "TechnicalPrompt",
311 prompt: "Debug authentication middleware for OAuth2",
312 },
313 {
314 name: "ShortPrompt",
315 prompt: "Fix bug",
316 },
317 }
318
319 for _, tc := range tests {
320 t.Run(tc.name, func(t *testing.T) {
321 t.Parallel()
322
323 ctx := testutil.Context(t, testutil.WaitShort)
324
325 taskName, err := generateFromAnthropic(ctx, tc.prompt, apiKey, getAnthropicModelFromEnv())
326 require.NoError(t, err)
327
328 t.Log("Task name:", taskName.Name)
329 t.Log("Task display name:", taskName.DisplayName)
330
331 // Validate task name
332 require.NotEmpty(t, taskName.DisplayName)
333 require.NoError(t, codersdk.NameValid(taskName.Name))
334
335 // Validate display name
336 require.NotEmpty(t, taskName.DisplayName)
337 require.NotEqual(t, "task-unnamed", taskName.Name)
338 require.NotEqual(t, "Task Unnamed", taskName.DisplayName)
339 })
340 }
341}

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
NameValidFunction · 0.92
generateFromAnthropicFunction · 0.85
getAnthropicModelFromEnvFunction · 0.85
SkipMethod · 0.80
LogMethod · 0.80
NotEmptyMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected