|
1 | 1 | import { ButtonStyle, MessageFlags } from "discord-api-types/v10"; |
| 2 | +import { MAX_DATE_TIMESTAMP_MS } from "openclaw/plugin-sdk/number-runtime"; |
2 | 3 | import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 4 | import type { DiscordComponentEntry, DiscordModalEntry } from "./components.js"; |
4 | 5 | |
@@ -379,6 +380,36 @@ describe("discord component registry", () => {
|
379 | 380 | second.clearDiscordComponentEntries(); |
380 | 381 | }); |
381 | 382 | |
| 383 | +it("expires component entries registered while the process clock is invalid", () => { |
| 384 | +const dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(Number.NaN); |
| 385 | +try { |
| 386 | +registerDiscordComponentEntries({ |
| 387 | +entries: [{ id: "btn_invalid_clock", kind: "button", label: "Invalid clock" }], |
| 388 | +modals: [], |
| 389 | +ttlMs: 1000, |
| 390 | +}); |
| 391 | + |
| 392 | +expect(resolveDiscordComponentEntry({ id: "btn_invalid_clock", consume: false })).toBeNull(); |
| 393 | +} finally { |
| 394 | +dateNowSpy.mockRestore(); |
| 395 | +} |
| 396 | +}); |
| 397 | + |
| 398 | +it("expires component entries whose calculated expiry exceeds the Date range", () => { |
| 399 | +const dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(MAX_DATE_TIMESTAMP_MS); |
| 400 | +try { |
| 401 | +registerDiscordComponentEntries({ |
| 402 | +entries: [{ id: "btn_overflow", kind: "button", label: "Overflow" }], |
| 403 | +modals: [], |
| 404 | +ttlMs: 1000, |
| 405 | +}); |
| 406 | +} finally { |
| 407 | +dateNowSpy.mockRestore(); |
| 408 | +} |
| 409 | + |
| 410 | +expect(resolveDiscordComponentEntry({ id: "btn_overflow", consume: false })).toBeNull(); |
| 411 | +}); |
| 412 | + |
382 | 413 | it("persists component and modal entries when runtime state is available", async () => { |
383 | 414 | const componentRegister = vi.fn().mockResolvedValue(undefined); |
384 | 415 | const modalRegister = vi.fn().mockResolvedValue(undefined); |
|