Files
plugins/packages/commandcode/models.test.mjs
T
yetone 49e9d89d59 commandcode 0.1.12: each plan lists only the models it may use; a Go account no longer lists GOAT's (01huadalang on Discord)
01huadalang, signed in on the Go plan, was shown models only GOAT and above
may use. Command Code's /provider/v1/models is the same 87 models for every
plan (read with a GOAT key and without one on 2026-10-13: the same but for
"created"); which of them a plan may use is the CLI's own table (command-code
1.79.2, evaluateModelAccess: each model's category, premium or open, and
each plan's allowedCategories and blockedModels), and the Provider API turns
the rest away only when asked (403 "MODEL_NOT_IN_PLAN: Claude Opus 5.5
available in Provider and above plans or extra on demand usage").

Cause: the plugin filtered Go's list by a copy of CLI 1.73.0's table, which
didn't have Claude Haiku 5.5 (1.79.2: "haiku 5.5 in goat plan", blocked for
Go), and didn't filter any other plan at all, so GOAT, Pro and Provider were
shown models their plan refuses (a real GOAT account listed all 87, Claude
Opus 5.5 and GPT-6 Sol among them).

Now:
- PLAN_MODELS is CLI 1.79.2's table by plan name: Go and GOAT the open
  models only, Go also blocked from GOAT's (Sonnet 5.5, Haiku 5.5, GPT-5.6
  Sol, Grok 4.6/4.7, Muse Spark 1.2/1.3, Gemini 3.7/3.8 Flash, MiMo V2.6 Pro
  UltraSpeed), Pro blocked from Opus, Fable, GPT-6 Astra, GPT-6.1 Sol and
  Fugu Ultra, Provider from GPT-6.1 Sol, Max/Ultra/Teams Pro everything.
  GO_REFUSED is derived from it. Blocks are by id: the CLI's own block of
  "vercel-ai-gateway:xiaomi/mimo-v2.6-pro-ultraspeed" misses its "cai"
  model, and Go stays kept off it as before.
- provider.models filters every plan's list (and the default list standing
  in when the list can't be read) by it.
- A plan not read (billing/subscriptions failing, nothing saved), "No plan",
  or a plan name the table doesn't know keeps the whole list.
- Bought or free credits (billing/credits) let every model, as the CLI does;
  credits not read are taken as last read, else none, so the plan's list
  stands and a model it leaves out is still refused by Command Code.
- The refusal itself is unchanged: the Provider API's 403 reaches the agent
  as it came, and on Go's endpoint failure() says "Model not in plan: …".

Tests: plan-models.test.mjs is new, built from real bytes in testdata
(models-2026-10-13.json, a GOAT account's subscriptions and credits replies
with its ids zeroed, the two MODEL_NOT_IN_PLAN refusals). The Go case uses
the GOAT reply with Go's planId: there is no Go account here. All 7 fail on
0.1.11. Broken by hand, each goes red: Haiku 5.5 unblocked for Go (Go test),
no plan filter (5 tests), credits ignored, an unread plan refusing premium,
the stand-in list unfiltered, credits unread taken as extra.
models.test.mjs's pictures test moves from Pro to Max, since Pro's list no
longer has Claude Opus 5.5.

Ran: TMPDIR=<scratch> HOME=<scratch>/home bun test (all packages, 1144 pass,
0 fail) and bun scripts/check.mjs commandcode. The new provider.models hook
against the owner's real GOAT account (saved plan and none) lists 66 models:
Sonnet 5.5, Haiku 5.5 and GPT-5.6 Sol in, Opus 5.5, Sonnet 5 and GPT-6 Sol
out; a 1-token request confirmed GOAT gets Haiku 5.5 (200) and is refused
Sonnet 5 (403 MODEL_NOT_IN_PLAN).
Not tried: a real Go account (none here), an account with bought credits,
and the new version inside a running OpenCode/magpie; magpie needs the
mover's min raised to 0.1.12 for moved users to get it.
2026-10-13 00:44:50 +08:00

132 lines
7.3 KiB
JavaScript

// A Go account lists every model Command Code lets Go use, not ten, as
// magpie's built-in does (internal/provider/commandcode_plan.go, cmdGoFetch;
// commandcode_go_models_test.go, TestCommandCodeGoModels): the Provider
// API's list, asked without the key, less the models Go is refused; the
// CLI's table when the list can't be had. testdata/models.json is that list
// as api.commandcode.ai answered it (2026-10-01, 86 models), the built-in
// test's testdata/commandcode_models.json.
import { afterEach, expect, test } from "bun:test"
import { readFileSync } from "node:fs"
import { join } from "node:path"
import { CommandCodePlugin, _internal } from "./index.mjs"
const real = globalThis.fetch
afterEach(() => {
globalThis.fetch = real
_internal.subsSeen.clear()
})
const list = readFileSync(join(import.meta.dir, "testdata", "models.json"), "utf8")
const go = { type: "api", key: "go-key", metadata: { plan: "Go" } }
// models asks the provider.models hook for a Go account's list, the list
// answered with reply (a body, or a status)
async function models(reply) {
const asked = []
globalThis.fetch = async (url, init = {}) => {
const path = new URL(String(url)).pathname
const h = new Headers(init.headers)
if (path === "/alpha/billing/subscriptions") return Response.json({ success: true, data: { planId: "individual-go-monthly", status: "active" } })
if (path === "/provider/v1/models") {
asked.push({ auth: h.get("Authorization"), key: h.get("x-api-key") })
return typeof reply === "number" ? new Response("", { status: reply }) : new Response(reply, { status: 200 })
}
return new Response("", { status: 404 })
}
const hooks = await CommandCodePlugin()
const ms = await hooks.provider.models({ models: {} }, { auth: go })
return { ms, asked }
}
test("Go lists Command Code's models less those Go is refused, asked without the key", async () => {
const { ms, asked } = await models(list)
expect(asked).toEqual([{ auth: null, key: null }])
const got = Object.keys(ms)
expect(got.length).toBe(56)
for (const id of ["gpt-6-luna", "deepseek/deepseek-v4.1-flash", "moonshotai/Kimi-K2.6", "zai-org/GLM-5.2", "Qwen/Qwen3.7-Max", "stepfun/Step-5-Preview", "tencent/hy4-preview", "google/gemini-3.6-flash", "xai/grok-4.5"])
expect(got).toContain(id)
for (const id of ["claude-opus-5-5", "claude-sonnet-5-5", "gpt-6-sol", "gpt-5.6-sol", "xai/grok-4.7", "google/gemini-3.8-flash", "xiaomi/mimo-v2.6-pro-ultraspeed"])
expect(got).not.toContain(id)
// the list's order, and the table's names, reasoning levels and pictures
expect(got[0]).toBe("gpt-6-luna")
const k3 = ms["moonshotai/Kimi-K3"]
expect(k3.name).toBe("Kimi K3")
expect(Object.keys(k3.variants)).toEqual(["low", "high", "max"])
expect(k3.capabilities.attachment).toBe(true)
expect(k3.limit.context).toBe(1_000_000)
expect(ms[Symbol.for("magpie.fellBack")]).toBeUndefined()
// every Go model on chat completions, which the fetch sends to /alpha/generate
expect(new Set(Object.values(ms).map((m) => m.api.npm))).toEqual(new Set(["@ai-sdk/openai-compatible"]))
})
test("the CLI's table stands in when the list can't be had, and offers nothing Go is refused", async () => {
expect(_internal.GO_MODELS.length).toBe(57)
for (const m of _internal.GO_MODELS) expect(_internal.GO_REFUSED.has(m.id)).toBe(false)
for (const reply of [500, "not json", JSON.stringify({ data: [] }), JSON.stringify({ data: [{ id: "claude-opus-5-5" }, { id: "gpt-6-sol" }] })]) {
const { ms } = await models(reply)
expect(Object.keys(ms)).toEqual(_internal.GO_MODELS.map((m) => m.id))
expect(ms[Symbol.for("magpie.fellBack")]).toBe(true)
}
})
test("the list's failures read as the built-in's", async () => {
const url = "https://api.commandcode.ai/provider/v1/models"
const fail = async (res) => {
globalThis.fetch = async () => res
return (await _internal.goModels().then(() => null, (e) => e)).message
}
expect(await fail(new Response('{"error":{"message":"down"}}', { status: 503 }))).toBe(`${url}: 503 Service Unavailable (down)`)
expect(await fail(new Response("", { status: 500 }))).toBe(`${url}: 500 Internal Server Error`)
expect(await fail(new Response("<html>", { status: 200 }))).toBe(`${url}: not a model list`)
expect(await fail(Response.json({ data: [] }))).toBe(`${url}: no models listed`)
expect(await fail(Response.json({ data: [{ id: "claude-opus-5-5" }, { id: "gpt-6-sol" }] }))).toBe("Command Code listed no models for the Go plan")
})
// Command Code's list says nothing of pictures, and magpie's plugin host
// takes a model whose capabilities.input.image is a boolean as the plugin's
// answer, over models.dev's (internal/plugin/host.js, imageSaid): a false
// said for every model left each one of a moved plan without image input
// (ARNO on magpie 0.1.810). A model the plugin knows takes pictures says
// so; of one it doesn't know, nothing is said, and magpie answers from
// models.dev as the built-in does.
test("a model says it takes pictures when known, and nothing when not", async () => {
const pro = { type: "api", key: "max-key", metadata: { plan: "Max" } }
globalThis.fetch = async (url) => {
const path = new URL(String(url)).pathname
if (path === "/alpha/billing/subscriptions") return Response.json({ success: true, data: { planId: "individual-max-monthly", status: "active" } })
if (path === "/provider/v1/models") return new Response(list, { status: 200 })
return new Response("", { status: 404 })
}
const hooks = await CommandCodePlugin()
const ms = await hooks.provider.models({ models: {} }, { auth: pro })
expect(Object.keys(ms).length).toBe(86)
const said = (id) => ms[id].capabilities.input.image
// Claude, the default list's and the CLI's table's
for (const id of ["claude-opus-5-5", "claude-haiku-4-5-20251001", "gpt-6-sol", "gpt-6-luna", "moonshotai/Kimi-K3", "Qwen/Qwen3.8-Flash", "stealth/pixel-canary", "MiniMaxAI/MiniMax-M3"]) {
expect(said(id)).toBe(true)
expect(ms[id].capabilities.attachment).toBe(true)
}
// text alone, or not known: not said either way
for (const id of ["deepseek/deepseek-v4-pro", "zai-org/GLM-5.3", "MiniMaxAI/MiniMax-M2.7", "tencent/hy4-preview"]) {
expect(said(id)).toBeUndefined()
expect("image" in ms[id].capabilities.input).toBe(false)
}
for (const m of Object.values(ms)) expect(said(m.id) === true || said(m.id) === undefined).toBe(true)
// a list that says, is taken at its word
globalThis.fetch = async (url) => {
const path = new URL(String(url)).pathname
if (path === "/alpha/billing/subscriptions") return Response.json({ success: true, data: { planId: "individual-max-monthly", status: "active" } })
return Response.json({ data: [{ id: "claude-opus-5-5", modalities: { input: ["text"] } }, { id: "x/seer", modalities: { input: ["text", "image"] } }] })
}
_internal.subsSeen.clear()
const said2 = await (await CommandCodePlugin()).provider.models({ models: {} }, { auth: { ...pro, key: "max-key-2" } })
expect(said2["claude-opus-5-5"].capabilities.input.image).toBe(false)
expect(said2["x/seer"].capabilities.input.image).toBe(true)
// Go: the table's pictures, nothing said of the rest
const { ms: g } = await models(list)
expect(g["moonshotai/Kimi-K3"].capabilities.input.image).toBe(true)
expect(g["zai-org/GLM-5.2"].capabilities.input).not.toHaveProperty("image")
})