Files
openclaw/src/gateway/protocol/exec-approvals-validators.test.ts
Jesse Merhi 297a164536 Highlight exec command risks in Web approvals (#77153)
Summary:
- Adds parser-derived exec approval command-span metadata through host registration, gateway validation, generated Swift models, Control UI parsing/rendering, tests, and changelog.
- Reproducibility: not applicable. this is a feature PR rather than a bug report. The before/after behavior is ... rom current main’s plain command rendering to PR-head span generation, validation, and Web rendering tests.

Automerge notes:
- PR branch already contained follow-up commit before automerge: refactor: use neutral exec command spans
- PR branch already contained follow-up commit before automerge: refactor: simplify exec command span extraction
- PR branch already contained follow-up commit before automerge: refactor: inline approval command span params
- PR branch already contained follow-up commit before automerge: fix: keep exec approval spans lazy
- PR branch already contained follow-up commit before automerge: build: refresh exec approval protocol models
- PR branch already contained follow-up commit before automerge: Highlight exec command risks in Web approvals

Validation:
- ClawSweeper review passed for head 8d9977eb53.
- Required merge gates passed before the squash merge.

Prepared head SHA: 8d9977eb53
Review: https://github.com/openclaw/openclaw/pull/77153#issuecomment-4368769228

Co-authored-by: jesse-merhi <79823012+jesse-merhi@users.noreply.github.com>
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
2026-05-08 06:38:41 +00:00

103 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
validateExecApprovalRequestParams,
validateExecApprovalsNodeSetParams,
validateExecApprovalsSetParams,
} from "./index.js";
describe("exec approvals protocol validators", () => {
it("accepts runtime-owned allowlist metadata on gateway and node set payloads", () => {
const file = {
version: 1 as const,
agents: {
main: {
allowlist: [
{
id: "entry-1",
pattern: "cmd:allow-always:abcdef",
source: "allow-always" as const,
commandText: "python3 -c 'print(123)'",
argPattern: "-c *",
lastUsedAt: 1775154056736,
lastUsedCommand: "python3 -c 'print(123)'",
lastResolvedPath: "/usr/bin/python3",
},
],
},
},
};
expect(validateExecApprovalsSetParams({ file, baseHash: "abc123" })).toBe(true);
expect(
validateExecApprovalsNodeSetParams({
nodeId: "node-1",
file,
baseHash: "abc123",
}),
).toBe(true);
});
it("rejects unknown allowlist metadata", () => {
expect(
validateExecApprovalsSetParams({
file: {
version: 1,
agents: {
main: {
allowlist: [
{
pattern: "/usr/bin/python3",
source: "unknown-source",
},
],
},
},
},
baseHash: "abc123",
}),
).toBe(false);
expect(
validateExecApprovalsSetParams({
file: {
version: 1,
agents: {
main: {
allowlist: [
{
pattern: "/usr/bin/python3",
randomMetadata: true,
},
],
},
},
},
baseHash: "abc123",
}),
).toBe(false);
});
it("requires command spans to have non-negative starts and positive exclusive ends", () => {
expect(
validateExecApprovalRequestParams({
command: "echo hi",
commandSpans: [{ startIndex: 0, endIndex: 4 }],
}),
).toBe(true);
expect(
validateExecApprovalRequestParams({
command: "echo hi",
commandSpans: [{ startIndex: 0, endIndex: 0 }],
}),
).toBe(false);
expect(
validateExecApprovalRequestParams({
command: "echo hi",
commandSpans: [{ startIndex: -1, endIndex: 4 }],
}),
).toBe(false);
});
});