Files
plugins/packages/zen-free/models.test.mjs
T
yetone da27b4ce6b zen-free 0.1.9: a free model Zen lists is offered the hour it lists it, before OpenCode's catalog or docs describe it, and a list read with them out of reach isn't said as fallen back (yetone/magpie#2385)
Zen made deepseek-v4.1-flash-free free (in its /models as the public key
reads it, 2026-10-15) and the plugin never offered it. Two causes:

- buildModels left out a listed model that neither the catalog
  (models.opencode.ai) nor the docs' endpoint table described: a free
  model Zen lists before they catch up, or every model but the snapshot's
  when either can't be read. A listed id ending in -free with no word from
  either is now asked through the provider's own package
  (openai-compatible, chat), as OpenCode asks a model with no package of
  its own. A paid or unknown id that doesn't say -free still needs the
  catalog; the docs saying SystemOne still keep one out.
- A discovery with the catalog or the docs unread was marked
  magpie.fellBack, though Zen's own list was read. magpie answers a
  fallen-back list by keeping the last list read in full
  (plugin.keepListed), so a user who can't reach GitHub's raw host or the
  catalog kept that old list, and every model Zen made free since stayed
  out. Only a failed read of Zen's /models is fallen back now; models
  verified before are still kept while Zen lists them.

Tests (no network; the fixture server serves
fixtures/zen-models-2026-10-15.json, Zen's /models byte for byte):
- "a free model Zen lists that the catalog and the docs don't describe is
  offered, on chat (#2385)": catalog 503, docs 404 -> the ten free models
  Zen lists (Jev, "test" and the paid ones out), deepseek-v4.1-flash-free
  on chat, muse-spark-1.3 on Responses, not fallen back; a request for it
  goes to /chat/completions
- "... before the catalog has it is offered with the catalog read (#2385)"
- models.test: an unknown -free id is offered on the provider's package,
  "unknown-paid", "freebie" and "free-model" aren't, SystemOne stays out
  (replaces "unknown models require a known protocol rather than a
  guessed chat endpoint")
- two partial-discovery tests now expect no fellBack
Broken by hand: models.mjs back to 0.1.8's -> 3 fail; provider.mjs back
to 0.1.8's -> 3 fail; both fixed: bun test 174 pass, 0 fail (bun 1.4.2).
bun scripts/check.mjs zen-free: ok.

Not tried: a live request to deepseek-v4.1-flash-free through the plugin
(one GET of Zen's /models was the only network used). A future free
model Zen serves on Responses or Messages that the catalog doesn't
describe yet would be offered on chat and refused by Zen until the
catalog has it.

No magpie mover to raise: zen-free isn't a moved built-in, and magpie
updates @magpie-community plugins by itself within the hour.
2026-10-15 19:46:57 +08:00

116 lines
6.0 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
const subject = import("./models.mjs").catch(() => ({}));
const provider = {
npm: "@ai-sdk/openai-compatible",
models: {
"coder-free": {
name: "Coder Free",
cost: { input: 0, output: 0 },
limit: { context: 200000, input: 160000, output: 32000 },
reasoning: true,
tool_call: true,
modalities: { input: ["text", "image"], output: ["text"] },
reasoning_options: [{ type: "effort", values: ["low", "high"] }],
},
"zero-cost": { cost: { input: 0, output: 0 } },
paid: { cost: { input: 1, output: 3 } },
"old-free": { status: "deprecated", cost: { input: 0, output: 0 } },
"decision-free": { provider: { npm: "@vendor/systemone" } },
"responses-free": { provider: { npm: "@ai-sdk/openai" } },
"messages-free": { provider: { npm: "@ai-sdk/anthropic" } },
"gone-free": {},
},
};
const ids = Object.keys(provider.models).filter((id) => id !== "gone-free");
const baseURL = "https://opencode.ai/zen/v1";
test("lists only live free models with supported protocols and excludes retired models", async () => {
const { buildModels } = await subject;
assert.equal(typeof buildModels, "function", "model discovery must be implemented");
const models = buildModels(ids, provider, {}, baseURL);
assert.deepEqual(Object.keys(models).sort(), [
"coder-free",
"messages-free",
"responses-free",
"zero-cost",
]);
assert.equal(models["coder-free"].free, true);
assert.equal(models["coder-free"].providerID, "opencode-zen-free");
assert.deepEqual(models["coder-free"].limit, { context: 200000, input: 160000, output: 32000 });
assert.equal(models["coder-free"].capabilities.input.image, true);
assert.equal(models["coder-free"].capabilities.toolcall, true);
assert.deepEqual(Object.keys(models["coder-free"].variants), ["low", "high"]);
assert.equal(models["responses-free"].api.npm, "@ai-sdk/openai");
assert.equal(models["messages-free"].api.npm, "@ai-sdk/anthropic");
});
test("endpoint documentation overrides inherited SDK and excludes SystemOne", async () => {
const { buildModels, parseProtocolDocs } = await subject;
assert.equal(typeof parseProtocolDocs, "function", "protocol parsing must be implemented");
const protocols = parseProtocolDocs(
[
"| Coder | coder-free | `https://opencode.ai/zen/v1/messages` | sdk |",
"| Decision | decision-free | `https://opencode.ai/zen/v1/systemone` | - |",
].join("\n"),
);
const models = buildModels(ids, provider, protocols, baseURL);
assert.equal(models["coder-free"].api.npm, "@ai-sdk/anthropic");
assert.equal(models["decision-free"], undefined);
});
// A model Zen lists as -free before the catalog or the docs describe it is
// asked as the provider's own package asks (chat), as OpenCode asks a model
// with no package of its own (yetone/magpie#2385); anything else unknown
// still needs their word.
test("an unknown -free model is offered on the provider's package; another unknown model is not", async () => {
const { buildModels } = await subject;
assert.equal(typeof buildModels, "function", "model discovery must be implemented");
assert.deepEqual(
Object.keys(buildModels(["new-free", "unknown-paid", "freebie", "free-model"], {}, {}, baseURL)),
["new-free"],
);
assert.equal(buildModels(["new-free"], {}, {}, baseURL)["new-free"].api.npm, "@ai-sdk/openai-compatible");
assert.equal(
buildModels(["new-free"], { npm: "@ai-sdk/openai" }, {}, baseURL)["new-free"].api.npm,
"@ai-sdk/openai",
);
// the docs saying SystemOne keep it out
assert.deepEqual(Object.keys(buildModels(["new-free"], {}, { "new-free": "systemone" }, baseURL)), []);
const models = buildModels(["new-free"], {}, { "new-free": "chat" }, baseURL);
assert.equal(models["new-free"].api.url, baseURL);
assert.equal(models["new-free"].cost.input, 0);
});
// Rows as OpenCode's console docs have them since 2026-10-12
// (services/www/src/docs/content/console/models.mdx), and the pricing
// table beside it that names no endpoint (#2305 on yetone/magpie).
const consoleDocs = [
"| Claude Haiku 4.5 | claude-haiku-4-5 | `https://opencode.ai/inference/v1/messages` | `@ai-sdk/anthropic` |",
"| Gemini 3 Flash | gemini-3-flash | `https://opencode.ai/inference/v1/models/gemini-3-flash` | `@ai-sdk/google` |",
"| Jev 1.13 Free | jev-1.13-free | `https://opencode.ai/inference/v1/systemone` | - |",
"| Big Pickle | big-pickle | `https://opencode.ai/inference/v1/chat/completions` | `@ai-sdk/openai-compatible` |",
"| Step 5 Preview Free | step-5-preview-free | `https://opencode.ai/inference/v1/chat/completions` | `@ai-sdk/openai-compatible` |",
"| Muse Spark 1.3 Contributor Free | muse-spark-1.3-contributor-free | `https://opencode.ai/inference/v1/responses` | `@ai-sdk/openai` |",
"| Step 5 Preview Free | Free | Free | Free | - |",
].join("\n");
test("reads the console docs' endpoint table, and Jev stays out as SystemOne", async () => {
const { buildModels, parseProtocolDocs, bootstrapProtocols } = await subject;
const protocols = parseProtocolDocs(consoleDocs);
assert.deepEqual(protocols, {
"claude-haiku-4-5": "anthropic",
"jev-1.13-free": "systemone",
"big-pickle": "chat",
"step-5-preview-free": "chat",
"muse-spark-1.3-contributor-free": "responses",
});
// the snapshot kept for when the docs can't be read says the same
for (const [id, protocol] of Object.entries(protocols)) {
if (bootstrapProtocols[id]) assert.equal(bootstrapProtocols[id], protocol, id);
}
const models = buildModels(["jev-1.13-free", "step-5-preview-free"], {}, protocols, baseURL);
assert.deepEqual(Object.keys(models), ["step-5-preview-free"]);
});