mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
fix(cli): render task validation JSON failures (#127750)
This commit is contained in:
committed by
GitHub
parent
8d2024542e
commit
2e04f762ea
@@ -371,6 +371,107 @@ describe("cli json stdout contract", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "audit limit in human mode",
|
||||
args: ["tasks", "audit", "--limit", "5abc"],
|
||||
message: "--limit must be a positive integer, for example --limit 25.",
|
||||
human: true,
|
||||
},
|
||||
{
|
||||
name: "notify policy in human mode",
|
||||
args: ["tasks", "notify", "task-123", "sometimes"],
|
||||
message: "Notify policy must be done_only, state_changes, or silent.",
|
||||
human: true,
|
||||
},
|
||||
{
|
||||
name: "routed audit limit with leaf JSON",
|
||||
args: ["tasks", "audit", "--json", "--limit", "5abc"],
|
||||
message: "--limit must be a positive integer, for example --limit 25.",
|
||||
},
|
||||
{
|
||||
name: "routed audit limit with parent JSON",
|
||||
args: ["tasks", "--json", "audit", "--limit", "5abc"],
|
||||
message: "--limit must be a positive integer, for example --limit 25.",
|
||||
},
|
||||
{
|
||||
name: "Commander audit limit with leaf JSON",
|
||||
args: ["tasks", "audit", "--limit", "5abc", "--json"],
|
||||
message: "--limit must be a positive integer, for example --limit 25.",
|
||||
commander: true,
|
||||
},
|
||||
{
|
||||
name: "Commander audit limit with parent JSON",
|
||||
args: ["tasks", "--json", "audit", "--limit", "5abc"],
|
||||
message: "--limit must be a positive integer, for example --limit 25.",
|
||||
commander: true,
|
||||
},
|
||||
{
|
||||
name: "routed audit with an inherited runtime",
|
||||
args: ["tasks", "--json", "--runtime", "cli", "audit"],
|
||||
message: "`tasks audit` does not support inherited option --runtime.",
|
||||
},
|
||||
{
|
||||
name: "Commander audit with an inherited status",
|
||||
args: ["tasks", "--json", "--status", "running", "audit"],
|
||||
message: "`tasks audit` does not support inherited option --status.",
|
||||
commander: true,
|
||||
},
|
||||
{
|
||||
name: "routed maintenance with an inherited runtime",
|
||||
args: ["tasks", "--runtime", "cli", "maintenance", "--json"],
|
||||
message: "`tasks maintenance` does not support inherited option --runtime.",
|
||||
},
|
||||
{
|
||||
name: "routed TaskFlow list with an inherited task status",
|
||||
args: ["tasks", "--json", "--status", "running", "flow", "list"],
|
||||
message: "`tasks flow list` does not support inherited option --status.",
|
||||
},
|
||||
{
|
||||
name: "Commander TaskFlow show with an inherited runtime",
|
||||
args: ["tasks", "--runtime", "cli", "flow", "--json", "show", "flow-123"],
|
||||
message: "`tasks flow show` does not support inherited option --runtime.",
|
||||
commander: true,
|
||||
},
|
||||
{
|
||||
name: "routed audit limit through dual-TTY finalization",
|
||||
args: ["tasks", "audit", "--json", "--limit", "5abc"],
|
||||
message: "--limit must be a positive integer, for example --limit 25.",
|
||||
tty: true,
|
||||
},
|
||||
])("renders task registration validation failures for $name", async (testCase) => {
|
||||
await withTempHome(
|
||||
async (tempHome) => {
|
||||
const preload = `data:text/javascript,${encodeURIComponent(
|
||||
'Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true }); Object.defineProperty(process.stderr, "isTTY", { value: true, configurable: true });',
|
||||
)}`;
|
||||
const result = runBuiltCli(tempHome, testCase.args, {
|
||||
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
|
||||
OPENCLAW_CONFIG_PATH: path.join(tempHome, "missing-openclaw.json"),
|
||||
...("commander" in testCase ? { OPENCLAW_DISABLE_ROUTE_FIRST: "1" } : {}),
|
||||
...("tty" in testCase ? { NODE_OPTIONS: `--import=${preload}`, FORCE_COLOR: "1" } : {}),
|
||||
});
|
||||
|
||||
expect(result.status, result.stderr).toBe(1);
|
||||
expect(result.stdout, result.stderr).not.toMatch(/[\u001B\u0007]/u);
|
||||
if ("human" in testCase) {
|
||||
expect(result.stdout).toBe("");
|
||||
} else {
|
||||
expect(JSON.parse(result.stdout)).toEqual({
|
||||
ok: false,
|
||||
error: { type: "cli_error", message: testCase.message },
|
||||
});
|
||||
}
|
||||
expect(result.stderr).toContain(testCase.message);
|
||||
expect(result.stderr.split(testCase.message)).toHaveLength(2);
|
||||
if ("tty" in testCase) {
|
||||
expect(result.stderr).toContain("\u001B[?25h");
|
||||
}
|
||||
},
|
||||
{ prefix: "openclaw-task-registration-json-failure-e2e-" },
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ name: "qr", command: ["qr"] },
|
||||
{ name: "clawbot qr", command: ["clawbot", "qr"] },
|
||||
|
||||
Reference in New Issue
Block a user