Files
plugins/packages/factory/rate.test.mjs
T
garry569andgarry569 d8f8981d33 factory 0.1.43: droid 1.7.0 models (#927)
droid 1.7.0's new models in the Factory plugin: Fable 5.2, Kimi K3.1 Pro,
MiniMax M3.1 Flash, Nemotron 3.5 Super, Inkling, Muse Spark 1.2, Beam 1.0,
and GPT-6 Sol/Luna, GPT-5.6 Sol and GLM-5.2 Fast. Each is at droid's
limits, efforts, images and token multiplier, with apiProviders[0] as the
upstream. gpt-6-sol/gpt-6-luna at service_tier "priority" now go to their
Fast Mode models. GLM-5.2 Fast is its own chat model and is not a tier of
GLM-5.2. GPT-5.6 Sol Fast Mode gets Sol's 20% promotion until 2026-11-22.
Muse Spark 1.2 is left out of CORE (no billingPool "core"). GPT-6.1 Terra,
Muse Spark Open, GPT-6.1 Sol Ultra Fast and Muse Spark 1.3 are left out,
each with a reason. The first 24 models are unchanged (#119).

Review at 9524dcfc6e45b7c2c15245bd1e200d72aeebe17f:
- droid 1.7.0 linux-x64 downloaded in WSL (magpie-desktop). SHA-256
  4700746f52ec88e3758a18737be13bb74519276de97bc329054e8dae08f15f42
  matches. All 24 excerpt lines of testdata/droid-1.7.0-models.txt are in
  the binary byte for byte (grep -F). The base entries gpt-6-sol (0.8),
  gpt-6-luna (0.04), gpt-5.6-sol (2) and glm-5.2 match the plugin's.
- Each new row was checked against its entry: id, context/output, efforts
  (off dropped, or kept as none only for GLM-5.2 Fast), images,
  multiplier, upstream and wire.
- First 24 ids are equal on main and the PR, and main's order is kept.
  CORE gains exactly kimi-k3.1-pro, minimax-m3.1-flash,
  nemotron-3.5-super, inkling, beam-1.0 and glm-5.2-fast.
- In WSL, bun 1.4.2, HOME a temp dir: `bun test packages/factory` gave
  193 pass, 0 fail. `bun scripts/check.mjs` passes.
- Broken by hand. main's index.mjs with the new tests: 14 fail. Muse kept
  in CORE: 7 fail. The Sol Fast promotion removed: 2 fail. Fable 5.2 moved
  first: the first-24 test fails. Luna Fast at 0.04: 3 fail. Beam with
  images: 1 fails.

Not tried: real requests to Factory. Kimi K3.1 Pro, Nemotron 3.5 Super,
MiniMax M3.1 Flash, Beam 1.0, GLM-5.2 Fast and Fable 5.2 are behind
statsig gates whose default is off in the binary. The author's account
listed them, but other accounts may not, as with Gemini 4 Argon.

Co-authored-by: garry569 <garry569@users.noreply.github.com>
2026-11-10 16:05:29 +08:00

125 lines
6.1 KiB
JavaScript

// A model's price reaches magpie as its rate: droid's own picker shows a model
// by the token multiplier its entry keeps (cost.tokenMultiplier), and magpie
// shows the same beside the model, so a cheap one is picked without opening
// droid. A promotion running comes off it, with the multiplier before the
// discount as rateWas — magpie strikes that through beside the price, as it
// does for WorkBuddy's credits and Qoder's price factors. The cases are droid
// 0.241.1's registry costs, 0.251.0's 1017 entry and 1.7.0's new models,
// saved in testdata.
import { expect, test } from "bun:test"
import { readFileSync } from "node:fs"
import { FactoryAuthPlugin, _internal } from "./index.mjs"
const DROID = ["droid-0.241.1-costs.txt", "droid-0.251.0-deepseek-1017.txt", "droid-1.7.0-models.txt"]
.map((name) => readFileSync(new URL(`./testdata/${name}`, import.meta.url), "utf8")).join("\n")
// cost is a model's cost text, as its entry keeps it (Inkling's key unquoted).
function cost(id) {
const line = DROID.split("\n").find((l) => l.startsWith(`"${id}":`) || l.startsWith(`${id}:{id:"${id}",`))
if (!line) throw new Error(`${id} is not in the fixture`)
return line.slice(line.indexOf("cost:"))
}
// multiplier is the token multiplier an entry lists.
function multiplier(id) {
return Number(cost(id).match(/tokenMultiplier:([\d.]+)/)[1])
}
// promotions are the ones an entry names: droid keeps them apart from it, by a
// name, or inline in the entry itself.
function promotions(id) {
const text = cost(id)
const inline = text.match(/promotions:\[\{discount:([\d.]+),startsAt:new Date\("([^"]+)"\)(?:,expiresAt:new Date\("([^"]+)"\))?/)
if (inline) return [{ discount: +inline[1], from: inline[2], to: inline[3] ?? null }]
const named = text.match(/promotions:\[([A-Za-z_$][\w$]*(?:,[A-Za-z_$][\w$]*)*)\]/)
if (!named) return []
const defs = Object.fromEntries(
[...DROID.matchAll(/^([A-Za-z_$][\w$]*)=\{discount:([\d.]+),startsAt:new Date\("([^"]+)"\)(?:,expiresAt:new Date\("([^"]+)"\))?/gm)].map((m) => [
m[1],
{ discount: +m[2], from: m[3], to: m[4] ?? null },
]),
)
return named[1].split(",").map((n) => {
const d = defs[n.trim()]
if (!d) throw new Error(`promotion ${n} is not defined in the fixture`)
return d
})
}
// price is what magpie shows for a model at now: the multiplier less the first
// promotion running then, and the multiplier before it when one runs.
function price(id, now) {
const base = multiplier(id)
const p = promotions(id).find((p) => now >= Date.parse(p.from) && (!p.to || now < Date.parse(p.to)))
if (!p) return { rate: base, rateWas: 0 }
return { rate: Number((base * (1 - p.discount)).toFixed(4)), rateWas: base }
}
test("every model's rate is the token multiplier its droid registry entry lists", () => {
for (const m of _internal.MODELS) {
expect(m.rate).toBe(multiplier(m.id))
}
})
test("a promotion running comes off the rate, the multiplier before it as rateWas", () => {
const now = Date.parse("2026-10-14T21:30:00Z")
const models = _internal.configModels(now)
for (const m of _internal.MODELS) {
expect(models[m.id].rate).toBe(price(m.id, now).rate)
expect(models[m.id].rateWas).toBe(price(m.id, now).rateWas)
}
// the five droid 0.241.1 offers a price off on: Sol's 20%, Mistral Large 4's
// launch discount, and Gemini 4 Argon's, 3.8 Flash's and 3.7 Flash's 50%;
// and Sol's 20% on GPT-5.6 Sol Fast Mode in 1.7.0
const discounted = _internal.MODELS.filter((m) => models[m.id].rateWas > 0).map((m) => m.id)
expect(discounted).toEqual(["gpt-5.6-sol", "mistral-large-4", "gemini-4-argon", "gemini-3.8-flash", "gemini-3.7-flash", "gpt-5.6-sol-fast"])
expect(models["gpt-5.6-sol-fast"].rate).toBe(3.2)
expect(models["gpt-5.6-sol-fast"].rateWas).toBe(4)
expect(models["gemini-4-argon"].rate).toBe(0.8)
expect(models["gemini-4-argon"].rateWas).toBe(1.6)
})
test("a promotion that has ended, or hasn't started, is no discount at all", () => {
// Gemini 4 Argon's 50% off ends 2026-12-01T08:00Z; GLM-5.6 Sol's 20% starts
// 2026-08-22T00:00Z. Either way the multiplier is the price.
const after = _internal.configModels(Date.parse("2026-12-02T00:00:00Z"))
expect(after["gemini-4-argon"].rate).toBe(1.6)
expect(after["gemini-4-argon"].rateWas).toBe(0)
const before = _internal.configModels(Date.parse("2026-08-01T00:00:00Z"))
expect(before["gpt-5.6-sol"].rate).toBe(2)
expect(before["gpt-5.6-sol"].rateWas).toBe(0)
})
// magpie reads a model's rate from a provider hook's models, not from a config
// hook's (host.js, providers()): a price given only in config never reaches the
// model list. So the same list is offered both ways.
test("the provider hook carries every model with its rate, as magpie reads it", async () => {
const now = Date.parse("2026-10-14T21:30:00Z")
const models = _internal.providerModels({ id: "factory" }, now)
expect(Object.keys(models).sort()).toEqual(_internal.MODELS.map((m) => m.id).sort())
for (const m of _internal.MODELS) {
const got = models[m.id]
expect(got.rate).toBe(price(m.id, now).rate)
expect(got.rateWas).toBe(price(m.id, now).rateWas)
// the fields magpie reads a provider's model list for
expect(got.id).toBe(m.id)
expect(got.name).toBe(m.name)
expect(got.api).toEqual({ id: m.id, url: m.wire.api, npm: m.wire.npm })
expect(got.limit).toEqual({ context: m.context, output: m.output })
expect(got.capabilities.reasoning).toBe(m.efforts.length > 0)
expect(got.capabilities.input.image).toBe(m.images)
expect(Object.keys(got.variants)).toEqual([...m.efforts])
}
expect(models["gemini-4-argon"].rate).toBe(0.8)
expect(models["gemini-4-argon"].rateWas).toBe(1.6)
})
test("the plugin answers a provider hook, which a config hook alone doesn't", async () => {
const hooks = await FactoryAuthPlugin({ client: { auth: { set: async () => {} } } })
expect(hooks.provider?.id).toBe("factory")
expect(typeof hooks.provider.models).toBe("function")
const models = await hooks.provider.models({ id: "factory" }, {})
expect(models["gpt-6.1-sol"].rate).toBeGreaterThan(0)
expect(Object.keys(models)).toHaveLength(_internal.MODELS.length)
})