forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.test.ts
More file actions
86 lines (76 loc) · 2.77 KB
/
Copy pathconstants.test.ts
File metadata and controls
86 lines (76 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { describe, it, expect } from "vitest"
import {
GEMINI_CLI_HEADERS,
getRandomizedHeaders,
type HeaderSet,
} from "./constants.ts"
describe("GEMINI_CLI_HEADERS", () => {
it("contains only User-Agent with GeminiCLI format", () => {
expect(GEMINI_CLI_HEADERS).toEqual({
"User-Agent": "GeminiCLI/1.0.0/gemini-2.5-flash",
})
})
it("does not contain X-Goog-Api-Client", () => {
expect(GEMINI_CLI_HEADERS).not.toHaveProperty("X-Goog-Api-Client")
})
it("does not contain Client-Metadata", () => {
expect(GEMINI_CLI_HEADERS).not.toHaveProperty("Client-Metadata")
})
})
describe("getRandomizedHeaders", () => {
describe("gemini-cli style", () => {
it("returns only User-Agent header", () => {
const headers = getRandomizedHeaders("gemini-cli")
expect(headers).toHaveProperty("User-Agent")
expect(headers["X-Goog-Api-Client"]).toBeUndefined()
expect(headers["Client-Metadata"]).toBeUndefined()
})
it("returns a User-Agent in GeminiCLI format", () => {
const headers = getRandomizedHeaders("gemini-cli")
expect(headers["User-Agent"]).toMatch(/^GeminiCLI\/\d+\.\d+\.\d+\/gemini-2\.5-flash$/)
})
it("returns one of the expected GeminiCLI user agents", () => {
const expectedAgents = [
"GeminiCLI/1.2.0/gemini-2.5-flash",
"GeminiCLI/1.1.0/gemini-2.5-flash",
"GeminiCLI/1.0.0/gemini-2.5-flash",
]
for (let i = 0; i < 20; i++) {
const headers = getRandomizedHeaders("gemini-cli")
expect(expectedAgents).toContain(headers["User-Agent"])
}
})
})
describe("antigravity style", () => {
it("returns all three headers", () => {
const headers = getRandomizedHeaders("antigravity")
expect(headers["User-Agent"]).toBeDefined()
expect(headers["X-Goog-Api-Client"]).toBeDefined()
expect(headers["Client-Metadata"]).toBeDefined()
})
it("returns User-Agent in antigravity format", () => {
const headers = getRandomizedHeaders("antigravity")
expect(headers["User-Agent"]).toMatch(/^antigravity\//)
})
})
})
describe("HeaderSet type", () => {
it("allows omitting X-Goog-Api-Client and Client-Metadata", () => {
const headers: HeaderSet = {
"User-Agent": "test",
}
expect(headers["User-Agent"]).toBe("test")
expect(headers["X-Goog-Api-Client"]).toBeUndefined()
expect(headers["Client-Metadata"]).toBeUndefined()
})
it("allows including all three headers", () => {
const headers: HeaderSet = {
"User-Agent": "test",
"X-Goog-Api-Client": "test-client",
"Client-Metadata": "test-metadata",
}
expect(headers["User-Agent"]).toBe("test")
expect(headers["X-Goog-Api-Client"]).toBe("test-client")
expect(headers["Client-Metadata"]).toBe("test-metadata")
})
})