mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:10:43 +00:00
test: share msteams message handler mocks
This commit is contained in:
@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../../runtime-api.js";
|
||||
import type { GraphThreadMessage } from "../graph-thread.js";
|
||||
import { _resetThreadParentContextCachesForTest } from "../thread-parent-context.js";
|
||||
import { createMSTeamsMessageHandler } from "./message-handler.js";
|
||||
import { getRuntimeApiMockState } from "./message-handler.mock-support.js";
|
||||
import { createMessageHandlerDeps } from "./message-handler.test-support.js";
|
||||
|
||||
type HandlerInput = Parameters<ReturnType<typeof createMSTeamsMessageHandler>>[0];
|
||||
@@ -15,14 +16,7 @@ type TestAttachment = {
|
||||
content: string;
|
||||
};
|
||||
|
||||
const runtimeApiMockState = vi.hoisted(() => ({
|
||||
dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
|
||||
queuedFinal: false,
|
||||
counts: {},
|
||||
capturedCtxPayload: params.ctxPayload,
|
||||
})),
|
||||
}));
|
||||
|
||||
const runtimeApiMockState = getRuntimeApiMockState();
|
||||
const graphThreadMockState = vi.hoisted(() => ({
|
||||
resolveTeamGroupId: vi.fn(async () => "group-1"),
|
||||
fetchChannelMessage: vi.fn<
|
||||
@@ -44,16 +38,6 @@ const graphThreadMockState = vi.hoisted(() => ({
|
||||
>(async () => []),
|
||||
}));
|
||||
|
||||
vi.mock("../../runtime-api.js", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("../../runtime-api.js")>("../../runtime-api.js");
|
||||
return {
|
||||
...actual,
|
||||
dispatchReplyFromConfigWithSettledDispatcher:
|
||||
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../graph-thread.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../graph-thread.js")>("../graph-thread.js");
|
||||
return {
|
||||
@@ -64,14 +48,6 @@ vi.mock("../graph-thread.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../reply-dispatcher.js", () => ({
|
||||
createMSTeamsReplyDispatcher: () => ({
|
||||
dispatcher: {},
|
||||
replyOptions: {},
|
||||
markDispatchIdle: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("msteams monitor handler authz", () => {
|
||||
function createDeps(cfg: OpenClawConfig) {
|
||||
const readAllowFromStore = vi.fn(async () => ["attacker-aad"]);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
const runtimeApiMockState = vi.hoisted(() => ({
|
||||
dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
|
||||
queuedFinal: false,
|
||||
counts: {},
|
||||
capturedCtxPayload: params.ctxPayload,
|
||||
})),
|
||||
}));
|
||||
|
||||
export function getRuntimeApiMockState() {
|
||||
return runtimeApiMockState;
|
||||
}
|
||||
|
||||
vi.mock("../../runtime-api.js", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("../../runtime-api.js")>("../../runtime-api.js");
|
||||
return {
|
||||
...actual,
|
||||
dispatchReplyFromConfigWithSettledDispatcher:
|
||||
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../reply-dispatcher.js", () => ({
|
||||
createMSTeamsReplyDispatcher: () => ({
|
||||
dispatcher: {},
|
||||
replyOptions: {},
|
||||
markDispatchIdle: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
@@ -2,30 +2,14 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../runtime-api.js";
|
||||
import { _resetThreadParentContextCachesForTest } from "../thread-parent-context.js";
|
||||
import { createMSTeamsMessageHandler } from "./message-handler.js";
|
||||
import { getRuntimeApiMockState } from "./message-handler.mock-support.js";
|
||||
import {
|
||||
buildChannelActivity,
|
||||
channelConversationId,
|
||||
createMessageHandlerDeps,
|
||||
} from "./message-handler.test-support.js";
|
||||
|
||||
const runtimeApiMockState = vi.hoisted(() => ({
|
||||
dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
|
||||
queuedFinal: false,
|
||||
counts: {},
|
||||
capturedCtxPayload: params.ctxPayload,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../../runtime-api.js", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("../../runtime-api.js")>("../../runtime-api.js");
|
||||
return {
|
||||
...actual,
|
||||
dispatchReplyFromConfigWithSettledDispatcher:
|
||||
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
|
||||
};
|
||||
});
|
||||
|
||||
const runtimeApiMockState = getRuntimeApiMockState();
|
||||
const fetchChannelMessageMock = vi.hoisted(() => vi.fn());
|
||||
const fetchThreadRepliesMock = vi.hoisted(() => vi.fn(async () => []));
|
||||
const resolveTeamGroupIdMock = vi.hoisted(() => vi.fn(async () => "group-1"));
|
||||
@@ -40,14 +24,6 @@ vi.mock("../graph-thread.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../reply-dispatcher.js", () => ({
|
||||
createMSTeamsReplyDispatcher: () => ({
|
||||
dispatcher: {},
|
||||
replyOptions: {},
|
||||
markDispatchIdle: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("msteams thread parent context injection", () => {
|
||||
type MessageHandler = ReturnType<typeof createMSTeamsMessageHandler>;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../runtime-api.js";
|
||||
import "./message-handler.mock-support.js";
|
||||
import { createMSTeamsMessageHandler } from "./message-handler.js";
|
||||
import {
|
||||
buildChannelActivity,
|
||||
@@ -7,24 +8,6 @@ import {
|
||||
createMessageHandlerDeps,
|
||||
} from "./message-handler.test-support.js";
|
||||
|
||||
const runtimeApiMockState = vi.hoisted(() => ({
|
||||
dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
|
||||
queuedFinal: false,
|
||||
counts: {},
|
||||
capturedCtxPayload: params.ctxPayload,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../../runtime-api.js", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("../../runtime-api.js")>("../../runtime-api.js");
|
||||
return {
|
||||
...actual,
|
||||
dispatchReplyFromConfigWithSettledDispatcher:
|
||||
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../graph-thread.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../graph-thread.js")>("../graph-thread.js");
|
||||
return {
|
||||
@@ -35,14 +18,6 @@ vi.mock("../graph-thread.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../reply-dispatcher.js", () => ({
|
||||
createMSTeamsReplyDispatcher: () => ({
|
||||
dispatcher: {},
|
||||
replyOptions: {},
|
||||
markDispatchIdle: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("msteams thread session isolation", () => {
|
||||
it("appends thread suffix to session key for channel thread replies", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
|
||||
Reference in New Issue
Block a user