fix(stats): prefer Go catalog pricing (#43120)

This commit is contained in:
opencode-agent[bot] 2026-08-17 15:20:06 -05:00 committed by GitHub
parent 42fc297d30
commit 728ae7c949
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 1 deletions

View file

@ -0,0 +1,47 @@
import { describe, expect, mock, test } from "bun:test"
mock.module("@solidjs/router", () => ({ query: (load: () => unknown) => load }))
const { buildModelCatalog, findModelCatalogEntry } = await import("./model-catalog")
describe("model catalog pricing", () => {
test("prefers OpenCode Go pricing over a zero-cost coding plan with the same model id", () => {
const catalog = buildModelCatalog(
{
models: {
"zhipuai/glm-5.3": {
id: "zhipuai/glm-5.3",
name: "GLM-5.3",
},
},
},
{
"opencode-go": {
id: "opencode-go",
models: {
"glm-5.3": {
id: "glm-5.3",
cost: { input: 1.4, output: 4.4, cache_read: 0.26 },
},
},
},
"zhipuai-coding-plan": {
id: "zhipuai-coding-plan",
models: {
"glm-5.3": {
id: "glm-5.3",
cost: { input: 0, output: 0, cache_read: 0 },
},
},
},
},
)
expect(findModelCatalogEntry(catalog, "glm-5.3")?.cost).toEqual({
input: 1.4,
output: 4.4,
cacheRead: 0.26,
cacheWrite: undefined,
})
})
})

View file

@ -119,7 +119,7 @@ export function catalogSlug(value: string) {
.replace(/-{2,}/g, "-")
}
function buildModelCatalog(payload: unknown, pricingPayload?: unknown, labPayload?: unknown): ModelCatalog {
export function buildModelCatalog(payload: unknown, pricingPayload?: unknown, labPayload?: unknown): ModelCatalog {
const costs = readCatalogCosts(pricingPayload)
const labDescriptions = readCatalogLabDescriptions(payload, pricingPayload, labPayload)
const models = readCatalogModels(payload)
@ -129,6 +129,7 @@ function buildModelCatalog(payload: unknown, pricingPayload?: unknown, labPayloa
cost:
costs.get(catalogIdKey(model.id)) ??
costs.get(`${model.lab}/${model.slug}`) ??
costs.get(`opencode-go/${model.slug}`) ??
costs.get(model.slug) ??
model.cost,
}))