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

Function TestGenerateFromAnthropicMock

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

Source from the content-addressed store, hash-verified

224}
225
226func 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 )

Callers

nothing calls this directly

Calls 10

ContextFunction · 0.92
NameValidFunction · 0.92
fakeAnthropicSSEFunction · 0.85
generateFromAnthropicFunction · 0.85
RunMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
CleanupMethod · 0.65
HeaderMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected