mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:10:44 +00:00
perf(test): defer matrix approval reaction imports
This commit is contained in:
@@ -2734,19 +2734,25 @@ describe("matrix monitor handler draft streaming", () => {
|
||||
const { deliver, opts, finish } = await dispatch();
|
||||
|
||||
opts.onPartialReply?.({ text: "Alpha" });
|
||||
await vi.waitFor(() => {
|
||||
expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
{ interval: 1 },
|
||||
);
|
||||
|
||||
opts.onPartialReply?.({ text: "AlphaBeta" });
|
||||
await vi.waitFor(() => {
|
||||
expect(editMessageMatrixMock).toHaveBeenCalledWith(
|
||||
"!room:example.org",
|
||||
"$draft1",
|
||||
"AlphaBeta",
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
expect(editMessageMatrixMock).toHaveBeenCalledWith(
|
||||
"!room:example.org",
|
||||
"$draft1",
|
||||
"AlphaBeta",
|
||||
expect.anything(),
|
||||
);
|
||||
},
|
||||
{ interval: 1 },
|
||||
);
|
||||
|
||||
await opts.onBlockReplyQueued?.({ text: "Alpha" });
|
||||
|
||||
@@ -2758,9 +2764,12 @@ describe("matrix monitor handler draft streaming", () => {
|
||||
});
|
||||
await deliver({ text: "Alpha" }, { kind: "block" });
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
expect(sendSingleTextMessageMatrixMock).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
{ interval: 1 },
|
||||
);
|
||||
expect(sendSingleTextMessageMatrixMock.mock.calls[0]?.[1]).toBe("Beta");
|
||||
expect(editMessageMatrixMock).toHaveBeenCalledWith(
|
||||
"!room:example.org",
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { getSessionBindingService } from "openclaw/plugin-sdk/session-binding-runtime";
|
||||
import { isMatrixApprovalReactionAuthorizedSender } from "../../approval-reaction-auth.js";
|
||||
import {
|
||||
resolveMatrixApprovalReactionTarget,
|
||||
unregisterMatrixApprovalReactionTarget,
|
||||
} from "../../approval-reactions.js";
|
||||
import { isApprovalNotFoundError, resolveMatrixApproval } from "../../exec-approval-resolver.js";
|
||||
import type { CoreConfig } from "../../types.js";
|
||||
import { resolveMatrixAccountConfig } from "../account-config.js";
|
||||
import { extractMatrixReactionAnnotation } from "../reaction-common.js";
|
||||
@@ -14,6 +12,23 @@ import type { PluginRuntime } from "./runtime-api.js";
|
||||
import { resolveMatrixThreadRootId, resolveMatrixThreadRouting } from "./threads.js";
|
||||
import type { MatrixRawEvent, RoomMessageEventContent } from "./types.js";
|
||||
|
||||
let approvalReactionAuthPromise:
|
||||
| Promise<typeof import("../../approval-reaction-auth.js")>
|
||||
| undefined;
|
||||
let execApprovalResolverPromise:
|
||||
| Promise<typeof import("../../exec-approval-resolver.js")>
|
||||
| undefined;
|
||||
|
||||
function loadApprovalReactionAuth(): Promise<typeof import("../../approval-reaction-auth.js")> {
|
||||
approvalReactionAuthPromise ??= import("../../approval-reaction-auth.js");
|
||||
return approvalReactionAuthPromise;
|
||||
}
|
||||
|
||||
function loadExecApprovalResolver(): Promise<typeof import("../../exec-approval-resolver.js")> {
|
||||
execApprovalResolverPromise ??= import("../../exec-approval-resolver.js");
|
||||
return execApprovalResolverPromise;
|
||||
}
|
||||
|
||||
export type MatrixReactionNotificationMode = "off" | "own";
|
||||
|
||||
export function resolveMatrixReactionNotificationMode(params: {
|
||||
@@ -41,9 +56,11 @@ async function maybeResolveMatrixApprovalReaction(params: {
|
||||
return false;
|
||||
}
|
||||
const approvalKind = params.target.approvalId.startsWith("plugin:") ? "plugin" : "exec";
|
||||
const { isMatrixApprovalReactionAuthorizedSender } = await loadApprovalReactionAuth();
|
||||
if (!isMatrixApprovalReactionAuthorizedSender({ ...params, approvalKind })) {
|
||||
return false;
|
||||
}
|
||||
const { isApprovalNotFoundError, resolveMatrixApproval } = await loadExecApprovalResolver();
|
||||
try {
|
||||
await resolveMatrixApproval({
|
||||
cfg: params.cfg,
|
||||
|
||||
Reference in New Issue
Block a user