Files
plugins/packages/workbuddy/custom.test.mjs
T
yetone 51f24a363a workbuddy 0.2.28: list an enterprise's custom: models (#1015)
An enterprise account's own models ("custom:<name>|<name>", modelType
"enterprise") come in /v3/config's models but not in the cli agent's
list. WorkBuddy's CLI (bundled in WorkBuddy 5.5.6, AgentManager.
computeModels) appends every config model whose id starts with
"custom:" to the agent's list itself, after the agent's own ones.
liveModels read only the agent's list, so the models were missing
entirely, and a forced chat to them worked. They are now appended in
the config's order with their context, output, images, price and
efforts, and the id goes to WorkBuddy as given, "|" and all. They stay
on chat (nativeOf matches only a bare claude- id), where the reporter's
chat was served. Both sites share liveModels; nothing else enumerates
the config. The CLI also appends models tagged "custom" or "chat":
those in a desktop's cached config are its local models with their own
url and apiKey, so they stay out.

PR #1016 (yetihan) joined the two spellings instead (an agent-listed
custom:x|x against a bare detail id x); the issue's literal entry,
run against d2e21b7b, lists neither model (expected 2, got 0).

Run (mica, HOME=$(mktemp -d), at a181b898, this change on edc6dbcd;
the rebase onto 934e6b33 adds antigravity commits only):
bun test packages/workbuddy 342 pass, 0 fail across 32 files;
bun scripts/check.mjs exit 0. Earlier the same on mote at dba24067.
The root `bun test` was not run before the push: both machines'
suite.lock were held by other sessions' Go and GUI suites (mica's for
6h), and it is queued on mote behind them; its result goes on #1015.
Broken by hand: the append turned off, 5 of 6 custom.test.mjs red
(the no-cli-agent case passes, as it should); the de-duplication
removed, the "listed once" test red.
Not tried: a real enterprise account; none is available, so the
fixture is the issue's own JSON shape and the "not in the cli agent's
list" placement is inferred from the report and the CLI's code.

Reported-by: CnsMaple
Co-authored-by: zhou.han <18181754+yetihan@users.noreply.github.com>
Refs #1015
2026-11-12 02:20:29 +08:00

87 lines
3.8 KiB
JavaScript

// plugins#1015 (CnsMaple): an enterprise account's own models,
// "custom:<name>|<name>" with modelType "enterprise", are in /v3/config's
// models but in no agent's list. WorkBuddy's CLI appends every "custom:"
// model to the agent's list itself; the plugin read only the agent's list,
// so they were missing. The entries are the issue's shape, word for word.
import { afterEach, expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const custom = (name) => ({
id: `custom:${name}|${name}`,
name,
modelType: "enterprise",
maxInputTokens: 256000,
maxOutputTokens: 64000,
supportsImages: true,
supportsReasoning: true,
supportsToolCall: true,
reasoning: { supportedEfforts: ["minimal", "low", "medium", "high", "xhigh", "max"], defaultEffort: "medium", canDisableThinking: true },
})
const config = JSON.stringify({
code: 0,
data: {
agents: [
{ name: "cli", models: ["glm-5.3"] },
{ name: "compact", models: ["glm-5.3"] },
],
models: [
{ id: "glm-5.3", name: "GLM-5.3", maxInputTokens: 1000000, maxOutputTokens: 131072, credits: "x0.08" },
custom("claude-opus-5-5"),
custom("gpt-5.6-sol"),
{ id: "kimi-k2.5", name: "Kimi-K2.5" }, // in no agent's list, and no custom model: left out as before
],
},
})
async function listed(site) {
globalThis.fetch = async () => new Response(config)
return _internal.liveModels(_internal.SITES[site], { access: "a", uid: "u", enterpriseId: "ent-1" })
}
for (const site of ["workbuddy", "workbuddy-ai"]) {
test(`${site}: an enterprise's custom: models are listed after the agent's, id as given`, async () => {
const out = await listed(site)
expect(out.map((m) => m.id)).toEqual(["glm-5.3", "custom:claude-opus-5-5|claude-opus-5-5", "custom:gpt-5.6-sol|gpt-5.6-sol"])
})
test(`${site}: a custom: model carries its context, output, images and efforts`, async () => {
const m = (await listed(site)).find((x) => x.id === "custom:claude-opus-5-5|claude-opus-5-5")
expect(m.name).toBe("claude-opus-5-5")
expect(m.context).toBe(256000)
expect(m.output).toBe(64000)
expect(m.images).toBe(true)
expect(m.efforts).toEqual(["none", "minimal", "low", "medium", "high", "xhigh", "max"])
expect(m.effort).toBe("medium")
// no credits in its entry: neither free nor priced
expect(m.free).toBeUndefined()
expect(m.rate).toBeUndefined()
const info = _internal.modelOf(_internal.SITES[site], { id: site }, m)
expect(info.id).toBe("custom:claude-opus-5-5|claude-opus-5-5")
expect(info.api.id).toBe("custom:claude-opus-5-5|claude-opus-5-5")
// on chat, where the reporter's chat to it was served
expect(info.api.npm).toBe("@ai-sdk/openai-compatible")
expect(info.limit).toEqual({ context: 256000, output: 64000 })
expect(Object.keys(info.variants)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh", "max"])
})
}
test("a custom: model the agent names already is listed once, where the agent put it", async () => {
const cfg = JSON.parse(config)
cfg.data.agents[0].models = ["custom:gpt-5.6-sol|gpt-5.6-sol", "glm-5.3"]
globalThis.fetch = async () => new Response(JSON.stringify(cfg))
const out = await _internal.liveModels(_internal.SITES.workbuddy, { access: "a", uid: "u" })
expect(out.map((m) => m.id)).toEqual(["custom:gpt-5.6-sol|gpt-5.6-sol", "glm-5.3", "custom:claude-opus-5-5|claude-opus-5-5"])
})
test("a config with no cli agent lists nothing, custom: models too", async () => {
const cfg = JSON.parse(config)
cfg.data.agents = [{ name: "compact", models: ["glm-5.3"] }]
globalThis.fetch = async () => new Response(JSON.stringify(cfg))
expect(await _internal.liveModels(_internal.SITES.workbuddy, { access: "a", uid: "u" })).toEqual([])
})