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
50 changes: 50 additions & 0 deletions src/api/providers/fetchers/__tests__/roo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"
import { getRooModels } from "../roo"
import { Package } from "../../../../shared/package"

// Mock fetch globally
const mockFetch = vi.fn()
Expand Down Expand Up @@ -976,4 +977,53 @@ describe("getRooModels", () => {
// Should use 3.0.0 version settings (highest that's <= current plugin version)
expect(model.feature).toBe("current")
})

it("should apply highest versionedSettings for nightly builds (package name)", async () => {
const mockResponse = {
object: "list",
data: [
{
id: "test/nightly-version-model",
object: "model",
created: 1234567890,
owned_by: "test",
name: "Nightly Model",
description: "Model with multiple versioned settings",
context_window: 128000,
max_tokens: 8192,
type: "language",
pricing: {
input: "0.0001",
output: "0.0002",
},
settings: {
feature: "plain",
},
versionedSettings: {
"3.36.3": { feature: "v3" },
"2.0.0": { feature: "v2" },
},
},
],
}

mockFetch.mockResolvedValueOnce({
ok: true,
json: async () => mockResponse,
})

// Simulate nightly build via package name
const originalName = Package.name
;(Package as { name: string }).name = "roo-code-nightly"

try {
const models = await getRooModels(baseUrl, apiKey)
const model = models["test/nightly-version-model"] as Record<string, unknown>

// Should pick the highest available versionedSettings even though 3.36.3 > 0.0.7465
expect(model.feature).toBe("v3")
} finally {
;(Package as { name: string }).name = originalName
}
})
})
18 changes: 18 additions & 0 deletions src/api/providers/fetchers/__tests__/versionedSettings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
resolveVersionedSettings,
type VersionedSettings,
} from "../versionedSettings"
import { Package } from "../../../../shared/package"

describe("versionedSettings", () => {
describe("compareSemver", () => {
Expand Down Expand Up @@ -113,6 +114,23 @@ describe("versionedSettings", () => {
const result = findHighestMatchingVersion(versionedSettings, "3.36.4")
expect(result).toBeUndefined()
})

it("should treat nightly builds (by package name) as always eligible and pick highest version", () => {
const versionedSettings: VersionedSettings = {
"3.36.3": { feature: "v3" },
"2.0.0": { feature: "v2" },
}

const originalName = Package.name
;(Package as { name: string }).name = "roo-code-nightly"

try {
const result = findHighestMatchingVersion(versionedSettings, "1.0.0")
expect(result).toBe("3.36.3")
} finally {
;(Package as { name: string }).name = originalName
}
})
})

describe("resolveVersionedSettings", () => {
Expand Down
14 changes: 14 additions & 0 deletions src/api/providers/fetchers/versionedSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import cmp from "semver-compare"

import { Package } from "../../../shared/package"

function isNightlyBuild(): boolean {
return Package.name.toLowerCase().includes("nightly")
}

/**
* Type for versioned settings where the version is the key.
* Each version key maps to a settings object that should be used
Expand Down Expand Up @@ -68,6 +72,16 @@ export function findHighestMatchingVersion(
): string | undefined {
const versions = Object.keys(versionedSettings)

if (versions.length === 0) {
return undefined
}

// Nightly builds should always pick the highest available versioned settings
if (isNightlyBuild()) {
versions.sort((a, b) => compareSemver(b, a))
return versions[0]
}

// Filter to versions that are <= currentVersion
const matchingVersions = versions.filter((version) => meetsMinimumVersion(version, currentVersion))

Expand Down
Loading