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.
This commit is contained in:
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user