mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 08:41:18 +00:00
* fix(gateway): approval registry hardening and protocol-surface follow-ups
Follow-up delta to the merged #103579 head, rebased onto current main:
- gateway-protocol wire types derive from owner-module schema consts
(types.ts tombstone) and ProtocolSchemas leaves the package index so the
public plugin-sdk d.ts graph tree-shakes the registry declaration
- approval access authority follows the operator.approvals scope tier with
reviewerDeviceIds as the opt-in restriction (cross-surface
first-answer-wins; requester identity gates only legacy adapters)
- plugin node.invoke approvals register directly so unrenderable
presentations fail closed before request routing
- exec-approval manager reconciliation with #103515 revocation hardening
(resolution source attribution, one-shot ask-fallback consumption)
- surface-report pins and plugin-sdk API baseline refreshed; Swift models
regenerated
* feat(channels): add typed operator approval actions
Squash-rebased #103679 segment onto the durable-approval-registry tip on
current main. Typed approval/command/select presentation actions replace
raw-string inference across slack/telegram/discord/matrix/imessage/whatsapp,
approval.resolve carries an explicit kind, and channel adapters map native
callback envelopes through the typed action registry.
Drift reconciliation: deprecated buildExecApprovalInteractiveReply assertions
dropped (#104650 removed the shims); worker_environments bootstrap-column
migration kept alongside the approval resolution_ref backfill; plugin-sdk API
baseline regenerated.
(cherry picked from commit 68765a5d39d2118c88a7a54d00387337912d4494)
(cherry picked from commit 8642ac12af142e4b751f4f30d4b114615e7e5f66)
(cherry picked from commit 036c4bc39499925fc03de16ec9302e346769350a)
(cherry picked from commit 19dc350d6bc34e29a5169c6bc80971b0ad12adde)
(cherry picked from commit fc978b0bad86aef421c79f6a211b25cc1b743c01)
(cherry picked from commit 10de4d1ed5071f9be6ad1ee5d1e32c0fa8c9d11c)
(cherry picked from commit 9a664ced1b1fa740172b258f355f1a82925ae41c)
(cherry picked from commit c5ff69abbf444139e9e007bfa45beb0f00ffea54)
(cherry picked from commit d466a80795)
(cherry picked from commit f5b4fe40dd5c961322f8553cc80b2fdfb3f6503e)
(cherry picked from commit 7340b4749a4cc4c72f7a41cce1bc9cb550cae038)
(cherry picked from commit a151f41808f23ae60b10305ccd2bc959b9169a86)
* fix(approvals): preserve typed transport ownership
* test(imessage): narrow chunked approval text
* refactor(protocol): remove retired type tombstone
* fix(plugin-sdk): align surface budgets after rebase
* docs(changelog): note typed operator approvals
* docs(changelog): defer typed approval release note
335 lines
9.7 KiB
TypeScript
335 lines
9.7 KiB
TypeScript
/**
|
|
* Tests approval renderer payload and text formatting.
|
|
*/
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildApprovalPendingReplyPayload,
|
|
buildApprovalResolvedReplyPayload,
|
|
buildPluginApprovalPendingReplyPayload,
|
|
buildPluginApprovalResolvedReplyPayload,
|
|
buildTypedApprovalPendingReplyPayload,
|
|
buildTypedPluginApprovalPendingReplyPayload,
|
|
} from "./approval-renderers.js";
|
|
|
|
describe("plugin-sdk/approval-renderers", () => {
|
|
it("preserves command controls when shipped approvalKind metadata is supplied", () => {
|
|
expect(
|
|
buildApprovalPendingReplyPayload({
|
|
approvalKind: "plugin",
|
|
approvalId: "plugin:legacy-approval",
|
|
approvalSlug: "legacy-a",
|
|
text: "Approval required",
|
|
allowedDecisions: ["deny"],
|
|
}),
|
|
).toEqual({
|
|
text: "Approval required",
|
|
presentation: {
|
|
blocks: [
|
|
{
|
|
type: "buttons",
|
|
buttons: [
|
|
{
|
|
label: "Deny",
|
|
action: { type: "command", command: "/approve plugin:legacy-approval deny" },
|
|
value: "/approve plugin:legacy-approval deny",
|
|
style: "danger",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
channelData: {
|
|
execApproval: {
|
|
approvalId: "plugin:legacy-approval",
|
|
approvalSlug: "legacy-a",
|
|
approvalKind: "plugin",
|
|
agentId: undefined,
|
|
allowedDecisions: ["deny"],
|
|
sessionKey: undefined,
|
|
state: "pending",
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it("preserves command controls in the shipped plugin approval builder", () => {
|
|
const payload = buildPluginApprovalPendingReplyPayload({
|
|
request: {
|
|
id: "plugin-legacy",
|
|
request: {
|
|
title: "Sensitive action",
|
|
description: "Needs approval",
|
|
allowedDecisions: ["allow-once"],
|
|
},
|
|
createdAtMs: 1_000,
|
|
expiresAtMs: 61_000,
|
|
},
|
|
nowMs: 1_000,
|
|
});
|
|
|
|
expect(payload.text).toContain("Reply with: /approve plugin-legacy allow-once");
|
|
expect(payload.text).not.toContain("allow-once|deny");
|
|
expect(payload.presentation).toEqual({
|
|
blocks: [
|
|
{
|
|
type: "buttons",
|
|
buttons: [
|
|
{
|
|
label: "Allow Once",
|
|
action: { type: "command", command: "/approve plugin-legacy allow-once" },
|
|
value: "/approve plugin-legacy allow-once",
|
|
style: "success",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
name: "builds shared approval payloads with typed plugin decisions",
|
|
payload: buildTypedApprovalPendingReplyPayload({
|
|
approvalKind: "plugin",
|
|
approvalId: "plugin:approval-123",
|
|
approvalSlug: "plugin:a",
|
|
text: "Approval required @everyone",
|
|
}),
|
|
textExpected: (text: string) => expect(text).toContain("@everyone"),
|
|
presentationExpected: {
|
|
blocks: [
|
|
{
|
|
type: "buttons",
|
|
buttons: [
|
|
{
|
|
label: "Allow Once",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin:approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "allow-once",
|
|
},
|
|
style: "success",
|
|
},
|
|
{
|
|
label: "Allow Always",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin:approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "allow-always",
|
|
},
|
|
style: "primary",
|
|
},
|
|
{
|
|
label: "Deny",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin:approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "deny",
|
|
},
|
|
style: "danger",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
channelDataExpected: undefined,
|
|
},
|
|
{
|
|
name: "builds plugin pending payloads with approval metadata and extra channel data",
|
|
payload: buildTypedPluginApprovalPendingReplyPayload({
|
|
request: {
|
|
id: "plugin-approval-123",
|
|
request: {
|
|
title: "Sensitive action",
|
|
description: "Needs approval",
|
|
},
|
|
createdAtMs: 1_000,
|
|
expiresAtMs: 61_000,
|
|
},
|
|
nowMs: 1_000,
|
|
approvalSlug: "custom-slug",
|
|
channelData: {
|
|
telegram: {
|
|
quoteText: "quoted",
|
|
},
|
|
},
|
|
}),
|
|
textExpected: (text: string) => expect(text).toContain("Plugin approval required"),
|
|
presentationExpected: {
|
|
blocks: [
|
|
{
|
|
type: "buttons",
|
|
buttons: [
|
|
{
|
|
label: "Allow Once",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "allow-once",
|
|
},
|
|
style: "success",
|
|
},
|
|
{
|
|
label: "Allow Always",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "allow-always",
|
|
},
|
|
style: "primary",
|
|
},
|
|
{
|
|
label: "Deny",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "deny",
|
|
},
|
|
style: "danger",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
channelDataExpected: {
|
|
execApproval: {
|
|
agentId: undefined,
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
approvalSlug: "custom-slug",
|
|
allowedDecisions: ["allow-once", "allow-always", "deny"],
|
|
sessionKey: undefined,
|
|
state: "pending",
|
|
},
|
|
telegram: {
|
|
quoteText: "quoted",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "adds fail-closed deny to request-scoped plugin decisions",
|
|
payload: buildTypedPluginApprovalPendingReplyPayload({
|
|
request: {
|
|
id: "plugin-approval-123",
|
|
request: {
|
|
title: "Sensitive action",
|
|
description: "Needs approval",
|
|
allowedDecisions: ["allow-once"],
|
|
},
|
|
createdAtMs: 1_000,
|
|
expiresAtMs: 61_000,
|
|
},
|
|
nowMs: 1_000,
|
|
allowedDecisions: ["allow-once"],
|
|
}),
|
|
textExpected: (text: string) => {
|
|
expect(text).toContain("Reply with: /approve plugin-approval-123 allow-once");
|
|
expect(text).not.toContain("allow-once|deny");
|
|
},
|
|
presentationExpected: {
|
|
blocks: [
|
|
{
|
|
type: "buttons",
|
|
buttons: [
|
|
{
|
|
label: "Allow Once",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "allow-once",
|
|
},
|
|
style: "success",
|
|
},
|
|
{
|
|
label: "Deny",
|
|
action: {
|
|
type: "approval",
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
decision: "deny",
|
|
},
|
|
style: "danger",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
channelDataExpected: {
|
|
execApproval: {
|
|
agentId: undefined,
|
|
approvalId: "plugin-approval-123",
|
|
approvalKind: "plugin",
|
|
approvalSlug: "plugin-a",
|
|
allowedDecisions: ["allow-once", "deny"],
|
|
sessionKey: undefined,
|
|
state: "pending",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "builds generic resolved payloads with approval metadata",
|
|
payload: buildApprovalResolvedReplyPayload({
|
|
approvalId: "req-123",
|
|
approvalSlug: "req-123",
|
|
text: "resolved @everyone",
|
|
}),
|
|
textExpected: (text: string) => expect(text).toBe("resolved @everyone"),
|
|
presentationExpected: undefined,
|
|
channelDataExpected: {
|
|
execApproval: {
|
|
approvalId: "req-123",
|
|
approvalSlug: "req-123",
|
|
state: "resolved",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "builds plugin resolved payloads with optional channel data",
|
|
payload: buildPluginApprovalResolvedReplyPayload({
|
|
resolved: {
|
|
id: "plugin-approval-123",
|
|
decision: "allow-once",
|
|
resolvedBy: "discord:user:1",
|
|
ts: 2_000,
|
|
},
|
|
channelData: {
|
|
discord: {
|
|
components: [{ type: "container" }],
|
|
},
|
|
},
|
|
}),
|
|
textExpected: (text: string) => expect(text).toContain("Plugin approval allowed once"),
|
|
presentationExpected: undefined,
|
|
channelDataExpected: {
|
|
execApproval: {
|
|
approvalId: "plugin-approval-123",
|
|
approvalSlug: "plugin-a",
|
|
state: "resolved",
|
|
},
|
|
discord: {
|
|
components: [{ type: "container" }],
|
|
},
|
|
},
|
|
},
|
|
])("$name", ({ payload, textExpected, presentationExpected, channelDataExpected }) => {
|
|
if (payload.text === undefined) {
|
|
throw new Error("expected rendered approval text");
|
|
}
|
|
textExpected(payload.text);
|
|
if (presentationExpected) {
|
|
expect(payload.presentation).toEqual(presentationExpected);
|
|
expect(payload.interactive).toBeUndefined();
|
|
}
|
|
if (channelDataExpected) {
|
|
expect(payload.channelData).toEqual(channelDataExpected);
|
|
}
|
|
});
|
|
});
|