Skip to content

Commit d3d43eb

Browse files
authored
fix(cli): reject missing repeatable inference inputs (#130608)
1 parent 59fc8fc commit d3d43eb

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎docs/cli/infer.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ A good infer-based skill maps common user intents to the right subcommand, inclu
101101

102102
- Use `--json` when the output feeds another command or script; text output otherwise.
103103
- Use `--provider` or `--model provider/model` to pin a specific backend.
104+
- `image edit` and `image describe-many` require at least one `--file`; `embedding create` requires at least one `--text`. Repeat the flag for multiple inputs. Omitting it is a usage error, not an empty successful result, and no inference request is sent.
104105
- Use `model run --thinking <level>` for a one-shot thinking/reasoning override: `off`, `minimal`, `low`, `medium`, `high`, `adaptive`, `xhigh`, or `max`.
105106
- For `image describe`, `audio transcribe`, and `video describe`, `--model` must use the form `<provider/model>`.
106107
- For `image describe`, `--file` accepts local paths and HTTP(S) URLs; remote URLs go through the normal media-fetch SSRF policy.

‎src/cli/capability-cli.test.ts‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,32 @@ vi.mock("../plugins/web-search-providers.runtime.js", () => ({
568568
}));
569569

570570
describe("capability cli", () => {
571+
it.each(
572+
[
573+
{ args: ["image", "edit", "--prompt", "crop the image"], option: "--file <path>" },
574+
{ args: ["image", "describe-many"], option: "--file <path>" },
575+
{ args: ["embedding", "create"], option: "--text <text>" },
576+
].flatMap(({ args, option }) =>
577+
["infer", "capability"].map((root) => ({ args, option, root })),
578+
),
579+
)("rejects missing required repeatable input for $root $args", async ({ root, args, option }) => {
580+
const argv = [root, ...args, "--json"];
581+
const program = new Command().exitOverride().configureOutput({ writeErr: () => {} });
582+
await registerCapabilityCli(program, ["node", "openclaw", ...argv]);
583+
584+
await expect(
585+
program.parseAsync(argv, { from: "user" }).then(() => undefined),
586+
).rejects.toMatchObject({
587+
code: "commander.missingMandatoryOptionValue",
588+
message: `error: required option '${option}' not specified`,
589+
});
590+
expect(mocks.resolveCommandConfigWithSecrets).not.toHaveBeenCalled();
591+
expect(mocks.generateImage).not.toHaveBeenCalled();
592+
expect(mocks.describeImageFile).not.toHaveBeenCalled();
593+
expect(mocks.createEmbeddingProvider).not.toHaveBeenCalled();
594+
expect(mocks.runtime.writeJson).not.toHaveBeenCalled();
595+
});
596+
571597
afterEach(() => {
572598
vi.unstubAllGlobals();
573599
vi.unstubAllEnvs();
@@ -2417,6 +2443,8 @@ describe("capability cli", () => {
24172443
"edit",
24182444
"--file",
24192445
inputPath,
2446+
"--file",
2447+
inputPath,
24202448
"--prompt",
24212449
"make three variants",
24222450
"--count",
@@ -2425,6 +2453,7 @@ describe("capability cli", () => {
24252453
);
24262454

24272455
expect(firstImageGenerationCall()?.count).toBe(3);
2456+
expect(firstImageGenerationCall()?.inputImages).toHaveLength(2);
24282457
});
24292458

24302459
it("rejects unsupported image output format and background hints", async () => {
@@ -3678,15 +3707,20 @@ describe("capability cli", () => {
36783707
);
36793708

36803709
it("uses only embedding providers for embedding creation", async () => {
3681-
await runCapability("embedding", "create", "--text", "hello", "--json");
3710+
await runCapability("embedding", "create", "--text", "hello", "--text", "world", "--json");
36823711

36833712
expect(firstEmbeddingProviderCall()?.provider).toBe("auto");
36843713
expect(firstEmbeddingProviderCall()?.fallback).toBe("none");
36853714
expect(firstJsonOutput()?.capability).toBe("embedding.create");
36863715
expect(firstJsonOutput()?.provider).toBe("openai");
36873716
expect(firstJsonOutput()?.model).toBe("text-embedding-3-small");
3688-
expect(firstJsonOutput()).toMatchObject({ outputs: [{ embedding: [0.1, 0.2] }] });
3689-
expect(mocks.embedBatch).toHaveBeenCalledWith(["hello"], { inputType: "document" });
3717+
expect(firstJsonOutput()).toMatchObject({
3718+
outputs: [
3719+
{ text: "hello", embedding: [0.1, 0.2] },
3720+
{ text: "world", embedding: [0.1, 0.2] },
3721+
],
3722+
});
3723+
expect(mocks.embedBatch).toHaveBeenCalledWith(["hello", "world"], { inputType: "document" });
36903724
expect(closeEmbeddingProviderMock).toHaveBeenCalledTimes(1);
36913725
});
36923726

‎src/cli/capability-cli/embedding.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function registerEmbeddingCapabilityCommands(capability: Command): void {
111111
embedding
112112
.command("create")
113113
.description("Create embeddings")
114-
.requiredOption("--text <text>", "Input text", collectOption, [])
114+
.requiredOption("--text <text>", "Input text", collectOption)
115115
.option("--provider <id>", "Provider id")
116116
.option("--model <provider/model>", "Model override")
117117
.option(

‎src/cli/capability-cli/image.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export function registerImageCapabilityCommands(capability: Command): void {
366366
image
367367
.command("edit")
368368
.description("Edit images with one or more input files")
369-
.requiredOption("--file <path>", "Input file", collectOption, [])
369+
.requiredOption("--file <path>", "Input file", collectOption)
370370
.requiredOption("--prompt <text>", "Prompt text"),
371371
).action(async (opts, command) => {
372372
await runCommandWithRuntime(defaultRuntime, async () => {
@@ -410,7 +410,7 @@ export function registerImageCapabilityCommands(capability: Command): void {
410410
image
411411
.command("describe-many")
412412
.description("Describe multiple image files")
413-
.requiredOption("--file <path>", "Image file", collectOption, [])
413+
.requiredOption("--file <path>", "Image file", collectOption)
414414
.option("--prompt <text>", "Prompt hint")
415415
.option("--model <provider/model>", "Model override")
416416
.option("--timeout-ms <ms>", "Provider request timeout in milliseconds")

0 commit comments

Comments
 (0)