Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: reject unrepresentable one-time routine dates
Afloat9859d7dc67c9
diff --git a/server/routine-once-range.test.ts b/server/routine-once-range.test.tsnew file mode 100644index 0000000000..8282c90599--- /dev/null+++ b/server/routine-once-range.test.ts@@ -0,0 +1,29 @@+import { describe, expect, it } from "vitest";++import { formatInstant } from "./routine-cron-text.ts";+import { MAX_DATE_MS } from "./routine-intervals.ts";+import { cleanSchedule, loadSchedule, nextOccurrence, type RoutineScheduleInput } from "./routine-schedules.ts";++describe("one-time schedules with representable dates", () => {+ it.each([MAX_DATE_MS + 1, -MAX_DATE_MS - 1, 1e100, -1e100])("rejects the finite but unrepresentable timestamp %s", (at) => {+ expect(() => cleanSchedule({ type: "once", at }, 0)).toThrow("Choose a valid date and time");+ expect(loadSchedule({ type: "once", at }, 0)).toBeNull();+ });++ it("rejects an out-of-range numeric string accepted by the input coercion", () => {+ expect(() => cleanSchedule({ type: "once", at: "1e100" } as unknown as RoutineScheduleInput, 0))+ .toThrow("Choose a valid date and time");+ });++ it.each([-MAX_DATE_MS, 0, Date.parse("2026-11-12T10:00:00Z"), MAX_DATE_MS])("keeps the valid timestamp %s displayable", (at) => {+ const schedule = cleanSchedule({ type: "once", at }, at - 1);+ expect(schedule).toEqual({ type: "once", at });+ expect(nextOccurrence(schedule, at - 1)).toBe(at);+ expect(() => formatInstant(at, "UTC")).not.toThrow();+ });++ it("keeps numeric-string compatibility for a valid timestamp", () => {+ const at = Date.parse("2026-11-12T10:00:00Z");+ expect(cleanSchedule({ type: "once", at: String(at) } as unknown as RoutineScheduleInput, 0)).toEqual({ type: "once", at });+ });+});diff --git a/server/routine-schedules.ts b/server/routine-schedules.tsindex 5951640da1..80a880a4c8 100644--- a/server/routine-schedules.ts+++ b/server/routine-schedules.ts@@ -121,7 +121,7 @@ function parseSchedule(schedule: RoutineScheduleInput, after: number): RoutineSc}if (schedule?.type === "once") {const at = Number(schedule.at);- if (!Number.isFinite(at)) throw new Error("Choose a valid date and time");+ if (!Number.isFinite(at) || Math.abs(at) > MAX_DATE_MS) throw new Error("Choose a valid date and time");return { type: "once", at };}if (schedule?.type === "daily") {