diff --git a/packages/qoder/README.md b/packages/qoder/README.md index 25698af..49291da 100644 --- a/packages/qoder/README.md +++ b/packages/qoder/README.md @@ -296,6 +296,13 @@ the account's credentials. - 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. +- With the identity read and sent, a list with no daily claim is + `inactive`, with a message (since 0.2.32) saying Qoder offered this + device's identity no daily credits campaign, that Qoder decides that per + device, and that the credits can be claimed in Qoder desktop when it + shows them (#304: a Linux CLI identity was offered none while the same + account's desktop identity was). The plugin never sends another + device's identity. Qoder CN (since 0.2.30) sends its own device identity the same way when Qoder CN is installed: its desktop 0.4.9 and CLI (`qoderclicn`) both ask diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index e81e69d..396e650 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -1655,6 +1655,12 @@ class RuntimeMissing extends Error { } } +// noCampaign is why a check-in asked with this machine's own device +// identity found nothing to claim: all the list says is that it offered +// that identity no daily credits, not why. +const noCampaign = (name) => + `${name} check-in: ${name} offered this device's identity, read from this machine's own ${name} runtime-info, no daily credits campaign right now. ${name} decides per device whether to offer it; if ${name} desktop shows today's credits, claim them there` + // Read the SDK identity as Qoder does: environment 3 is international, 0 // Qoder CN; on Windows and macOS the uid goes over stdin, never into the // command line. @@ -2094,7 +2100,11 @@ const makePlugin = (site) => async ({ client }) => { // (no Qoder CN on this machine) or ask again (it didn't answer). if (unread instanceof RuntimeMissing) return { outcome: "ineligible", message: unread.message } if (unread) return { outcome: "failed", message: unread.message } - return { outcome: "inactive" } + // Asked with this machine's own identity and still offered nothing: + // Qoder decides per device (plugins#304, a Linux CLI identity was + // offered none while the same account's desktop identity was), so + // say that much, and where the credits can still be claimed. + return { outcome: "inactive", message: noCampaign(site.name) } } const claimRes = await call(base.replace(/\/$/, "") + "/" + encodeURIComponent(campaign.campaignId) + "/claim", "POST", "{}") let claim = {} diff --git a/packages/qoder/native-checkin.test.mjs b/packages/qoder/native-checkin.test.mjs index cd017f5..ed6c572 100644 --- a/packages/qoder/native-checkin.test.mjs +++ b/packages/qoder/native-checkin.test.mjs @@ -80,9 +80,26 @@ test("an already-claimed campaign is done without another claim", async () => { expect(p.seen.map((x) => x.path)).toEqual(["/sash/api/v1/me/campaigns"]) }) -test("no benefit campaign is inactive", async () => { +// plugins#304 (ReneXiong): the identity was read and sent, and the list +// still had no CLAIM_BENEFIT. Qoder decides that per device, so the answer +// says it was this device's identity that was offered nothing, and that +// Qoder desktop can still claim it, instead of a bare "inactive". +test("no benefit campaign is inactive, saying this device's identity was offered none", async () => { const p = await checkin(QoderAuthPlugin, () => json({ campaigns: [{ campaignId: "x", actionType: "VIEW_DETAILS", claimStatus: "CLAIMABLE" }] })) - expect(p.out).toEqual({ outcome: "inactive" }) + expect(p.out.outcome).toBe("inactive") + expect(p.out.message).toContain("Qoder offered this device's identity") + expect(p.out.message).toContain("no daily credits campaign") + expect(p.out.message).toContain("claim them there") + expect(p.out.message).toContain("Qoder desktop") + expect(reads).toHaveLength(1) +}) + +test("CN offered nothing with Qoder CN's own identity is inactive, naming Qoder CN", async () => { + const p = await checkin(QoderCNAuthPlugin, () => json({ campaigns: [] }), "https://openapi.qoder.com.cn") + expect(p.out.outcome).toBe("inactive") + expect(p.out.message).toContain("Qoder CN offered this device's identity") + expect(p.out.message).toContain("Qoder CN desktop") + expect(reads).toHaveLength(1) }) test("a claim answer with nested data is read", async () => { diff --git a/packages/qoder/package.json b/packages/qoder/package.json index 8f10661..be7a5c4 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-qoder-auth", - "version": "0.2.31", + "version": "0.2.32", "description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)", "type": "module", "main": "./index.mjs",