test(cron): improve fire-and-forget harness coverage

This commit is contained in:
Peter Steinberger
2026-02-22 11:29:15 +00:00
parent c343132dbb
commit 0a758dc710
3 changed files with 63 additions and 61 deletions

View File

@@ -3,6 +3,7 @@ import os from "node:os";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import { CronService } from "./service.js";
import { writeCronStoreSnapshot } from "./service.test-harness.js";
const noopLogger = {
debug: vi.fn(),
@@ -167,29 +168,24 @@ describe("CronService read ops while job is running", () => {
const requestHeartbeatNow = vi.fn();
const nowMs = Date.parse("2025-12-13T00:00:00.000Z");
await fs.mkdir(path.dirname(store.storePath), { recursive: true });
await fs.writeFile(
store.storePath,
JSON.stringify({
version: 1,
jobs: [
{
id: "startup-catchup",
name: "startup catch-up",
enabled: true,
createdAtMs: nowMs - 86_400_000,
updatedAtMs: nowMs - 86_400_000,
schedule: { kind: "at", at: new Date(nowMs - 60_000).toISOString() },
sessionTarget: "isolated",
wakeMode: "next-heartbeat",
payload: { kind: "agentTurn", message: "startup replay" },
delivery: { mode: "none" },
state: { nextRunAtMs: nowMs - 60_000 },
},
],
}),
"utf-8",
);
await writeCronStoreSnapshot({
storePath: store.storePath,
jobs: [
{
id: "startup-catchup",
name: "startup catch-up",
enabled: true,
createdAtMs: nowMs - 86_400_000,
updatedAtMs: nowMs - 86_400_000,
schedule: { kind: "at", at: new Date(nowMs - 60_000).toISOString() },
sessionTarget: "isolated",
wakeMode: "next-heartbeat",
payload: { kind: "agentTurn", message: "startup replay" },
delivery: { mode: "none" },
state: { nextRunAtMs: nowMs - 60_000 },
},
],
});
const isolatedRun = createDeferredIsolatedRun();