55 createNoopLogger ,
66 withCronServiceForTest ,
77} from "./service.test-harness.js" ;
8+ import { createCronServiceState } from "./service/state.js" ;
9+ import { executeJobCore } from "./service/timer.js" ;
810import type { CronJob } from "./types.js" ;
911
1012const noopLogger = createNoopLogger ( ) ;
@@ -60,6 +62,39 @@ describe("CronService", () => {
6062 } ) ;
6163
6264 it ( "skips main jobs with empty systemEvent text" , async ( ) => {
65+ const enqueueSystemEvent = vi . fn ( ) ;
66+ const requestHeartbeat = vi . fn ( ) ;
67+ const state = createCronServiceState ( {
68+ cronEnabled : true ,
69+ storePath : "cron-empty-systemevent-test.json" ,
70+ log : noopLogger ,
71+ nowMs : ( ) => Date . now ( ) ,
72+ enqueueSystemEvent,
73+ requestHeartbeat,
74+ runIsolatedAgentJob : vi . fn ( async ( ) => ( { status : "ok" as const } ) ) ,
75+ } ) ;
76+ const job : CronJob = {
77+ id : "empty-systemevent-test" ,
78+ name : "empty systemEvent test" ,
79+ enabled : true ,
80+ schedule : { kind : "at" , at : "2025-12-13T00:00:01.000Z" } ,
81+ sessionTarget : "main" ,
82+ wakeMode : "now" ,
83+ payload : { kind : "systemEvent" , text : " " } ,
84+ createdAtMs : Date . now ( ) ,
85+ updatedAtMs : Date . now ( ) ,
86+ state : { } ,
87+ } ;
88+
89+ const result = await executeJobCore ( state , job ) ;
90+
91+ expect ( result . status ) . toBe ( "skipped" ) ;
92+ expect ( result . error ) . toMatch ( / n o n - e m p t y / i) ;
93+ expect ( enqueueSystemEvent ) . not . toHaveBeenCalled ( ) ;
94+ expect ( requestHeartbeat ) . not . toHaveBeenCalled ( ) ;
95+ } ) ;
96+
97+ it ( "drops persisted main jobs with empty systemEvent text before they run" , async ( ) => {
6398 await withCronService ( true , async ( { cron, enqueueSystemEvent, requestHeartbeat } ) => {
6499 const atMs = Date . parse ( "2025-12-13T00:00:01.000Z" ) ;
65100 await cron . add ( {
@@ -77,9 +112,8 @@ describe("CronService", () => {
77112 expect ( enqueueSystemEvent ) . not . toHaveBeenCalled ( ) ;
78113 expect ( requestHeartbeat ) . not . toHaveBeenCalled ( ) ;
79114
80- const job = await waitForFirstJob ( cron , ( current ) => current ?. state . lastStatus === "skipped" ) ;
81- expect ( job ?. state . lastStatus ) . toBe ( "skipped" ) ;
82- expect ( job ?. state . lastError ) . toMatch ( / n o n - e m p t y / i) ;
115+ const job = await waitForFirstJob ( cron , ( current ) => current === undefined ) ;
116+ expect ( job ) . toBeUndefined ( ) ;
83117 } ) ;
84118 } ) ;
85119
0 commit comments