Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/api/providers/__tests__/constants.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// npx vitest run src/api/providers/__tests__/constants.spec.ts

import { describe, it, expect } from "vitest"
import { DEFAULT_HEADERS } from "../constants"
import { Package } from "../../../shared/package"

describe("DEFAULT_HEADERS", () => {
it("should contain all required headers", () => {
expect(DEFAULT_HEADERS).toHaveProperty("HTTP-Referer")
expect(DEFAULT_HEADERS).toHaveProperty("X-Title")
expect(DEFAULT_HEADERS).toHaveProperty("User-Agent")
})

it("should have correct HTTP-Referer value", () => {
expect(DEFAULT_HEADERS["HTTP-Referer"]).toBe("https://github.com/RooVetGit/Roo-Cline")
})

it("should have correct X-Title value", () => {
expect(DEFAULT_HEADERS["X-Title"]).toBe("Roo Code")
})

it("should have correct User-Agent format", () => {
const userAgent = DEFAULT_HEADERS["User-Agent"]
expect(userAgent).toBe(`RooCode/${Package.version}`)

// Verify it follows the tool_name/version pattern
expect(userAgent).toMatch(/^[a-zA-Z-]+\/\d+\.\d+\.\d+$/)
})

it("should have User-Agent with correct tool name", () => {
const userAgent = DEFAULT_HEADERS["User-Agent"]
expect(userAgent.startsWith("RooCode/")).toBe(true)
})

it("should have User-Agent with semantic version format", () => {
const userAgent = DEFAULT_HEADERS["User-Agent"]
const version = userAgent.split("/")[1]

// Check semantic version format (major.minor.patch)
expect(version).toMatch(/^\d+\.\d+\.\d+$/)

// Verify current version matches package version
expect(version).toBe(Package.version)
})

it("should be an object with string values", () => {
expect(typeof DEFAULT_HEADERS).toBe("object")
expect(DEFAULT_HEADERS).not.toBeNull()

Object.values(DEFAULT_HEADERS).forEach((value) => {
expect(typeof value).toBe("string")
expect(value.length).toBeGreaterThan(0)
})
})

it("should have exactly 3 headers", () => {
const headerKeys = Object.keys(DEFAULT_HEADERS)
expect(headerKeys).toHaveLength(3)
expect(headerKeys).toEqual(["HTTP-Referer", "X-Title", "User-Agent"])
})
})
2 changes: 2 additions & 0 deletions src/api/providers/__tests__/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApiHandlerOptions } from "../../../shared/api"
import { Anthropic } from "@anthropic-ai/sdk"
import OpenAI from "openai"
import { openAiModelInfoSaneDefaults } from "@roo-code/types"
import { Package } from "../../../shared/package"

const mockCreate = vitest.fn()

Expand Down Expand Up @@ -104,6 +105,7 @@ describe("OpenAiHandler", () => {
defaultHeaders: {
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope, but 🤨

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... forever linked to that in OpenRouter

"X-Title": "Roo Code",
"User-Agent": `RooCode/${Package.version}`,
},
})
})
Expand Down
2 changes: 2 additions & 0 deletions src/api/providers/__tests__/openrouter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import OpenAI from "openai"

import { OpenRouterHandler } from "../openrouter"
import { ApiHandlerOptions } from "../../../shared/api"
import { Package } from "../../../shared/package"

// Mock dependencies
vitest.mock("openai")
Expand Down Expand Up @@ -62,6 +63,7 @@ describe("OpenRouterHandler", () => {
defaultHeaders: {
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
"X-Title": "Roo Code",
"User-Agent": `RooCode/${Package.version}`,
},
})
})
Expand Down
2 changes: 2 additions & 0 deletions src/api/providers/__tests__/requesty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import OpenAI from "openai"

import { RequestyHandler } from "../requesty"
import { ApiHandlerOptions } from "../../../shared/api"
import { Package } from "../../../shared/package"

const mockCreate = vitest.fn()

Expand Down Expand Up @@ -59,6 +60,7 @@ describe("RequestyHandler", () => {
defaultHeaders: {
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
"X-Title": "Roo Code",
"User-Agent": `RooCode/${Package.version}`,
},
})
})
Expand Down
3 changes: 3 additions & 0 deletions src/api/providers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Package } from "../../shared/package"

export const DEFAULT_HEADERS = {
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
"X-Title": "Roo Code",
"User-Agent": `RooCode/${Package.version}`,
}
Loading