fix(cli): reject malformed timeout values

This commit is contained in:
Peter Steinberger
2026-05-27 13:04:39 -04:00
parent de5971eedc
commit 5f7e21e26a
12 changed files with 195 additions and 42 deletions

View File

@@ -106,6 +106,7 @@ import {
getModelsCommandSecretTargetIds,
getTtsCommandSecretTargetIds,
} from "./command-secret-targets.js";
import { parseTimeoutMsWithFallback } from "./parse-timeout.js";
import { removeCommandByName } from "./program/command-tree.js";
import { collectOption } from "./program/helpers.js";
@@ -1179,6 +1180,13 @@ function parseOptionalPositiveInteger(raw: unknown, label: string): number | und
return value;
}
function parseOptionalTimeoutMs(raw: string | number | undefined): number | undefined {
if (raw === undefined || (typeof raw === "string" && raw.trim() === "")) {
return undefined;
}
return parseTimeoutMsWithFallback(raw, 0, { invalidType: "error" });
}
function normalizeImageOutputFormat(
raw: string | undefined,
): ImageGenerationOutputFormat | undefined {
@@ -1961,7 +1969,7 @@ export function registerCapabilityCli(program: Command) {
opts.openaiBackground as string | undefined,
"--openai-background",
),
timeoutMs: parseOptionalFiniteNumber(opts.timeoutMs, "--timeout-ms"),
timeoutMs: parseOptionalTimeoutMs(opts.timeoutMs),
output: opts.output as string | undefined,
});
emitJsonOrText(defaultRuntime, Boolean(opts.json), result, formatEnvelopeForText);
@@ -2000,7 +2008,7 @@ export function registerCapabilityCli(program: Command) {
opts.openaiBackground as string | undefined,
"--openai-background",
),
timeoutMs: parseOptionalFiniteNumber(opts.timeoutMs, "--timeout-ms"),
timeoutMs: parseOptionalTimeoutMs(opts.timeoutMs),
output: opts.output as string | undefined,
});
emitJsonOrText(defaultRuntime, Boolean(opts.json), result, formatEnvelopeForText);
@@ -2022,7 +2030,7 @@ export function registerCapabilityCli(program: Command) {
files: [String(opts.file)],
model: opts.model as string | undefined,
prompt: opts.prompt as string | undefined,
timeoutMs: parseOptionalFiniteNumber(opts.timeoutMs, "--timeout-ms"),
timeoutMs: parseOptionalTimeoutMs(opts.timeoutMs),
});
emitJsonOrText(defaultRuntime, Boolean(opts.json), result, formatEnvelopeForText);
});
@@ -2043,7 +2051,7 @@ export function registerCapabilityCli(program: Command) {
files: opts.file as string[],
model: opts.model as string | undefined,
prompt: opts.prompt as string | undefined,
timeoutMs: parseOptionalFiniteNumber(opts.timeoutMs, "--timeout-ms"),
timeoutMs: parseOptionalTimeoutMs(opts.timeoutMs),
});
emitJsonOrText(defaultRuntime, Boolean(opts.json), result, formatEnvelopeForText);
});
@@ -2352,7 +2360,7 @@ export function registerCapabilityCli(program: Command) {
durationSeconds: parseOptionalFiniteNumber(opts.duration, "--duration"),
audio: opts.audio === true ? true : undefined,
watermark: opts.watermark === true ? true : undefined,
timeoutMs: parseOptionalFiniteNumber(opts.timeoutMs, "--timeout-ms"),
timeoutMs: parseOptionalTimeoutMs(opts.timeoutMs),
});
emitJsonOrText(defaultRuntime, Boolean(opts.json), result, formatEnvelopeForText);
});