sensenova: a key-only account lists what its key serves (#1158)

A key-only sign-in keeps no console token, so planIds() could never read
the plan, the listing threw "plan read failed" and fell back to the static
bootstrap list, which has no glm-5.3. models() now skips the plan read for
auth.type "api" and lists the key's own /models (still through
catalogModels, so the 403 stray and image-output models stay out). OAuth
and password accounts still intersect the catalogue with the plan.

glm-5.3 is not added to the bootstrap list: testdata.test.mjs holds that
list to the recorded free plan, which doesn't cover glm-5.3.

Run (mica, temp HOME): bun test in packages/sensenova, 59 pass;
bun scripts/check.mjs sensenova ok.
Broken by hand: with the old `await coveredOrThrow()` the new test fails
(plan read attempted, glm-5.3 missing).
Not tried: a real SenseNova key-only account.
This commit is contained in:
yetone
2026-11-15 01:22:56 +08:00
parent 1cc5a033f8
commit 122d945ea7
3 changed files with 40 additions and 6 deletions
+33 -1
View File
@@ -240,4 +240,36 @@ test("create_key defaults on outside magpie, where the host has no option", () =
expect(optionEnabled({ option: () => true }, {}, "create_key", true)).toBe(true)
// pruning stays opt-in in both hosts
expect(optionEnabled(undefined, {}, "prune_old_keys", false)).toBe(false)
})
})
test("a key-only account lists what its key serves, with no plan read (plugins#1158)", async () => {
// a key-only sign-in keeps no console token, so the pools can't be read;
// the key's own /models is the only live word on what it can call, and the
// static fallback (a free plan's models, no glm-5.3) must not stand in for it
f = fakeSenseNova()
const listed = {
data: [
{ id: "glm-5.3", name: "glm-5.3", context_length: 1048576, max_output_length: 131072, input_modalities: ["text"], output_modalities: ["text"], supported_features: ["tools", "reasoning"] },
...CATALOGUE.data,
],
}
let poolReads = 0
f.route("GET /lite/console/v1/tokenplan/pool-usage", () => {
poolReads++
return json({ error: "no" }, 401)
})
f.route("GET /models", (r) => {
expect(r.headers.get("authorization")).toBe("Bearer sk-test")
return json(listed)
})
const p = await plugin()
const keyOnly = { type: "api", key: "sk-test" }
const models = await p.provider.models({ id: "sensenova-token-plan", models: { "glm-5.2": {} } }, { auth: keyOnly })
expect(Object.keys(models)).toContain("glm-5.3")
expect(models["glm-5.3"].limit).toEqual({ context: 1048576, output: 131072 })
// the image-output model still draws, key-only or not
expect(Object.keys(models)).not.toContain("sensenova-u1.5-lite")
// the model every key 403s stays out too
expect(Object.keys(models)).not.toContain("deepseek-v4.1-flash")
expect(poolReads).toBe(0)
})
+6 -4
View File
@@ -276,9 +276,11 @@ export async function SenseNovaAuthPlugin({ client, magpie } = {}, options = {})
};
try {
// The plan is asked before the catalogue: coverage that names no
// models ends here, and /models is never called.
const covered = await coveredOrThrow();
if (!covered.size) return {};
// models ends here, and /models is never called. A key-only account
// has no console token to read the plan with, so what its key lists
// is all there is to go on (plugins#1158).
const covered = auth.type === "api" ? null : await coveredOrThrow();
if (covered && !covered.size) return {};
// the listing reads the catalogue raw: the live row is the authority
// for what a model takes (curated knowledge stays in the bootstrap
// config, where nothing live has answered yet)
@@ -298,7 +300,7 @@ export async function SenseNovaAuthPlugin({ client, magpie } = {}, options = {})
{ images: hostIsMagpie },
);
if (!live.length) return fellBack(declared);
const filtered = filterByPlan(live, covered);
const filtered = covered ? filterByPlan(live, covered) : live;
if (!filtered.length) return {};
return Object.fromEntries(
filtered.map((m) => [
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-sensenova-auth",
"version": "0.2.3",
"version": "0.2.4",
"description": "SenseNova (SenseTime 日日新) Token Plan in OpenCode and magpie: browser or password sign-in for the credit pools, windows and grants, plus the plan's models through a Token Plan API key",
"type": "module",
"main": "./opencode.mjs",