@@ -14,11 +14,9 @@ import {
1414 saveCronStore ,
1515} from "../../../cron/store.js" ;
1616import { runOpenClawStateWriteTransaction } from "../../../state/openclaw-state-db.js" ;
17- import { resolveOpenClawStateSqlitePath } from "../../../state/openclaw-state-db.paths.js" ;
1817import { withRestoredMocks } from "../../../test-utils/vitest-spies.js" ;
1918import {
2019 collectLegacyCronStoreHealthFindings ,
21- collectLegacyCronStoreRepairEffects ,
2220 collectLegacyWhatsAppCrontabHealthWarning ,
2321 maybeRepairLegacyCronStore ,
2422 noteLegacyWhatsAppCrontabHealthCheck ,
@@ -302,146 +300,6 @@ describe("collectLegacyCronStoreHealthFindings", () => {
302300 } ) ;
303301} ) ;
304302
305- describe ( "collectLegacyCronStoreRepairEffects" , ( ) => {
306- it ( "does not create the shared state database while previewing legacy cron state" , async ( ) => {
307- const storePath = await makeTempStorePath ( ) ;
308- const stateDir = path . join ( path . dirname ( storePath ) , "state-root" ) ;
309- vi . stubEnv ( "OPENCLAW_STATE_DIR" , stateDir ) ;
310- const stateDbPath = resolveOpenClawStateSqlitePath ( { OPENCLAW_STATE_DIR : stateDir } ) ;
311- await writeLegacyCronArrayStore ( storePath , [ createLegacyCronJob ( ) ] ) ;
312-
313- await expect (
314- collectLegacyCronStoreHealthFindings ( { cfg : createCronConfig ( storePath ) } ) ,
315- ) . resolves . toEqual (
316- expect . arrayContaining ( [
317- expect . objectContaining ( {
318- checkId : "core/doctor/legacy-cron-store" ,
319- requirement : "legacy-cron-store" ,
320- } ) ,
321- ] ) ,
322- ) ;
323- await expect (
324- collectLegacyCronStoreRepairEffects ( { cfg : createCronConfig ( storePath ) } ) ,
325- ) . resolves . toEqual (
326- expect . arrayContaining ( [
327- expect . objectContaining ( {
328- action : "would-migrate-legacy-cron-store" ,
329- target : storePath ,
330- } ) ,
331- ] ) ,
332- ) ;
333-
334- expect ( fsSync . existsSync ( stateDbPath ) ) . toBe ( false ) ;
335- } ) ;
336-
337- it ( "previews legacy cron store repair effects without mutating files" , async ( ) => {
338- const storePath = await makeTempStorePath ( ) ;
339- await writeLegacyCronArrayStore ( storePath , [
340- createLegacyCronJob ( {
341- jobId : "legacy-notify" ,
342- payload : {
343- kind : "systemEvent" ,
344- text : "Morning brief" ,
345- } ,
346- } ) ,
347- ] ) ;
348- const runLogPath = path . join ( path . dirname ( storePath ) , "runs" , "legacy-notify.jsonl" ) ;
349- await fs . mkdir ( path . dirname ( runLogPath ) , { recursive : true } ) ;
350- await fs . writeFile ( runLogPath , "" , "utf-8" ) ;
351-
352- const effects = await collectLegacyCronStoreRepairEffects ( {
353- cfg : createCronConfig ( storePath ) ,
354- } ) ;
355-
356- expect ( effects ) . toEqual (
357- expect . arrayContaining ( [
358- expect . objectContaining ( {
359- kind : "state" ,
360- action : "would-migrate-legacy-cron-store" ,
361- target : storePath ,
362- dryRunSafe : false ,
363- } ) ,
364- expect . objectContaining ( {
365- kind : "state" ,
366- action : "would-import-legacy-cron-run-logs" ,
367- target : path . join ( path . dirname ( storePath ) , "runs" ) ,
368- dryRunSafe : false ,
369- } ) ,
370- expect . objectContaining ( {
371- kind : "state" ,
372- action : "would-normalize-cron-store" ,
373- target : storePath ,
374- dryRunSafe : false ,
375- } ) ,
376- expect . objectContaining ( {
377- kind : "state" ,
378- action : "would-migrate-legacy-cron-notify-fallback" ,
379- target : storePath ,
380- dryRunSafe : false ,
381- } ) ,
382- ] ) ,
383- ) ;
384- await expect ( fs . readFile ( storePath , "utf-8" ) ) . resolves . toContain ( "legacy-notify" ) ;
385- await expect ( fs . stat ( runLogPath ) ) . resolves . toBeDefined ( ) ;
386- } ) ;
387-
388- it ( "previews quarantine and dreaming payload rewrite effects" , async ( ) => {
389- const storePath = await makeTempStorePath ( ) ;
390- await writeCronStore ( storePath , [
391- { id : "invalid-cron" , name : "Invalid cron" , payload : { kind : "systemEvent" } } ,
392- {
393- id : "memory-dreaming" ,
394- name : "Memory Dreaming Promotion" ,
395- description :
396- "[managed-by=memory-core.short-term-promotion] Promote weighted short-term recalls." ,
397- enabled : true ,
398- createdAtMs : Date . parse ( "2026-04-01T00:00:00.000Z" ) ,
399- updatedAtMs : Date . parse ( "2026-04-01T00:00:00.000Z" ) ,
400- schedule : { kind : "cron" , expr : "0 3 * * *" , tz : "UTC" } ,
401- sessionTarget : "main" ,
402- wakeMode : "now" ,
403- payload : {
404- kind : "systemEvent" ,
405- text : "__openclaw_memory_core_short_term_promotion_dream__" ,
406- } ,
407- state : { } ,
408- } ,
409- ] ) ;
410-
411- const effects = await collectLegacyCronStoreRepairEffects ( {
412- cfg : createCronConfig ( storePath ) ,
413- } ) ;
414-
415- expect ( effects ) . toEqual (
416- expect . arrayContaining ( [
417- expect . objectContaining ( {
418- action : "would-quarantine-invalid-cron-jobs" ,
419- target : resolveCronQuarantinePath ( storePath ) ,
420- } ) ,
421- expect . objectContaining ( {
422- action : "would-normalize-cron-store" ,
423- target : storePath ,
424- } ) ,
425- expect . objectContaining ( {
426- action : "would-rewrite-legacy-dreaming-cron-payload" ,
427- target : storePath ,
428- } ) ,
429- ] ) ,
430- ) ;
431- await expect ( fs . readFile ( storePath , "utf-8" ) ) . resolves . toContain ( "invalid-cron" ) ;
432- await expect ( fs . readFile ( storePath , "utf-8" ) ) . resolves . toContain ( "memory-dreaming" ) ;
433- } ) ;
434-
435- it ( "returns no repair effects for an already-normalized empty cron store" , async ( ) => {
436- const storePath = await makeTempStorePath ( ) ;
437- await writeCurrentCronStore ( storePath , [ ] ) ;
438-
439- await expect (
440- collectLegacyCronStoreRepairEffects ( { cfg : createCronConfig ( storePath ) } ) ,
441- ) . resolves . toEqual ( [ ] ) ;
442- } ) ;
443- } ) ;
444-
445303describe ( "maybeRepairLegacyCronStore" , ( ) => {
446304 it ( "reports quarantined cron rows even when the active store is already sanitized" , async ( ) => {
447305 const storePath = await makeTempStorePath ( ) ;
0 commit comments