From 98985a2426b1548f890285f0063f06d7f28f4be2 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 25 Oct 2026 14:28:06 +0800 Subject: [PATCH] codearts: the credit fixture's check-in stays on its sign-up's Beijing day at any hour (#322) creditFetcher put the check-in 52s after a sign-up taken from the wall clock, so in the last 52s of a Beijing day it fell on the next day and the usage test read runsOut 4000, not 5000. The sign-up is now noon in Beijing of the same day, so the check-in a minute later can't cross midnight. Test only; the plugin is unchanged, so no version bump. Run: bun test packages/codearts under TZ=UTC, Asia/Shanghai and America/Los_Angeles (sandbox HOME): 109 pass. The new guard test (now 30s and 1ms before Beijing midnight, at it, and at noon) is red with the old fixture (1 fail) and green with the new. bun scripts/check.mjs codearts: ok. --- packages/codearts/index.test.mjs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/codearts/index.test.mjs b/packages/codearts/index.test.mjs index 4ed6c72..e6af26d 100644 --- a/packages/codearts/index.test.mjs +++ b/packages/codearts/index.test.mjs @@ -404,8 +404,10 @@ const day = 86_400_000 const iso = (ms) => new Date(ms).toISOString() function creditFetcher(now = Date.now()) { const planEnd = now + 31 * day - const signUp = now + 30 * day - const checkin = signUp + 52_000 // the same Beijing day, a minute later + // Noon in Beijing, so the check-in a minute later is the same Beijing day + // whatever the wall clock (#322). + const signUp = Math.floor((now + 30 * day + 8 * 3600_000) / day) * day + 4 * 3600_000 + const checkin = signUp + 52_000 const ok = (data) => new Response(JSON.stringify({ code: 0, message: "ok", data }), { status: 200 }) const fetcher = async (url, init) => { const u = String(url) @@ -434,6 +436,16 @@ function creditFetcher(now = Date.now()) { return { fetcher, planEnd, signUp, checkin } } +test("the credit fixture's check-in is its sign-up's Beijing day at any hour (#322)", () => { + const bj = (ms) => new Date(ms + 8 * 3600_000).toISOString().slice(0, 10) + const midnight = Date.parse("2026-10-24T16:00:00Z") // 00:00 in Beijing + for (const now of [midnight - 30_000, midnight - 1, midnight, midnight + 12 * 3600_000]) { + const { signUp, checkin, planEnd } = creditFetcher(now) + assert.equal(bj(checkin), bj(signUp)) + assert.ok(signUp > now && checkin < planEnd) + } +}) + test("fetchCreditBatches reads every batch with its own expiry, signed", async () => { const { fetcher, planEnd, signUp, checkin } = creditFetcher() const seen = []