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",