mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:40:44 +00:00
test: share msteams runtime setup
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { MSTeamsConversationStore } from "./conversation-store.js";
|
||||
import {
|
||||
type MSTeamsActivityHandler,
|
||||
type MSTeamsMessageHandlerDeps,
|
||||
registerMSTeamsHandlers,
|
||||
} from "./monitor-handler.js";
|
||||
import { setMSTeamsRuntime } from "./runtime.js";
|
||||
import { installMSTeamsTestRuntime } from "./monitor-handler.test-helpers.js";
|
||||
import type { MSTeamsTurnContext } from "./sdk-types.js";
|
||||
|
||||
const runtimeApiMockState = vi.hoisted(() => ({
|
||||
@@ -35,43 +35,7 @@ vi.mock("./reply-dispatcher.js", () => ({
|
||||
}));
|
||||
|
||||
function createDeps(): MSTeamsMessageHandlerDeps {
|
||||
setMSTeamsRuntime({
|
||||
logging: { shouldLogVerbose: () => false },
|
||||
system: { enqueueSystemEvent: vi.fn() },
|
||||
channel: {
|
||||
debounce: {
|
||||
resolveInboundDebounceMs: () => 0,
|
||||
createInboundDebouncer: <T>(params: {
|
||||
onFlush: (entries: T[]) => Promise<void>;
|
||||
}): { enqueue: (entry: T) => Promise<void> } => ({
|
||||
enqueue: async (entry: T) => {
|
||||
await params.onFlush([entry]);
|
||||
},
|
||||
}),
|
||||
},
|
||||
pairing: {
|
||||
readAllowFromStore: vi.fn(async () => []),
|
||||
upsertPairingRequest: vi.fn(async () => null),
|
||||
},
|
||||
text: {
|
||||
hasControlCommand: () => false,
|
||||
},
|
||||
routing: {
|
||||
resolveAgentRoute: ({ peer }: { peer: { kind: string; id: string } }) => ({
|
||||
sessionKey: `msteams:${peer.kind}:${peer.id}`,
|
||||
agentId: "default",
|
||||
accountId: "default",
|
||||
}),
|
||||
},
|
||||
reply: {
|
||||
formatAgentEnvelope: ({ body }: { body: string }) => body,
|
||||
finalizeInboundContext: <T extends Record<string, unknown>>(ctx: T) => ctx,
|
||||
},
|
||||
session: {
|
||||
recordInboundSession: vi.fn(async () => undefined),
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
installMSTeamsTestRuntime();
|
||||
|
||||
return {
|
||||
cfg: {} as OpenClawConfig,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig, PluginRuntime } from "../runtime-api.js";
|
||||
import type { OpenClawConfig } from "../runtime-api.js";
|
||||
import {
|
||||
type MSTeamsActivityHandler,
|
||||
type MSTeamsMessageHandlerDeps,
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
import {
|
||||
createActivityHandler as baseCreateActivityHandler,
|
||||
createMSTeamsMessageHandlerDeps,
|
||||
installMSTeamsTestRuntime,
|
||||
} from "./monitor-handler.test-helpers.js";
|
||||
import { setMSTeamsRuntime } from "./runtime.js";
|
||||
import type { MSTeamsTurnContext } from "./sdk-types.js";
|
||||
import { createMSTeamsSsoTokenStoreMemory } from "./sso-token-store.js";
|
||||
import {
|
||||
@@ -20,46 +20,6 @@ import {
|
||||
parseSigninVerifyStateValue,
|
||||
} from "./sso.js";
|
||||
|
||||
function installTestRuntime(): void {
|
||||
setMSTeamsRuntime({
|
||||
logging: { shouldLogVerbose: () => false },
|
||||
system: { enqueueSystemEvent: vi.fn() },
|
||||
channel: {
|
||||
debounce: {
|
||||
resolveInboundDebounceMs: () => 0,
|
||||
createInboundDebouncer: <T>(params: {
|
||||
onFlush: (entries: T[]) => Promise<void>;
|
||||
}): { enqueue: (entry: T) => Promise<void> } => ({
|
||||
enqueue: async (entry: T) => {
|
||||
await params.onFlush([entry]);
|
||||
},
|
||||
}),
|
||||
},
|
||||
pairing: {
|
||||
readAllowFromStore: vi.fn(async () => []),
|
||||
upsertPairingRequest: vi.fn(async () => null),
|
||||
},
|
||||
text: {
|
||||
hasControlCommand: () => false,
|
||||
},
|
||||
routing: {
|
||||
resolveAgentRoute: ({ peer }: { peer: { kind: string; id: string } }) => ({
|
||||
sessionKey: `msteams:${peer.kind}:${peer.id}`,
|
||||
agentId: "default",
|
||||
accountId: "default",
|
||||
}),
|
||||
},
|
||||
reply: {
|
||||
formatAgentEnvelope: ({ body }: { body: string }) => body,
|
||||
finalizeInboundContext: <T extends Record<string, unknown>>(ctx: T) => ctx,
|
||||
},
|
||||
session: {
|
||||
recordInboundSession: vi.fn(async () => undefined),
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
}
|
||||
|
||||
function createActivityHandler() {
|
||||
const run = vi.fn(async () => undefined);
|
||||
const handler = baseCreateActivityHandler(run);
|
||||
@@ -409,7 +369,7 @@ describe("handleSigninVerifyStateInvoke", () => {
|
||||
|
||||
describe("msteams signin invoke handler registration", () => {
|
||||
beforeAll(() => {
|
||||
installTestRuntime();
|
||||
installMSTeamsTestRuntime();
|
||||
});
|
||||
|
||||
const blockedSigninScenarios = createBlockedSigninScenarios();
|
||||
|
||||
@@ -1,9 +1,68 @@
|
||||
import { vi } from "vitest";
|
||||
import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { OpenClawConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { MSTeamsConversationStore } from "./conversation-store.js";
|
||||
import type { MSTeamsAdapter } from "./messenger.js";
|
||||
import type { MSTeamsActivityHandler, MSTeamsMessageHandlerDeps } from "./monitor-handler.js";
|
||||
import type { MSTeamsPollStore } from "./polls.js";
|
||||
import { setMSTeamsRuntime } from "./runtime.js";
|
||||
|
||||
type RuntimeRoutePeer = { peer: { kind: string; id: string } };
|
||||
|
||||
type MSTeamsTestRuntimeOptions = {
|
||||
enqueueSystemEvent?: ReturnType<typeof vi.fn>;
|
||||
readAllowFromStore?: ReturnType<typeof vi.fn>;
|
||||
upsertPairingRequest?: ReturnType<typeof vi.fn>;
|
||||
recordInboundSession?: ReturnType<typeof vi.fn>;
|
||||
resolveAgentRoute?: (params: RuntimeRoutePeer) => unknown;
|
||||
resolveTextChunkLimit?: () => number;
|
||||
resolveStorePath?: () => string;
|
||||
};
|
||||
|
||||
export function installMSTeamsTestRuntime(options: MSTeamsTestRuntimeOptions = {}): void {
|
||||
setMSTeamsRuntime({
|
||||
logging: { shouldLogVerbose: () => false },
|
||||
system: { enqueueSystemEvent: options.enqueueSystemEvent ?? vi.fn() },
|
||||
channel: {
|
||||
debounce: {
|
||||
resolveInboundDebounceMs: () => 0,
|
||||
createInboundDebouncer: <T>(params: {
|
||||
onFlush: (entries: T[]) => Promise<void>;
|
||||
}): { enqueue: (entry: T) => Promise<void> } => ({
|
||||
enqueue: async (entry: T) => {
|
||||
await params.onFlush([entry]);
|
||||
},
|
||||
}),
|
||||
},
|
||||
pairing: {
|
||||
readAllowFromStore: options.readAllowFromStore ?? vi.fn(async () => []),
|
||||
upsertPairingRequest: options.upsertPairingRequest ?? vi.fn(async () => null),
|
||||
},
|
||||
text: {
|
||||
hasControlCommand: () => false,
|
||||
...(options.resolveTextChunkLimit
|
||||
? { resolveTextChunkLimit: options.resolveTextChunkLimit }
|
||||
: {}),
|
||||
},
|
||||
routing: {
|
||||
resolveAgentRoute:
|
||||
options.resolveAgentRoute ??
|
||||
(({ peer }: RuntimeRoutePeer) => ({
|
||||
sessionKey: `msteams:${peer.kind}:${peer.id}`,
|
||||
agentId: "default",
|
||||
accountId: "default",
|
||||
})),
|
||||
},
|
||||
reply: {
|
||||
formatAgentEnvelope: ({ body }: { body: string }) => body,
|
||||
finalizeInboundContext: <T extends Record<string, unknown>>(ctx: T) => ctx,
|
||||
},
|
||||
session: {
|
||||
recordInboundSession: options.recordInboundSession ?? vi.fn(async () => undefined),
|
||||
...(options.resolveStorePath ? { resolveStorePath: options.resolveStorePath } : {}),
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
}
|
||||
|
||||
export function createActivityHandler(
|
||||
run = vi.fn(async () => undefined),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { vi } from "vitest";
|
||||
import type { OpenClawConfig, PluginRuntime, RuntimeEnv } from "../../runtime-api.js";
|
||||
import type { OpenClawConfig, RuntimeEnv } from "../../runtime-api.js";
|
||||
import type { MSTeamsMessageHandlerDeps } from "../monitor-handler.js";
|
||||
import { setMSTeamsRuntime } from "../runtime.js";
|
||||
import { installMSTeamsTestRuntime } from "../monitor-handler.test-helpers.js";
|
||||
|
||||
export const channelConversationId = "19:general@thread.tacv2";
|
||||
|
||||
@@ -10,7 +10,7 @@ type MessageHandlerDepsOptions = {
|
||||
readAllowFromStore?: ReturnType<typeof vi.fn>;
|
||||
upsertPairingRequest?: ReturnType<typeof vi.fn>;
|
||||
recordInboundSession?: ReturnType<typeof vi.fn>;
|
||||
resolveAgentRoute?: ReturnType<typeof vi.fn>;
|
||||
resolveAgentRoute?: (params: { peer: { kind: string; id: string } }) => unknown;
|
||||
};
|
||||
|
||||
export function createMessageHandlerDeps(
|
||||
@@ -33,39 +33,15 @@ export function createMessageHandlerDeps(
|
||||
matchedBy: "default" as const,
|
||||
}));
|
||||
|
||||
setMSTeamsRuntime({
|
||||
logging: { shouldLogVerbose: () => false },
|
||||
system: { enqueueSystemEvent },
|
||||
channel: {
|
||||
debounce: {
|
||||
resolveInboundDebounceMs: () => 0,
|
||||
createInboundDebouncer: <T>(params: {
|
||||
onFlush: (entries: T[]) => Promise<void>;
|
||||
}): { enqueue: (entry: T) => Promise<void> } => ({
|
||||
enqueue: async (entry: T) => {
|
||||
await params.onFlush([entry]);
|
||||
},
|
||||
}),
|
||||
},
|
||||
pairing: {
|
||||
readAllowFromStore,
|
||||
upsertPairingRequest,
|
||||
},
|
||||
text: {
|
||||
hasControlCommand: () => false,
|
||||
resolveTextChunkLimit: () => 4000,
|
||||
},
|
||||
routing: { resolveAgentRoute },
|
||||
reply: {
|
||||
formatAgentEnvelope: ({ body }: { body: string }) => body,
|
||||
finalizeInboundContext: <T extends Record<string, unknown>>(ctx: T) => ctx,
|
||||
},
|
||||
session: {
|
||||
recordInboundSession,
|
||||
resolveStorePath: () => "/tmp/test-store",
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
installMSTeamsTestRuntime({
|
||||
enqueueSystemEvent,
|
||||
readAllowFromStore,
|
||||
upsertPairingRequest,
|
||||
recordInboundSession,
|
||||
resolveAgentRoute,
|
||||
resolveTextChunkLimit: () => 4000,
|
||||
resolveStorePath: () => "/tmp/test-store",
|
||||
});
|
||||
|
||||
const conversationStore = {
|
||||
get: vi.fn(async () => null),
|
||||
|
||||
Reference in New Issue
Block a user