fix(cli): set cron run exit code from run outcome (land #31121 by @Sid-Qin)
Landed-from: #31121 Contributor: @Sid-Qin Co-authored-by: Sid <sidqin0410@gmail.com>
This commit is contained in:
@@ -102,6 +102,7 @@ Docs: https://docs.openclaw.ai
|
||||
|
||||
### Fixes
|
||||
|
||||
- CLI/Cron run exit code: return exit code `0` only when `cron run` reports `{ ok: true, ran: true }`, and `1` for non-run/error outcomes so scripting/debugging reflects actual execution status. Landed from contributor PR #31121 by @Sid-Qin. Thanks @Sid-Qin.
|
||||
- Nodes/Screen recording guardrails: cap `nodes` tool `screen_record` `durationMs` to 5 minutes at both schema-validation and runtime invocation layers to prevent long-running blocking captures from unbounded durations. Landed from contributor PR #31106 by @BlueBirdBack. Thanks @BlueBirdBack.
|
||||
- Telegram/Empty final replies: skip outbound send for null/undefined final text payloads without media so Telegram typing indicators do not linger on `text must be non-empty` errors. Landed from contributor PR #30969 by @haosenwang1018. Thanks @haosenwang1018.
|
||||
- Routing/Binding peer-kind parity: treat `peer.kind` `group` and `channel` as equivalent for binding scope matching (while keeping `direct` separate) so Slack/public channel bindings do not silently fall through. Landed from contributor PR #31135 by @Sid-Qin. Thanks @Sid-Qin.
|
||||
|
||||
@@ -151,6 +151,58 @@ async function expectCronEditWithScheduleLookupExit(
|
||||
}
|
||||
|
||||
describe("cron cli", () => {
|
||||
it("exits 0 for cron run when job executes successfully", async () => {
|
||||
resetGatewayMock();
|
||||
callGatewayFromCli.mockImplementation(async (method: string) => {
|
||||
if (method === "cron.status") {
|
||||
return { enabled: true };
|
||||
}
|
||||
if (method === "cron.run") {
|
||||
return { ok: true, ran: true };
|
||||
}
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
const runtimeModule = await import("../runtime.js");
|
||||
const runtime = runtimeModule.defaultRuntime as { exit: (code: number) => void };
|
||||
const originalExit = runtime.exit;
|
||||
const exitSpy = vi.fn();
|
||||
runtime.exit = exitSpy;
|
||||
try {
|
||||
const program = buildProgram();
|
||||
await program.parseAsync(["cron", "run", "job-1"], { from: "user" });
|
||||
expect(exitSpy).toHaveBeenCalledWith(0);
|
||||
} finally {
|
||||
runtime.exit = originalExit;
|
||||
}
|
||||
});
|
||||
|
||||
it("exits 1 for cron run when job does not execute", async () => {
|
||||
resetGatewayMock();
|
||||
callGatewayFromCli.mockImplementation(async (method: string) => {
|
||||
if (method === "cron.status") {
|
||||
return { enabled: true };
|
||||
}
|
||||
if (method === "cron.run") {
|
||||
return { ok: true, ran: false };
|
||||
}
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
const runtimeModule = await import("../runtime.js");
|
||||
const runtime = runtimeModule.defaultRuntime as { exit: (code: number) => void };
|
||||
const originalExit = runtime.exit;
|
||||
const exitSpy = vi.fn();
|
||||
runtime.exit = exitSpy;
|
||||
try {
|
||||
const program = buildProgram();
|
||||
await program.parseAsync(["cron", "run", "job-1"], { from: "user" });
|
||||
expect(exitSpy).toHaveBeenCalledWith(1);
|
||||
} finally {
|
||||
runtime.exit = originalExit;
|
||||
}
|
||||
});
|
||||
|
||||
it("trims model and thinking on cron add", { timeout: CRON_CLI_TEST_TIMEOUT_MS }, async () => {
|
||||
await runCronCommand([
|
||||
"cron",
|
||||
|
||||
@@ -100,6 +100,8 @@ export function registerCronSimpleCommands(cron: Command) {
|
||||
mode: opts.due ? "due" : "force",
|
||||
});
|
||||
defaultRuntime.log(JSON.stringify(res, null, 2));
|
||||
const result = res as { ok?: boolean; ran?: boolean } | undefined;
|
||||
defaultRuntime.exit(result?.ok && result?.ran ? 0 : 1);
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(String(err)));
|
||||
defaultRuntime.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user