codearts 0.3.18: claim every daily check-in campaign, not only the first (#1110)
The delivery list holds more than one USER_LOGIN campaign: the ordinary daily check-in (34, 100), a contest's daily check-in (40, 1000, 2026-11-11 to 12-05) and the contest's one-time sign-up gift (42). dailyCampaign took the first, 42; once it was CONFIRMED the check-in answered done and claimed neither daily one. Now every USER_LOGIN campaign whose title is a daily one (签到/每日) is claimed and confirmed in turn, credit is their sum, grants and unconfirmed claims are kept per campaignId, and a campaign the account hasn't joined (not claimable, or refused with 需要先通过触发接口激活/未报名) is ineligible rather than a failed day. By @amqsy (#1110). Reviewed at ab9447b8: - WSL, HOME=$(mktemp -d): bun test in packages/codearts 211 pass; bun scripts/check.mjs codearts ok. - Broken by hand: dailyCampaigns back to the first USER_LOGIN item turns three of the new tests red. - The old single-claim _unconfirmed shape is still read. - Not tried: a real CodeArts account (the author's run on 2026-11-14 00:00 Beijing claimed +1100 on two accounts).
This commit is contained in:
@@ -175,7 +175,13 @@ rate), shown as `DeepSeek-V4.1-Flash-1017`, not folded into `DeepSeek-V4.1-Flash
|
||||
- `auth.checkin`: the client's 「限时福利 → 每日领取」 — `GET /v1/ops/delivery?channel=IDE`,
|
||||
`POST /v1/ops/claim`, then `POST /v1/ops/confirm` when the claim answers an id. A claim whose
|
||||
confirm failed is kept in that ledger for the day and confirmed at the next check-in; one the
|
||||
client leaves unconfirmed (`id: null`) never is. Turn on
|
||||
client leaves unconfirmed (`id: null`) never is. Every claimable campaign whose title is a
|
||||
daily one (`签到` / `每日`) is claimed: the ordinary daily check-in and a contest's daily
|
||||
check-in beside it (such as the 小红书 Skill 创新赛 daily 1000, 2026-11-11–12-05) are separate campaigns in that
|
||||
same list; a contest's one-time sign-up gift is left to the user. A contest check-in the
|
||||
account has not signed up for is not claimable, so it is skipped and the ordinary one is still
|
||||
claimed. The dates are the vendor list's own (`extra.endTime`), not hardcoded here, so the
|
||||
campaign stops being claimed when it ends. Turn on
|
||||
*Auto check-in* for CodeArts under **Settings → Usage → Plugins**.
|
||||
|
||||
## OfficeAce (the second provider)
|
||||
@@ -327,6 +333,10 @@ measurements and code of [HuHong-Tao](https://github.com/yuweihao17/codearts/pul
|
||||
时间读自码道控制台同一批接口,读不到时退回插件的签到账本 `~/.config/magpie/codearts-checkins.json`
|
||||
(这部分仍在用更多账号验证,请以控制台为准)。`auth.checkin` 与客户端「限时福利 → 每日领取」一致
|
||||
(插件领取后确认失败的,当天记在签到账本里,下次签到时补确认;客户端本就不确认的 `id: null` 领取不会被确认),
|
||||
活动列表里标题为签到/每日(`签到` / `每日`)的每一个可领活动都会领取:普通每日签到和赛事附带的
|
||||
每日签到(例如小红书 Skill 创新赛的每日 1000 积分,2026-11-11–12-05)是同一列表里的不同活动,赛事的一次性报名礼
|
||||
留给用户自己领;没报名该赛事的账号,赛事签到不可领,会被跳过,普通每日签到仍照常领取,
|
||||
日期取自服务端活动列表的 `extra.endTime`,代码里没有写死,活动结束后自然不再领取,
|
||||
在 **设置 → 用量 → Plugins** 打开「每日自动签到」即可。
|
||||
- **OfficeAce(第二个供应商)**:officeace 卡片提供与 CodeArts 卡片相同的「华为云登录」,账号体系是同一套:
|
||||
码道的 STS 三元组能签 OfficeAce 的订阅接口(V11-HMAC)并通过它的 CLAW 权限校验,反之 OfficeAce 的三元组也能签
|
||||
|
||||
+157
-60
@@ -157,6 +157,10 @@ const OPS_CLAIM_URL = `${SNAP_HOST}/v1/ops/claim`
|
||||
const OPS_CONFIRM_URL = `${SNAP_HOST}/v1/ops/confirm`
|
||||
const OPS_CHANNEL = "IDE"
|
||||
const DAILY_CHECKIN_TYPE = "USER_LOGIN"
|
||||
// A campaign of that type is a daily check-in when its title says so; the list
|
||||
// also holds one-time USER_LOGIN campaigns (a contest's sign-up gift), which are
|
||||
// not the daily check-in and are left to the user.
|
||||
const DAILY_CHECKIN_TITLE = /签到|每日/
|
||||
// States the IDE disables the claim button in: today's benefit is in already.
|
||||
const CLAIMED_STATUSES = ["CLAIMED", "CONFIRMED", "CONSUMED"]
|
||||
// Unsigned headers snap-access routes on (signing them breaks the signature).
|
||||
@@ -2068,24 +2072,36 @@ async function snapRequest(method, url, cred, fetcher, payload) {
|
||||
const raw = safeJson(text)
|
||||
if (!raw || Array.isArray(raw)) return { ok: false, message: "the answer could not be read" }
|
||||
if (raw.code !== undefined && Number(raw.code) !== 0) {
|
||||
return { ok: false, message: firstOf(raw.message, raw.msg, `code ${raw.code}`) }
|
||||
return { ok: false, code: Number(raw.code), message: firstOf(raw.message, raw.msg, `code ${raw.code}`) }
|
||||
}
|
||||
return { ok: true, data: "data" in raw ? raw.data : raw }
|
||||
}
|
||||
|
||||
// ---- daily check-in ----------------------------------------------------------
|
||||
|
||||
/** The account's 「每日领取」 campaign from the activity list, or a reason it can't be read. */
|
||||
async function dailyCampaign(cred, fetcher) {
|
||||
/** The account's 「每日领取」 campaigns from the activity list, or a reason they can't be read. */
|
||||
async function dailyCampaigns(cred, fetcher) {
|
||||
const listed = await snapRequest("GET", OPS_DELIVERY_URL, cred, fetcher)
|
||||
if (!listed.ok) return { error: `活动列表读取失败:${listed.message}` }
|
||||
const items = asRecord(listed.data).items
|
||||
if (!Array.isArray(items)) return { error: "活动列表缺少 items" }
|
||||
return { item: items.find((it) => asRecord(it).type === DAILY_CHECKIN_TYPE) }
|
||||
return {
|
||||
items: items.filter(
|
||||
(it) => asRecord(it).type === DAILY_CHECKIN_TYPE && DAILY_CHECKIN_TITLE.test(String(asRecord(it).title ?? "")),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
const isClaimedToday = (item) => !item?.claimable && CLAIMED_STATUSES.includes(item?.status)
|
||||
|
||||
const sameCampaign = (a, b) => String(a?.campaignId) === String(b?.campaignId)
|
||||
|
||||
// A claim the vendor turns down because the account has not joined that
|
||||
// campaign (a contest's daily check-in before signing up for the contest): the
|
||||
// account is not eligible, not a failure to retry.
|
||||
const INELIGIBLE_CLAIM = /需要先通过触发接口激活|未参与|未报名|无资格/
|
||||
const isIneligibleClaim = (failure) => INELIGIBLE_CLAIM.test(String(failure?.message ?? ""))
|
||||
|
||||
// ---- credit batches and when they lapse ------------------------------------
|
||||
|
||||
const PACKAGE_TYPE_METRICS = {
|
||||
@@ -2216,7 +2232,11 @@ function recordGrant(file, account, grant) {
|
||||
const keep = Date.now() - LEDGER_KEEP_DAYS * 86_400_000
|
||||
const day = beijingDay(vendorDate(grant.at))
|
||||
const list = (Array.isArray(all[account]) ? all[account] : [])
|
||||
.filter((g) => (vendorDate(g.expiresAt) ?? 0) > keep && beijingDay(vendorDate(g.at) ?? 0) !== day)
|
||||
.filter(
|
||||
(g) =>
|
||||
(vendorDate(g.expiresAt) ?? 0) > keep &&
|
||||
!(beijingDay(vendorDate(g.at) ?? 0) === day && String(g.campaignId ?? "") === String(grant.campaignId ?? "")),
|
||||
)
|
||||
all[account] = [...list, grant]
|
||||
writeLedger(file, all)
|
||||
} catch {
|
||||
@@ -2230,21 +2250,23 @@ function recordGrant(file, account, grant) {
|
||||
// here, so it is never confirmed. Kept for its Beijing day only.
|
||||
const UNCONFIRMED = "_unconfirmed"
|
||||
|
||||
/** Today's claim this plugin left unconfirmed for `account`, if any. */
|
||||
/** Today's claims this plugin left unconfirmed for `account`, if any. */
|
||||
function readUnconfirmed(file, account) {
|
||||
const left = asRecord(asRecord(readLedger(file)[UNCONFIRMED])[account])
|
||||
return left.day === beijingDay() ? left : undefined
|
||||
if (left.day !== beijingDay()) return []
|
||||
if (Array.isArray(left.claims)) return left.claims
|
||||
return left.campaignId !== undefined ? [left] : []
|
||||
}
|
||||
|
||||
/** Keep the claim left unconfirmed for `account`, or with null drop it; other days' go. */
|
||||
function recordUnconfirmed(file, account, left) {
|
||||
/** Keep the claims left unconfirmed for `account`, or with an empty list drop them; other days' go. */
|
||||
function recordUnconfirmed(file, account, claims) {
|
||||
try {
|
||||
const all = readLedger(file)
|
||||
const today = beijingDay()
|
||||
const kept = Object.fromEntries(
|
||||
Object.entries(asRecord(all[UNCONFIRMED])).filter(([k, v]) => k !== account && asRecord(v).day === today),
|
||||
)
|
||||
if (left) kept[account] = { ...left, day: today }
|
||||
if (Array.isArray(claims) && claims.length > 0) kept[account] = { day: today, claims }
|
||||
all[UNCONFIRMED] = kept
|
||||
writeLedger(file, all)
|
||||
} catch {
|
||||
@@ -2262,52 +2284,125 @@ function grantExpiry(benefit, at) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Press the daily check-in, exactly as the IDE's 「限时福利 → 每日领取」 does:
|
||||
* list the activities, claim the `USER_LOGIN` one with `{campaignId, channel}`,
|
||||
* and confirm it when the claim answers an id (`benefit.id !== null`), or the
|
||||
* credits stay pending. Answers magpie's check-in outcome; never throws.
|
||||
* `unconfirmed` is today's claim this plugin left unconfirmed (the ledger's);
|
||||
* an answer's own `unconfirmed` is one to keep there.
|
||||
* Press the daily check-ins, exactly as the IDE's 「限时福利 → 每日领取」 does:
|
||||
* list the activities, claim every claimable `USER_LOGIN` item with
|
||||
* `{campaignId, channel}`, and confirm each when its claim answers an id
|
||||
* (`benefit.id !== null`), or the credits stay pending. The list holds more than
|
||||
* one such item: the ordinary daily check-in, and the campaigns a contest adds
|
||||
* beside it. Answers magpie's check-in outcome; never throws. `unconfirmed` is
|
||||
* today's list of claims this plugin left unconfirmed (the ledger's); an
|
||||
* answer's own `unconfirmed` is one to keep there.
|
||||
*/
|
||||
async function dailyCheckin(cred, fetcher, { unconfirmed } = {}) {
|
||||
const first = await dailyCampaign(cred, fetcher)
|
||||
if (first.error) return { outcome: "failed", message: first.error }
|
||||
const item = first.item
|
||||
if (!item) return { outcome: "inactive", message: "当前没有每日领取活动" }
|
||||
const credit = num(item.benefitAmount)
|
||||
// Claimed here, but the confirm failed: confirm it now, or the credits stay
|
||||
// pending. Only that claim: one the IDE leaves unconfirmed is `CLAIMED` as
|
||||
// well, and the IDE never confirms it. When the confirm fails, only the
|
||||
// activity tells whether it was confirmed after all; still claimed, it is a
|
||||
// failure magpie tries again later that day.
|
||||
const campaign = item.campaignId !== undefined && item.campaignId !== null && item.campaignId !== ""
|
||||
const leftHere = unconfirmed && String(unconfirmed.campaignId) === String(item.campaignId)
|
||||
if (!item.claimable && item.status === "CLAIMED" && campaign && leftHere) {
|
||||
const confirmed = await snapRequest("POST", OPS_CONFIRM_URL, cred, fetcher, { campaignId: item.campaignId })
|
||||
if (confirmed.ok) return claimedOutcome(asRecord(unconfirmed.benefit), credit)
|
||||
const again = await dailyCampaign(cred, fetcher)
|
||||
if (isClaimedToday(again.item) && again.item.status !== "CLAIMED") return { outcome: "done", message: "今天已领取" }
|
||||
return { outcome: "failed", message: `领取确认失败:${confirmed.message}` }
|
||||
}
|
||||
if (isClaimedToday(item)) return { outcome: "done", message: "今天已领取" }
|
||||
if (!item.claimable) return { outcome: "ineligible", message: `当前不可领取(status=${item.status ?? "null"})` }
|
||||
if (!campaign) return { outcome: "failed", message: "活动缺少 campaignId" }
|
||||
const listed = await dailyCampaigns(cred, fetcher)
|
||||
if (listed.error) return { outcome: "failed", message: listed.error }
|
||||
const items = listed.items
|
||||
if (items.length === 0) return { outcome: "inactive", message: "当前没有每日领取活动" }
|
||||
|
||||
const claimed = await snapRequest("POST", OPS_CLAIM_URL, cred, fetcher, { campaignId: item.campaignId, channel: OPS_CHANNEL })
|
||||
if (!claimed.ok) {
|
||||
// Claimed elsewhere a moment ago (the IDE, another magpie): look again.
|
||||
const again = await dailyCampaign(cred, fetcher)
|
||||
if (isClaimedToday(again.item)) return { outcome: "done", message: "今天已领取" }
|
||||
return { outcome: "failed", message: `领取失败:${claimed.message}` }
|
||||
}
|
||||
const benefit = asRecord(claimed.data)
|
||||
if (claimed.data && benefit.id !== null) {
|
||||
const confirmed = await snapRequest("POST", OPS_CONFIRM_URL, cred, fetcher, { campaignId: item.campaignId })
|
||||
if (!confirmed.ok) {
|
||||
return { outcome: "failed", message: `领取确认失败:${confirmed.message}`, unconfirmed: { campaignId: item.campaignId, benefit } }
|
||||
const left = [].concat(unconfirmed ?? [])
|
||||
const results = []
|
||||
const grants = []
|
||||
const kept = []
|
||||
|
||||
for (const item of items) {
|
||||
const credit = num(item.benefitAmount)
|
||||
const campaign = item.campaignId !== undefined && item.campaignId !== null && item.campaignId !== ""
|
||||
const leftHere = campaign ? left.find((claim) => sameCampaign(claim, item)) : undefined
|
||||
// Claimed here, but the confirm failed: confirm it now, or the credits stay
|
||||
// pending. Only that claim: one the IDE leaves unconfirmed is `CLAIMED` as
|
||||
// well, and the IDE never confirms it. When the confirm fails, only the
|
||||
// activity tells whether it was confirmed after all; still claimed, it is a
|
||||
// failure magpie tries again later that day.
|
||||
if (!item.claimable && item.status === "CLAIMED" && campaign && leftHere) {
|
||||
const confirmed = await snapRequest("POST", OPS_CONFIRM_URL, cred, fetcher, { campaignId: item.campaignId })
|
||||
if (confirmed.ok) {
|
||||
const outcome = claimedOutcome(asRecord(leftHere.benefit), credit)
|
||||
if (outcome.grant) grants.push({ ...outcome.grant, campaignId: item.campaignId })
|
||||
results.push(outcome)
|
||||
continue
|
||||
}
|
||||
const again = await dailyCampaigns(cred, fetcher)
|
||||
const seen = again.items?.find((it) => sameCampaign(it, item))
|
||||
if (isClaimedToday(seen) && seen.status !== "CLAIMED") {
|
||||
results.push({ outcome: "done", message: "今天已领取" })
|
||||
continue
|
||||
}
|
||||
kept.push(leftHere)
|
||||
results.push({ outcome: "failed", message: `领取确认失败:${confirmed.message}` })
|
||||
continue
|
||||
}
|
||||
if (isClaimedToday(item)) {
|
||||
results.push({ outcome: "done", message: "今天已领取" })
|
||||
continue
|
||||
}
|
||||
if (!item.claimable) {
|
||||
results.push({ outcome: "ineligible", message: `当前不可领取(status=${item.status ?? "null"})` })
|
||||
continue
|
||||
}
|
||||
if (!campaign) {
|
||||
results.push({ outcome: "failed", message: "活动缺少 campaignId" })
|
||||
continue
|
||||
}
|
||||
|
||||
const claimed = await snapRequest("POST", OPS_CLAIM_URL, cred, fetcher, { campaignId: item.campaignId, channel: OPS_CHANNEL })
|
||||
if (!claimed.ok) {
|
||||
// Claimed elsewhere a moment ago (the IDE, another magpie): look again.
|
||||
const again = await dailyCampaigns(cred, fetcher)
|
||||
const seen = again.items?.find((it) => sameCampaign(it, item))
|
||||
if (isClaimedToday(seen)) {
|
||||
results.push({ outcome: "done", message: "今天已领取" })
|
||||
continue
|
||||
}
|
||||
if (isIneligibleClaim(claimed)) {
|
||||
results.push({ outcome: "ineligible", message: claimed.message })
|
||||
continue
|
||||
}
|
||||
results.push({ outcome: "failed", message: `领取失败:${claimed.message}` })
|
||||
continue
|
||||
}
|
||||
const benefit = asRecord(claimed.data)
|
||||
if (claimed.data && benefit.id !== null) {
|
||||
const confirmed = await snapRequest("POST", OPS_CONFIRM_URL, cred, fetcher, { campaignId: item.campaignId })
|
||||
if (!confirmed.ok) {
|
||||
kept.push({ campaignId: item.campaignId, benefit })
|
||||
results.push({ outcome: "failed", message: `领取确认失败:${confirmed.message}` })
|
||||
continue
|
||||
}
|
||||
}
|
||||
const outcome = claimedOutcome(benefit, credit)
|
||||
if (outcome.grant) grants.push({ ...outcome.grant, campaignId: item.campaignId })
|
||||
results.push(outcome)
|
||||
}
|
||||
return claimedOutcome(benefit, credit)
|
||||
|
||||
const failed = results.filter((result) => result.outcome === "failed")
|
||||
const claimed = results.filter((result) => result.outcome === "claimed")
|
||||
const done = results.filter((result) => result.outcome === "done")
|
||||
const ineligible = results.filter((result) => result.outcome === "ineligible")
|
||||
|
||||
let outcome
|
||||
let credit
|
||||
let message
|
||||
if (failed.length > 0) {
|
||||
outcome = "failed"
|
||||
message = failed.length === 1 ? failed[0].message : `${failed[0].message}(另有 ${failed.length - 1} 个活动失败)`
|
||||
} else if (claimed.length > 0) {
|
||||
outcome = "claimed"
|
||||
credit = claimed.reduce((sum, result) => sum + (result.credit ?? 0), 0)
|
||||
message = credit > 0 ? `+${credit} 积分` : "已领取"
|
||||
} else if (done.length > 0) {
|
||||
outcome = "done"
|
||||
message = "今天已领取"
|
||||
} else {
|
||||
outcome = "ineligible"
|
||||
message = ineligible[0]?.message ?? ""
|
||||
}
|
||||
|
||||
const answer = { outcome, ...(credit > 0 ? { credit } : {}), message }
|
||||
if (grants.length === 1) answer.grant = grants[0]
|
||||
else if (grants.length > 1) answer.grants = grants
|
||||
if (kept.length === 1) answer.unconfirmed = kept[0]
|
||||
else if (kept.length > 1) answer.unconfirmed = kept
|
||||
return answer
|
||||
}
|
||||
|
||||
/** The outcome of a check-in that went through, with the grant the ledger keeps. */
|
||||
@@ -3472,23 +3567,25 @@ export const CodeArtsAuthPlugin = async ({ client } = {}, options = {}) => {
|
||||
// The account's own memory first: the ledger is written best effort,
|
||||
// and a write that failed mustn't lose the claim; the ledger carries it
|
||||
// to another process, or past a restart.
|
||||
const held = state.unconfirmed?.day === today ? state.unconfirmed : undefined
|
||||
const held = state.unconfirmed?.day === today ? state.unconfirmed.claims : undefined
|
||||
const left = held ?? readUnconfirmed(ledgerPath, key)
|
||||
const { grant, unconfirmed, ...r } = await dailyCheckin(cred, fetcher, { unconfirmed: left })
|
||||
const { grant, grants, unconfirmed, ...r } = await dailyCheckin(cred, fetcher, { unconfirmed: left })
|
||||
// A claim whose confirm failed is kept for the next check-in; one
|
||||
// confirmed now, or found done, is dropped.
|
||||
if (unconfirmed) {
|
||||
state.unconfirmed = { ...unconfirmed, day: today }
|
||||
recordUnconfirmed(ledgerPath, key, unconfirmed)
|
||||
} else if (left && r.outcome !== "failed") {
|
||||
const kept = Array.isArray(unconfirmed) ? unconfirmed : unconfirmed ? [unconfirmed] : []
|
||||
if (kept.length > 0) {
|
||||
state.unconfirmed = { day: today, claims: kept }
|
||||
recordUnconfirmed(ledgerPath, key, kept)
|
||||
} else if (left?.length > 0 && r.outcome !== "failed") {
|
||||
state.unconfirmed = null
|
||||
recordUnconfirmed(ledgerPath, key, null)
|
||||
recordUnconfirmed(ledgerPath, key, [])
|
||||
}
|
||||
if (r.outcome === "claimed") {
|
||||
const newGrants = grants ?? (grant ? [grant] : [])
|
||||
if (newGrants.length > 0) {
|
||||
// The new batch shows at the next usage read; the ledger keeps it in
|
||||
// case the vendor's batch list can't be read.
|
||||
state.batchesAt = 0
|
||||
if (grant) recordGrant(ledgerPath, key, grant)
|
||||
for (const item of newGrants) recordGrant(ledgerPath, key, item)
|
||||
}
|
||||
return r
|
||||
},
|
||||
|
||||
@@ -2450,6 +2450,115 @@ test("checkin claims and confirms the daily benefit the way the IDE does", async
|
||||
assert.equal(calls.filter((c) => c.url === x.OPS_CLAIM_URL).length, 1)
|
||||
})
|
||||
|
||||
test("checkin claims both daily check-ins, and leaves a contest's one-time sign-up gift alone", async () => {
|
||||
const cred = await makeCred()
|
||||
const items = [
|
||||
{ campaignId: 42, type: "USER_LOGIN", title: "Skill创新赛报名礼", claimable: true, status: "ELIGIBLE", benefitAmount: 2000 },
|
||||
{ campaignId: 40, type: "USER_LOGIN", title: "Skill创新赛每日签到礼", claimable: true, status: "ELIGIBLE", benefitAmount: 1000 },
|
||||
{ campaignId: 34, type: "USER_LOGIN", title: "每日签到领100积分", claimable: true, status: "ELIGIBLE", benefitAmount: 100 },
|
||||
{ campaignId: 4, type: "NEW_USER_REGISTER", claimable: false, status: "CONSUMED" },
|
||||
]
|
||||
const calls = []
|
||||
const fetcher = async (url, init) => {
|
||||
const u = String(url)
|
||||
const body = init.body ? JSON.parse(new TextDecoder().decode(init.body)) : undefined
|
||||
calls.push({ url: u, method: init.method, body })
|
||||
const ok = (data) => new Response(JSON.stringify({ code: 0, message: "ok", data }), { status: 200 })
|
||||
if (u === x.OPS_DELIVERY_URL) return ok({ items })
|
||||
if (u === x.OPS_CLAIM_URL) {
|
||||
const item = items.find((it) => it.campaignId === body.campaignId)
|
||||
item.claimable = false
|
||||
item.status = "CLAIMED"
|
||||
return ok({ id: body.campaignId + 1000, benefitAmount: item.benefitAmount })
|
||||
}
|
||||
if (u === x.OPS_CONFIRM_URL) {
|
||||
items.find((it) => it.campaignId === body.campaignId).status = "CONFIRMED"
|
||||
return ok(null)
|
||||
}
|
||||
throw new Error(`unexpected ${u}`)
|
||||
}
|
||||
|
||||
const { grants, ...r } = await x.dailyCheckin(cred, fetcher)
|
||||
assert.deepEqual(r, { outcome: "claimed", credit: 1100, message: "+1100 积分" })
|
||||
assert.deepEqual(grants.map((g) => [g.campaignId, g.credit]), [[40, 1000], [34, 100]])
|
||||
assert.deepEqual(calls.filter((c) => c.url === x.OPS_CLAIM_URL).map((c) => c.body.campaignId), [40, 34])
|
||||
assert.deepEqual(calls.filter((c) => c.url === x.OPS_CONFIRM_URL).map((c) => c.body.campaignId), [40, 34])
|
||||
assert.deepEqual(
|
||||
[items[0].claimable, items[0].status],
|
||||
[true, "ELIGIBLE"],
|
||||
"the one-time sign-up gift is not claimed",
|
||||
)
|
||||
|
||||
// Later the same day: both are in, and neither is claimed again.
|
||||
assert.equal((await x.dailyCheckin(cred, fetcher)).outcome, "done")
|
||||
assert.equal(calls.filter((c) => c.url === x.OPS_CLAIM_URL).length, 2)
|
||||
})
|
||||
|
||||
test("a contest check-in the account has not joined is skipped, and the official one still claims", async () => {
|
||||
const cred = await makeCred()
|
||||
const items = [
|
||||
{ campaignId: 40, type: "USER_LOGIN", title: "Skill创新赛每日签到礼", claimable: false, status: "ENTRY", benefitAmount: 1000 },
|
||||
{ campaignId: 34, type: "USER_LOGIN", title: "每日签到领100积分", claimable: true, status: "ELIGIBLE", benefitAmount: 100 },
|
||||
]
|
||||
const claims = []
|
||||
const ok = (data) => new Response(JSON.stringify({ code: 0, message: "ok", data }), { status: 200 })
|
||||
const fetcher = async (url, init) => {
|
||||
const u = String(url)
|
||||
const body = init.body ? JSON.parse(new TextDecoder().decode(init.body)) : undefined
|
||||
if (u === x.OPS_DELIVERY_URL) return ok({ items })
|
||||
if (u === x.OPS_CLAIM_URL) {
|
||||
claims.push(body.campaignId)
|
||||
const item = items.find((it) => it.campaignId === body.campaignId)
|
||||
item.claimable = false
|
||||
item.status = "CLAIMED"
|
||||
return ok({ id: body.campaignId, benefitAmount: item.benefitAmount })
|
||||
}
|
||||
if (u === x.OPS_CONFIRM_URL) {
|
||||
items.find((it) => it.campaignId === body.campaignId).status = "CONFIRMED"
|
||||
return ok(null)
|
||||
}
|
||||
throw new Error(`unexpected ${u}`)
|
||||
}
|
||||
const { grant, ...r } = await x.dailyCheckin(cred, fetcher)
|
||||
assert.deepEqual(r, { outcome: "claimed", credit: 100, message: "+100 积分" })
|
||||
assert.equal(grant.campaignId, 34)
|
||||
assert.deepEqual(claims, [34], "the contest campaign is not claimed")
|
||||
})
|
||||
|
||||
test("a contest check-in refused for not having signed up is ineligible, not a failed day", async () => {
|
||||
const cred = await makeCred()
|
||||
const items = [
|
||||
{ campaignId: 40, type: "USER_LOGIN", title: "Skill创新赛每日签到礼", claimable: true, status: "ELIGIBLE", benefitAmount: 1000 },
|
||||
{ campaignId: 34, type: "USER_LOGIN", title: "每日签到领100积分", claimable: true, status: "ELIGIBLE", benefitAmount: 100 },
|
||||
]
|
||||
const claims = []
|
||||
const ok = (data) => new Response(JSON.stringify({ code: 0, message: "ok", data }), { status: 200 })
|
||||
const fetcher = async (url, init) => {
|
||||
const u = String(url)
|
||||
const body = init.body ? JSON.parse(new TextDecoder().decode(init.body)) : undefined
|
||||
if (u === x.OPS_DELIVERY_URL) return ok({ items })
|
||||
if (u === x.OPS_CLAIM_URL) {
|
||||
claims.push(body.campaignId)
|
||||
if (body.campaignId === 40) {
|
||||
return new Response(JSON.stringify({ code: 40001, message: "该活动类型需要先通过触发接口激活" }), { status: 200 })
|
||||
}
|
||||
const item = items.find((it) => it.campaignId === body.campaignId)
|
||||
item.claimable = false
|
||||
item.status = "CLAIMED"
|
||||
return ok({ id: body.campaignId, benefitAmount: item.benefitAmount })
|
||||
}
|
||||
if (u === x.OPS_CONFIRM_URL) {
|
||||
items.find((it) => it.campaignId === body.campaignId).status = "CONFIRMED"
|
||||
return ok(null)
|
||||
}
|
||||
throw new Error(`unexpected ${u}`)
|
||||
}
|
||||
const { grant, ...r } = await x.dailyCheckin(cred, fetcher)
|
||||
assert.deepEqual(r, { outcome: "claimed", credit: 100, message: "+100 积分" })
|
||||
assert.equal(grant.campaignId, 34)
|
||||
assert.deepEqual(claims, [40, 34])
|
||||
})
|
||||
|
||||
test("a claimed check-in is kept, and the usage card says when those credits run out", async () => {
|
||||
const cred = await makeCred()
|
||||
const ledgerPath = path.join(ledgerDir, "integrated.json")
|
||||
@@ -2603,7 +2712,7 @@ test("a confirm that failed is made by the next check-in, in another magpie too,
|
||||
}
|
||||
assert.equal((await checkin()).outcome, "failed")
|
||||
const kept = JSON.parse(fs.readFileSync(ledgerPath, "utf8"))._unconfirmed
|
||||
assert.deepEqual(Object.values(kept).map((v) => [v.campaignId, v.day]), [[1, x.beijingDay()]])
|
||||
assert.deepEqual(Object.values(kept).map((v) => [v.claims?.[0]?.campaignId, v.day]), [[1, x.beijingDay()]])
|
||||
assert.deepEqual(await checkin(), { outcome: "claimed", credit: 1000, message: "+1000 积分" })
|
||||
assert.equal(confirms, 2)
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(ledgerPath, "utf8"))._unconfirmed, {}, "confirmed, so forgotten")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-codearts-auth",
|
||||
"version": "0.3.17",
|
||||
"version": "0.3.18",
|
||||
"description": "Huawei Cloud in OpenCode and magpie: CodeArts (码道) and OfficeAce (AgentArts), each from its own Huawei Cloud OAuth sign-in — models, credit rates, credit usage and the daily check-in (unofficial)",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user