Files
yetone c9a52b3baf 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.
2026-10-24 17:41:18 +08:00

37 lines
1.6 KiB
JavaScript

// 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)
}
})