mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 22:40:58 +00:00
CLI/completion: fix generator OOM and harden plugin registries (#45537)
* fix: avoid OOM during completion script generation * CLI/completion: fix PowerShell nested command paths * CLI/completion: cover generated shell scripts * Changelog: note completion generator follow-up * Plugins: reserve shared registry names --------- Co-authored-by: Xiaoyi <xiaoyi@example.com> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
52
src/cli/completion-cli.test.ts
Normal file
52
src/cli/completion-cli.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Command } from "commander";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getCompletionScript } from "./completion-cli.js";
|
||||
|
||||
function createCompletionProgram(): Command {
|
||||
const program = new Command();
|
||||
program.name("openclaw");
|
||||
program.description("CLI root");
|
||||
program.option("-v, --verbose", "Verbose output");
|
||||
|
||||
const gateway = program.command("gateway").description("Gateway commands");
|
||||
gateway.option("--force", "Force the action");
|
||||
|
||||
gateway.command("status").description("Show gateway status").option("--json", "JSON output");
|
||||
gateway.command("restart").description("Restart gateway");
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
describe("completion-cli", () => {
|
||||
it("generates zsh functions for nested subcommands", () => {
|
||||
const script = getCompletionScript("zsh", createCompletionProgram());
|
||||
|
||||
expect(script).toContain("_openclaw_gateway()");
|
||||
expect(script).toContain("(status) _openclaw_gateway_status ;;");
|
||||
expect(script).toContain("(restart) _openclaw_gateway_restart ;;");
|
||||
expect(script).toContain("--force[Force the action]");
|
||||
});
|
||||
|
||||
it("generates PowerShell command paths without the executable prefix", () => {
|
||||
const script = getCompletionScript("powershell", createCompletionProgram());
|
||||
|
||||
expect(script).toContain("if ($commandPath -eq 'gateway') {");
|
||||
expect(script).toContain("if ($commandPath -eq 'gateway status') {");
|
||||
expect(script).not.toContain("if ($commandPath -eq 'openclaw gateway') {");
|
||||
expect(script).toContain("$completions = @('status','restart','--force')");
|
||||
});
|
||||
|
||||
it("generates fish completions for root and nested command contexts", () => {
|
||||
const script = getCompletionScript("fish", createCompletionProgram());
|
||||
|
||||
expect(script).toContain(
|
||||
'complete -c openclaw -n "__fish_use_subcommand" -a "gateway" -d \'Gateway commands\'',
|
||||
);
|
||||
expect(script).toContain(
|
||||
'complete -c openclaw -n "__fish_seen_subcommand_from gateway" -a "status" -d \'Show gateway status\'',
|
||||
);
|
||||
expect(script).toContain(
|
||||
"complete -c openclaw -n \"__fish_seen_subcommand_from gateway\" -l force -d 'Force the action'",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user