Skip to content

Commit 2818d40

Browse files
committed
feat: add User-Agent header to API providers
- Add User-Agent header with format 'roo-cline/3.22.6' to DEFAULT_HEADERS - Update all provider tests to expect the new User-Agent header - Add comprehensive test coverage for constants file - Ensures consistent User-Agent across all API providers (OpenAI, OpenRouter, Requesty, etc.) Addresses partner request for standardized User-Agent header following <tool_name>/<version> pattern
1 parent cb4652e commit 2818d40

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// npx vitest run src/api/providers/__tests__/constants.spec.ts
2+
3+
import { describe, it, expect } from "vitest"
4+
import { DEFAULT_HEADERS } from "../constants"
5+
6+
describe("DEFAULT_HEADERS", () => {
7+
it("should contain all required headers", () => {
8+
expect(DEFAULT_HEADERS).toHaveProperty("HTTP-Referer")
9+
expect(DEFAULT_HEADERS).toHaveProperty("X-Title")
10+
expect(DEFAULT_HEADERS).toHaveProperty("User-Agent")
11+
})
12+
13+
it("should have correct HTTP-Referer value", () => {
14+
expect(DEFAULT_HEADERS["HTTP-Referer"]).toBe("https://github.com/RooVetGit/Roo-Cline")
15+
})
16+
17+
it("should have correct X-Title value", () => {
18+
expect(DEFAULT_HEADERS["X-Title"]).toBe("Roo Code")
19+
})
20+
21+
it("should have correct User-Agent format", () => {
22+
const userAgent = DEFAULT_HEADERS["User-Agent"]
23+
expect(userAgent).toBe("roo-cline/3.22.6")
24+
25+
// Verify it follows the tool_name/version pattern
26+
expect(userAgent).toMatch(/^[a-z-]+\/\d+\.\d+\.\d+$/)
27+
})
28+
29+
it("should have User-Agent with correct tool name", () => {
30+
const userAgent = DEFAULT_HEADERS["User-Agent"]
31+
expect(userAgent.startsWith("roo-cline/")).toBe(true)
32+
})
33+
34+
it("should have User-Agent with semantic version format", () => {
35+
const userAgent = DEFAULT_HEADERS["User-Agent"]
36+
const version = userAgent.split("/")[1]
37+
38+
// Check semantic version format (major.minor.patch)
39+
expect(version).toMatch(/^\d+\.\d+\.\d+$/)
40+
41+
// Verify current version
42+
expect(version).toBe("3.22.6")
43+
})
44+
45+
it("should be an object with string values", () => {
46+
expect(typeof DEFAULT_HEADERS).toBe("object")
47+
expect(DEFAULT_HEADERS).not.toBeNull()
48+
49+
Object.values(DEFAULT_HEADERS).forEach((value) => {
50+
expect(typeof value).toBe("string")
51+
expect(value.length).toBeGreaterThan(0)
52+
})
53+
})
54+
55+
it("should have exactly 3 headers", () => {
56+
const headerKeys = Object.keys(DEFAULT_HEADERS)
57+
expect(headerKeys).toHaveLength(3)
58+
expect(headerKeys).toEqual(["HTTP-Referer", "X-Title", "User-Agent"])
59+
})
60+
})

src/api/providers/__tests__/openai.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ describe("OpenAiHandler", () => {
104104
defaultHeaders: {
105105
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
106106
"X-Title": "Roo Code",
107+
"User-Agent": "roo-cline/3.22.6",
107108
},
108109
})
109110
})

src/api/providers/__tests__/openrouter.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe("OpenRouterHandler", () => {
6262
defaultHeaders: {
6363
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
6464
"X-Title": "Roo Code",
65+
"User-Agent": "roo-cline/3.22.6",
6566
},
6667
})
6768
})

src/api/providers/__tests__/requesty.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe("RequestyHandler", () => {
5959
defaultHeaders: {
6060
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
6161
"X-Title": "Roo Code",
62+
"User-Agent": "roo-cline/3.22.6",
6263
},
6364
})
6465
})

src/api/providers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const DEFAULT_HEADERS = {
22
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
33
"X-Title": "Roo Code",
4+
"User-Agent": "roo-cline/3.22.6",
45
}

0 commit comments

Comments
 (0)