qoder 0.2.43: the check-in says when to ask again, as the 10:00 (UTC+8) campaign opens

sdytman on Discord: Qoder's daily credits start at 10:00, can the plugin's
check-in follow it? Qoder's /me/campaigns lists each day's CLAIM_BENEFIT
campaign with startAt 10:00 and endAt 09:59 the next day, both UTC+8
("Daily reset: 10:00 (UTC+8)"), read with a real account at 09:27 CST on
10-28. Qoder.app 0.4.3 polls that list every 5 minutes and treats
startAt <= now < endAt as active; there is no next-time field. A check-in
before 10:00 met yesterday's campaign, and magpie settled for the Beijing
day, so today's campaign waited until tomorrow, or was lost.

checkin now returns until: the next campaign's opening (the later of
endAt and startAt + 1 day, or the next startAt in the gap) plus a minute,
on done, claimed and "not offered yet". All in epoch time, so the
machine's zone doesn't matter; qoder and qoder-cn share the code. magpie
asks again at until once it reads it (yetone/magpie, next release).

Run (mote): checkin-window, native-checkin and checkin tests under
TZ=UTC, Etc/GMT+8 and Asia/Shanghai, 66 pass each; HOME=$(mktemp -d)
bun test, 2938 pass 0 fail 8 skip; bun scripts/check.mjs. A real qoder
account at 09:35 CST: claimed 100, until 2026-10-28T02:01:00Z.
Broken by hand: nextOpens returning endAt only, 11 of 13 checkin-window
tests red; askAgain returning {}, 12 of 13 red.
Not tried: a real Qoder CN account (none here); the server's list in the
09:59-10:00 gap.
This commit is contained in:
yetone
2026-10-28 09:37:56 +08:00
parent ae48bf07f3
commit fd40b20c3b
7 changed files with 252 additions and 9 deletions
+3 -1
View File
@@ -215,10 +215,12 @@ Each package is a folder under `packages/<name>/`:
`checkin(getAuth, provider)`. magpie calls it once a day for each
signed-in account while the user has it on (Settings → Usage →
Plugins), and shows what came of it on the account's Usage card. It
returns `{ outcome, credit?, streak?, message? }`, `outcome` being
returns `{ outcome, credit?, streak?, message?, until? }`, `outcome` being
`claimed` (checked in now), `done` (already today), `ineligible`,
`inactive` (no check-in event now), `captcha` or `failed`; a throw is
`failed` with its message, and only `failed` is tried again that day.
`until` (RFC 3339) is when the vendor's own day turns, if not at
Beijing midnight: magpie asks again then (Qoder's opens at 10:00 UTC+8).
Never solve a captcha: return `captcha` and the user checks in in the
vendor's app. Needs magpie with the hook (after v0.1.1083);
[the contract](https://github.com/yetone/magpie/blob/main/docs/subsystems/provider-plugins.md#a-plugins-daily-check-in).
+13
View File
@@ -390,6 +390,19 @@ Qoder CN's `runtime-info` for environment `0` (the international one is
- `<openapi>` is `openapi.qoder.sh` (Qoder) or `openapi.qoder.com.cn`
(Qoder CN). Other pages on those hosts are still refused.
**When it is asked (0.2.43).** The daily 100 credits are a campaign of
their own each day, listed from 10:00 (UTC+8) to 09:59 the next day
(`startAt`/`endAt`; the campaign's own text says "Daily reset: 10:00
(UTC+8)", a live list on 2026-10-28). A check-in before 10:00 meets the day
before's campaign: it claims that one if it is still open. Every answer
that knows the window carries `until`, the next campaign's opening (a day
after this one's start, or its end when it runs longer) plus a minute, and
magpie (with `until` support) asks again then, so today's credits are
claimed a minute or two after 10:00 (UTC+8), whatever the computer's time
zone, with nothing to set. Between the old campaign's end at 09:59 and
10:00 the check-in is `failed` with `until` 10:01. An older magpie ignores
`until` and asks once a Beijing calendar day, as before.
Taken from [wallechfox/qoder-checkin](https://github.com/wallechfox/qoder-checkin),
which a user reports works, and Qoder desktop 0.4.3's campaign requests.
International campaign discovery was checked with a real account on
+128
View File
@@ -0,0 +1,128 @@
// The daily credits' window (sdytman on Discord: qoder每天10点开始签到).
// Qoder lists each day's 100 credits from 10:00 (UTC+8) to 09:59 the next
// day; testdata/campaigns-1028.json is a live list read at 09:27 (UTC+8)
// on 2026-10-28, the day before's campaign still open. A check-in says
// when the next one opens (until), so magpie asks again then instead of at
// the next calendar day, whatever zone the machine is in: run this file
// with TZ=UTC and TZ=Etc/GMT+8 (UTC-8) too.
import { afterEach, beforeEach, expect, setSystemTime, spyOn, test } from "bun:test"
import * as childProcess from "node:child_process"
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join, sep } from "node:path"
import { QoderAuthPlugin, QoderCNAuthPlugin } from "./index.mjs"
const real = globalThis.fetch
const originalRuntime = process.env.QODER_RUNTIME_INFO
const originalCNRuntime = process.env.QODERCN_RUNTIME_INFO
let sandbox, native
beforeEach(() => {
sandbox = mkdtempSync(join(tmpdir(), "qoder-checkin-window-"))
process.env.QODER_RUNTIME_INFO = join(sandbox, process.platform === "win32" ? "runtime-info.exe" : "runtime-info")
writeFileSync(process.env.QODER_RUNTIME_INFO, "fixture")
process.env.QODERCN_RUNTIME_INFO = process.env.QODER_RUNTIME_INFO
native = spyOn(childProcess, "execFile").mockImplementation((file, args, options, done) => ({
stdin: { on() {}, end() { queueMicrotask(() => done(null, JSON.stringify({ machineToken: "mt", machineType: "cfe1" }))) } },
}))
})
afterEach(() => {
globalThis.fetch = real
native.mockRestore()
setSystemTime()
if (originalRuntime === undefined) delete process.env.QODER_RUNTIME_INFO
else process.env.QODER_RUNTIME_INFO = originalRuntime
if (originalCNRuntime === undefined) delete process.env.QODERCN_RUNTIME_INFO
else process.env.QODERCN_RUNTIME_INFO = originalCNRuntime
const target = realpathSync(sandbox)
if (!target.startsWith(realpathSync(tmpdir()) + sep)) throw new Error("test directory escaped temp root")
rmSync(target, { recursive: true, force: true })
})
// the live list: the campaign of 10-27 10:00 to 10-28 09:59 (UTC+8)
const LIVE = JSON.parse(readFileSync(join(import.meta.dir, "testdata", "campaigns-1028.json"), "utf8"))
const OCT27 = LIVE.campaigns[0]
// the next day's, as Qoder lists one: a day later, the same length
const OCT28 = { ...OCT27, campaignId: "oct28", campaignKey: "act-20261028-1", startAt: OCT27.startAt + 86400, endAt: OCT27.endAt + 86400 }
const listOf = (...cs) => ({ ...LIVE, campaigns: cs })
const account = () => ({
type: "oauth", access: "jt", refresh: "rt", expires: Date.now() + 3_600_000,
accountId: "one@x", uid: "u1", deviceToken: "dt", deviceRefresh: "drt",
})
const json = (v, status = 200) => new Response(JSON.stringify(v), { status })
async function checkin(make, list) {
let auth = account()
const claims = []
globalThis.fetch = async (url) => {
const u = new URL(String(url))
if (u.pathname.endsWith("/claim")) {
claims.push(u.pathname.split("/").at(-2))
return json({ status: "CLAIMED", benefit: { amount: 100 } })
}
return json(list)
}
const hooks = await make({ client: { auth: { set: async ({ body }) => (auth = body) } } })
return { out: await hooks.auth.checkin(async () => auth), claims }
}
// 10:01 (UTC+8) on the day: a minute after the campaign opens
const askAt = (day) => `2026-10-${day}T02:01:00.000Z`
test("the live list's fixture is the day before's campaign, 10:00 to 09:59 (UTC+8)", () => {
expect(new Date(OCT27.startAt * 1000).toISOString()).toBe("2026-10-27T02:00:00.000Z")
expect(new Date(OCT27.endAt * 1000).toISOString()).toBe("2026-10-28T01:59:00.000Z")
expect(OCT27.placements[0].content.en.description).toContain("Daily reset: 10:00 (UTC+8)")
})
for (const make of [QoderAuthPlugin, QoderCNAuthPlugin]) {
const site = make === QoderAuthPlugin ? "qoder" : "qoder-cn"
test(`${site}: before 10:00 the day before's credits are claimed, and the check-in asks again at 10:00`, async () => {
setSystemTime(new Date("2026-10-28T01:27:00Z")) // 09:27 (UTC+8), as the live list was read
const p = await checkin(make, LIVE)
expect(p.claims).toEqual([OCT27.campaignId])
expect(p.out).toEqual({ outcome: "claimed", credit: 100, until: askAt(28) })
})
test(`${site}: before 10:00 with the day before's already claimed is done until 10:00, not the day`, async () => {
setSystemTime(new Date("2026-10-28T01:27:00Z"))
const p = await checkin(make, listOf({ ...OCT27, claimStatus: "CLAIMED" }))
expect(p.claims).toEqual([])
expect(p.out).toEqual({ outcome: "done", credit: 100, until: askAt(28) })
})
test(`${site}: after 10:00 today's credits are claimed, and the next ask is tomorrow 10:00`, async () => {
setSystemTime(new Date("2026-10-28T02:01:30Z")) // 10:01 (UTC+8)
const p = await checkin(make, listOf({ ...OCT27, claimStatus: "CLAIMED", endAt: OCT27.endAt }, OCT28))
expect(p.claims).toEqual(["oct28"])
expect(p.out).toEqual({ outcome: "claimed", credit: 100, until: askAt(29) })
})
test(`${site}: across midnight (UTC+8) a claimed campaign holds until 10:00, not until the date changes`, async () => {
for (const t of ["2026-10-28T15:59:00Z", "2026-10-28T16:01:00Z"]) { // 23:59 and 00:01 (UTC+8)
setSystemTime(new Date(t))
const p = await checkin(make, listOf({ ...OCT28, claimStatus: "CLAIMED" }))
expect(p.out).toEqual({ outcome: "done", credit: 100, until: askAt(29) })
}
})
test(`${site}: between the old campaign's end and 10:00 the check-in fails and asks again at 10:00`, async () => {
setSystemTime(new Date("2026-10-28T01:59:30Z")) // 09:59:30 (UTC+8)
const p = await checkin(make, listOf({ ...OCT27, claimStatus: "CLAIMED" }))
expect(p.out).toEqual({ outcome: "failed", message: "campaigns: today's credits aren't offered yet", until: askAt(28) })
})
}
test("a campaign longer than a day is asked again at its end", async () => {
setSystemTime(new Date("2026-10-28T03:00:00Z"))
const long = { ...OCT28, claimStatus: "CLAIMED", endAt: OCT28.startAt + 3 * 86400 }
const p = await checkin(QoderAuthPlugin, listOf(long))
expect(p.out.until).toBe(new Date((long.endAt + 60) * 1000).toISOString())
})
test("times in milliseconds read the same as in seconds", async () => {
setSystemTime(new Date("2026-10-28T01:27:00Z"))
const p = await checkin(QoderAuthPlugin, listOf({ ...OCT27, claimStatus: "CLAIMED", startAt: OCT27.startAt * 1000, endAt: OCT27.endAt * 1000 }))
expect(p.out).toEqual({ outcome: "done", credit: 100, until: askAt(28) })
})
+39 -4
View File
@@ -2089,6 +2089,36 @@ function gfmt(n) {
const RFC3339 = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(Z|[+-]\d\d:\d\d)$/i
// Qoder's daily credits are a campaign of their own each day, listed from
// 10:00 (UTC+8) to 09:59 the next day: its startAt and endAt, and its own
// words, "Daily reset: 10:00 (UTC+8)" (a live list, 2026-10-28; sdytman on
// Discord: qoder每天10点开始签到). So the check-in's day is the campaign's,
// not the calendar's in any zone: a check-in before 10:00 meets the day
// before's campaign, and the next one opens a day after that one's start,
// a minute after its end. A check-in says when (until, RFC 3339), and
// magpie asks again then, whatever the machine's time zone.
const DAY_MS = 86_400_000
// a minute's room for a computer clock that runs ahead of Qoder's
const OPEN_ROOM_MS = 60_000
// at is a time Qoder gives, in seconds or milliseconds, as milliseconds.
const at = (v) => {
const n = Number(v)
if (v === null || v === undefined || v === "" || !Number.isFinite(n) || n <= 0) return undefined
return n > 1e12 ? n : n * 1000
}
// nextOpens is when the campaign after c is expected to open: a day after
// c's start, or c's end when it runs longer than a day.
const nextOpens = (c) => {
const start = at(c?.startAt), end = at(c?.endAt)
if (end === undefined) return undefined
return start === undefined ? end : Math.max(end, start + DAY_MS)
}
// askAgain is a check-in's until: when to ask again, with room.
const askAgain = (t) => (Number.isFinite(t) ? { until: new Date(t + OPEN_ROOM_MS).toISOString() } : {})
// when is a time Qoder gives: an RFC 3339 string, else seconds or
// milliseconds, as a number or its text.
function when(v) {
@@ -2586,16 +2616,21 @@ const makePlugin = (site) => async ({ client }) => {
}
if (listRes.status !== 200) return { outcome: "failed", message: `campaigns: HTTP ${listRes.status}` }
const now = Date.now()
const active = (c) => (!c.startAt || c.startAt * 1000 <= now) && (!c.endAt || c.endAt * 1000 > now)
const active = (c) => (at(c.startAt) ?? -Infinity) <= now && now < (at(c.endAt) ?? Infinity)
const campaigns = (Array.isArray(list.campaigns) ? list.campaigns : []).filter((x) => x?.actionType === "CLAIM_BENEFIT")
const campaign = campaigns.find((x) => x.claimStatus === "CLAIMABLE")
if (!campaign) {
const done = campaigns.find((x) => x.claimStatus === "CLAIMED" && active(x))
if (done) {
const amount = Number(done.benefit?.amount)
return { outcome: "done", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}) }
return { outcome: "done", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}), ...askAgain(nextOpens(done)) }
}
// the next day's credits open at a time the list says: ask then,
// not half an hour later
if (campaigns.length) {
const next = Math.min(...campaigns.flatMap((c) => [at(c.startAt), nextOpens(c)]).filter((t) => t > now))
return { outcome: "failed", message: "campaigns: today's credits aren't offered yet", ...askAgain(next) }
}
if (campaigns.length) return { outcome: "failed", message: "campaigns: today's credits aren't offered yet" }
// Asked without Qoder CN's identity and offered nothing: what an
// international list says to a request without one, so say why
// (no Qoder CN on this machine) or ask again (it didn't answer).
@@ -2620,7 +2655,7 @@ const makePlugin = (site) => async ({ client }) => {
if (claimRes.status !== 200) return { outcome: "failed", message: `claim: HTTP ${claimRes.status}` }
if (said === "CLAIMED") {
const amount = Number(claim?.benefit?.amount ?? claim?.data?.benefit?.amount ?? campaign.benefit?.amount)
return { outcome: "claimed", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}) }
return { outcome: "claimed", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}), ...askAgain(nextOpens(campaign)) }
}
return { outcome: "failed", message: `claim: ${said || "unknown answer"}` }
} catch (e) {
+3 -3
View File
@@ -208,15 +208,15 @@ test("yesterday's claimed entry does not hide today's claimable campaign", async
{ campaignId: "new", actionType: "CLAIM_BENEFIT", claimStatus: "CLAIMABLE", startAt: Math.floor(Date.now()/1000)-100, endAt: Math.floor(Date.now()/1000)+86000, benefit: { amount: 100 } },
] }
const p = await checkin(QoderAuthPlugin, (u) => u.pathname.endsWith("/claim") ? json({ status: "CLAIMED", benefit: { amount: 125 } }) : json(list))
expect(p.out).toEqual({ outcome: "claimed", credit: 125 })
expect(p.out).toMatchObject({ outcome: "claimed", credit: 125 })
})
test("an active claimed campaign is done, and an unavailable one retries", async () => {
const active = { campaignId: "c", actionType: "CLAIM_BENEFIT", claimStatus: "CLAIMED", startAt: Math.floor(Date.now()/1000)-100, endAt: Math.floor(Date.now()/1000)+1000, benefit: { amount: 100 } }
let p = await checkin(QoderAuthPlugin, () => json({ campaigns: [active] }))
expect(p.out).toEqual({ outcome: "done", credit: 100 })
expect(p.out).toMatchObject({ outcome: "done", credit: 100 })
p = await checkin(QoderAuthPlugin, () => json({ campaigns: [{ ...active, claimStatus: "DISABLED" }] }))
expect(p.out).toEqual({ outcome: "failed", message: "campaigns: today's credits aren't offered yet" })
expect(p.out).toMatchObject({ outcome: "failed", message: "campaigns: today's credits aren't offered yet" })
})
test("a refused device token is rotated and the claim asked again", async () => {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.42",
"version": "0.2.43",
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)",
"type": "module",
"main": "./index.mjs",
+65
View File
@@ -0,0 +1,65 @@
{
"showCampaign": true,
"claimable": true,
"campaignUrl": "",
"campaigns": [
{
"campaignId": "01a17b2f-85d0-70e9-9c27-4a1fcc314a48",
"campaignKey": "act-20261027-207",
"actionType": "CLAIM_BENEFIT",
"startAt": 1793066400,
"endAt": 1793152740,
"claimStatus": "CLAIMABLE",
"benefit": {
"kind": "CREDITS",
"amount": 100,
"modelScope": {
"modelSeries": {
"key": "ALL_MODELS"
}
},
"validity": {
"mode": "RELATIVE_DAYS",
"days": 30
}
},
"placements": [
{
"type": "POPUP",
"campaignUrl": "https://openapi.qoder.sh/growth-page/activity-iframe",
"content": {
"en": {
"buttonText": "",
"description": "Daily reset: 10:00 (UTC+8). Valid for 30 days after claiming.",
"detailUrl": "https://docs.qoder.com/events/100credits",
"title": "Claim 100 Credits Daily"
},
"zh": {
"buttonText": "",
"description": "每日 10:00(UTC+8)刷新,领取后 30 天有效",
"detailUrl": "https://docs.qoder.com/zh/events/100credits",
"title": "每天领 100 Credits"
}
}
},
{
"type": "USAGE",
"content": {
"en": {
"buttonText": "",
"description": "Daily reset: 10:00 (UTC+8). Valid for 30 days after claiming.",
"detailUrl": "https://docs.qoder.com/events/100credits",
"title": "Claim 100 Credits Daily"
},
"zh": {
"buttonText": "",
"description": "每日 10:00(UTC+8)刷新,领取后 30 天有效",
"detailUrl": "https://docs.qoder.com/zh/events/100credits",
"title": "每天领 100 Credits"
}
}
}
]
}
]
}