mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 16:30:36 +00:00
refactor(test): centralize trigger and cron test helpers
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createMockCronStateForJobs } from "./service.test-harness.js";
|
||||
import { recomputeNextRuns, recomputeNextRunsForMaintenance } from "./service/jobs.js";
|
||||
import type { CronServiceState } from "./service/state.js";
|
||||
import type { CronJob } from "./types.js";
|
||||
|
||||
/**
|
||||
@@ -19,32 +19,6 @@ describe("issue #17852 - daily cron jobs should not skip days", () => {
|
||||
const HOUR_MS = 3_600_000;
|
||||
const DAY_MS = 24 * HOUR_MS;
|
||||
|
||||
function createMockState(jobs: CronJob[], nowMs: number): CronServiceState {
|
||||
return {
|
||||
store: { version: 1, jobs },
|
||||
running: false,
|
||||
timer: null,
|
||||
storeLoadedAtMs: nowMs,
|
||||
storeFileMtimeMs: null,
|
||||
op: Promise.resolve(),
|
||||
warnedDisabled: false,
|
||||
deps: {
|
||||
storePath: "/mock/path",
|
||||
cronEnabled: true,
|
||||
nowMs: () => nowMs,
|
||||
enqueueSystemEvent: () => {},
|
||||
requestHeartbeatNow: () => {},
|
||||
runIsolatedAgentJob: async () => ({ status: "ok" }),
|
||||
log: {
|
||||
debug: () => {},
|
||||
info: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
} as never,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createDailyThreeAmJob(threeAM: number): CronJob {
|
||||
return {
|
||||
id: "daily-job",
|
||||
@@ -71,7 +45,7 @@ describe("issue #17852 - daily cron jobs should not skip days", () => {
|
||||
|
||||
const job = createDailyThreeAmJob(threeAM);
|
||||
|
||||
const state = createMockState([job], now);
|
||||
const state = createMockCronStateForJobs({ jobs: [job], nowMs: now });
|
||||
recomputeNextRunsForMaintenance(state);
|
||||
|
||||
// Maintenance should NOT touch existing past-due nextRunAtMs.
|
||||
@@ -88,7 +62,7 @@ describe("issue #17852 - daily cron jobs should not skip days", () => {
|
||||
|
||||
const job = createDailyThreeAmJob(threeAM);
|
||||
|
||||
const state = createMockState([job], now);
|
||||
const state = createMockCronStateForJobs({ jobs: [job], nowMs: now });
|
||||
recomputeNextRuns(state);
|
||||
|
||||
// The full recomputeNextRuns advances it to TOMORROW — skipping today's
|
||||
|
||||
Reference in New Issue
Block a user