trae 0.2.21: a check-in's credit is the day's credits, not credits plus extra_credits (zhujiu on magpie's Discord)
zhujiu (magpie Discord #feedback, 10-25): "trae签到的积分为100而不是200 …
显示错误了". The card showed a claimed Trae CN check-in as 200 credits;
the account got 100.
Cause: auth.checkin's claimed outcome was the claim's credits +
extra_credits, falling back to the status's credits + extra_credits.
Trae CN's real claim answer names no credit at all ({"code":0,
"message":"success"}, plugins#194), so the fallback always ran, and a
real account's status carries both fields at 100 ({"checked_in": false,
"code": 0, "credits": 100, "did_checked_in": false, "enable": true,
"extra_credits": 100}, yetone/magpie#808): 100 + 100 = 200. magpie's own
Go check-in (internal/provider/trae_checkin.go, used only for plugins
before 0.2.17) fell back to the status's credits alone, and its real run
recorded credit 100 (plugins#194).
Now the credit is the claim's credits, else its extra_credits when it
names only that (#260's case), else the status's credits; the two are
never added. The done outcome already read credits alone. Trae Global
has no check-in, so this is CN only. What extra_credits means on Trae's
side is not known; nothing seen shows it granted on top.
Tests (native-checkin.test.mjs): the real status and claim answers give
credit 100; a claim naming both gives 100; a checked-in day with
extra_credits is done with 100. On origin/main's index.mjs the first two
fail (Expected credit 100, Received 200). HOME=<scratch> bun test in
packages/trae: 206 pass, 0 fail; bun scripts/check.mjs trae: ok.
Not tried with a real Trae CN account (none here); the shapes are the
real ones quoted in #808 and plugins#194. PR #333 touches the same
fallback line and needs a rebase.
This commit is contained in:
@@ -407,9 +407,12 @@ answered it 9074 even with the client's headers.
|
|||||||
in today, and that holds for the day. No device id is ever changed or
|
in today, and that holds for the day. No device id is ever changed or
|
||||||
rotated to get round a 9095 or a 9074, and no account is given another
|
rotated to get round a 9095 or a 9074, and no account is given another
|
||||||
account's device or its own client's device unless the client is signed
|
account's device or its own client's device unless the client is signed
|
||||||
in as that account. The credit a claim granted is its `credits` plus
|
in as that account. The credit a claim granted is its `credits`, or
|
||||||
its `extra_credits`, either alone; the status answer's is the fallback
|
its `extra_credits` when it names only that; Trae CN's claim usually
|
||||||
when the claim says none.
|
names neither (`{"code":0,"message":"success"}`), and then the status
|
||||||
|
answer's `credits` is the credit. The two are never added: the status
|
||||||
|
carries `extra_credits` beside `credits` (100 and 100 on a real
|
||||||
|
account) while the day gives 100.
|
||||||
|
|
||||||
Only `api.trae.cn`'s `/trae/api/` pages are sent this way; any other URL
|
Only `api.trae.cn`'s `/trae/api/` pages are sent this way; any other URL
|
||||||
that isn't a chat request is still refused (400). Needs 0.1.4 or later.
|
that isn't a chat request is still refused (400). Needs 0.1.4 or later.
|
||||||
|
|||||||
+11
-6
@@ -2902,13 +2902,18 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
if (String(ce.code) === "9074") return { outcome: "ineligible", message: `${ce.message} — check in in the Trae CN app` }
|
if (String(ce.code) === "9074") return { outcome: "ineligible", message: `${ce.message} — check in in the Trae CN app` }
|
||||||
if (claim.status !== 200 || (ce.code && String(ce.code) !== "0")) return { outcome: "failed", message: ce.message || statusLine(claim.status) }
|
if (claim.status !== 200 || (ce.code && String(ce.code) !== "0")) return { outcome: "failed", message: ce.message || statusLine(claim.status) }
|
||||||
if (!answer || typeof answer !== "object" || Array.isArray(answer)) return { outcome: "failed", message: `check-in claim: unreadable reply ${claimText.trim().slice(0, 120) || "(empty)"}` }
|
if (!answer || typeof answer !== "object" || Array.isArray(answer)) return { outcome: "failed", message: `check-in claim: unreadable reply ${claimText.trim().slice(0, 120) || "(empty)"}` }
|
||||||
// a claim may answer extra_credits with no credits beside it, and either
|
// The credit is the day's credits, never credits plus extra_credits.
|
||||||
// may be absent: Number(undefined) is NaN, and NaN + n is NaN, which
|
// Trae CN's real claim answers {"code":0,"message":"success"}, with no
|
||||||
// reads as no credit at all
|
// credit at all (plugins#194), so the status's credits stand in. Its
|
||||||
|
// status carries extra_credits beside credits, at the same 100 on a
|
||||||
|
// real account (yetone/magpie#808: credits 100, extra_credits 100),
|
||||||
|
// while the account gets 100: adding the two showed 200 (zhujiu on
|
||||||
|
// magpie's Discord, 10-25). A claim that names its own credit is
|
||||||
|
// taken first; one naming extra_credits alone is that (#260). Either
|
||||||
|
// may be absent, and Number(undefined) is NaN, which reads as none.
|
||||||
const n = (v) => (Number.isFinite(Number(v)) ? Number(v) : 0)
|
const n = (v) => (Number.isFinite(Number(v)) ? Number(v) : 0)
|
||||||
const credit = n(answer.credits) + n(answer.extra_credits)
|
const credit = n(answer.credits) || n(answer.extra_credits) || n(body.credits)
|
||||||
const fallback = n(body.credits) + n(body.extra_credits)
|
return { outcome: "claimed", ...(credit > 0 ? { credit } : {}) }
|
||||||
return { outcome: "claimed", ...(credit > 0 ? { credit } : fallback > 0 ? { credit: fallback } : {}) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const usage = async (getAuth) => {
|
const usage = async (getAuth) => {
|
||||||
|
|||||||
@@ -33,6 +33,30 @@ test("a claim answering neither credit says so, and the status's is the fallback
|
|||||||
expect(await checkin()).toEqual({ outcome: "claimed" })
|
expect(await checkin()).toEqual({ outcome: "claimed" })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// zhujiu on magpie's Discord (10-25): a check-in shown as 200 points, when
|
||||||
|
// the account got 100. The status is a real account's (yetone/magpie#808),
|
||||||
|
// the claim's answer Trae CN's real one (plugins#194): it names no credit,
|
||||||
|
// so the status's stands in, and its extra_credits is not added on top.
|
||||||
|
test("a claim with no credit of its own is the status's credits, not credits plus extra_credits", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST " + STATUS, () => json({ checked_in: false, code: 0, credits: 100, did_checked_in: false, enable: true, extra_credits: 100 }))
|
||||||
|
f.route("POST " + CLAIM, () => json({ code: 0, message: "success" }))
|
||||||
|
expect(await checkin()).toEqual({ outcome: "claimed", credit: 100 })
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a claim naming both credits and extra_credits is its credits, once", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST " + STATUS, () => json({ checked_in: false, code: 0, credits: 100, enable: true, extra_credits: 100 }))
|
||||||
|
f.route("POST " + CLAIM, () => json({ code: 0, credits: 100, extra_credits: 100 }))
|
||||||
|
expect(await checkin()).toEqual({ outcome: "claimed", credit: 100 })
|
||||||
|
})
|
||||||
|
|
||||||
|
test("an already-checked day with extra_credits is its credits", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST " + STATUS, () => json({ checked_in: true, code: 0, credits: 100, did_checked_in: true, enable: true, extra_credits: 100 }))
|
||||||
|
expect(await checkin()).toEqual({ outcome: "done", credit: 100 })
|
||||||
|
})
|
||||||
|
|
||||||
test("a claimable day is claimed through Trae's own pages", async () => {
|
test("a claimable day is claimed through Trae's own pages", async () => {
|
||||||
f = fakeTrae()
|
f = fakeTrae()
|
||||||
f.route("POST " + STATUS, () => json({ code: 0, enable: true, checked_in: false }))
|
f.route("POST " + STATUS, () => json({ code: 0, enable: true, checked_in: false }))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@magpie-community/opencode-trae-auth",
|
"name": "@magpie-community/opencode-trae-auth",
|
||||||
"version": "0.2.20",
|
"version": "0.2.21",
|
||||||
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
|
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./index.mjs",
|
"main": "./index.mjs",
|
||||||
|
|||||||
Reference in New Issue
Block a user