From bb688ea81a6b7d32604fa3e70c7885db07110543 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 20 Oct 2026 16:15:34 +0800 Subject: [PATCH] qoder: test that auth.checkin claims on a PAT account's job token (#262) #262's check-in tests went through the loader's campaigns fetch; the daily check-in magpie presses is auth.checkin, whose PAT change nothing covered. One test claims on qoder and qoder-cn with a PAT account (job token, no deviceToken refresh); one checks a 403 is "failed", not rotated. Run on 0a8e5ab + this: bun test packages/qoder 157 pass, 0 fail; bun scripts/check.mjs passes. With the checkin hook's PAT lines reverted by hand both new tests fail. Test only, no version bump. --- packages/qoder/native-checkin.test.mjs | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/qoder/native-checkin.test.mjs b/packages/qoder/native-checkin.test.mjs index 3fcde5f..b2f54af 100644 --- a/packages/qoder/native-checkin.test.mjs +++ b/packages/qoder/native-checkin.test.mjs @@ -128,3 +128,31 @@ test("a refused device token is rotated and the claim asked again", async () => expect(p.out).toEqual({ outcome: "claimed", credit: 100 }) expect(p.auth().deviceToken).toBe("dt-new") }) + +test("a PAT account's daily check-in claims on its job token, with no device token to rotate", async () => { + for (const [make, origin] of [[QoderAuthPlugin, "https://openapi.qoder.sh"], [QoderCNAuthPlugin, "https://openapi.qoder.com.cn"]]) { + let auth = { ...account(), patAuth: true, pat: "pt-x", deviceToken: "", deviceRefresh: "" } + const seen = [] + globalThis.fetch = async (url, init = {}) => { + const u = new URL(String(url)) + seen.push({ origin: u.origin, path: u.pathname, auth: init.headers.Authorization }) + if (init.headers.Authorization !== "Bearer jt") return new Response("", { status: 401 }) + return u.pathname.endsWith("/claim") ? json({ status: "CLAIMED" }) : json(LIST) + } + const hooks = await make({ client: { auth: { set: async ({ body }) => (auth = body) } } }) + const out = await hooks.auth.checkin(async () => auth) + expect(out).toEqual({ outcome: "claimed", credit: 100 }) + expect(seen.map((s) => s.origin + s.path)).toEqual([origin + "/sash/api/v1/me/campaigns", origin + "/sash/api/v1/me/campaigns/c1/claim"]) + expect(auth.deviceToken).toBe("") + } +}) + +test("a PAT account's refused check-in is failed, not rotated", async () => { + let auth = { ...account(), patAuth: true, pat: "pt-x", deviceToken: "", deviceRefresh: "" } + const seen = [] + globalThis.fetch = async (url) => (seen.push(new URL(String(url)).pathname), json({}, 403)) + const hooks = await QoderCNAuthPlugin({ client: { auth: { set: async ({ body }) => (auth = body) } } }) + const out = await hooks.auth.checkin(async () => auth) + expect(out).toEqual({ outcome: "failed", message: "campaigns: HTTP 403" }) + expect(seen).toEqual(["/sash/api/v1/me/campaigns"]) +})