Skip to content

Commit 91726e9

Browse files
fix(cron): reject invalid no-output timeout (#96516)
* fix(cron): reject invalid no-output timeout * fix(cron): validate command output limits --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
1 parent 289865b commit 91726e9

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

src/cli/cron-cli.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,29 @@ describe("cron cli", () => {
658658
},
659659
);
660660

661+
describe.each(["--no-output-timeout-seconds", "--output-max-bytes"])(
662+
"cron add %s validation",
663+
(flag) => {
664+
it.each(["", "0", "-1", "1.5", "1000ms"])("rejects invalid value %j", async (value) => {
665+
await expectCronCommandExit([
666+
"cron",
667+
"add",
668+
"--name",
669+
"Invalid command limit",
670+
"--every",
671+
"10m",
672+
"--command",
673+
"echo ok",
674+
flag,
675+
value,
676+
]);
677+
678+
expectRuntimeErrorContaining(`Invalid ${flag} (must be a positive integer).`);
679+
expect(callGatewayFromCli.mock.calls.some((call) => call[0] === "cron.add")).toBe(false);
680+
});
681+
},
682+
);
683+
661684
it("rejects cron add with both message and command payloads", async () => {
662685
await expectCronCommandExit([
663686
"cron",

src/cli/cron-cli/register.cron-add.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { sanitizeAgentId } from "../../routing/session-key.js";
1010
import { defaultRuntime } from "../../runtime.js";
1111
import type { GatewayRpcOpts } from "../gateway-rpc.js";
1212
import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js";
13-
import {
14-
parsePositiveIntOrUndefined,
15-
parseStrictPositiveIntOrUndefined,
16-
} from "../program/helpers.js";
13+
import { parseStrictPositiveIntOrUndefined } from "../program/helpers.js";
1714
import { resolveCronCreateScheduleFromArgs } from "./schedule-options.js";
1815
import {
1916
getCronChannelOptions,
@@ -234,8 +231,19 @@ export function registerCronAddCommand(cron: Command) {
234231
? opts.outputTimeoutSeconds
235232
: undefined);
236233
const noOutputTimeoutSeconds =
237-
parsePositiveIntOrUndefined(rawNoOutputTimeoutSeconds);
238-
const outputMaxBytes = parsePositiveIntOrUndefined(opts.outputMaxBytes);
234+
parseStrictPositiveIntOrUndefined(rawNoOutputTimeoutSeconds);
235+
if (
236+
rawNoOutputTimeoutSeconds !== undefined &&
237+
noOutputTimeoutSeconds === undefined
238+
) {
239+
throw new Error(
240+
"Invalid --no-output-timeout-seconds (must be a positive integer).",
241+
);
242+
}
243+
const outputMaxBytes = parseStrictPositiveIntOrUndefined(opts.outputMaxBytes);
244+
if (opts.outputMaxBytes !== undefined && outputMaxBytes === undefined) {
245+
throw new Error("Invalid --output-max-bytes (must be a positive integer).");
246+
}
239247
return {
240248
kind: "command" as const,
241249
argv: commandArgv ?? ["sh", "-lc", commandShell ?? ""],

0 commit comments

Comments
 (0)