mirror of https://github.com/openclaw/openclaw.git
test: tighten system run command normalization coverage
This commit is contained in:
parent
576134ec73
commit
2083b0581d
|
|
@ -96,6 +96,18 @@ describe("system run command helpers", () => {
|
||||||
expect(res.commandText).toBe("echo hi");
|
expect(res.commandText).toBe("echo hi");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("validateSystemRunCommandConsistency trims rawCommand before comparison", () => {
|
||||||
|
const res = validateSystemRunCommandConsistency({
|
||||||
|
argv: ["echo", "hi"],
|
||||||
|
rawCommand: " echo hi ",
|
||||||
|
});
|
||||||
|
expect(res.ok).toBe(true);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("unreachable");
|
||||||
|
}
|
||||||
|
expect(res.commandText).toBe("echo hi");
|
||||||
|
});
|
||||||
|
|
||||||
test("validateSystemRunCommandConsistency rejects mismatched rawCommand vs direct argv", () => {
|
test("validateSystemRunCommandConsistency rejects mismatched rawCommand vs direct argv", () => {
|
||||||
expectRawCommandMismatch({
|
expectRawCommandMismatch({
|
||||||
argv: ["uname", "-a"],
|
argv: ["uname", "-a"],
|
||||||
|
|
@ -182,6 +194,18 @@ describe("system run command helpers", () => {
|
||||||
expect(res.details?.code).toBe("MISSING_COMMAND");
|
expect(res.details?.code).toBe("MISSING_COMMAND");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("resolveSystemRunCommand treats non-array command values as missing", () => {
|
||||||
|
const res = resolveSystemRunCommand({
|
||||||
|
command: "echo hi",
|
||||||
|
rawCommand: "echo hi",
|
||||||
|
});
|
||||||
|
expect(res.ok).toBe(false);
|
||||||
|
if (res.ok) {
|
||||||
|
throw new Error("unreachable");
|
||||||
|
}
|
||||||
|
expect(res.details?.code).toBe("MISSING_COMMAND");
|
||||||
|
});
|
||||||
|
|
||||||
test("resolveSystemRunCommand returns an empty success payload when no command is provided", () => {
|
test("resolveSystemRunCommand returns an empty success payload when no command is provided", () => {
|
||||||
const res = resolveSystemRunCommand({});
|
const res = resolveSystemRunCommand({});
|
||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
|
|
@ -206,6 +230,19 @@ describe("system run command helpers", () => {
|
||||||
expect(res.commandText).toBe("echo 123 false null");
|
expect(res.commandText).toBe("echo 123 false null");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("resolveSystemRunCommandRequest trims legacy rawCommand shell payloads", () => {
|
||||||
|
const res = resolveSystemRunCommandRequest({
|
||||||
|
command: ["/bin/sh", "-lc", "echo hi"],
|
||||||
|
rawCommand: " echo hi ",
|
||||||
|
});
|
||||||
|
expect(res.ok).toBe(true);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("unreachable");
|
||||||
|
}
|
||||||
|
expect(res.previewText).toBe("echo hi");
|
||||||
|
expect(res.commandText).toBe('/bin/sh -lc "echo hi"');
|
||||||
|
});
|
||||||
|
|
||||||
test("resolveSystemRunCommandRequest accepts legacy shell payloads but returns canonical command text", () => {
|
test("resolveSystemRunCommandRequest accepts legacy shell payloads but returns canonical command text", () => {
|
||||||
const res = resolveSystemRunCommandRequest({
|
const res = resolveSystemRunCommandRequest({
|
||||||
command: ["cmd.exe", "/d", "/s", "/c", "echo", "SAFE&&whoami"],
|
command: ["cmd.exe", "/d", "/s", "/c", "echo", "SAFE&&whoami"],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue