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.
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user