test(cron): add Asia/Shanghai year-regression coverage [AI-assisted] (openclaw#30565) thanks @liuxiaopai-ai

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: liuxiaopai-ai <73659136+liuxiaopai-ai@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
Mark L
2026-03-02 09:46:06 +08:00
committed by GitHub
parent 65e13c7b6e
commit e076665e5e
2 changed files with 15 additions and 0 deletions

View File

@@ -13,6 +13,20 @@ describe("cron schedule", () => {
expect(next).toBe(Date.parse("2025-12-17T17:00:00.000Z"));
});
it("does not roll back year for Asia/Shanghai daily cron schedules (#30351)", () => {
// 2026-03-01 08:00:00 in Asia/Shanghai
const nowMs = Date.parse("2026-03-01T00:00:00.000Z");
const next = computeNextRunAtMs(
{ kind: "cron", expr: "0 8 * * *", tz: "Asia/Shanghai" },
nowMs,
);
// Next 08:00 local should be the following day, not a past year.
expect(next).toBe(Date.parse("2026-03-02T00:00:00.000Z"));
expect(next).toBeGreaterThan(nowMs);
expect(new Date(next ?? 0).getUTCFullYear()).toBe(2026);
});
it("throws a clear error when cron expr is missing at runtime", () => {
const nowMs = Date.parse("2025-12-13T00:00:00.000Z");
expect(() =>