From 6219a7115a0ee51ab3cefc91abe7f791a75ac9cd Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 22 Oct 2026 11:46:14 +0800 Subject: [PATCH] qoder 0.2.27: no Qoder on the machine is an ineligible check-in that says what to do once (#304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a machine that never had Qoder desktop or Qoder CLI, the international daily check-in failed with "device identity runtime not found" and magpie showed "签到失败,magpie 稍后重试", asking again every 30 minutes all day. It can't succeed: Qoder lists the daily CLAIM_BENEFIT only on a request carrying Cosy-MachineToken/Cosy-MachineType, and those come from Qoder's own signed runtime-info helper (#49 showed the list without them has no claim). The plugin never computes or invents that identity, so without the helper there is nothing to send. What changed: - campaignRuntime throws RuntimeMissing when no helper is found anywhere; auth.checkin answers it with outcome "ineligible" (settled for the Beijing day by magpie, asked again the next day) and a message that says to install Qoder desktop, or install Qoder CLI and sign in once, or set QODER_RUNTIME_INFO. "ineligible" is the plugin hook word Trae's 9074 already uses for "check in in the vendor's app"; own-app is not a hook outcome (magpie's provider-plugins.md). - A helper that exists but fails or gives an invalid identity is still "failed" and retried. The fetch path (campaign) keeps its 502, now with the clearer message. Qoder CN is unchanged (it needs no helper). - README: the daily check-in section says the above. What was run (at bb020ce, origin/main fetched just before; no new commits): - HOME= bun test in packages/qoder: 175 pass, 0 fail (15 files). - bun scripts/check.mjs qoder: ok. node --check, git diff --check: ok. - New test "no Qoder on this machine is ineligible…": with main's index.mjs put back by hand it fails (Expected "ineligible", Received "failed"); with this change it passes. The second new test pins that a present-but-unreadable helper stays "failed". Not tried: a real account on a machine without Qoder (this Mac has Qoder.app; the test hides every path through a stat spy instead). Not tried: fetching Qoder's helper the way qodercli caches it into ~/.qoder/.bin, which would let check-in work without the user installing anything; that needs qodercli's download source, not read here. --- packages/qoder/README.md | 13 ++++++++++--- packages/qoder/index.mjs | 19 ++++++++++++++++++- packages/qoder/native-checkin.test.mjs | 26 ++++++++++++++++++++++++++ packages/qoder/package.json | 2 +- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/packages/qoder/README.md b/packages/qoder/README.md index bbb28e2..b19c75b 100644 --- a/packages/qoder/README.md +++ b/packages/qoder/README.md @@ -277,9 +277,16 @@ the account's credentials. - 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. -- A missing helper or invalid identity is an error, rather than a false - "no activity" result. Qoder CN keeps its existing requests and does - not need this local helper. +- With no helper anywhere (a machine that never had Qoder desktop or + Qoder CLI), the check-in is `ineligible` for the day, with a message + saying to install one (or set `QODER_RUNTIME_INFO`); magpie asks again + the next day rather than every 30 minutes (#304). The identity comes + only from Qoder's own helper: the plugin never makes one up, so such an + international account gets no daily claim until Qoder is installed. +- A helper that is there but can't be read, or gives an invalid identity, + is `failed` and asked again later, rather than a false "no activity" + result. Qoder CN keeps its existing requests and does not need this + local helper. - **List:** `GET /sash/api/v1/me/campaigns`: `campaigns[]` with `campaignId`, `actionType`, `claimStatus` (`CLAIMABLE`, `CLAIMED`), diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index 6cf597c..de3a712 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -1408,7 +1408,21 @@ async function campaignRuntime({ home = homedir(), platform = process.platform, 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") + throw new RuntimeMissing() +} + +// RuntimeMissing: no Qoder desktop or CLI on this machine to read the +// device identity from. Qoder offers the daily credits only on a request +// carrying it (without it the list answers 200 with no CLAIM_BENEFIT), and +// the identity is the output of Qoder's own signed helper, which the plugin +// never makes up. Asking again won't change that until the user installs +// Qoder, so the check-in says what to do once instead of "tries again later". +class RuntimeMissing extends Error { + constructor() { + super( + "Qoder check-in: device identity runtime not found. Qoder gives the daily credits only to a device its own app identifies, and this machine has neither Qoder desktop nor Qoder CLI to read that identity from. Install Qoder desktop (or install Qoder CLI and sign in to it once), or set QODER_RUNTIME_INFO to its runtime-info executable; magpie checks in again the next day", + ) + } } // Read the SDK identity as Qoder does: environment 3 is international; on @@ -1851,6 +1865,9 @@ const makePlugin = (site) => async ({ client }) => { } return { outcome: "failed", message: `claim: ${said || "unknown answer"}` } } catch (e) { + // no Qoder on this machine: an answer for the day, not a failure + // magpie would ask again every 30 minutes (plugins#304) + if (e instanceof RuntimeMissing) return { outcome: "ineligible", message: e.message } return { outcome: "failed", message: e?.message ?? String(e), ...(e?.expired ? { signIn: "expired" } : {}) } } } diff --git a/packages/qoder/native-checkin.test.mjs b/packages/qoder/native-checkin.test.mjs index b2f54af..c7684b5 100644 --- a/packages/qoder/native-checkin.test.mjs +++ b/packages/qoder/native-checkin.test.mjs @@ -96,6 +96,32 @@ test("CN claims without the native runtime", async () => { expect(reads).toHaveLength(0) }) +// plugins#304: on a machine that never had Qoder there is no helper to read +// the identity from, and without it Qoder hides the daily credits. That is +// an answer for the day with what to do once, not "tries again later". +test("no Qoder on this machine is ineligible, saying how to get its identity, and asks nothing", async () => { + delete process.env.QODER_RUNTIME_INFO + const nowhere = spyOn(fsPromises, "stat").mockImplementation(() => Promise.reject(Object.assign(new Error("ENOENT"), { code: "ENOENT" }))) + try { + const p = await checkin(QoderAuthPlugin, () => json(LIST)) + expect(p.out.outcome).toBe("ineligible") + expect(p.out.message).toContain("Install Qoder desktop") + expect(p.out.message).toContain("QODER_RUNTIME_INFO") + expect(p.seen).toHaveLength(0) + expect(reads).toHaveLength(0) + } finally { + nowhere.mockRestore() + } +}) + +test("a helper that is there but can't be read is failed, to be asked again", async () => { + nativeError = new Error("fixture helper unavailable") + const p = await checkin(QoderAuthPlugin, () => json(LIST)) + expect(p.out.outcome).toBe("failed") + expect(p.out.message).toContain("could not read device identity") + expect(p.seen).toHaveLength(0) +}) + test("an unreadable list reply is failed", async () => { const p = await checkin(QoderAuthPlugin, () => new Response("")) expect(p.out).toMatchObject({ outcome: "failed" }) diff --git a/packages/qoder/package.json b/packages/qoder/package.json index 8c89638..3042405 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-qoder-auth", - "version": "0.2.26", + "version": "0.2.27", "description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)", "type": "module", "main": "./index.mjs",