mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-08 15:51:06 +00:00
fix(types): align portable runtime helpers
This commit is contained in:
@@ -52,6 +52,11 @@ type CreateDiscordComponentModal =
|
||||
typeof import("./agent-components.js").createDiscordComponentModal;
|
||||
type CreateDiscordComponentStringSelect =
|
||||
typeof import("./agent-components.js").createDiscordComponentStringSelect;
|
||||
type DispatchReplyWithBufferedBlockDispatcherFn =
|
||||
typeof import("openclaw/plugin-sdk/reply-dispatch-runtime").dispatchReplyWithBufferedBlockDispatcher;
|
||||
type DispatchReplyWithBufferedBlockDispatcherResult = Awaited<
|
||||
ReturnType<DispatchReplyWithBufferedBlockDispatcherFn>
|
||||
>;
|
||||
|
||||
let createDiscordComponentButton: CreateDiscordComponentButton;
|
||||
let createDiscordComponentStringSelect: CreateDiscordComponentStringSelect;
|
||||
@@ -81,12 +86,7 @@ describe("discord component interactions", () => {
|
||||
...overrides,
|
||||
}) as DiscordAccountConfig;
|
||||
|
||||
type DispatchParams = {
|
||||
ctx: Record<string, unknown>;
|
||||
dispatcherOptions: {
|
||||
deliver: (payload: { text?: string }) => Promise<void> | void;
|
||||
};
|
||||
};
|
||||
type DispatchParams = Parameters<DispatchReplyWithBufferedBlockDispatcherFn>[0];
|
||||
|
||||
type ComponentContext = Parameters<CreateDiscordComponentButton>[0];
|
||||
|
||||
@@ -285,10 +285,22 @@ describe("discord component interactions", () => {
|
||||
resetDiscordComponentRuntimeMocks();
|
||||
lastDispatchCtx = undefined;
|
||||
enqueueSystemEventMock.mockClear();
|
||||
dispatchReplyMock.mockClear().mockImplementation(async (params: DispatchParams) => {
|
||||
lastDispatchCtx = params.ctx;
|
||||
await params.dispatcherOptions.deliver({ text: "ok" });
|
||||
});
|
||||
dispatchReplyMock
|
||||
.mockClear()
|
||||
.mockImplementation(
|
||||
async (params: DispatchParams): Promise<DispatchReplyWithBufferedBlockDispatcherResult> => {
|
||||
lastDispatchCtx = params.ctx;
|
||||
await params.dispatcherOptions.deliver({ text: "ok" }, { kind: "final" });
|
||||
return {
|
||||
queuedFinal: false,
|
||||
counts: {
|
||||
block: 0,
|
||||
final: 1,
|
||||
tool: 0,
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
recordInboundSessionMock.mockClear().mockResolvedValue(undefined);
|
||||
readSessionUpdatedAtMock.mockClear().mockReturnValue(undefined);
|
||||
resolveStorePathMock.mockClear().mockReturnValue("/tmp/openclaw-sessions-test.json");
|
||||
|
||||
@@ -4,11 +4,14 @@ import { resolvePinnedMainDmOwnerFromAllowlist } from "../../../../src/security/
|
||||
|
||||
type UnknownMock = Mock<(...args: unknown[]) => unknown>;
|
||||
type AsyncUnknownMock = Mock<(...args: unknown[]) => Promise<unknown>>;
|
||||
type DispatchReplyWithBufferedBlockDispatcherFn =
|
||||
typeof import("openclaw/plugin-sdk/reply-dispatch-runtime").dispatchReplyWithBufferedBlockDispatcher;
|
||||
type DispatchReplyMock = Mock<DispatchReplyWithBufferedBlockDispatcherFn>;
|
||||
|
||||
type DiscordComponentRuntimeMocks = {
|
||||
buildPluginBindingResolvedTextMock: UnknownMock;
|
||||
dispatchPluginInteractiveHandlerMock: AsyncUnknownMock;
|
||||
dispatchReplyMock: UnknownMock;
|
||||
dispatchReplyMock: DispatchReplyMock;
|
||||
enqueueSystemEventMock: UnknownMock;
|
||||
readAllowFromStoreMock: AsyncUnknownMock;
|
||||
readSessionUpdatedAtMock: UnknownMock;
|
||||
@@ -22,7 +25,7 @@ const runtimeMocks = vi.hoisted(
|
||||
(): DiscordComponentRuntimeMocks => ({
|
||||
buildPluginBindingResolvedTextMock: vi.fn(),
|
||||
dispatchPluginInteractiveHandlerMock: vi.fn(),
|
||||
dispatchReplyMock: vi.fn(),
|
||||
dispatchReplyMock: vi.fn<DispatchReplyWithBufferedBlockDispatcherFn>(),
|
||||
enqueueSystemEventMock: vi.fn(),
|
||||
readAllowFromStoreMock: vi.fn(),
|
||||
readSessionUpdatedAtMock: vi.fn(),
|
||||
@@ -36,7 +39,7 @@ const runtimeMocks = vi.hoisted(
|
||||
export const readAllowFromStoreMock: AsyncUnknownMock = runtimeMocks.readAllowFromStoreMock;
|
||||
export const dispatchPluginInteractiveHandlerMock: AsyncUnknownMock =
|
||||
runtimeMocks.dispatchPluginInteractiveHandlerMock;
|
||||
export const dispatchReplyMock: UnknownMock = runtimeMocks.dispatchReplyMock;
|
||||
export const dispatchReplyMock: DispatchReplyMock = runtimeMocks.dispatchReplyMock;
|
||||
export const enqueueSystemEventMock: UnknownMock = runtimeMocks.enqueueSystemEventMock;
|
||||
export const upsertPairingRequestMock: AsyncUnknownMock = runtimeMocks.upsertPairingRequestMock;
|
||||
export const recordInboundSessionMock: AsyncUnknownMock = runtimeMocks.recordInboundSessionMock;
|
||||
@@ -104,7 +107,7 @@ vi.mock("../monitor/agent-components.runtime.js", () => {
|
||||
),
|
||||
dispatchPluginInteractiveHandler: (...args: unknown[]) =>
|
||||
dispatchPluginInteractiveHandlerMock(...args),
|
||||
dispatchReplyWithBufferedBlockDispatcher: (...args: unknown[]) => dispatchReplyMock(...args),
|
||||
dispatchReplyWithBufferedBlockDispatcher: dispatchReplyMock,
|
||||
finalizeInboundContext: vi.fn((ctx) => ctx),
|
||||
parsePluginBindingApprovalCustomId,
|
||||
recordInboundSession: (...args: unknown[]) => recordInboundSessionMock(...args),
|
||||
|
||||
@@ -54,24 +54,18 @@ function countMatrixExecApprovalEligibleAccounts(params: {
|
||||
cfg: params.cfg,
|
||||
accountId,
|
||||
});
|
||||
const filters = config?.enabled
|
||||
? {
|
||||
agentFilter: config.agentFilter,
|
||||
sessionFilter: config.sessionFilter,
|
||||
}
|
||||
: {
|
||||
agentFilter: undefined,
|
||||
sessionFilter: undefined,
|
||||
};
|
||||
if (!config?.enabled) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
isChannelExecApprovalClientEnabledFromConfig({
|
||||
enabled: config?.enabled,
|
||||
enabled: config.enabled,
|
||||
approverCount: getMatrixExecApprovalApprovers({ cfg: params.cfg, accountId }).length,
|
||||
}) &&
|
||||
matchesApprovalRequestFilters({
|
||||
request: params.request.request,
|
||||
agentFilter: filters.agentFilter,
|
||||
sessionFilter: filters.sessionFilter,
|
||||
agentFilter: config.agentFilter,
|
||||
sessionFilter: config.sessionFilter,
|
||||
})
|
||||
);
|
||||
}).length;
|
||||
|
||||
@@ -112,7 +112,7 @@ function expectChannels(call: Record<string, unknown>, channel: string) {
|
||||
}
|
||||
|
||||
function readAgentCommandCall(fromEnd = 1) {
|
||||
const calls = vi.mocked(agentCommand).mock.calls as unknown[][];
|
||||
const calls = vi.mocked(agentCommand).mock.calls;
|
||||
return (calls.at(-fromEnd)?.[0] ?? {}) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ describe("gateway server agent", () => {
|
||||
test("agent routes bare /new through session reset before running greeting prompt", async () => {
|
||||
await writeMainSessionEntry({ sessionId: "sess-main-before-reset" });
|
||||
const spy = vi.mocked(agentCommand);
|
||||
const calls = spy.mock.calls as unknown[][];
|
||||
const calls = spy.mock.calls;
|
||||
const callsBefore = calls.length;
|
||||
const res = await rpcReq(ws, "agent", {
|
||||
message: "/new",
|
||||
|
||||
Reference in New Issue
Block a user