| import { describe, expect, it } from "vitest"; |
| import type { CronJob } from "../../cron/types.js"; |
| import type { RuntimeEnv } from "../../runtime.js"; |
| import { printCronList } from "./shared.js"; |
|
|
| describe("printCronList", () => { |
| it("handles job with undefined sessionTarget (#9649)", () => { |
| const logs: string[] = []; |
| const mockRuntime = { |
| log: (msg: string) => logs.push(msg), |
| error: () => {}, |
| exit: () => {}, |
| } as RuntimeEnv; |
|
|
| |
| const jobWithUndefinedTarget = { |
| id: "test-job-id", |
| agentId: "main", |
| name: "Test Job", |
| enabled: true, |
| createdAtMs: Date.now(), |
| updatedAtMs: Date.now(), |
| schedule: { kind: "at", at: new Date(Date.now() + 3600000).toISOString() }, |
| |
| wakeMode: "next-heartbeat", |
| payload: { kind: "systemEvent", text: "test" }, |
| state: { nextRunAtMs: Date.now() + 3600000 }, |
| } as CronJob; |
|
|
| |
| expect(() => printCronList([jobWithUndefinedTarget], mockRuntime)).not.toThrow(); |
|
|
| |
| expect(logs.length).toBeGreaterThan(1); |
| expect(logs.some((line) => line.includes("test-job-id"))).toBe(true); |
| }); |
|
|
| it("handles job with defined sessionTarget", () => { |
| const logs: string[] = []; |
| const mockRuntime = { |
| log: (msg: string) => logs.push(msg), |
| error: () => {}, |
| exit: () => {}, |
| } as RuntimeEnv; |
|
|
| const jobWithTarget: CronJob = { |
| id: "test-job-id-2", |
| agentId: "main", |
| name: "Test Job 2", |
| enabled: true, |
| createdAtMs: Date.now(), |
| updatedAtMs: Date.now(), |
| schedule: { kind: "at", at: new Date(Date.now() + 3600000).toISOString() }, |
| sessionTarget: "isolated", |
| wakeMode: "next-heartbeat", |
| payload: { kind: "systemEvent", text: "test" }, |
| state: { nextRunAtMs: Date.now() + 3600000 }, |
| }; |
|
|
| expect(() => printCronList([jobWithTarget], mockRuntime)).not.toThrow(); |
| expect(logs.some((line) => line.includes("isolated"))).toBe(true); |
| }); |
| }); |
|
|