import { describe, expect, it, vi } from "vitest"; import type { ReplyPayload } from "../auto-reply/types.js";
vi.mock("./exec-approval-surface.js", () => ({
describeNativeExecApprovalClientSetup: vi.fn(
(params: {
channel?: string | null;
channelLabel?: string | null;
accountId?: string | null;
}) => { const channel = (params.channel ?? "").trim().toLowerCase(); const label = params.channelLabel ?? channel; const accountId = params.accountId?.trim(); const accountPrefix =
accountId && accountId !== "default"
? `channels.${channel}.accounts.${accountId}`
: `channels.${channel}`; if (channel === "matrix") { return `Approve it from the Web UI or terminal UI for now. ${label} supports native exec approvals forthis account. Configure \`${accountPrefix}.execApprovals.approvers\` or \`${accountPrefix}.dm.allowFrom\`; leave \`${accountPrefix}.execApprovals.enabled\` unset/\`auto\` or set it to \`true\`.`;
} if (channel === "discord") { return `Approve it from the Web UI or terminal UI for now. ${label} supports native exec approvals forthis account. Configure \`${accountPrefix}.execApprovals.approvers\` or \`commands.ownerAllowFrom\`; leave \`${accountPrefix}.execApprovals.enabled\` unset/\`auto\` or set it to \`true\`.`;
} if (channel === "slack") { return `Approve it from the Web UI or terminal UI for now. ${label} supports native exec approvals forthis account. Configure \`${accountPrefix}.execApprovals.approvers\` or \`commands.ownerAllowFrom\`; leave \`${accountPrefix}.execApprovals.enabled\` unset/\`auto\` or set it to \`true\`.`;
} if (channel === "telegram") { return `Approve it from the Web UI or terminal UI for now. ${label} supports native exec approvals forthis account. Configure \`${accountPrefix}.execApprovals.approvers\`; if you leave it unset, OpenClaw can infer numeric owner IDs from \`${accountPrefix}.allowFrom\` or direct-message \`${accountPrefix}.defaultTo\` when possible. Leave \`${accountPrefix}.execApprovals.enabled\` unset/\`auto\` or set it to \`true\`.`;
} returnnull;
},
),
listNativeExecApprovalClientLabels: vi.fn(() => ["Discord", "Matrix", "Slack", "Telegram"]),
supportsNativeExecApprovalClient: vi.fn((channel?: string | null) =>
["discord", "matrix", "slack", "telegram"].includes((channel ?? "").trim().toLowerCase()),
),
}));
const unavailableReasonCases = [
{
reason: "initiating-platform-disabled" as const,
channelLabel: "Slack",
expected: "Exec approval is required, but native chat exec approvals are not configured on Slack.",
},
{
reason: "initiating-platform-unsupported" as const,
channelLabel: undefined,
expected: "Exec approval is required, but this platform does not support chat exec approvals.",
},
{
reason: "no-approval-route" as const,
channelLabel: undefined,
expected: "Exec approval is required, but no interactive approval client is currently available.",
},
] as const;
it("returns the approver DM notice text", () => {
expect(getExecApprovalApproverDmNoticeText()).toBe( "Approval required. I sent approval DMs to the approvers for this account.",
);
});
it("mentions Matrix in the fallback native approval guidance", () => { const text = buildExecApprovalUnavailableReplyPayload({
reason: "no-approval-route",
}).text;
expect(text).toContain("native chat approval client such as");
expect(text).toContain("Discord");
expect(text).toContain("Matrix");
expect(text).toContain("Slack");
expect(text).toContain("Telegram");
});
it("avoids repeating allowFrom guidance in the no-route fallback", () => { const text = buildExecApprovalUnavailableReplyPayload({
reason: "no-approval-route",
}).text;
expect(text).not.toContain( "Then retry the command. If those accounts already know your owner ID via allowFrom or owner config",
);
expect(text).toContain( "You can usually leave execApprovals.approvers unset when owner config already identifies the approvers.",
);
});
it("explains how to enable Matrix native approvals when Matrix is the initiating platform", () => { const text = buildExecApprovalUnavailableReplyPayload({
reason: "initiating-platform-disabled",
channel: "matrix",
channelLabel: "Matrix",
}).text;
expect(text).toContain("native chat exec approvals are not configured on Matrix");
expect(text).toContain("Matrix supports native exec approvals for this account");
expect(text).toContain("`channels.matrix.execApprovals.approvers`");
expect(text).toContain("`channels.matrix.dm.allowFrom`");
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.