forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.test.ts
More file actions
112 lines (90 loc) · 4.24 KB
/
Copy pathversion.test.ts
File metadata and controls
112 lines (90 loc) · 4.24 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"
/**
* Regression tests for the version fallback mechanism.
*
* Issue #468: On WSL2/AlmaLinux with strict firewall rules, both the
* auto-updater API and changelog fetch fail. The plugin then uses the
* hardcoded fallback version in User-Agent headers. If the fallback is
* too old, the backend rejects requests for newer models (e.g., Gemini 3.1 Pro)
* with "not available on this version".
*
* These tests verify the fallback is current and that the
* network-failure path correctly uses it.
*/
// Reset module state between tests so versionLocked starts fresh
beforeEach(() => {
vi.resetModules()
})
afterEach(() => {
vi.unstubAllGlobals()
})
describe("ANTIGRAVITY_VERSION_FALLBACK", () => {
it("defaults to the exported fallback constant", async () => {
const { ANTIGRAVITY_VERSION_FALLBACK, getAntigravityVersion } = await import("../constants.ts")
expect(getAntigravityVersion()).toBe(ANTIGRAVITY_VERSION_FALLBACK)
})
it("is at least 1.18.0 to support Gemini 3.1 Pro", async () => {
const { getAntigravityVersion } = await import("../constants.ts")
const [major, minor] = getAntigravityVersion().split(".").map(Number)
expect(major).toBeGreaterThanOrEqual(1)
if (major === 1) expect(minor).toBeGreaterThanOrEqual(18)
})
})
describe("setAntigravityVersion", () => {
it("updates the version on first call", async () => {
const { getAntigravityVersion, setAntigravityVersion } = await import("../constants.ts")
setAntigravityVersion("2.0.0")
expect(getAntigravityVersion()).toBe("2.0.0")
})
it("locks after first call — subsequent calls are ignored", async () => {
const { getAntigravityVersion, setAntigravityVersion } = await import("../constants.ts")
setAntigravityVersion("2.0.0")
setAntigravityVersion("3.0.0")
expect(getAntigravityVersion()).toBe("2.0.0")
})
})
describe("initAntigravityVersion — network failure path", () => {
it("falls back to hardcoded version when both fetches throw", async () => {
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("network unreachable")))
const { ANTIGRAVITY_VERSION_FALLBACK, getAntigravityVersion } = await import("../constants.ts")
const { initAntigravityVersion } = await import("./version.ts")
await initAntigravityVersion()
expect(getAntigravityVersion()).toBe(ANTIGRAVITY_VERSION_FALLBACK)
})
it("falls back to hardcoded version when both fetches return non-ok", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({ ok: false, status: 503, text: async () => "" }),
)
const { ANTIGRAVITY_VERSION_FALLBACK, getAntigravityVersion } = await import("../constants.ts")
const { initAntigravityVersion } = await import("./version.ts")
await initAntigravityVersion()
expect(getAntigravityVersion()).toBe(ANTIGRAVITY_VERSION_FALLBACK)
})
it("uses API version when auto-updater responds", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({ ok: true, text: async () => "1.19.0" }),
)
const { getAntigravityVersion } = await import("../constants.ts")
const { initAntigravityVersion } = await import("./version.ts")
await initAntigravityVersion()
expect(getAntigravityVersion()).toBe("1.19.0")
})
it("fallback version appears in User-Agent header", async () => {
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("timeout")))
const { ANTIGRAVITY_VERSION_FALLBACK, getAntigravityHeaders } = await import("../constants.ts")
const { initAntigravityVersion } = await import("./version.ts")
await initAntigravityVersion()
const headers = getAntigravityHeaders()
expect(headers["User-Agent"]).toContain(`Antigravity/${ANTIGRAVITY_VERSION_FALLBACK}`)
})
it("fallback version appears in randomized antigravity headers", async () => {
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("timeout")))
const { ANTIGRAVITY_VERSION_FALLBACK, getRandomizedHeaders } = await import("../constants.ts")
const { initAntigravityVersion } = await import("./version.ts")
await initAntigravityVersion()
const headers = getRandomizedHeaders("antigravity")
expect(headers["User-Agent"]).toContain(ANTIGRAVITY_VERSION_FALLBACK)
})
})