From c9a52b3bafd67c5607dad3ffa6ea8723d27f5399 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 24 Oct 2026 17:41:18 +0800 Subject: [PATCH] opendesign 0.1.7: the sign-in names this computer, never "magpie" (#357) The device authorization sent `host: hostname() || "magpie"`. The Open Design CLI, `vela login` (@powerformer/vela-cli 0.1.7, darwin-arm64 binary), sends `{"cliVersion","host","profile":"prod"}` with host from os.Hostname(), and when the name can't be read it stops with "resolve hostname: %w" instead of sending a name of its own. The plugin now does the same: this computer's name, or a sign-in that stops and says why, with nothing sent. Run: - vela 0.1.7 `login` in a sandbox HOME/AMR_HOME with VELA_API_URL at a local recorder: body {"cliVersion":"0.1.7","host":"yetone-mac-mini.local", "profile":"prod"} - bun test (packages/opendesign): 24 pass, 0 fail - bun scripts/check.mjs: ok - no-magpie.test.mjs against HEAD's index.mjs: 2 of 2 red Not changed: cliVersion stays "0.1.4" and the User-Agent stays the package's own name; neither names magpie. Not tried: a live sign-in. There is no Open Design account to approve it. --- packages/opendesign/index.mjs | 12 ++++++--- packages/opendesign/no-magpie.test.mjs | 36 ++++++++++++++++++++++++++ packages/opendesign/package.json | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 packages/opendesign/no-magpie.test.mjs diff --git a/packages/opendesign/index.mjs b/packages/opendesign/index.mjs index 8063a0b..23bb1e1 100644 --- a/packages/opendesign/index.mjs +++ b/packages/opendesign/index.mjs @@ -121,10 +121,16 @@ async function api(base, path, { key, body, method = "GET", signal } = {}) { // startDevice opens a device authorization: a code, the page that approves // it, and the secret the approval is polled with. -async function startDevice({ signal } = {}) { +// host is this computer's name, as `vela login` sends it (os.Hostname()); +// when it can't be read the CLI stops with "resolve hostname", and so does +// this, rather than send a name of its own. +async function startDevice({ signal, host = hostname } = {}) { + let name = "" + try { name = String(host() ?? "").trim() } catch {} + if (!name) throw new Error("Open Design sign-in: this computer's name couldn't be read, and the sign-in sends it") const r = await api(CONTROL, "/api/v1/cli/device-authorizations", { method: "POST", - body: { cliVersion: CLI_VERSION, host: hostname() || "magpie", profile: "prod" }, + body: { cliVersion: CLI_VERSION, host: name, profile: "prod" }, signal, }) const d = r.body @@ -499,4 +505,4 @@ export const OpenDesignAuthPlugin = async () => { // _internal is what the tests read through; magpie calls every exported // function as a plugin, so only the plugin itself is exported bare. -export const _internal = { authOf, allowances, controlKeyOf, credits, modelsOf, money, runtimeKeyOf, said, thePlan, usedPercent, waitForDevice, windowName, when, workspaceOf } +export const _internal = { authOf, allowances, controlKeyOf, credits, modelsOf, money, runtimeKeyOf, said, startDevice, thePlan, usedPercent, waitForDevice, windowName, when, workspaceOf } diff --git a/packages/opendesign/no-magpie.test.mjs b/packages/opendesign/no-magpie.test.mjs new file mode 100644 index 0000000..1d36bbd --- /dev/null +++ b/packages/opendesign/no-magpie.test.mjs @@ -0,0 +1,36 @@ +// The device authorization names this computer, never magpie (#357): +// `vela login` 0.1.7 sends {cliVersion, host: os.Hostname(), profile} and +// stops when the name can't be read, so the plugin does the same. +import { test, expect, afterEach } from "bun:test" +import { hostname } from "node:os" +import { _internal as I } from "./index.mjs" + +const realFetch = globalThis.fetch +afterEach(() => { globalThis.fetch = realFetch }) + +function record() { + const sent = [] + globalThis.fetch = async (input, init) => { + const headers = [...new Headers(init?.headers)].map(([k, v]) => `${k}: ${v}`).join("\n") + sent.push({ text: `${input}\n${headers}\n${String(init?.body ?? "")}`, body: JSON.parse(String(init?.body ?? "{}")) }) + return Response.json({ deviceId: "d1", deviceSecret: "s1", userCode: "ABC123", activationUrl: "https://open-design.ai/cloud/cli/activate?deviceId=d1", pollIntervalSeconds: 2 }, { status: 201 }) + } + return sent +} + +test("the device authorization sends this computer's name and nothing naming magpie", async () => { + expect(I.startDevice).toBeFunction() + const sent = record() + await I.startDevice() + expect(sent.length).toBe(1) + expect(sent[0].body.host).toBe(hostname()) + expect(sent[0].text.toLowerCase()).not.toContain("magpie") +}) + +test("a computer whose name can't be read stops, as the CLI does, and sends nothing", async () => { + for (const host of [() => "", () => { throw new Error("no name") }]) { + const sent = record() + await expect(I.startDevice({ host })).rejects.toThrow("computer's name") + expect(sent.length).toBe(0) + } +}) diff --git a/packages/opendesign/package.json b/packages/opendesign/package.json index e520900..a4e66ad 100644 --- a/packages/opendesign/package.json +++ b/packages/opendesign/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-opendesign-auth", - "version": "0.1.6", + "version": "0.1.7", "description": "Open Design Cloud (Design Plan) in OpenCode and magpie: the account's device sign-in, its models, and the plan's 5-hour and 7-day allowance", "type": "module", "main": "./index.mjs",