From 5e80f39d3f17a3f55b4b76d7a0bf3e6dbe61dce7 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 8 Oct 2026 20:35:44 +0800 Subject: [PATCH] qoder 0.2.10: international check-in finds Qoder's device identity runtime where Qoder CLI and the Linux desktop really keep it (ARNO on Discord: "device identity runtime not found") 0.2.9 (#49) looked for the CLI's cached runtime in ~/.qoder/.bin/umid---*/ on every platform. qodercli 1.1.66 (npm) and the worker in Qoder desktop 0.4.3 (extractBinary) make that folder only on Windows (umid-win32--\runtime-info.exe with sgsdk.dll); on macOS and Linux they write a file, ~/.qoder/.bin/runtime-info---. And the Linux desktop installs to /opt/Qoder/resources/umid/runtime-info (Qoder 0.4.3's .deb and .rpm), which wasn't looked at. So a macOS user with only the CLI, and every Linux user, got HTTP 502 on the international check-in, while Qoder CN (which needs no runtime) checked in. campaignRuntime now looks at /opt/Qoder on Linux, reads the CLI's cache as the CLI writes it (the newest matching file, a .tmp being written skipped), and follows the CLI's own folder settings (QODER_CONFIG_DIR, QODER_CLI_HOME, QODER_CONFIG_DIR_NAME). Windows and macOS desktop lookup is unchanged. checkin.test.mjs lays out the CLI cache as qodercli writes it on win32/x64, darwin arm64/x64 and linux x64/arm64, plus /opt/Qoder and the config-folder variables: 6 of the new tests fail on 0.2.9 (the Windows case passes on both, as 0.2.9 had it right), all pass now. bun test packages/qoder (87 pass) and scripts/check.mjs qoder under a temp HOME pass. On this Mac the real lookup returns /Applications/Qoder.app/Contents/Resources/umid/runtime-info. Not run: the runtime itself against a real account, or on Linux/Windows. --- packages/qoder/README.md | 11 +++-- packages/qoder/checkin.test.mjs | 84 ++++++++++++++++++++++++--------- packages/qoder/index.mjs | 38 +++++++++++---- packages/qoder/package.json | 2 +- 4 files changed, 102 insertions(+), 33 deletions(-) diff --git a/packages/qoder/README.md b/packages/qoder/README.md index 51dbf4e..0931c4c 100644 --- a/packages/qoder/README.md +++ b/packages/qoder/README.md @@ -200,9 +200,14 @@ in-flight read and caching it in memory for an hour. The same identity goes on the list, the claim and a device-token retry; it is not saved in the account's credentials. -- Install Qoder desktop or run Qoder CLI to make its native runtime - available. The plugin finds the desktop's standard Windows/macOS - location or the CLI's matching `~/.qoder/.bin/umid-*` cache. +- Install Qoder desktop, or sign in to Qoder CLI once, to make its native + runtime available. The plugin finds the desktop's `resources/umid` + (`Qoder.app` on macOS, `%LOCALAPPDATA%\Programs\Qoder` on Windows, + `/opt/Qoder` on Linux) or the runtime the CLI caches in `~/.qoder/.bin` + (`runtime-info---*` on macOS and Linux, + `umid-win32-x64-*\runtime-info.exe` on Windows; `QODER_CONFIG_DIR`, + `QODER_CLI_HOME` and `QODER_CONFIG_DIR_NAME` move it as they move the + CLI's folder). - For another installation location, set `QODER_RUNTIME_INFO` to the absolute path of Qoder's installed `runtime-info` executable (`runtime-info.exe` on Windows), with its accompanying SDK files. diff --git a/packages/qoder/checkin.test.mjs b/packages/qoder/checkin.test.mjs index f719d13..74ecf67 100644 --- a/packages/qoder/checkin.test.mjs +++ b/packages/qoder/checkin.test.mjs @@ -129,32 +129,74 @@ test("Windows finds the Qoder desktop's installed runtime", async () => { expect(await _internal.campaignRuntime({ home: sandbox, platform: "win32", arch: "x64", env: { LOCALAPPDATA: sandbox } })).toBe(file) }) -for (const [platform, arch] of [["win32", "x64"], ["darwin", "arm64"], ["linux", "x64"]]) { - test(`${platform}/${arch}: finds the newest matching CLI runtime`, async () => { - const cache = join(sandbox, ".qoder", ".bin") - const name = platform === "win32" ? "runtime-info.exe" : "runtime-info" - const old = join(cache, `umid-${platform}-${arch}-ffff`) - const newest = join(cache, `umid-${platform}-${arch}-aaaa`) - const other = join(cache, `umid-${platform}-other-ffff`) - for (const dir of [old, newest, other]) { +// Keep desktop discovery inside the fixture, even on a Mac with Qoder installed. +async function inSandbox(run) { + const inspect = spyOn(fsPromises, "stat").mockImplementation((path, ...args) => { + if (!String(path).startsWith(sandbox + sep)) return Promise.reject(new Error("outside fixture")) + return realStat(path, ...args) + }) + try { + return await run() + } finally { + inspect.mockRestore() + } +} + +// cliCache lays out Qoder CLI's .bin as qodercli 1.1.66 writes it +// (extractBinary): a folder umid-win32-- holding runtime-info.exe +// and sgsdk.dll on Windows; a file runtime-info--- +// elsewhere, beside its .tmp while it is being written. It returns the +// newest matching runtime. +function cliCache(config, platform, arch) { + const cache = join(config, ".bin") + mkdirSync(cache, { recursive: true }) + const make = (hash, a, time) => { + let file + if (platform === "win32") { + const dir = join(cache, `umid-win32-${a}-${hash}`) mkdirSync(dir, { recursive: true }) - writeFileSync(join(dir, name), "fixture") - } - utimesSync(old, new Date(1000), new Date(1000)) - utimesSync(newest, new Date(2000), new Date(2000)) - // Keep desktop discovery inside this fixture, even on a Mac with Qoder installed. - const inspect = spyOn(fsPromises, "stat").mockImplementation((path, ...args) => { - if (!String(path).startsWith(sandbox + sep)) return Promise.reject(new Error("outside fixture")) - return realStat(path, ...args) - }) - try { - expect(await _internal.campaignRuntime({ home: sandbox, platform, arch, env: {} })).toBe(join(newest, name)) - } finally { - inspect.mockRestore() + writeFileSync(join(dir, "sgsdk.dll"), "fixture") + file = join(dir, "runtime-info.exe") + } else { + file = join(cache, `runtime-info-${platform}-${a}-${hash}`) } + writeFileSync(file, "fixture") + utimesSync(file, new Date(time), new Date(time)) + return file + } + make("ffffffffffffffff", arch, 1000) + make("eeeeeeeeeeeeeeee", "other", 3000) + const newest = make("aaaaaaaaaaaaaaaa", arch, 2000) + if (platform !== "win32") writeFileSync(join(cache, `runtime-info-${platform}-${arch}-bbbbbbbbbbbbbbbb.0a1b2c3d.tmp`), "partial") + return newest +} + +for (const [platform, arch] of [["win32", "x64"], ["darwin", "arm64"], ["darwin", "x64"], ["linux", "x64"], ["linux", "arm64"]]) { + test(`${platform}/${arch}: finds the newest runtime Qoder CLI cached`, async () => { + const newest = cliCache(join(sandbox, ".qoder"), platform, arch) + expect(await inSandbox(() => _internal.campaignRuntime({ home: sandbox, platform, arch, env: {}, opt: join(sandbox, "opt") }))).toBe(newest) }) } +test("finds the runtime under Qoder CLI's own config folder", async () => { + const dir = cliCache(join(sandbox, "custom"), "linux", "x64") + const named = cliCache(join(sandbox, "clihome", ".qoder-work"), "linux", "x64") + const run = (env) => inSandbox(() => _internal.campaignRuntime({ home: join(sandbox, "nobody"), platform: "linux", arch: "x64", env, opt: join(sandbox, "opt") })) + expect(await run({ QODER_CONFIG_DIR: join(sandbox, "custom") })).toBe(dir) + expect(await run({ QODER_CLI_HOME: join(sandbox, "clihome"), QODER_CONFIG_DIR_NAME: ".qoder-work" })).toBe(named) +}) + +test("Linux finds the Qoder desktop's /opt/Qoder runtime", async () => { + const file = join(sandbox, "opt", "Qoder", "resources", "umid", "runtime-info") + mkdirSync(dirname(file), { recursive: true }) + writeFileSync(file, "fixture") + expect(await inSandbox(() => _internal.campaignRuntime({ home: sandbox, platform: "linux", arch: "x64", env: {}, opt: join(sandbox, "opt") }))).toBe(file) +}) + +test("no runtime anywhere says how to get one", async () => { + await expect(inSandbox(() => _internal.campaignRuntime({ home: sandbox, platform: "linux", arch: "x64", env: {}, opt: join(sandbox, "opt") }))).rejects.toThrow("device identity runtime not found") +}) + test("unavailable native identity fails the request and can be retried", async () => { nativeError = new Error("fixture helper unavailable") const p = await loader(QoderAuthPlugin, () => json(LIST)) diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index 1d51ecd..e4d48a8 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -1037,23 +1037,45 @@ const CAMPAIGN_MACHINE_TTL = 60 * 60 * 1000 // Qoder's desktop client renews its // campaignRuntime uses Qoder's own native device identity helper, installed // by its desktop client or cached by its CLI. A made-up token (including the // chat envelope's machine id and type 5) doesn't reveal international claims. -async function campaignRuntime({ home = homedir(), platform = process.platform, arch = process.arch, env = process.env } = {}) { +// +// Where each one keeps it (Qoder desktop 0.4.3's packages, qodercli 1.1.66): +// - desktop: /resources/umid/runtime-info(.exe): Qoder.app on +// macOS, %LOCALAPPDATA%\Programs\Qoder (the user installer) on Windows, +// /opt/Qoder (the .deb and the .rpm) on Linux; +// - CLI: /.bin, where is QODER_CONFIG_DIR, else +// QODER_CLI_HOME (or the home folder) joined with QODER_CONFIG_DIR_NAME +// (or .qoder): a file runtime-info--- on macOS and +// Linux, a folder umid-win32-- holding runtime-info.exe on +// Windows. +async function campaignRuntime({ home = homedir(), platform = process.platform, arch = process.arch, env = process.env, opt = "/opt" } = {}) { if (env.QODER_RUNTIME_INFO) return resolve(env.QODER_RUNTIME_INFO) const name = platform === "win32" ? "runtime-info.exe" : "runtime-info" + const isFile = async (path) => (await stat(path).catch(() => null))?.isFile() ?? false const paths = [] if (platform === "win32") { const local = env.LOCALAPPDATA || join(home, "AppData", "Local") paths.push(join(local, "Programs", "Qoder", "resources", "umid", name)) } else if (platform === "darwin") { for (const dir of ["/Applications", join(home, "Applications")]) paths.push(join(dir, "Qoder.app", "Contents", "Resources", "umid", name)) + } else if (platform === "linux") { + paths.push(join(opt, "Qoder", "resources", "umid", name)) } - for (const path of paths) if ((await stat(path).catch(() => null))?.isFile()) return path - const cache = join(home, ".qoder", ".bin") - const dirs = (await readdir(cache, { withFileTypes: true }).catch(() => [])) - .filter((d) => d.isDirectory() && d.name.startsWith(`umid-${platform}-${arch}-`)) - const cached = await Promise.all(dirs.map(async (d) => ({ path: join(cache, d.name, name), time: (await stat(join(cache, d.name))).mtimeMs }))) - for (const { path } of cached.sort((a, b) => b.time - a.time)) if ((await stat(path).catch(() => null))?.isFile()) return path - throw new Error("Qoder check-in: device identity runtime not found; install Qoder desktop or run Qoder CLI, or set QODER_RUNTIME_INFO to its runtime-info executable") + for (const path of paths) if (await isFile(path)) return path + const config = env.QODER_CONFIG_DIR || join(env.QODER_CLI_HOME || env.GEMINI_CLI_HOME || home, env.QODER_CONFIG_DIR_NAME || ".qoder") + const cache = join(config, ".bin") + const entries = await readdir(cache, { withFileTypes: true }).catch(() => []) + const found = [] + for (const d of entries) { + let path + if (platform === "win32") { + if (d.isDirectory() && d.name.startsWith(`umid-win32-${arch}-`)) path = join(cache, d.name, name) + } else if (d.isFile() && d.name.startsWith(`runtime-info-${platform}-${arch}-`) && !d.name.endsWith(".tmp")) { + path = join(cache, d.name) + } + if (path && (await isFile(path))) found.push({ path, time: (await stat(path)).mtimeMs }) + } + if (found.length) return found.sort((a, b) => b.time - a.time)[0].path + throw new Error("Qoder check-in: device identity runtime not found; install Qoder desktop or sign in to Qoder CLI once, or set QODER_RUNTIME_INFO to its runtime-info executable") } // Read the SDK identity as Qoder does: environment 3 is international; on diff --git a/packages/qoder/package.json b/packages/qoder/package.json index f57eadc..22bff7d 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-qoder-auth", - "version": "0.2.9", + "version": "0.2.10", "description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)", "type": "module", "main": "./index.mjs",