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

Function TestModelFromConfig_UserAgent

coderd/x/chatd/chatprovider/useragent_test.go:34–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func TestModelFromConfig_UserAgent(t *testing.T) {
35 t.Parallel()
36 ctx := testutil.Context(t, testutil.WaitShort)
37
38 expectedUA := chatprovider.UserAgent()
39 called := make(chan struct{})
40 serverURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
41 assert.Equal(t, expectedUA, req.Header.Get("User-Agent"))
42 close(called)
43 return chattest.OpenAINonStreamingResponse("hello")
44 })
45
46 keys := chatprovider.ProviderAPIKeys{
47 ByProvider: map[string]string{"openai": "test-key"},
48 BaseURLByProvider: map[string]string{"openai": serverURL},
49 }
50
51 model, err := chatprovider.ModelFromConfig("openai", "gpt-4", keys, expectedUA, nil, nil)
52 require.NoError(t, err)
53
54 // Make a real call so Fantasy sends an HTTP request to the
55 // fake server, which asserts the User-Agent header.
56 _, err = model.Generate(ctx, fantasy.Call{
57 Prompt: []fantasy.Message{
58 {
59 Role: fantasy.MessageRoleUser,
60 Content: []fantasy.MessagePart{
61 fantasy.TextPart{Text: "hello"},
62 },
63 },
64 },
65 })
66 require.NoError(t, err)
67 _ = testutil.TryReceive(ctx, t, called)
68}

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
UserAgentFunction · 0.92
NewOpenAIFunction · 0.92
ModelFromConfigFunction · 0.92
TryReceiveFunction · 0.92
GetMethod · 0.65
EqualMethod · 0.45
GenerateMethod · 0.45

Tested by

no test coverage detected