Adds @magpie-community/agent-deepzora: Deepzora on magpie's Agents page, through a reversible bridge that adds a magpie-agent provider to ~/.deepzora/config.toml and the key to ~/.deepzora/.env, and puts both back on disconnect. The package is reasonix-desktop's bridge with Deepzora's names; vendor.mjs is byte for byte the merged reasonix-desktop copy (sha256 46e08060…). Run at the reviewed head 858f09aa, on a separate test Mac, Bun 1.4.2 and Node 22.22.0, temp HOME: - bun test packages/deepzora: 12 pass; node --test: 12 pass - bun scripts/check.mjs: ok; npm pack --dry-run: 13 files, 57.0 kB - a probe over the bridge in temp dirs (corrupt and half-written TOML, user edits across a switch and a disconnect, pre-existing keys in four forms, CRLF, read-only dir, 0-byte config): each as expected - full root bun test at 858f09aa: 8482 pass, 20 skip, 0 fail Broken by hand: 17 breaks, 13 red. Four stay green (an edited credential on switch, a half-written control file read as disconnect, no provider_access cleanup, no lock), the same gaps reasonix-desktop's tests have; listed in the review. Not tried: a real Deepzora binary or session, acceptance.mjs and resident-acceptance.mjs, Windows (Deepzora uses %APPDATA%\deepzora there; the descriptor has no per-OS paths), a Deepzora Desktop settings save while connected. The first npm publish of @magpie-community/agent-deepzora is the maintainer's. Co-authored-by: SivanCola <SivanCola@users.noreply.github.com>
68 lines
3.5 KiB
JavaScript
68 lines
3.5 KiB
JavaScript
// Exercise normal plugin disable in a real resident Magpie host. No accounts,
|
|
// real agent configuration, or inference requests are used.
|
|
import assert from "node:assert/strict"
|
|
import fs from "node:fs"
|
|
import os from "node:os"
|
|
import path from "node:path"
|
|
import net from "node:net"
|
|
import { spawn, execFile } from "node:child_process"
|
|
import { promisify } from "node:util"
|
|
import { fileURLToPath } from "node:url"
|
|
import { parseTOML } from "./vendor.mjs"
|
|
|
|
const exec = promisify(execFile)
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "deepzora-resident-"))
|
|
const repo = path.resolve(fileURLToPath(new URL(".", import.meta.url)))
|
|
const magpie = process.env.MAGPIE_BIN || "magpie"
|
|
const probe = net.createServer()
|
|
await new Promise(resolve => probe.listen(0, "127.0.0.1", resolve))
|
|
const port = probe.address().port
|
|
await new Promise(resolve => probe.close(resolve))
|
|
const addr = `127.0.0.1:${port}`
|
|
const env = { ...process.env, HOME: root, USERPROFILE: root, XDG_CONFIG_HOME: path.join(root, ".config"), XDG_CACHE_HOME: path.join(root, ".cache"), XDG_STATE_HOME: path.join(root, ".state"), DEEPZORA_HOME: path.join(root, ".deepzora"), DEEPZORA_STATE_HOME: path.join(root, ".deepzora-state"), MAGPIE_NO_ACCOUNTS: "1", MAGPIE_ADDR: addr }
|
|
const dir = env.DEEPZORA_HOME
|
|
const config = path.join(dir, "config.toml")
|
|
const credentials = path.join(dir, ".env")
|
|
const original = '# resident fixture\ndefault_model = "mine/model"\n'
|
|
const run = args => exec(magpie, args, { cwd: root, env, timeout: 120000, maxBuffer: 2 << 20 })
|
|
const until = async predicate => {
|
|
const deadline = Date.now() + 20000
|
|
while (Date.now() < deadline) {
|
|
if (await predicate()) return
|
|
await new Promise(resolve => setTimeout(resolve, 100))
|
|
}
|
|
throw new Error("Resident Magpie did not complete the expected state transition")
|
|
}
|
|
let child
|
|
let closed
|
|
try {
|
|
fs.mkdirSync(dir, { recursive: true })
|
|
fs.mkdirSync(path.join(env.XDG_CONFIG_HOME, "magpie"), { recursive: true })
|
|
fs.writeFileSync(config, original)
|
|
fs.writeFileSync(credentials, "OTHER_KEY=fixture-original\n")
|
|
fs.writeFileSync(path.join(env.XDG_CONFIG_HOME, "magpie/providers.json"), JSON.stringify({ providers: [{ id: "fixture", name: "Fixture", key: "fixture-only", chat: "http://127.0.0.1:9/v1", models: ["model"] }] }))
|
|
await run(["plugin", "add", repo])
|
|
await run(["deepzora", "fixture/model"])
|
|
child = spawn(magpie, ["serve"], { cwd: root, env, stdio: "ignore" })
|
|
closed = new Promise(resolve => child.once("exit", resolve))
|
|
await until(async () => {
|
|
try { return (await fetch(`http://${addr}/api/hello`, { signal: AbortSignal.timeout(500) })).ok } catch { return false }
|
|
})
|
|
await fetch(`http://${addr}/v1/models`, { signal: AbortSignal.timeout(10000) })
|
|
await until(() => parseTOML(fs.readFileSync(config, "utf8")).default_model === "magpie-agent/fixture/model")
|
|
await run(["plugin", "off", repo])
|
|
// Refreshing the catalog observes plugins.json and closes the old host.
|
|
await fetch(`http://${addr}/v1/models`, { signal: AbortSignal.timeout(10000) })
|
|
await until(() => fs.readFileSync(config, "utf8") === original)
|
|
assert.equal(fs.readFileSync(credentials, "utf8"), "OTHER_KEY=fixture-original\n")
|
|
console.log("PASS: disabling the plugin with resident Magpie restores TOML and credentials without a manual sync")
|
|
} finally {
|
|
if (child && child.exitCode === null) {
|
|
child.kill("SIGTERM")
|
|
const timer = setTimeout(() => child.kill("SIGKILL"), 3000)
|
|
await closed
|
|
clearTimeout(timer)
|
|
}
|
|
fs.rmSync(root, { recursive: true, force: true })
|
|
}
|