mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test(cron): relax event assertions for context keys
This commit is contained in:
@@ -84,7 +84,10 @@ describe("CronService delivery plan consistency", () => {
|
||||
|
||||
const result = await cron.run(job.id, "force");
|
||||
expect(result).toEqual({ ok: true, ran: true });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("Cron: done", { agentId: undefined });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"Cron: done",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
|
||||
@@ -72,7 +72,10 @@ describe("CronService interval/cron jobs fire on time", () => {
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
const updated = jobs.find((current) => current.id === job.id);
|
||||
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("tick", { agentId: undefined });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"tick",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(updated?.state.lastStatus).toBe("ok");
|
||||
// nextRunAtMs must advance by at least one full interval past the due time.
|
||||
expect(updated?.state.nextRunAtMs).toBeGreaterThanOrEqual(firstDueAt + 10_000);
|
||||
@@ -120,7 +123,10 @@ describe("CronService interval/cron jobs fire on time", () => {
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
const updated = jobs.find((current) => current.id === job.id);
|
||||
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("cron-tick", { agentId: undefined });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"cron-tick",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(updated?.state.lastStatus).toBe("ok");
|
||||
// nextRunAtMs should be the next whole-minute boundary (60s later).
|
||||
expect(updated?.state.nextRunAtMs).toBe(firstDueAt + 60_000);
|
||||
|
||||
@@ -110,9 +110,10 @@ describe("#16156: cron.list() must not silently advance past-due recurring jobs"
|
||||
const updated = jobs.find((j) => j.id === job.id);
|
||||
|
||||
// Job must have actually executed.
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("cron-tick", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"cron-tick",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(updated?.state.lastStatus).toBe("ok");
|
||||
// nextRunAtMs must advance to a future minute boundary after execution.
|
||||
expect(updated?.state.nextRunAtMs).toBeGreaterThan(firstDueAt);
|
||||
@@ -164,9 +165,10 @@ describe("#16156: cron.list() must not silently advance past-due recurring jobs"
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
const updated = jobs.find((j) => j.id === job.id);
|
||||
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("tick-5", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"tick-5",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(updated?.state.lastStatus).toBe("ok");
|
||||
|
||||
cron.stop();
|
||||
|
||||
@@ -118,7 +118,10 @@ describe("Cron issue regressions", () => {
|
||||
const result = await cron.run(forceNow.id, "force");
|
||||
|
||||
expect(result).toEqual({ ok: true, ran: true });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("force", { agentId: undefined });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"force",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
|
||||
const job = await cron.add({
|
||||
name: "isolated",
|
||||
|
||||
@@ -85,7 +85,10 @@ describe("CronService restart catch-up", () => {
|
||||
|
||||
await cron.start();
|
||||
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("digest now", { agentId: undefined });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"digest now",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(requestHeartbeatNow).toHaveBeenCalled();
|
||||
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
|
||||
@@ -94,9 +94,10 @@ describe("CronService", () => {
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
const updated = jobs.find((j) => j.id === job.id);
|
||||
expect(updated?.enabled).toBe(false);
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("hello", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"hello",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(requestHeartbeatNow).toHaveBeenCalled();
|
||||
|
||||
await cron.list({ includeDisabled: true });
|
||||
@@ -137,9 +138,10 @@ describe("CronService", () => {
|
||||
|
||||
const jobs = await cron.list({ includeDisabled: true });
|
||||
expect(jobs.find((j) => j.id === job.id)).toBeUndefined();
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("hello", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"hello",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(requestHeartbeatNow).toHaveBeenCalled();
|
||||
|
||||
cron.stop();
|
||||
@@ -197,9 +199,10 @@ describe("CronService", () => {
|
||||
|
||||
expect(runHeartbeatOnce).toHaveBeenCalledTimes(1);
|
||||
expect(requestHeartbeatNow).not.toHaveBeenCalled();
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("hello", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"hello",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(job.state.runningAtMs).toBeTypeOf("number");
|
||||
|
||||
resolveHeartbeat?.({ status: "ran", durationMs: 123 });
|
||||
@@ -252,7 +255,10 @@ describe("CronService", () => {
|
||||
}),
|
||||
);
|
||||
expect(requestHeartbeatNow).not.toHaveBeenCalled();
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("hello", { agentId: "ops" });
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"hello",
|
||||
expect.objectContaining({ agentId: "ops" }),
|
||||
);
|
||||
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
@@ -347,9 +353,10 @@ describe("CronService", () => {
|
||||
(evt) => evt.jobId === job.id && evt.action === "finished" && evt.status === "ok",
|
||||
);
|
||||
expect(runIsolatedAgentJob).toHaveBeenCalledTimes(1);
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("Cron: done", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"Cron: done",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(requestHeartbeatNow).toHaveBeenCalled();
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
@@ -545,9 +552,10 @@ describe("CronService", () => {
|
||||
(evt) => evt.jobId === job.id && evt.action === "finished" && evt.status === "error",
|
||||
);
|
||||
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith("Cron (error): last output", {
|
||||
agentId: undefined,
|
||||
});
|
||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||
"Cron (error): last output",
|
||||
expect.objectContaining({ agentId: undefined }),
|
||||
);
|
||||
expect(requestHeartbeatNow).toHaveBeenCalled();
|
||||
cron.stop();
|
||||
await store.cleanup();
|
||||
|
||||
Reference in New Issue
Block a user