mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 16:41:23 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -29,6 +29,13 @@ vi.mock("../runtime.js", () => ({
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
|
||||
type CronUpdatePatch = {
|
||||
patch?: {
|
||||
payload?: { message?: string };
|
||||
delivery?: { mode?: string; channel?: string; to?: string; bestEffort?: boolean };
|
||||
};
|
||||
};
|
||||
|
||||
function buildProgram() {
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
@@ -36,6 +43,14 @@ function buildProgram() {
|
||||
return program;
|
||||
}
|
||||
|
||||
async function runCronEditAndGetPatch(editArgs: string[]): Promise<CronUpdatePatch> {
|
||||
callGatewayFromCli.mockClear();
|
||||
const program = buildProgram();
|
||||
await program.parseAsync(["cron", "edit", "job-1", ...editArgs], { from: "user" });
|
||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
||||
return (updateCall?.[2] ?? {}) as CronUpdatePatch;
|
||||
}
|
||||
|
||||
describe("cron cli", () => {
|
||||
it("trims model and thinking on cron add", { timeout: 60_000 }, async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
@@ -347,34 +362,15 @@ describe("cron cli", () => {
|
||||
});
|
||||
|
||||
it("includes delivery fields when explicitly provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const program = buildProgram();
|
||||
|
||||
// Update message AND delivery - should include both
|
||||
await program.parseAsync(
|
||||
[
|
||||
"cron",
|
||||
"edit",
|
||||
"job-1",
|
||||
"--message",
|
||||
"Updated message",
|
||||
"--deliver",
|
||||
"--channel",
|
||||
"telegram",
|
||||
"--to",
|
||||
"19098680",
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
||||
const patch = updateCall?.[2] as {
|
||||
patch?: {
|
||||
payload?: { message?: string };
|
||||
delivery?: { mode?: string; channel?: string; to?: string };
|
||||
};
|
||||
};
|
||||
const patch = await runCronEditAndGetPatch([
|
||||
"--message",
|
||||
"Updated message",
|
||||
"--deliver",
|
||||
"--channel",
|
||||
"telegram",
|
||||
"--to",
|
||||
"19098680",
|
||||
]);
|
||||
|
||||
// Should include everything
|
||||
expect(patch?.patch?.payload?.message).toBe("Updated message");
|
||||
@@ -384,22 +380,11 @@ describe("cron cli", () => {
|
||||
});
|
||||
|
||||
it("includes best-effort delivery when provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--message", "Updated message", "--best-effort-deliver"],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
||||
const patch = updateCall?.[2] as {
|
||||
patch?: {
|
||||
payload?: { message?: string };
|
||||
delivery?: { bestEffort?: boolean; mode?: string };
|
||||
};
|
||||
};
|
||||
const patch = await runCronEditAndGetPatch([
|
||||
"--message",
|
||||
"Updated message",
|
||||
"--best-effort-deliver",
|
||||
]);
|
||||
|
||||
expect(patch?.patch?.payload?.message).toBe("Updated message");
|
||||
expect(patch?.patch?.delivery?.mode).toBe("announce");
|
||||
@@ -407,22 +392,11 @@ describe("cron cli", () => {
|
||||
});
|
||||
|
||||
it("includes no-best-effort delivery when provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--message", "Updated message", "--no-best-effort-deliver"],
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const updateCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.update");
|
||||
const patch = updateCall?.[2] as {
|
||||
patch?: {
|
||||
payload?: { message?: string };
|
||||
delivery?: { bestEffort?: boolean; mode?: string };
|
||||
};
|
||||
};
|
||||
const patch = await runCronEditAndGetPatch([
|
||||
"--message",
|
||||
"Updated message",
|
||||
"--no-best-effort-deliver",
|
||||
]);
|
||||
|
||||
expect(patch?.patch?.payload?.message).toBe("Updated message");
|
||||
expect(patch?.patch?.delivery?.mode).toBe("announce");
|
||||
|
||||
Reference in New Issue
Block a user