test(cron): relax event assertions for context keys

This commit is contained in:
Peter Steinberger
2026-02-15 03:53:49 +00:00
parent f1a76e1a36
commit 9db2ebed00
6 changed files with 52 additions and 27 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();

View File

@@ -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",

View File

@@ -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 });

View File

@@ -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();