@openclaw/msteams 2026.5.2-beta.2 → 2026.5.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/api.js +3 -0
  2. package/dist/channel-D7hdreTh.js +984 -0
  3. package/dist/channel-config-api.js +2 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.runtime-BC1ruIfN.js +573 -0
  6. package/dist/config-schema-B8QezH6t.js +15 -0
  7. package/dist/contract-api.js +2 -0
  8. package/dist/graph-users-9uQJepqr.js +1354 -0
  9. package/dist/index.js +22 -0
  10. package/dist/oauth-BWJyilR1.js +114 -0
  11. package/dist/oauth.token-xxpoLWy5.js +115 -0
  12. package/dist/policy-DTnU2GR7.js +142 -0
  13. package/dist/probe-D_H8yFps.js +2194 -0
  14. package/dist/resolve-allowlist-D41JSziq.js +219 -0
  15. package/dist/runtime-api-DV1iVMn1.js +28 -0
  16. package/dist/runtime-api.js +2 -0
  17. package/dist/secret-contract-BuoEXmPS.js +35 -0
  18. package/dist/secret-contract-api.js +2 -0
  19. package/dist/setup-entry.js +15 -0
  20. package/dist/setup-plugin-api.js +64 -0
  21. package/dist/setup-surface-BLkFQYIQ.js +313 -0
  22. package/dist/src-CFp1QpFd.js +4064 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +14 -6
  25. package/api.ts +0 -3
  26. package/channel-config-api.ts +0 -1
  27. package/channel-plugin-api.ts +0 -2
  28. package/config-api.ts +0 -4
  29. package/contract-api.ts +0 -4
  30. package/index.ts +0 -20
  31. package/runtime-api.ts +0 -73
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-entry.ts +0 -13
  34. package/setup-plugin-api.ts +0 -3
  35. package/src/ai-entity.ts +0 -7
  36. package/src/approval-auth.ts +0 -44
  37. package/src/attachments/bot-framework.test.ts +0 -461
  38. package/src/attachments/bot-framework.ts +0 -362
  39. package/src/attachments/download.ts +0 -311
  40. package/src/attachments/graph.test.ts +0 -416
  41. package/src/attachments/graph.ts +0 -484
  42. package/src/attachments/html.ts +0 -122
  43. package/src/attachments/payload.ts +0 -14
  44. package/src/attachments/remote-media.test.ts +0 -137
  45. package/src/attachments/remote-media.ts +0 -112
  46. package/src/attachments/shared.test.ts +0 -530
  47. package/src/attachments/shared.ts +0 -626
  48. package/src/attachments/types.ts +0 -47
  49. package/src/attachments.graph.test.ts +0 -342
  50. package/src/attachments.helpers.test.ts +0 -246
  51. package/src/attachments.test-helpers.ts +0 -17
  52. package/src/attachments.test.ts +0 -687
  53. package/src/attachments.ts +0 -18
  54. package/src/block-streaming-config.test.ts +0 -61
  55. package/src/channel-api.ts +0 -1
  56. package/src/channel.actions.test.ts +0 -742
  57. package/src/channel.directory.test.ts +0 -200
  58. package/src/channel.runtime.ts +0 -56
  59. package/src/channel.setup.ts +0 -77
  60. package/src/channel.test.ts +0 -128
  61. package/src/channel.ts +0 -1136
  62. package/src/config-schema.ts +0 -6
  63. package/src/config-ui-hints.ts +0 -12
  64. package/src/conversation-store-fs.test.ts +0 -74
  65. package/src/conversation-store-fs.ts +0 -149
  66. package/src/conversation-store-helpers.test.ts +0 -202
  67. package/src/conversation-store-helpers.ts +0 -105
  68. package/src/conversation-store-memory.ts +0 -51
  69. package/src/conversation-store.shared.test.ts +0 -225
  70. package/src/conversation-store.ts +0 -71
  71. package/src/directory-live.test.ts +0 -156
  72. package/src/directory-live.ts +0 -111
  73. package/src/doctor.ts +0 -27
  74. package/src/errors.test.ts +0 -133
  75. package/src/errors.ts +0 -246
  76. package/src/feedback-reflection-prompt.ts +0 -117
  77. package/src/feedback-reflection-store.ts +0 -114
  78. package/src/feedback-reflection.test.ts +0 -237
  79. package/src/feedback-reflection.ts +0 -283
  80. package/src/file-consent-helpers.test.ts +0 -326
  81. package/src/file-consent-helpers.ts +0 -126
  82. package/src/file-consent-invoke.ts +0 -150
  83. package/src/file-consent.test.ts +0 -363
  84. package/src/file-consent.ts +0 -287
  85. package/src/graph-chat.ts +0 -55
  86. package/src/graph-group-management.test.ts +0 -318
  87. package/src/graph-group-management.ts +0 -168
  88. package/src/graph-members.test.ts +0 -89
  89. package/src/graph-members.ts +0 -48
  90. package/src/graph-messages.actions.test.ts +0 -243
  91. package/src/graph-messages.read.test.ts +0 -391
  92. package/src/graph-messages.search.test.ts +0 -213
  93. package/src/graph-messages.test-helpers.ts +0 -50
  94. package/src/graph-messages.ts +0 -534
  95. package/src/graph-teams.test.ts +0 -215
  96. package/src/graph-teams.ts +0 -114
  97. package/src/graph-thread.test.ts +0 -246
  98. package/src/graph-thread.ts +0 -146
  99. package/src/graph-upload.test.ts +0 -258
  100. package/src/graph-upload.ts +0 -531
  101. package/src/graph-users.ts +0 -29
  102. package/src/graph.test.ts +0 -516
  103. package/src/graph.ts +0 -293
  104. package/src/inbound.test.ts +0 -221
  105. package/src/inbound.ts +0 -148
  106. package/src/index.ts +0 -4
  107. package/src/media-helpers.test.ts +0 -202
  108. package/src/media-helpers.ts +0 -105
  109. package/src/mentions.test.ts +0 -244
  110. package/src/mentions.ts +0 -114
  111. package/src/messenger.test.ts +0 -865
  112. package/src/messenger.ts +0 -605
  113. package/src/monitor-handler/access.ts +0 -125
  114. package/src/monitor-handler/inbound-media.test.ts +0 -289
  115. package/src/monitor-handler/inbound-media.ts +0 -180
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  117. package/src/monitor-handler/message-handler.authz.test.ts +0 -669
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  119. package/src/monitor-handler/message-handler.test-support.ts +0 -100
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
  122. package/src/monitor-handler/message-handler.ts +0 -1000
  123. package/src/monitor-handler/reaction-handler.test.ts +0 -267
  124. package/src/monitor-handler/reaction-handler.ts +0 -210
  125. package/src/monitor-handler/thread-session.ts +0 -17
  126. package/src/monitor-handler.adaptive-card.test.ts +0 -162
  127. package/src/monitor-handler.feedback-authz.test.ts +0 -314
  128. package/src/monitor-handler.file-consent.test.ts +0 -423
  129. package/src/monitor-handler.sso.test.ts +0 -563
  130. package/src/monitor-handler.test-helpers.ts +0 -180
  131. package/src/monitor-handler.ts +0 -534
  132. package/src/monitor-handler.types.ts +0 -27
  133. package/src/monitor-types.ts +0 -6
  134. package/src/monitor.lifecycle.test.ts +0 -278
  135. package/src/monitor.test.ts +0 -119
  136. package/src/monitor.ts +0 -442
  137. package/src/oauth.flow.ts +0 -77
  138. package/src/oauth.shared.ts +0 -37
  139. package/src/oauth.test.ts +0 -305
  140. package/src/oauth.token.ts +0 -158
  141. package/src/oauth.ts +0 -130
  142. package/src/outbound.test.ts +0 -130
  143. package/src/outbound.ts +0 -71
  144. package/src/pending-uploads-fs.test.ts +0 -246
  145. package/src/pending-uploads-fs.ts +0 -235
  146. package/src/pending-uploads.test.ts +0 -173
  147. package/src/pending-uploads.ts +0 -121
  148. package/src/policy.test.ts +0 -240
  149. package/src/policy.ts +0 -262
  150. package/src/polls-store-memory.ts +0 -32
  151. package/src/polls.test.ts +0 -160
  152. package/src/polls.ts +0 -323
  153. package/src/presentation.ts +0 -68
  154. package/src/probe.test.ts +0 -77
  155. package/src/probe.ts +0 -132
  156. package/src/reply-dispatcher.test.ts +0 -437
  157. package/src/reply-dispatcher.ts +0 -346
  158. package/src/reply-stream-controller.test.ts +0 -235
  159. package/src/reply-stream-controller.ts +0 -147
  160. package/src/resolve-allowlist.test.ts +0 -250
  161. package/src/resolve-allowlist.ts +0 -309
  162. package/src/revoked-context.ts +0 -17
  163. package/src/runtime.ts +0 -9
  164. package/src/sdk-types.ts +0 -59
  165. package/src/sdk.test.ts +0 -666
  166. package/src/sdk.ts +0 -884
  167. package/src/secret-contract.ts +0 -49
  168. package/src/secret-input.ts +0 -7
  169. package/src/send-context.ts +0 -231
  170. package/src/send.test.ts +0 -493
  171. package/src/send.ts +0 -637
  172. package/src/sent-message-cache.test.ts +0 -15
  173. package/src/sent-message-cache.ts +0 -56
  174. package/src/session-route.ts +0 -40
  175. package/src/setup-core.ts +0 -160
  176. package/src/setup-surface.test.ts +0 -202
  177. package/src/setup-surface.ts +0 -320
  178. package/src/sso-token-store.test.ts +0 -72
  179. package/src/sso-token-store.ts +0 -166
  180. package/src/sso.ts +0 -300
  181. package/src/storage.ts +0 -25
  182. package/src/store-fs.ts +0 -44
  183. package/src/streaming-message.test.ts +0 -262
  184. package/src/streaming-message.ts +0 -297
  185. package/src/test-runtime.ts +0 -16
  186. package/src/thread-parent-context.test.ts +0 -224
  187. package/src/thread-parent-context.ts +0 -159
  188. package/src/token-response.ts +0 -11
  189. package/src/token.test.ts +0 -259
  190. package/src/token.ts +0 -195
  191. package/src/user-agent.test.ts +0 -86
  192. package/src/user-agent.ts +0 -53
  193. package/src/webhook-timeouts.ts +0 -27
  194. package/src/welcome-card.test.ts +0 -81
  195. package/src/welcome-card.ts +0 -57
  196. package/test-api.ts +0 -1
  197. package/tsconfig.json +0 -16
@@ -1,54 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { translateMSTeamsDmConversationIdForGraph } from "../inbound.js";
3
-
4
- describe("translateMSTeamsDmConversationIdForGraph", () => {
5
- it("translates a: conversation ID to Graph format for DMs", () => {
6
- const result = translateMSTeamsDmConversationIdForGraph({
7
- isDirectMessage: true,
8
- conversationId: "a:1abc2def3",
9
- aadObjectId: "user-aad-id",
10
- appId: "bot-app-id",
11
- });
12
- expect(result).toBe("19:user-aad-id_bot-app-id@unq.gbl.spaces");
13
- });
14
-
15
- it("passes through non-a: conversation IDs unchanged", () => {
16
- const result = translateMSTeamsDmConversationIdForGraph({
17
- isDirectMessage: true,
18
- conversationId: "19:existing@unq.gbl.spaces",
19
- aadObjectId: "user-aad-id",
20
- appId: "bot-app-id",
21
- });
22
- expect(result).toBe("19:existing@unq.gbl.spaces");
23
- });
24
-
25
- it("passes through when aadObjectId is missing", () => {
26
- const result = translateMSTeamsDmConversationIdForGraph({
27
- isDirectMessage: true,
28
- conversationId: "a:1abc2def3",
29
- aadObjectId: null,
30
- appId: "bot-app-id",
31
- });
32
- expect(result).toBe("a:1abc2def3");
33
- });
34
-
35
- it("passes through when appId is missing", () => {
36
- const result = translateMSTeamsDmConversationIdForGraph({
37
- isDirectMessage: true,
38
- conversationId: "a:1abc2def3",
39
- aadObjectId: "user-aad-id",
40
- appId: null,
41
- });
42
- expect(result).toBe("a:1abc2def3");
43
- });
44
-
45
- it("passes through for non-DM conversations even with a: prefix", () => {
46
- const result = translateMSTeamsDmConversationIdForGraph({
47
- isDirectMessage: false,
48
- conversationId: "a:1abc2def3",
49
- aadObjectId: "user-aad-id",
50
- appId: "bot-app-id",
51
- });
52
- expect(result).toBe("a:1abc2def3");
53
- });
54
- });
@@ -1,100 +0,0 @@
1
- import { vi } from "vitest";
2
- import type { OpenClawConfig, RuntimeEnv } from "../../runtime-api.js";
3
- import type { MSTeamsMessageHandlerDeps } from "../monitor-handler.js";
4
- import { installMSTeamsTestRuntime } from "../monitor-handler.test-helpers.js";
5
-
6
- export const channelConversationId = "19:general@thread.tacv2";
7
-
8
- type MessageHandlerDepsOptions = {
9
- enqueueSystemEvent?: ReturnType<typeof vi.fn>;
10
- readAllowFromStore?: ReturnType<typeof vi.fn>;
11
- upsertPairingRequest?: ReturnType<typeof vi.fn>;
12
- recordInboundSession?: ReturnType<typeof vi.fn>;
13
- resolveAgentRoute?: (params: { peer: { kind: string; id: string } }) => unknown;
14
- };
15
-
16
- export function createMessageHandlerDeps(
17
- cfg: OpenClawConfig,
18
- options: MessageHandlerDepsOptions = {},
19
- ) {
20
- const enqueueSystemEvent = options.enqueueSystemEvent ?? vi.fn();
21
- const readAllowFromStore = options.readAllowFromStore ?? vi.fn(async () => []);
22
- const upsertPairingRequest = options.upsertPairingRequest ?? vi.fn(async () => null);
23
- const recordInboundSession =
24
- options.recordInboundSession ?? vi.fn(async (_params: { sessionKey: string }) => undefined);
25
- const resolveAgentRoute =
26
- options.resolveAgentRoute ??
27
- vi.fn(({ peer }: { peer: { kind: string; id: string } }) => ({
28
- sessionKey: `agent:main:msteams:${peer.kind}:${peer.id}`,
29
- agentId: "main",
30
- accountId: "default",
31
- mainSessionKey: "agent:main:main",
32
- lastRoutePolicy: "session" as const,
33
- matchedBy: "default" as const,
34
- }));
35
-
36
- installMSTeamsTestRuntime({
37
- enqueueSystemEvent,
38
- readAllowFromStore,
39
- upsertPairingRequest,
40
- recordInboundSession,
41
- resolveAgentRoute,
42
- resolveTextChunkLimit: () => 4000,
43
- resolveStorePath: () => "/tmp/test-store",
44
- });
45
-
46
- const conversationStore = {
47
- get: vi.fn(async () => null),
48
- upsert: vi.fn(async () => undefined),
49
- list: vi.fn(async () => []),
50
- remove: vi.fn(async () => false),
51
- findPreferredDmByUserId: vi.fn(async () => null),
52
- findByUserId: vi.fn(async () => null),
53
- } satisfies MSTeamsMessageHandlerDeps["conversationStore"];
54
-
55
- const deps: MSTeamsMessageHandlerDeps = {
56
- cfg,
57
- runtime: { error: vi.fn() } as unknown as RuntimeEnv,
58
- appId: "test-app",
59
- adapter: {} as MSTeamsMessageHandlerDeps["adapter"],
60
- tokenProvider: {
61
- getAccessToken: vi.fn(async () => "token"),
62
- },
63
- textLimit: 4000,
64
- mediaMaxBytes: 1024 * 1024,
65
- conversationStore,
66
- pollStore: {
67
- recordVote: vi.fn(async () => null),
68
- } as unknown as MSTeamsMessageHandlerDeps["pollStore"],
69
- log: {
70
- info: vi.fn(),
71
- debug: vi.fn(),
72
- error: vi.fn(),
73
- } as unknown as MSTeamsMessageHandlerDeps["log"],
74
- };
75
-
76
- return {
77
- conversationStore,
78
- deps,
79
- enqueueSystemEvent,
80
- readAllowFromStore,
81
- upsertPairingRequest,
82
- recordInboundSession,
83
- resolveAgentRoute,
84
- };
85
- }
86
-
87
- export function buildChannelActivity(overrides: Record<string, unknown> = {}) {
88
- return {
89
- id: "msg-1",
90
- type: "message",
91
- text: "hello",
92
- from: { id: "user-id", aadObjectId: "user-aad", name: "Test User" },
93
- recipient: { id: "bot-id", name: "Bot" },
94
- conversation: { id: channelConversationId, conversationType: "channel" },
95
- channelData: { team: { id: "team-1" } },
96
- attachments: [],
97
- entities: [{ type: "mention", mentioned: { id: "bot-id" } }],
98
- ...overrides,
99
- };
100
- }
@@ -1,223 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { OpenClawConfig } from "../../runtime-api.js";
3
- import { _resetThreadParentContextCachesForTest } from "../thread-parent-context.js";
4
- import "./message-handler-mock-support.test-support.js";
5
- import { getRuntimeApiMockState } from "./message-handler-mock-support.test-support.js";
6
- import { createMSTeamsMessageHandler } from "./message-handler.js";
7
- import {
8
- buildChannelActivity,
9
- channelConversationId,
10
- createMessageHandlerDeps,
11
- } from "./message-handler.test-support.js";
12
-
13
- const runtimeApiMockState = getRuntimeApiMockState();
14
- const fetchChannelMessageMock = vi.hoisted(() => vi.fn());
15
- const fetchThreadRepliesMock = vi.hoisted(() => vi.fn(async () => []));
16
- const resolveTeamGroupIdMock = vi.hoisted(() => vi.fn(async () => "group-1"));
17
-
18
- vi.mock("../graph-thread.js", () => {
19
- const stripHtmlFromTeamsMessage = (html: string) =>
20
- html
21
- .replace(/<at[^>]*>(.*?)<\/at>/gi, "@$1")
22
- .replace(/<[^>]*>/g, " ")
23
- .replace(/&amp;/g, "&")
24
- .replace(/&lt;/g, "<")
25
- .replace(/&gt;/g, ">")
26
- .replace(/&quot;/g, '"')
27
- .replace(/&#39;/g, "'")
28
- .replace(/&nbsp;/g, " ")
29
- .replace(/\s+/g, " ")
30
- .trim();
31
- return {
32
- stripHtmlFromTeamsMessage,
33
- resolveTeamGroupId: resolveTeamGroupIdMock,
34
- fetchChannelMessage: fetchChannelMessageMock,
35
- fetchThreadReplies: fetchThreadRepliesMock,
36
- };
37
- });
38
-
39
- describe("msteams thread parent context injection", () => {
40
- type MessageHandler = ReturnType<typeof createMSTeamsMessageHandler>;
41
-
42
- function findParentSystemEventCall(
43
- mock: ReturnType<typeof vi.fn>,
44
- ): [string, { sessionKey: string; contextKey?: string }] | undefined {
45
- const calls = mock.mock.calls as Array<[string, { sessionKey: string; contextKey?: string }]>;
46
- return calls.find(([text]) => text.startsWith("Replying to @"));
47
- }
48
-
49
- async function dispatchThreadReply(handler: MessageHandler, id: string) {
50
- await handler({
51
- activity: buildChannelActivity({ id, replyToId: "thread-root-123" }),
52
- sendActivity: vi.fn(async () => undefined),
53
- } as unknown as Parameters<MessageHandler>[0]);
54
- }
55
-
56
- async function dispatchTwoThreadReplies(handler: MessageHandler) {
57
- await dispatchThreadReply(handler, "msg-reply-1");
58
- await dispatchThreadReply(handler, "msg-reply-2");
59
- }
60
-
61
- beforeEach(() => {
62
- _resetThreadParentContextCachesForTest();
63
- fetchChannelMessageMock.mockReset();
64
- fetchThreadRepliesMock.mockReset();
65
- fetchThreadRepliesMock.mockImplementation(async () => []);
66
- resolveTeamGroupIdMock.mockReset();
67
- resolveTeamGroupIdMock.mockImplementation(async () => "group-1");
68
- runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher.mockClear();
69
- });
70
-
71
- const cfg: OpenClawConfig = {
72
- channels: { msteams: { groupPolicy: "open" } },
73
- } as OpenClawConfig;
74
-
75
- it("enqueues a Replying to @sender system event on the first thread reply", async () => {
76
- fetchChannelMessageMock.mockResolvedValueOnce({
77
- id: "thread-root-123",
78
- from: { user: { displayName: "Alice", id: "alice-id" } },
79
- body: { content: "Can someone investigate the latency spike?", contentType: "text" },
80
- });
81
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
82
- const handler = createMSTeamsMessageHandler(deps);
83
-
84
- await handler({
85
- activity: buildChannelActivity({ id: "msg-reply-1", replyToId: "thread-root-123" }),
86
- sendActivity: vi.fn(async () => undefined),
87
- } as unknown as Parameters<typeof handler>[0]);
88
-
89
- const parentCall = findParentSystemEventCall(enqueueSystemEvent);
90
- expect(parentCall).toBeDefined();
91
- expect(parentCall?.[0]).toBe("Replying to @Alice: Can someone investigate the latency spike?");
92
- expect(parentCall?.[1]?.contextKey).toContain("msteams:thread-parent:");
93
- expect(parentCall?.[1]?.contextKey).toContain("thread-root-123");
94
- });
95
-
96
- it("caches parent fetches across thread replies in the same session", async () => {
97
- fetchChannelMessageMock.mockResolvedValue({
98
- id: "thread-root-123",
99
- from: { user: { displayName: "Alice" } },
100
- body: { content: "Original question", contentType: "text" },
101
- });
102
- const { deps } = createMessageHandlerDeps(cfg);
103
- const handler = createMSTeamsMessageHandler(deps);
104
-
105
- await dispatchTwoThreadReplies(handler);
106
-
107
- // Parent message fetched exactly once across two replies thanks to LRU cache.
108
- expect(fetchChannelMessageMock).toHaveBeenCalledTimes(1);
109
- });
110
-
111
- it("does not re-enqueue the same parent context within the same session", async () => {
112
- fetchChannelMessageMock.mockResolvedValue({
113
- id: "thread-root-123",
114
- from: { user: { displayName: "Alice" } },
115
- body: { content: "Original question", contentType: "text" },
116
- });
117
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
118
- const handler = createMSTeamsMessageHandler(deps);
119
-
120
- await dispatchTwoThreadReplies(handler);
121
-
122
- const parentCalls = enqueueSystemEvent.mock.calls.filter(
123
- ([text]) => typeof text === "string" && text.startsWith("Replying to @"),
124
- );
125
- expect(parentCalls).toHaveLength(1);
126
- });
127
-
128
- it("does not enqueue parent context when allowlist visibility blocks the parent sender", async () => {
129
- fetchChannelMessageMock.mockResolvedValue({
130
- id: "thread-root-123",
131
- from: { user: { displayName: "Mallory", id: "mallory-aad" } },
132
- body: { content: "Blocked context", contentType: "text" },
133
- });
134
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps({
135
- channels: {
136
- msteams: {
137
- groupPolicy: "allowlist",
138
- groupAllowFrom: ["alice-aad"],
139
- contextVisibility: "allowlist",
140
- teams: {
141
- "team-1": {
142
- channels: {
143
- [channelConversationId]: { requireMention: false },
144
- },
145
- },
146
- },
147
- },
148
- },
149
- } as OpenClawConfig);
150
- const handler = createMSTeamsMessageHandler(deps);
151
-
152
- await handler({
153
- activity: buildChannelActivity({
154
- id: "msg-reply-1",
155
- replyToId: "thread-root-123",
156
- from: { id: "alice-id", aadObjectId: "alice-aad", name: "Alice" },
157
- }),
158
- sendActivity: vi.fn(async () => undefined),
159
- } as unknown as Parameters<typeof handler>[0]);
160
-
161
- expect(findParentSystemEventCall(enqueueSystemEvent)).toBeUndefined();
162
- });
163
-
164
- it("handles Graph failure gracefully without throwing or emitting a parent event", async () => {
165
- fetchChannelMessageMock.mockRejectedValueOnce(new Error("graph down"));
166
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
167
- const handler = createMSTeamsMessageHandler(deps);
168
-
169
- await handler({
170
- activity: buildChannelActivity({ id: "msg-reply-1", replyToId: "thread-root-123" }),
171
- sendActivity: vi.fn(async () => undefined),
172
- } as unknown as Parameters<typeof handler>[0]);
173
-
174
- const parentCall = findParentSystemEventCall(enqueueSystemEvent);
175
- expect(parentCall).toBeUndefined();
176
- // Original inbound system event still fires (best-effort parent fetch does not block).
177
- expect(enqueueSystemEvent).toHaveBeenCalled();
178
- });
179
-
180
- it("does not fetch parent for DM replyToId", async () => {
181
- fetchChannelMessageMock.mockResolvedValue({
182
- id: "x",
183
- from: { user: { displayName: "Alice" } },
184
- body: { content: "should-not-happen", contentType: "text" },
185
- });
186
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps({
187
- channels: { msteams: { allowFrom: ["*"] } },
188
- } as OpenClawConfig);
189
- const handler = createMSTeamsMessageHandler(deps);
190
-
191
- await handler({
192
- activity: {
193
- ...buildChannelActivity(),
194
- conversation: { id: "a:dm-conversation", conversationType: "personal" },
195
- channelData: {},
196
- replyToId: "dm-parent",
197
- entities: [],
198
- },
199
- sendActivity: vi.fn(async () => undefined),
200
- } as unknown as Parameters<typeof handler>[0]);
201
-
202
- expect(fetchChannelMessageMock).not.toHaveBeenCalled();
203
- expect(findParentSystemEventCall(enqueueSystemEvent)).toBeUndefined();
204
- });
205
-
206
- it("does not fetch parent for top-level channel messages without replyToId", async () => {
207
- fetchChannelMessageMock.mockResolvedValue({
208
- id: "x",
209
- from: { user: { displayName: "Alice" } },
210
- body: { content: "should-not-happen", contentType: "text" },
211
- });
212
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
213
- const handler = createMSTeamsMessageHandler(deps);
214
-
215
- await handler({
216
- activity: buildChannelActivity({ id: "msg-root-1", replyToId: undefined }),
217
- sendActivity: vi.fn(async () => undefined),
218
- } as unknown as Parameters<typeof handler>[0]);
219
-
220
- expect(fetchChannelMessageMock).not.toHaveBeenCalled();
221
- expect(findParentSystemEventCall(enqueueSystemEvent)).toBeUndefined();
222
- });
223
- });
@@ -1,77 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { resolveMSTeamsRouteSessionKey } from "./thread-session.js";
3
-
4
- const channelConversationSessionKey = "agent:main:msteams:channel:19:channel@thread.tacv2";
5
-
6
- describe("msteams thread session isolation", () => {
7
- it("appends thread suffix to session key for channel thread replies", async () => {
8
- const sessionKey = resolveMSTeamsRouteSessionKey({
9
- baseSessionKey: channelConversationSessionKey,
10
- isChannel: true,
11
- replyToId: "thread-root-123",
12
- });
13
-
14
- expect(sessionKey).toContain("thread:");
15
- expect(sessionKey).toContain("thread-root-123");
16
- });
17
-
18
- it("does not append thread suffix for top-level channel messages", async () => {
19
- const sessionKey = resolveMSTeamsRouteSessionKey({
20
- baseSessionKey: channelConversationSessionKey,
21
- isChannel: true,
22
- replyToId: undefined,
23
- });
24
-
25
- expect(sessionKey).not.toContain("thread:");
26
- expect(sessionKey).toBe(channelConversationSessionKey);
27
- });
28
-
29
- it("produces different session keys for different threads in the same channel", async () => {
30
- const sessionKeyA = resolveMSTeamsRouteSessionKey({
31
- baseSessionKey: channelConversationSessionKey,
32
- isChannel: true,
33
- replyToId: "thread-A",
34
- });
35
- const sessionKeyB = resolveMSTeamsRouteSessionKey({
36
- baseSessionKey: channelConversationSessionKey,
37
- isChannel: true,
38
- replyToId: "thread-B",
39
- });
40
-
41
- expect(sessionKeyA).not.toBe(sessionKeyB);
42
- expect(sessionKeyA).toContain("thread-a"); // normalized lowercase
43
- expect(sessionKeyB).toContain("thread-b");
44
- });
45
-
46
- it("does not affect DM session keys", async () => {
47
- const sessionKey = resolveMSTeamsRouteSessionKey({
48
- baseSessionKey: "agent:main:msteams:dm:user-1",
49
- isChannel: false,
50
- replyToId: "some-reply-id",
51
- });
52
-
53
- expect(sessionKey).not.toContain("thread:");
54
- });
55
-
56
- it("does not affect group chat session keys", async () => {
57
- const sessionKey = resolveMSTeamsRouteSessionKey({
58
- baseSessionKey: "agent:main:msteams:group:19:group-chat-id@unq.gbl.spaces",
59
- isChannel: false,
60
- replyToId: "some-reply-id",
61
- });
62
-
63
- expect(sessionKey).not.toContain("thread:");
64
- });
65
-
66
- it("prefers conversation message id over replyToId for deep channel replies", async () => {
67
- const sessionKey = resolveMSTeamsRouteSessionKey({
68
- baseSessionKey: channelConversationSessionKey,
69
- isChannel: true,
70
- conversationMessageId: "thread-root",
71
- replyToId: "nested-reply",
72
- });
73
-
74
- expect(sessionKey).toContain("thread-root");
75
- expect(sessionKey).not.toContain("nested-reply");
76
- });
77
- });