mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 00:31:22 +00:00
* fix: ensure bypassPermissions on custom CLI backend args When users override cliBackends.claude-cli.args (e.g. to add --verbose or change --output-format), the override array replaces the default entirely. The normalization step only re-added --permission-mode bypassPermissions when the legacy --dangerously-skip-permissions flag was present — if neither flag existed, it did nothing. This causes cron and heartbeat runs to silently fail with "exec denied: Cron runs cannot wait for interactive exec approval" because the CLI subprocess launches in interactive permission mode. Fix: always inject --permission-mode bypassPermissions when no explicit permission-mode flag is found in the resolved args, regardless of whether the legacy flag was present. * test(anthropic): add claude-cli permission normalization coverage * fix(test-utils): include video generation providers * fix: preserve claude-cli bypassPermissions on custom args (#61114) (thanks @cathrynlavery) --------- Co-authored-by: Shadow <hi@shadowing.dev> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildAnthropicCliBackend } from "./cli-backend.js";
|
|
import { normalizeClaudeBackendConfig, normalizeClaudePermissionArgs } from "./cli-shared.js";
|
|
|
|
describe("normalizeClaudePermissionArgs", () => {
|
|
it("injects bypassPermissions when args omit permission flags", () => {
|
|
expect(
|
|
normalizeClaudePermissionArgs(["-p", "--output-format", "stream-json", "--verbose"]),
|
|
).toEqual([
|
|
"-p",
|
|
"--output-format",
|
|
"stream-json",
|
|
"--verbose",
|
|
"--permission-mode",
|
|
"bypassPermissions",
|
|
]);
|
|
});
|
|
|
|
it("removes legacy skip-permissions and injects bypassPermissions", () => {
|
|
expect(
|
|
normalizeClaudePermissionArgs(["-p", "--dangerously-skip-permissions", "--verbose"]),
|
|
).toEqual(["-p", "--verbose", "--permission-mode", "bypassPermissions"]);
|
|
});
|
|
|
|
it("keeps explicit permission-mode overrides", () => {
|
|
expect(normalizeClaudePermissionArgs(["-p", "--permission-mode", "acceptEdits"])).toEqual([
|
|
"-p",
|
|
"--permission-mode",
|
|
"acceptEdits",
|
|
]);
|
|
expect(normalizeClaudePermissionArgs(["-p", "--permission-mode=acceptEdits"])).toEqual([
|
|
"-p",
|
|
"--permission-mode=acceptEdits",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("normalizeClaudeBackendConfig", () => {
|
|
it("normalizes both args and resumeArgs for custom overrides", () => {
|
|
const normalized = normalizeClaudeBackendConfig({
|
|
command: "claude",
|
|
args: ["-p", "--output-format", "stream-json", "--verbose"],
|
|
resumeArgs: ["-p", "--output-format", "stream-json", "--verbose", "--resume", "{sessionId}"],
|
|
});
|
|
|
|
expect(normalized.args).toEqual([
|
|
"-p",
|
|
"--output-format",
|
|
"stream-json",
|
|
"--verbose",
|
|
"--permission-mode",
|
|
"bypassPermissions",
|
|
]);
|
|
expect(normalized.resumeArgs).toEqual([
|
|
"-p",
|
|
"--output-format",
|
|
"stream-json",
|
|
"--verbose",
|
|
"--resume",
|
|
"{sessionId}",
|
|
"--permission-mode",
|
|
"bypassPermissions",
|
|
]);
|
|
});
|
|
|
|
it("is wired through the anthropic cli backend normalize hook", () => {
|
|
const backend = buildAnthropicCliBackend();
|
|
const normalizeConfig = backend.normalizeConfig;
|
|
|
|
expect(normalizeConfig).toBeTypeOf("function");
|
|
|
|
const normalized = normalizeConfig?.({
|
|
...backend.config,
|
|
args: ["-p", "--output-format", "stream-json", "--verbose"],
|
|
resumeArgs: ["-p", "--output-format", "stream-json", "--verbose", "--resume", "{sessionId}"],
|
|
});
|
|
|
|
expect(normalized?.args).toContain("--permission-mode");
|
|
expect(normalized?.args).toContain("bypassPermissions");
|
|
expect(normalized?.resumeArgs).toContain("--permission-mode");
|
|
expect(normalized?.resumeArgs).toContain("bypassPermissions");
|
|
});
|
|
});
|