mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 14:40:34 +00:00
cron: separate webhook POST delivery from announce (#17901)
* cron: split webhook delivery from announce mode * cron: validate webhook delivery target * cron: remove legacy webhook fallback config * fix: finalize cron webhook delivery prep (#17901) (thanks @advaitpaliwal) --------- Co-authored-by: Tyler Yust <TYTYYUST@YAHOO.COM>
This commit is contained in:
@@ -30,6 +30,32 @@ describe("applyJobPatch", () => {
|
||||
expect(job.delivery).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps webhook delivery when switching to main session", () => {
|
||||
const now = Date.now();
|
||||
const job: CronJob = {
|
||||
id: "job-webhook",
|
||||
name: "job-webhook",
|
||||
enabled: true,
|
||||
createdAtMs: now,
|
||||
updatedAtMs: now,
|
||||
schedule: { kind: "every", everyMs: 60_000 },
|
||||
sessionTarget: "isolated",
|
||||
wakeMode: "now",
|
||||
payload: { kind: "agentTurn", message: "do it" },
|
||||
delivery: { mode: "webhook", to: "https://example.invalid/cron" },
|
||||
state: {},
|
||||
};
|
||||
|
||||
const patch: CronJobPatch = {
|
||||
sessionTarget: "main",
|
||||
payload: { kind: "systemEvent", text: "ping" },
|
||||
};
|
||||
|
||||
expect(() => applyJobPatch(job, patch)).not.toThrow();
|
||||
expect(job.sessionTarget).toBe("main");
|
||||
expect(job.delivery).toEqual({ mode: "webhook", to: "https://example.invalid/cron" });
|
||||
});
|
||||
|
||||
it("maps legacy payload delivery updates onto delivery", () => {
|
||||
const now = Date.now();
|
||||
const job: CronJob = {
|
||||
@@ -101,23 +127,55 @@ describe("applyJobPatch", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("updates notify via patch", () => {
|
||||
it("rejects webhook delivery without a valid http(s) target URL", () => {
|
||||
const now = Date.now();
|
||||
const job: CronJob = {
|
||||
id: "job-4",
|
||||
name: "job-4",
|
||||
id: "job-webhook-invalid",
|
||||
name: "job-webhook-invalid",
|
||||
enabled: true,
|
||||
notify: false,
|
||||
createdAtMs: now,
|
||||
updatedAtMs: now,
|
||||
schedule: { kind: "every", everyMs: 60_000 },
|
||||
sessionTarget: "isolated",
|
||||
sessionTarget: "main",
|
||||
wakeMode: "now",
|
||||
payload: { kind: "agentTurn", message: "do it" },
|
||||
payload: { kind: "systemEvent", text: "ping" },
|
||||
delivery: { mode: "webhook" },
|
||||
state: {},
|
||||
};
|
||||
|
||||
expect(() => applyJobPatch(job, { notify: true })).not.toThrow();
|
||||
expect(job.notify).toBe(true);
|
||||
expect(() => applyJobPatch(job, { enabled: true })).toThrow(
|
||||
"cron webhook delivery requires delivery.to to be a valid http(s) URL",
|
||||
);
|
||||
expect(() => applyJobPatch(job, { delivery: { mode: "webhook", to: "" } })).toThrow(
|
||||
"cron webhook delivery requires delivery.to to be a valid http(s) URL",
|
||||
);
|
||||
expect(() =>
|
||||
applyJobPatch(job, { delivery: { mode: "webhook", to: "ftp://example.invalid" } }),
|
||||
).toThrow("cron webhook delivery requires delivery.to to be a valid http(s) URL");
|
||||
expect(() => applyJobPatch(job, { delivery: { mode: "webhook", to: "not-a-url" } })).toThrow(
|
||||
"cron webhook delivery requires delivery.to to be a valid http(s) URL",
|
||||
);
|
||||
});
|
||||
|
||||
it("trims webhook delivery target URLs", () => {
|
||||
const now = Date.now();
|
||||
const job: CronJob = {
|
||||
id: "job-webhook-trim",
|
||||
name: "job-webhook-trim",
|
||||
enabled: true,
|
||||
createdAtMs: now,
|
||||
updatedAtMs: now,
|
||||
schedule: { kind: "every", everyMs: 60_000 },
|
||||
sessionTarget: "main",
|
||||
wakeMode: "now",
|
||||
payload: { kind: "systemEvent", text: "ping" },
|
||||
delivery: { mode: "webhook", to: "https://example.invalid/original" },
|
||||
state: {},
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
applyJobPatch(job, { delivery: { mode: "webhook", to: " https://example.invalid/trim " } }),
|
||||
).not.toThrow();
|
||||
expect(job.delivery).toEqual({ mode: "webhook", to: "https://example.invalid/trim" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user