-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: record user agent in AI Bridge interceptions #21769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ import ( | |
| "github.com/coder/coder/v2/coderd/httpmw" | ||
| "github.com/coder/coder/v2/codersdk" | ||
| "github.com/coder/coder/v2/enterprise/aibridged" | ||
| "github.com/coder/coder/v2/enterprise/aibridgedserver" | ||
| "github.com/coder/coder/v2/enterprise/coderd/coderdenttest" | ||
| "github.com/coder/coder/v2/testutil" | ||
| ) | ||
|
|
@@ -226,9 +227,11 @@ func TestIntegration(t *testing.T) { | |
| } | ||
| ] | ||
| }`)) | ||
| userAgent := "codex_cli_rs/0.87.0" | ||
| require.NoError(t, err, "make request to test server") | ||
| req.Header.Add("Authorization", "Bearer "+apiKey.Key) | ||
| req.Header.Add("Accept", "application/json") | ||
| req.Header.Add("User-Agent", userAgent) | ||
|
|
||
| // When: aibridged handles the request. | ||
| rec := httptest.NewRecorder() | ||
|
|
@@ -251,6 +254,11 @@ func TestIntegration(t *testing.T) { | |
| require.True(t, intc0.EndedAt.Valid) | ||
| require.False(t, intc0.EndedAt.Time.Before(intc0.StartedAt), "EndedAt should not be before StartedAt") | ||
| require.Less(t, intc0.EndedAt.Time.Sub(intc0.StartedAt), 5*time.Second) | ||
| require.True(t, intc0.Client.Valid) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test expects Consider:
This would make the test more meaningful and verify the actual user agent parsing behavior. |
||
| require.Equal(t, aibridge.ClientCodex, intc0.Client.String) | ||
|
|
||
| intc0Metadata := gjson.GetBytes(intc0.Metadata.RawMessage, aibridgedserver.MetadataUserAgentKey) | ||
| require.Equal(t, userAgent, intc0Metadata.String(), "interception metadata user agent should match request user agent") | ||
|
|
||
| prompts, err := db.GetAIBridgeUserPromptsByInterceptionID(ctx, interceptions[0].ID) | ||
| require.NoError(t, err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these 👍