mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:21:35 +00:00
test(cli): dedupe cron add/edit assertion harness
This commit is contained in:
@@ -42,6 +42,15 @@ type CronUpdatePatch = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CronAddParams = {
|
||||||
|
schedule?: { kind?: string; staggerMs?: number };
|
||||||
|
payload?: { model?: string; thinking?: string };
|
||||||
|
delivery?: { mode?: string };
|
||||||
|
deleteAfterRun?: boolean;
|
||||||
|
agentId?: string;
|
||||||
|
sessionTarget?: string;
|
||||||
|
};
|
||||||
|
|
||||||
function buildProgram() {
|
function buildProgram() {
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
program.exitOverride();
|
program.exitOverride();
|
||||||
@@ -62,6 +71,14 @@ async function runCronEditAndGetPatch(editArgs: string[]): Promise<CronUpdatePat
|
|||||||
return (updateCall?.[2] ?? {}) as CronUpdatePatch;
|
return (updateCall?.[2] ?? {}) as CronUpdatePatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runCronAddAndGetParams(addArgs: string[]): Promise<CronAddParams> {
|
||||||
|
resetGatewayMock();
|
||||||
|
const program = buildProgram();
|
||||||
|
await program.parseAsync(["cron", "add", ...addArgs], { from: "user" });
|
||||||
|
const addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
|
||||||
|
return (addCall?.[2] ?? {}) as CronAddParams;
|
||||||
|
}
|
||||||
|
|
||||||
describe("cron cli", () => {
|
describe("cron cli", () => {
|
||||||
it("trims model and thinking on cron add", { timeout: 60_000 }, async () => {
|
it("trims model and thinking on cron add", { timeout: 60_000 }, async () => {
|
||||||
resetGatewayMock();
|
resetGatewayMock();
|
||||||
@@ -208,48 +225,28 @@ describe("cron cli", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("omits empty model and thinking on cron edit", async () => {
|
it("omits empty model and thinking on cron edit", async () => {
|
||||||
resetGatewayMock();
|
const patch = await runCronEditAndGetPatch([
|
||||||
|
"--message",
|
||||||
const program = buildProgram();
|
"hello",
|
||||||
|
"--model",
|
||||||
await program.parseAsync(
|
" ",
|
||||||
["cron", "edit", "job-1", "--message", "hello", "--model", " ", "--thinking", " "],
|
"--thinking",
|
||||||
{ from: "user" },
|
" ",
|
||||||
);
|
]);
|
||||||
|
|
||||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
|
||||||
const patch = updateCall?.[2] as {
|
|
||||||
patch?: { payload?: { model?: string; thinking?: string } };
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(patch?.patch?.payload?.model).toBeUndefined();
|
expect(patch?.patch?.payload?.model).toBeUndefined();
|
||||||
expect(patch?.patch?.payload?.thinking).toBeUndefined();
|
expect(patch?.patch?.payload?.thinking).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("trims model and thinking on cron edit", async () => {
|
it("trims model and thinking on cron edit", async () => {
|
||||||
resetGatewayMock();
|
const patch = await runCronEditAndGetPatch([
|
||||||
|
|
||||||
const program = buildProgram();
|
|
||||||
|
|
||||||
await program.parseAsync(
|
|
||||||
[
|
|
||||||
"cron",
|
|
||||||
"edit",
|
|
||||||
"job-1",
|
|
||||||
"--message",
|
"--message",
|
||||||
"hello",
|
"hello",
|
||||||
"--model",
|
"--model",
|
||||||
" opus ",
|
" opus ",
|
||||||
"--thinking",
|
"--thinking",
|
||||||
" high ",
|
" high ",
|
||||||
],
|
]);
|
||||||
{ from: "user" },
|
|
||||||
);
|
|
||||||
|
|
||||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
|
||||||
const patch = updateCall?.[2] as {
|
|
||||||
patch?: { payload?: { model?: string; thinking?: string } };
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(patch?.patch?.payload?.model).toBe("opus");
|
expect(patch?.patch?.payload?.model).toBe("opus");
|
||||||
expect(patch?.patch?.payload?.thinking).toBe("high");
|
expect(patch?.patch?.payload?.thinking).toBe("high");
|
||||||
@@ -415,13 +412,7 @@ describe("cron cli", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("sets explicit stagger for cron add", async () => {
|
it("sets explicit stagger for cron add", async () => {
|
||||||
resetGatewayMock();
|
const params = await runCronAddAndGetParams([
|
||||||
const program = buildProgram();
|
|
||||||
|
|
||||||
await program.parseAsync(
|
|
||||||
[
|
|
||||||
"cron",
|
|
||||||
"add",
|
|
||||||
"--name",
|
"--name",
|
||||||
"staggered",
|
"staggered",
|
||||||
"--cron",
|
"--cron",
|
||||||
@@ -432,24 +423,13 @@ describe("cron cli", () => {
|
|||||||
"main",
|
"main",
|
||||||
"--system-event",
|
"--system-event",
|
||||||
"tick",
|
"tick",
|
||||||
],
|
]);
|
||||||
{ from: "user" },
|
|
||||||
);
|
|
||||||
|
|
||||||
const addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
|
|
||||||
const params = addCall?.[2] as { schedule?: { kind?: string; staggerMs?: number } };
|
|
||||||
expect(params?.schedule?.kind).toBe("cron");
|
expect(params?.schedule?.kind).toBe("cron");
|
||||||
expect(params?.schedule?.staggerMs).toBe(45_000);
|
expect(params?.schedule?.staggerMs).toBe(45_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets exact cron mode on add", async () => {
|
it("sets exact cron mode on add", async () => {
|
||||||
resetGatewayMock();
|
const params = await runCronAddAndGetParams([
|
||||||
const program = buildProgram();
|
|
||||||
|
|
||||||
await program.parseAsync(
|
|
||||||
[
|
|
||||||
"cron",
|
|
||||||
"add",
|
|
||||||
"--name",
|
"--name",
|
||||||
"exact",
|
"exact",
|
||||||
"--cron",
|
"--cron",
|
||||||
@@ -459,12 +439,7 @@ describe("cron cli", () => {
|
|||||||
"main",
|
"main",
|
||||||
"--system-event",
|
"--system-event",
|
||||||
"tick",
|
"tick",
|
||||||
],
|
]);
|
||||||
{ from: "user" },
|
|
||||||
);
|
|
||||||
|
|
||||||
const addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
|
|
||||||
const params = addCall?.[2] as { schedule?: { kind?: string; staggerMs?: number } };
|
|
||||||
expect(params?.schedule?.kind).toBe("cron");
|
expect(params?.schedule?.kind).toBe("cron");
|
||||||
expect(params?.schedule?.staggerMs).toBe(0);
|
expect(params?.schedule?.staggerMs).toBe(0);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user