zcode 0.1.6: ZCode's config out of reach, the plugin's table stands in marked Symbol.for("magpie.fellBack"), and magpie keeps the list it was told last, as the built-in keeps the one it fetched last. models.test.mjs (passes on Linux with no ZCode installed; with ZCode.app on macOS its own config is read, unmarked).

This commit is contained in:
yetone
2026-10-01 17:06:07 +08:00
parent ea1ab932ef
commit 7b70b40c7b
3 changed files with 40 additions and 3 deletions
+7 -2
View File
@@ -1048,9 +1048,14 @@ export async function ZCodeAuthPlugin({ client }) {
const start = await onStart(s).catch(() => false)
const base = start ? START_BASE : s.base
let ms = modelsOf(await zcodeConfig().catch(() => null), planID(base))
if (!ms.length) ms = start ? START_MODELS : MODELS
// ZCode's config can't be had: its table stands in, and magpie keeps
// the list it was told last, as the built-in keeps the one it fetched last
const fell = !ms.length
if (fell) ms = start ? START_MODELS : MODELS
const url = s.base + "/v1"
return Object.fromEntries(ms.map((m) => [m.id, model(m, url)]))
const out = Object.fromEntries(ms.map((m) => [m.id, model(m, url)]))
if (fell) out[Symbol.for("magpie.fellBack")] = true
return out
},
},
auth: {
+32
View File
@@ -0,0 +1,32 @@
// Run with HOME=$(mktemp -d) bun test: a plan's models when ZCode's config
// can't be had stand in from the plugin's table, said to be a fallback,
// so magpie keeps the list it was told last, as the built-in keeps the one
// it fetched last.
import { test, expect, beforeAll, afterAll } from "bun:test"
import { homedir, tmpdir } from "node:os"
import { existsSync, realpathSync } from "node:fs"
let ZCodeAuthPlugin
const fetched = globalThis.fetch
beforeAll(async () => {
if (![tmpdir(), realpathSync(tmpdir())].some((t) => homedir().startsWith(t))) throw new Error("run with HOME=$(mktemp -d) bun test")
;({ ZCodeAuthPlugin } = await import("./index.mjs"))
})
afterAll(() => {
globalThis.fetch = fetched
})
// an installed ZCode (macOS) has a config of its own, which is no fallback
const app = process.platform === "darwin" && existsSync("/Applications/ZCode.app/Contents/Resources/config/provider/zcode-builtin.json")
test("ZCode's config out of reach, the table stands in, said to be a fallback", async () => {
globalThis.fetch = async () => {
throw new Error("connection refused")
}
const hooks = await ZCodeAuthPlugin({ client: {} })
const ms = await hooks.provider.models({ models: {} }, { auth: { type: "api", key: "k" } })
expect(Object.keys(ms).length).toBeGreaterThan(0)
expect(ms[Symbol.for("magpie.fellBack")]).toBe(app ? undefined : true)
// OpenCode, reading the list, sees only the models
expect(Object.keys(ms).every((k) => ms[k].id === k)).toBe(true)
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zcode-auth",
"version": "0.1.5",
"version": "0.1.6",
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan",
"type": "module",
"main": "./index.mjs",