openclaw/src/infra/exec-approval-command-displ...

72 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
resolveExecApprovalCommandDisplay,
sanitizeExecApprovalDisplayText,
} from "./exec-approval-command-display.js";
describe("sanitizeExecApprovalDisplayText", () => {
it.each([
["echo hi\u200Bthere", "echo hi\\u{200B}there"],
["date\u3164\uFFA0\u115F\u1160가", "date\\u{3164}\\u{FFA0}\\u{115F}\\u{1160}가"],
])("sanitizes exec approval display text for %j", (input, expected) => {
expect(sanitizeExecApprovalDisplayText(input)).toBe(expected);
});
});
describe("resolveExecApprovalCommandDisplay", () => {
it.each([
{
name: "prefers explicit command fields and drops identical previews after trimming",
input: {
command: "echo hi",
commandPreview: " echo hi ",
host: "gateway" as const,
},
expected: {
commandText: "echo hi",
commandPreview: null,
},
},
{
name: "falls back to node systemRunPlan values and sanitizes preview text",
input: {
command: "",
host: "node" as const,
systemRunPlan: {
argv: ["python3", "-c", "print(1)"],
cwd: null,
commandText: 'python3 -c "print(1)"',
commandPreview: "print\u200B(1)",
agentId: null,
sessionKey: null,
},
},
expected: {
commandText: 'python3 -c "print(1)"',
commandPreview: "print\\u{200B}(1)",
},
},
{
name: "ignores systemRunPlan fallback for non-node hosts",
input: {
command: "",
host: "sandbox" as const,
systemRunPlan: {
argv: ["echo", "hi"],
cwd: null,
commandText: "echo hi",
commandPreview: "echo hi",
agentId: null,
sessionKey: null,
},
},
expected: {
commandText: "",
commandPreview: null,
},
},
])("$name", ({ input, expected }) => {
expect(resolveExecApprovalCommandDisplay(input)).toEqual(expected);
});
});