fix(cron): guard timestamp validation clocks · openclaw/openclaw@e49ef86
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { validateScheduleTimestamp } from "./validate-timestamp.js"; |
| 3 | + |
| 4 | +describe("validateScheduleTimestamp", () => { |
| 5 | +it("falls back instead of throwing for invalid validation clocks", () => { |
| 6 | +vi.useFakeTimers(); |
| 7 | +vi.setSystemTime(new Date("2026-02-23T12:00:00.000Z")); |
| 8 | +try { |
| 9 | +const result = validateScheduleTimestamp( |
| 10 | +{ kind: "at", at: "2026-02-23T11:00:00.000Z" }, |
| 11 | +Number.POSITIVE_INFINITY, |
| 12 | +); |
| 13 | + |
| 14 | +expect(result).toEqual({ |
| 15 | +ok: false, |
| 16 | +message: |
| 17 | +"schedule.at is in the past: 2026-02-23T11:00:00.000Z (60 minutes ago). Current time: 2026-02-23T12:00:00.000Z", |
| 18 | +}); |
| 19 | +} finally { |
| 20 | +vi.useRealTimers(); |
| 21 | +} |
| 22 | +}); |
| 23 | + |
| 24 | +it("rejects at timestamps more than ten years ahead", () => { |
| 25 | +const result = validateScheduleTimestamp( |
| 26 | +{ kind: "at", at: "2037-01-01T00:00:00.000Z" }, |
| 27 | +Date.parse("2026-01-01T00:00:00.000Z"), |
| 28 | +); |
| 29 | + |
| 30 | +expect(result.ok).toBe(false); |
| 31 | +if (!result.ok) { |
| 32 | +expect(result.message).toContain("schedule.at is too far in the future"); |
| 33 | +expect(result.message).toContain("2037-01-01T00:00:00.000Z"); |
| 34 | +} |
| 35 | +}); |
| 36 | +}); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。