Files
openclaw/src/infra/exec-approval-command-display.test.ts
2026-03-13 19:57:49 +00:00

67 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
resolveExecApprovalCommandDisplay,
sanitizeExecApprovalDisplayText,
} from "./exec-approval-command-display.js";
describe("sanitizeExecApprovalDisplayText", () => {
it("escapes unicode format characters but leaves other text intact", () => {
expect(sanitizeExecApprovalDisplayText("echo hi\u200Bthere")).toBe("echo hi\\u{200B}there");
});
});
describe("resolveExecApprovalCommandDisplay", () => {
it("prefers explicit command fields and drops identical previews after trimming", () => {
expect(
resolveExecApprovalCommandDisplay({
command: "echo hi",
commandPreview: " echo hi ",
host: "gateway",
}),
).toEqual({
commandText: "echo hi",
commandPreview: null,
});
});
it("falls back to node systemRunPlan values and sanitizes preview text", () => {
expect(
resolveExecApprovalCommandDisplay({
command: "",
host: "node",
systemRunPlan: {
argv: ["python3", "-c", "print(1)"],
cwd: null,
commandText: 'python3 -c "print(1)"',
commandPreview: "print\u200B(1)",
agentId: null,
sessionKey: null,
},
}),
).toEqual({
commandText: 'python3 -c "print(1)"',
commandPreview: "print\\u{200B}(1)",
});
});
it("ignores systemRunPlan fallback for non-node hosts", () => {
expect(
resolveExecApprovalCommandDisplay({
command: "",
host: "sandbox",
systemRunPlan: {
argv: ["echo", "hi"],
cwd: null,
commandText: "echo hi",
commandPreview: "echo hi",
agentId: null,
sessionKey: null,
},
}),
).toEqual({
commandText: "",
commandPreview: null,
});
});
});