Files
plugins/packages/devin/free.test.mjs
T
yetone eee889afab devin 0.1.27: SWE-2 never goes as a paid -lightning variant or a bare family id, and an unreadable model list is said, not swallowed
zws13579 (magpie Discord #general, devin 0.1.26): a Devin Free plan
account ($0) can't use SWE-2 through the plugin, while Devin CLI/Desktop
can. They listed five places SWE-2 could be lost silently; checked each
against the code:

1. configsFor swallowed every error (real). Its reason is now kept
   (c.error), logged once to stderr when the asks start failing (the host
   routes it to magpie's log), and usage adds an aside row "Free models:
   unknown: Devin's model list couldn't be read (<reason>)" when a quota
   window exists and Devin has never answered for the account. The windows
   still count every model then (a failed read means unknown).
2. notModels only rides on a window (as designed: with no window nothing
   counts SWE-2). A plan with no quota window gives none and no error;
   a test holds that. The real gap behind it was 1, now visible.
3. A family the account's list leaves out (picked from SNAPSHOT's list,
   which the OpenCode config offers) went to Devin as the bare family id
   ("swe-2"). variantFor now falls back to SNAPSHOT's family, so it goes
   as swe-2-high (swe-2-max at max). The listing is unchanged: no model
   is added that the account's list doesn't have.
4. variantFor's effort-less default and listed()'s free check took
   f.models[0]. Devin's captures (10-14, 10-15) list swe-2-high first, so
   it isn't hit today, but a first -lightning variant (High cost tier)
   would have sent effort-less SWE-2 to a paid variant and unmarked it
   free. defaultModel skips such suffixed variants.
5. v2Models/v2Setup: not a magpie path. magpie's host loads server()
   (DevinAuthPlugin), whose usage hook carries notModels; OpenCode 2 has
   no usage hook, and a free model's cost there is already 0.

usage.test.mjs's stub answered GetCliModelConfigs with a JSON parse
error, so those tests ran with the model list unreadable; it now serves
a one-model list, so they test what they name.

Run (mote, from the repo root, as CI): HOME=$(mktemp -d) bun test:
3866 pass, 9 skip, 0 fail; bun scripts/check.mjs: every package ok.
Broken by hand: the new free.test.mjs against origin/main's index.mjs:
3 red (lightning default "swe-2-medium-lightning", bare "swe-2", no
"Free models" row), 6 green.

Not tried: a real Devin Free plan account. No Free plan GetUserStatus or
GetCliModelConfigs has been captured, so whether Devin gives a Free
account SWE-2 at the Free cost tier (its pricing lists free SWE-2 for
Pro) is unknown; nothing here assumes a shape for it.
2026-10-30 22:08:48 +08:00

123 lines
5.9 KiB
JavaScript

// 太陽と向日葵 on magpie's Discord: SWE-2 is free, but with the account's
// quota used up magpie said the quota was used up and didn't send SWE-2 to
// it, while a test of the model worked. Devin marks SWE-2's variants Free
// (model_cost_tier 4) in GetCliModelConfigs; the day and the week leave them
// out, and the list says they're free.
import { afterEach, expect, test } from "bun:test"
import { readFileSync } from "node:fs"
import { join } from "node:path"
import { DevinAuthPlugin, _internal } from "./index.mjs"
const real = globalThis.fetch
afterEach(() => {
globalThis.fetch = real
_internal.forgetSaid()
})
// Devin's own response to GetCliModelConfigs (2026-10-14), cut to a few
// configs; SWE-2's three variants are its only Free ones
const realConfigs = readFileSync(join(import.meta.dir, "testdata", "model-configs.bin"))
const status = (plan = {}) => ({
userStatus: {
planStatus: {
planInfo: { planName: "Teams", teamsTier: "TEAMS_TIER_DEVIN_TEAMS", billingStrategy: "BILLING_STRATEGY_QUOTA", monthlyPromptCredits: -1, isDevin: true },
planEnd: "2026-10-26T21:45:55Z",
dailyQuotaResetAtUnix: "1790841600",
weeklyQuotaResetAtUnix: "1791100800",
...plan,
},
},
})
function serve(s, configs = () => new Response(realConfigs)) {
globalThis.fetch = async (url) => {
if (String(url).endsWith("/GetUserStatus")) return Response.json(s)
if (String(url).endsWith("/GetCliModelConfigs")) return configs()
throw new Error("unexpected fetch " + url)
}
}
const SWE2 = ["swe-2", "swe-2-high", "swe-2-max", "swe-2-medium"]
test("Devin's Free tier is read from its model configs", () => {
expect([..._internal.parseFree(new Uint8Array(realConfigs))].sort()).toEqual(["swe-2-high", "swe-2-max", "swe-2-medium"])
})
test("a used-up day and week don't count SWE-2", async () => {
// both used up: JSON leaves the 0% left out
serve(status())
const u = await (await DevinAuthPlugin()).auth.usage(async () => ({ type: "api", key: "key-free-usage" }))
expect(u.windows.map((w) => [w.name, w.used])).toEqual([["1 day", 100], ["7 days", 100]])
for (const w of u.windows) expect([...w.notModels].sort()).toEqual(SWE2)
})
test("with no word from Devin on its models, the day and week count every model", async () => {
serve(status(), () => new Response("no", { status: 503 }))
const u = await (await DevinAuthPlugin()).auth.usage(async () => ({ type: "api", key: "key-free-unknown" }))
expect(u.windows.map((w) => w.notModels)).toEqual([undefined, undefined])
})
test("the list marks SWE-2 free and nothing else", async () => {
serve(status())
const got = await (await DevinAuthPlugin()).provider.models({ models: {} }, { auth: { type: "api", key: "key-free-list" } })
expect(Object.keys(got).filter((id) => got[id].free).sort()).toEqual(SWE2.filter((id) => id in got).sort())
expect(got["swe-2"].free).toBe(true)
expect(got["gemini-4-argon"].free).toBeUndefined()
})
// zws13579 on magpie's Discord (devin 0.1.26): a Free plan account couldn't
// get SWE-2 through the plugin. No Free plan response has been captured;
// these hold the paths that would hide SWE-2 whatever its shape.
const swe2 = (ids) => ({ uid: "swe-2", label: "SWE-2", aliases: ["swe"], models: ids.map((id) => ({ id, name: id, context: 262000, output: 128000 })) })
test("SWE-2 with no effort goes as a free variant, not a -lightning one Devin lists first", () => {
const fams = [swe2(["swe-2-medium-lightning", "swe-2-high", "swe-2-medium", "swe-2-max"])]
expect(_internal.variantFor(fams, "swe-2", "")).toBe("swe-2-high")
expect(_internal.variantFor(fams, "swe-2", "medium")).toBe("swe-2-medium")
const free = new Set(["swe-2-high", "swe-2-medium", "swe-2-max"])
expect(_internal.listed(fams, [], {}, free).find((m) => m.id === "swe-2").free).toBe(true)
})
test("Devin's own list (2026-10-15, with -lightning variants) sends SWE-2 as swe-2-high", () => {
const fams = _internal.parseConfigFamilies(new Uint8Array(readFileSync(join(import.meta.dir, "testdata", "model-configs-1015.bin"))))
expect(_internal.variantFor(fams, "swe-2", "")).toBe("swe-2-high")
})
test("SWE-2 the account's list leaves out goes as SNAPSHOT's variant, not the bare family id", () => {
const fams = [{ uid: "kimi-k3", label: "Kimi K3", aliases: [], models: [{ id: "kimi-k3-high", name: "Kimi K3 High", context: 0, output: 0 }] }]
expect(_internal.variantFor(fams, "swe-2", "")).toBe("swe-2-high")
expect(_internal.variantFor(fams, "swe-2", "max")).toBe("swe-2-max")
expect(_internal.variantFor(fams, "swe-2-medium", "")).toBe("swe-2-medium")
expect(_internal.variantFor(fams, "kimi-k3", "")).toBe("kimi-k3-high")
})
test("a model list Devin won't give is said in usage and logged once, not swallowed", async () => {
serve(status(), () => new Response("no", { status: 503 }))
const logged = []
const was = console.error
console.error = (...a) => logged.push(a.join(" "))
try {
const plugin = await DevinAuthPlugin()
const u = await plugin.auth.usage(async () => ({ type: "api", key: "key-free-said" }))
expect(u.windows.slice(0, 2).map((w) => w.notModels)).toEqual([undefined, undefined])
const note = u.windows.find((w) => w.name === "Free models")
expect(note?.aside).toBe(true)
expect(note.display).toContain("503")
await plugin.auth.usage(async () => ({ type: "api", key: "key-free-said" }))
} finally {
console.error = was
}
expect(logged.filter((l) => l.includes("GetCliModelConfigs")).length).toBe(1)
})
test("a plan with no quota window shows none and no free-models row", async () => {
const s = status({ dailyQuotaResetAtUnix: undefined, weeklyQuotaResetAtUnix: undefined })
s.userStatus.planStatus.planInfo = { planName: "Free", billingStrategy: "BILLING_STRATEGY_CREDITS" }
serve(s, () => new Response("no", { status: 503 }))
const u = await (await DevinAuthPlugin()).auth.usage(async () => ({ type: "api", key: "key-free-none" }))
expect(u.error).toBeUndefined()
expect(u.windows).toEqual([])
})