






























@@ -1,6 +1,22 @@
11import { describe, expect, it, vi } from "vitest";
22import { matrixApprovalNativeRuntime } from "./approval-handler.runtime.js";
334+type MatrixDeliverPendingParams = Parameters<
5+typeof matrixApprovalNativeRuntime.transport.deliverPending
6+>[0];
7+8+function buildMatrixApprovalRoomTarget(
9+roomId: string,
10+): MatrixDeliverPendingParams["plannedTarget"] {
11+return {
12+surface: "approver-dm",
13+target: {
14+to: `room:${roomId}`,
15+},
16+reason: "preferred",
17+};
18+}
19+420describe("matrixApprovalNativeRuntime", () => {
521it("sends versioned Matrix approval content with pending exec approvals", async () => {
622const sendSingleTextMessage = vi.fn().mockResolvedValue({
@@ -10,6 +26,35 @@ describe("matrixApprovalNativeRuntime", () => {
1026roomId: "!room:example.org",
1127});
1228const reactMessage = vi.fn().mockResolvedValue(undefined);
29+const view = {
30+approvalKind: "exec",
31+approvalId: "req-1",
32+phase: "pending",
33+title: "Exec Approval Required",
34+description: "A command needs your approval.",
35+metadata: [],
36+ask: "on-request",
37+agentId: "agent-1",
38+commandText: "echo hi",
39+commandPreview: "echo hi",
40+cwd: "/repo",
41+host: "gateway",
42+actions: [
43+{
44+decision: "allow-once",
45+label: "Allow Once",
46+style: "success",
47+command: "/approve req-1 allow-once",
48+},
49+{
50+decision: "deny",
51+label: "Deny",
52+style: "danger",
53+command: "/approve req-1 deny",
54+},
55+],
56+expiresAtMs: 1_000,
57+} satisfies MatrixDeliverPendingParams["view"];
1358const pendingPayload = await matrixApprovalNativeRuntime.presentation.buildPendingPayload({
1459cfg: {} as never,
1560accountId: "default",
@@ -27,35 +72,7 @@ describe("matrixApprovalNativeRuntime", () => {
2772},
2873approvalKind: "exec",
2974nowMs: 100,
30-view: {
31-approvalKind: "exec",
32-approvalId: "req-1",
33-phase: "pending",
34-title: "Exec Approval Required",
35-description: "A command needs your approval.",
36-metadata: [],
37-ask: "on-request",
38-agentId: "agent-1",
39-commandText: "echo hi",
40-commandPreview: "echo hi",
41-cwd: "/repo",
42-host: "gateway",
43-actions: [
44-{
45-decision: "allow-once",
46-label: "Allow Once",
47-style: "success",
48-command: "/approve req-1 allow-once",
49-},
50-{
51-decision: "deny",
52-label: "Deny",
53-style: "danger",
54-command: "/approve req-1 deny",
55-},
56-],
57-expiresAtMs: 1_000,
58-} as never,
75+ view,
5976});
60776178await matrixApprovalNativeRuntime.transport.deliverPending({
@@ -70,16 +87,12 @@ describe("matrixApprovalNativeRuntime", () => {
7087},
7188request: {} as never,
7289approvalKind: "exec",
73-plannedTarget: {
74-surface: "approver-dm",
75-target: { to: "room:!room:example.org" },
76-reason: "preferred",
77-} as never,
90+plannedTarget: buildMatrixApprovalRoomTarget("!room:example.org"),
7891preparedTarget: {
7992to: "room:!room:example.org",
8093roomId: "!room:example.org",
8194},
82-view: {} as never,
95+ view,
8396 pendingPayload,
8497});
8598@@ -175,6 +188,24 @@ describe("matrixApprovalNativeRuntime", () => {
175188roomId: "!room:example.org",
176189});
177190const reactMessage = vi.fn().mockResolvedValue(undefined);
191+const view = {
192+approvalKind: "exec",
193+approvalId: "req-1",
194+phase: "pending",
195+title: "Exec Approval Required",
196+description: "A command needs your approval.",
197+metadata: [],
198+commandText: "echo hi",
199+actions: [
200+{
201+decision: "allow-once",
202+label: "Allow Once",
203+style: "success",
204+command: "/approve req-1 allow-once",
205+},
206+],
207+expiresAtMs: 1_000,
208+} satisfies MatrixDeliverPendingParams["view"];
178209const pendingPayload = await matrixApprovalNativeRuntime.presentation.buildPendingPayload({
179210cfg: {} as never,
180211accountId: "default",
@@ -189,24 +220,7 @@ describe("matrixApprovalNativeRuntime", () => {
189220},
190221approvalKind: "exec",
191222nowMs: 100,
192-view: {
193-approvalKind: "exec",
194-approvalId: "req-1",
195-phase: "pending",
196-title: "Exec Approval Required",
197-description: "A command needs your approval.",
198-metadata: [],
199-commandText: "echo hi",
200-actions: [
201-{
202-decision: "allow-once",
203-label: "Allow Once",
204-style: "success",
205-command: "/approve req-1 allow-once",
206-},
207-],
208-expiresAtMs: 1_000,
209-} as never,
223+ view,
210224});
211225212226const entry = await matrixApprovalNativeRuntime.transport.deliverPending({
@@ -222,16 +236,12 @@ describe("matrixApprovalNativeRuntime", () => {
222236},
223237request: {} as never,
224238approvalKind: "exec",
225-plannedTarget: {
226-surface: "approver-dm",
227-target: { to: "room:!room:example.org" },
228-reason: "preferred",
229-} as never,
239+plannedTarget: buildMatrixApprovalRoomTarget("!room:example.org"),
230240preparedTarget: {
231241to: "room:!room:example.org",
232242roomId: "!room:example.org",
233243},
234-view: {} as never,
244+ view,
235245 pendingPayload,
236246});
237247此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。