it("session reaper runs even when job execution throws", async () => { const store = await makeStorePath(); const now = Date.parse("2026-02-10T10:00:00.000Z");
// Write a store with a due job that will trigger execution.
await fs.mkdir(path.dirname(store.storePath), { recursive: true });
await fs.writeFile(
store.storePath,
JSON.stringify({
version: 1,
jobs: [createDueIsolatedJob({ id: "failing-job", nowMs: now })],
}), "utf-8",
);
// Create a mock sessionStorePath to track if the reaper is called. const sessionStorePath = path.join(path.dirname(store.storePath), "sessions", "sessions.json");
const state = createCronServiceState({
storePath: store.storePath,
cronEnabled: true,
log: noopLogger,
nowMs: () => now,
enqueueSystemEvent: vi.fn(),
requestHeartbeatNow: vi.fn(), // This will throw, simulating a failure during job execution.
runIsolatedAgentJob: vi.fn().mockRejectedValue(new Error("gateway down")),
sessionStorePath,
});
// After onTimer finishes (even with a job error), state.running must be // false — proving the finally block executed.
expect(state.running).toBe(false);
// The timer must be re-armed.
expect(state.timer).not.toBeNull();
});
});
it("session reaper runs when resolveSessionStorePath is provided", async () => { const store = await makeStorePath(); const now = Date.parse("2026-02-10T10:00:00.000Z");
// The resolveSessionStorePath callback should have been invoked to build // the set of store paths for the session reaper.
expect(resolvedPaths.length).toBeGreaterThan(0);
expect(state.running).toBe(false);
});
});
it("prunes expired cron-run sessions even when cron store load throws", async () => { const store = await makeStorePath(); const now = Date.parse("2026-02-10T10:00:00.000Z"); const sessionStorePath = path.join(path.dirname(store.storePath), "sessions", "sessions.json");
// Force onTimer's try-block to throw before normal execution flow.
await fs.mkdir(path.dirname(store.storePath), { recursive: true });
await fs.writeFile(store.storePath, "{invalid-json", "utf-8");
// Seed an expired cron-run session entry that should be pruned by the reaper.
await fs.mkdir(path.dirname(sessionStorePath), { recursive: true });
await fs.writeFile(
sessionStorePath,
JSON.stringify({ "agent:agent-default:cron:failing-job:run:stale": {
sessionId: "session-stale",
updatedAt: now - 3 * 24 * 3_600_000,
},
}), "utf-8",
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.