@kodelyth/msteams 2026.5.42 → 2026.6.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 (177) hide show
  1. package/klaw.plugin.json +726 -2
  2. package/package.json +16 -4
  3. package/api.ts +0 -3
  4. package/channel-config-api.ts +0 -1
  5. package/channel-plugin-api.ts +0 -2
  6. package/config-api.ts +0 -4
  7. package/contract-api.ts +0 -4
  8. package/index.ts +0 -20
  9. package/runtime-api.ts +0 -66
  10. package/secret-contract-api.ts +0 -5
  11. package/setup-entry.ts +0 -13
  12. package/setup-plugin-api.ts +0 -3
  13. package/src/ai-entity.ts +0 -7
  14. package/src/approval-auth.ts +0 -44
  15. package/src/attachments/bot-framework.test.ts +0 -506
  16. package/src/attachments/bot-framework.ts +0 -348
  17. package/src/attachments/download.ts +0 -328
  18. package/src/attachments/graph.test.ts +0 -441
  19. package/src/attachments/graph.ts +0 -489
  20. package/src/attachments/html.ts +0 -122
  21. package/src/attachments/payload.ts +0 -14
  22. package/src/attachments/remote-media.test.ts +0 -187
  23. package/src/attachments/remote-media.ts +0 -86
  24. package/src/attachments/shared.test.ts +0 -547
  25. package/src/attachments/shared.ts +0 -655
  26. package/src/attachments/types.ts +0 -47
  27. package/src/attachments.graph.test.ts +0 -414
  28. package/src/attachments.helpers.test.ts +0 -245
  29. package/src/attachments.test-helpers.ts +0 -17
  30. package/src/attachments.test.ts +0 -754
  31. package/src/attachments.ts +0 -18
  32. package/src/block-streaming-config.test.ts +0 -61
  33. package/src/channel-api.ts +0 -1
  34. package/src/channel.actions.test.ts +0 -797
  35. package/src/channel.directory.test.ts +0 -176
  36. package/src/channel.message-adapter.test.ts +0 -227
  37. package/src/channel.runtime.ts +0 -56
  38. package/src/channel.setup.ts +0 -77
  39. package/src/channel.test.ts +0 -136
  40. package/src/channel.ts +0 -1176
  41. package/src/config-schema.ts +0 -6
  42. package/src/config-ui-hints.ts +0 -40
  43. package/src/conversation-store-fs.test.ts +0 -81
  44. package/src/conversation-store-fs.ts +0 -149
  45. package/src/conversation-store-helpers.test.ts +0 -202
  46. package/src/conversation-store-helpers.ts +0 -105
  47. package/src/conversation-store-memory.ts +0 -51
  48. package/src/conversation-store.shared.test.ts +0 -260
  49. package/src/conversation-store.ts +0 -71
  50. package/src/directory-live.test.ts +0 -156
  51. package/src/directory-live.ts +0 -111
  52. package/src/doctor.ts +0 -27
  53. package/src/errors.test.ts +0 -154
  54. package/src/errors.ts +0 -270
  55. package/src/feedback-reflection-prompt.ts +0 -117
  56. package/src/feedback-reflection-store.ts +0 -113
  57. package/src/feedback-reflection.test.ts +0 -237
  58. package/src/feedback-reflection.ts +0 -268
  59. package/src/file-consent-helpers.test.ts +0 -328
  60. package/src/file-consent-helpers.ts +0 -115
  61. package/src/file-consent-invoke.ts +0 -150
  62. package/src/file-consent.test.ts +0 -378
  63. package/src/file-consent.ts +0 -223
  64. package/src/graph-chat.ts +0 -36
  65. package/src/graph-group-management.test.ts +0 -332
  66. package/src/graph-group-management.ts +0 -168
  67. package/src/graph-members.test.ts +0 -89
  68. package/src/graph-members.ts +0 -48
  69. package/src/graph-messages.actions.test.ts +0 -253
  70. package/src/graph-messages.read.test.ts +0 -391
  71. package/src/graph-messages.search.test.ts +0 -227
  72. package/src/graph-messages.test-helpers.ts +0 -50
  73. package/src/graph-messages.ts +0 -534
  74. package/src/graph-teams.test.ts +0 -222
  75. package/src/graph-teams.ts +0 -114
  76. package/src/graph-thread.test.ts +0 -252
  77. package/src/graph-thread.ts +0 -146
  78. package/src/graph-upload.test.ts +0 -253
  79. package/src/graph-upload.ts +0 -531
  80. package/src/graph-users.ts +0 -29
  81. package/src/graph.test.ts +0 -540
  82. package/src/graph.ts +0 -308
  83. package/src/inbound.test.ts +0 -221
  84. package/src/inbound.ts +0 -148
  85. package/src/index.ts +0 -4
  86. package/src/media-helpers.test.ts +0 -220
  87. package/src/media-helpers.ts +0 -105
  88. package/src/mentions.test.ts +0 -254
  89. package/src/mentions.ts +0 -114
  90. package/src/messenger.test.ts +0 -961
  91. package/src/messenger.ts +0 -608
  92. package/src/monitor-handler/access.ts +0 -136
  93. package/src/monitor-handler/inbound-media.test.ts +0 -314
  94. package/src/monitor-handler/inbound-media.ts +0 -180
  95. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  96. package/src/monitor-handler/message-handler.authz.test.ts +0 -739
  97. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  98. package/src/monitor-handler/message-handler.test-support.ts +0 -99
  99. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -225
  100. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -132
  101. package/src/monitor-handler/message-handler.ts +0 -1003
  102. package/src/monitor-handler/reaction-handler.test.ts +0 -325
  103. package/src/monitor-handler/reaction-handler.ts +0 -122
  104. package/src/monitor-handler/thread-session.ts +0 -30
  105. package/src/monitor-handler.adaptive-card.test.ts +0 -158
  106. package/src/monitor-handler.feedback-authz.test.ts +0 -357
  107. package/src/monitor-handler.file-consent.test.ts +0 -443
  108. package/src/monitor-handler.sso.test.ts +0 -576
  109. package/src/monitor-handler.test-helpers.ts +0 -181
  110. package/src/monitor-handler.ts +0 -538
  111. package/src/monitor-handler.types.ts +0 -27
  112. package/src/monitor-types.ts +0 -6
  113. package/src/monitor.lifecycle.test.ts +0 -457
  114. package/src/monitor.test.ts +0 -119
  115. package/src/monitor.ts +0 -476
  116. package/src/oauth.flow.ts +0 -77
  117. package/src/oauth.shared.ts +0 -37
  118. package/src/oauth.test.ts +0 -350
  119. package/src/oauth.token.ts +0 -162
  120. package/src/oauth.ts +0 -130
  121. package/src/outbound.test.ts +0 -400
  122. package/src/outbound.ts +0 -198
  123. package/src/pending-uploads-fs.test.ts +0 -261
  124. package/src/pending-uploads-fs.ts +0 -235
  125. package/src/pending-uploads.test.ts +0 -186
  126. package/src/pending-uploads.ts +0 -121
  127. package/src/policy.test.ts +0 -156
  128. package/src/policy.ts +0 -245
  129. package/src/polls-store-memory.ts +0 -32
  130. package/src/polls.test.ts +0 -169
  131. package/src/polls.ts +0 -312
  132. package/src/presentation.ts +0 -93
  133. package/src/probe.test.ts +0 -79
  134. package/src/probe.ts +0 -132
  135. package/src/reply-dispatcher.test.ts +0 -543
  136. package/src/reply-dispatcher.ts +0 -523
  137. package/src/reply-stream-controller.test.ts +0 -424
  138. package/src/reply-stream-controller.ts +0 -334
  139. package/src/resolve-allowlist.test.ts +0 -253
  140. package/src/resolve-allowlist.ts +0 -309
  141. package/src/revoked-context.ts +0 -17
  142. package/src/runtime.ts +0 -12
  143. package/src/sdk-types.ts +0 -59
  144. package/src/sdk.test.ts +0 -727
  145. package/src/sdk.ts +0 -916
  146. package/src/secret-contract.ts +0 -49
  147. package/src/secret-input.ts +0 -7
  148. package/src/send-context.test.ts +0 -93
  149. package/src/send-context.ts +0 -269
  150. package/src/send.test.ts +0 -588
  151. package/src/send.ts +0 -697
  152. package/src/sent-message-cache.test.ts +0 -106
  153. package/src/sent-message-cache.ts +0 -174
  154. package/src/session-route.ts +0 -40
  155. package/src/setup-core.ts +0 -162
  156. package/src/setup-surface.test.ts +0 -175
  157. package/src/setup-surface.ts +0 -319
  158. package/src/sso-token-store.test.ts +0 -74
  159. package/src/sso-token-store.ts +0 -166
  160. package/src/sso.ts +0 -300
  161. package/src/storage.ts +0 -25
  162. package/src/store-fs.ts +0 -42
  163. package/src/streaming-message.test.ts +0 -323
  164. package/src/streaming-message.ts +0 -327
  165. package/src/test-runtime.ts +0 -16
  166. package/src/thread-parent-context.test.ts +0 -224
  167. package/src/thread-parent-context.ts +0 -159
  168. package/src/token-response.ts +0 -11
  169. package/src/token.test.ts +0 -268
  170. package/src/token.ts +0 -194
  171. package/src/user-agent.test.ts +0 -121
  172. package/src/user-agent.ts +0 -53
  173. package/src/webhook-timeouts.ts +0 -27
  174. package/src/welcome-card.test.ts +0 -104
  175. package/src/welcome-card.ts +0 -57
  176. package/test-api.ts +0 -1
  177. 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,99 +0,0 @@
1
- import { vi } from "vitest";
2
- import type { KlawConfig, PluginRuntime, 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
- hasControlCommand?: PluginRuntime["channel"]["text"]["hasControlCommand"];
15
- };
16
-
17
- export function createMessageHandlerDeps(cfg: KlawConfig, options: MessageHandlerDepsOptions = {}) {
18
- const enqueueSystemEvent = options.enqueueSystemEvent ?? vi.fn();
19
- const readAllowFromStore = options.readAllowFromStore ?? vi.fn(async () => []);
20
- const upsertPairingRequest = options.upsertPairingRequest ?? vi.fn(async () => null);
21
- const recordInboundSession =
22
- options.recordInboundSession ?? vi.fn(async (_params: { sessionKey: string }) => undefined);
23
- const resolveAgentRoute =
24
- options.resolveAgentRoute ??
25
- vi.fn(({ peer }: { peer: { kind: string; id: string } }) => ({
26
- sessionKey: `agent:main:msteams:${peer.kind}:${peer.id}`,
27
- agentId: "main",
28
- accountId: "default",
29
- mainSessionKey: "agent:main:main",
30
- lastRoutePolicy: "session" as const,
31
- matchedBy: "default" as const,
32
- }));
33
-
34
- installMSTeamsTestRuntime({
35
- enqueueSystemEvent,
36
- readAllowFromStore,
37
- upsertPairingRequest,
38
- recordInboundSession,
39
- resolveAgentRoute,
40
- hasControlCommand: options.hasControlCommand,
41
- resolveTextChunkLimit: () => 4000,
42
- resolveStorePath: () => "/tmp/test-store",
43
- });
44
-
45
- const conversationStore = {
46
- get: vi.fn(async () => null),
47
- upsert: vi.fn(async () => undefined),
48
- list: vi.fn(async () => []),
49
- remove: vi.fn(async () => false),
50
- findPreferredDmByUserId: vi.fn(async () => null),
51
- findByUserId: vi.fn(async () => null),
52
- } satisfies MSTeamsMessageHandlerDeps["conversationStore"];
53
-
54
- const deps: MSTeamsMessageHandlerDeps = {
55
- cfg,
56
- runtime: { error: vi.fn() } as unknown as RuntimeEnv,
57
- appId: "test-app",
58
- adapter: {} as MSTeamsMessageHandlerDeps["adapter"],
59
- tokenProvider: {
60
- getAccessToken: vi.fn(async () => "token"),
61
- },
62
- textLimit: 4000,
63
- mediaMaxBytes: 1024 * 1024,
64
- conversationStore,
65
- pollStore: {
66
- recordVote: vi.fn(async () => null),
67
- } as unknown as MSTeamsMessageHandlerDeps["pollStore"],
68
- log: {
69
- info: vi.fn(),
70
- debug: vi.fn(),
71
- error: vi.fn(),
72
- } as unknown as MSTeamsMessageHandlerDeps["log"],
73
- };
74
-
75
- return {
76
- conversationStore,
77
- deps,
78
- enqueueSystemEvent,
79
- readAllowFromStore,
80
- upsertPairingRequest,
81
- recordInboundSession,
82
- resolveAgentRoute,
83
- };
84
- }
85
-
86
- export function buildChannelActivity(overrides: Record<string, unknown> = {}) {
87
- return {
88
- id: "msg-1",
89
- type: "message",
90
- text: "hello",
91
- from: { id: "user-id", aadObjectId: "user-aad", name: "Test User" },
92
- recipient: { id: "bot-id", name: "Bot" },
93
- conversation: { id: channelConversationId, conversationType: "channel" },
94
- channelData: { team: { id: "team-1" } },
95
- attachments: [],
96
- entities: [{ type: "mention", mentioned: { id: "bot-id" } }],
97
- ...overrides,
98
- };
99
- }
@@ -1,225 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { KlawConfig } 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: KlawConfig = {
72
- channels: { msteams: { groupPolicy: "open" } },
73
- } as KlawConfig;
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
- if (!parentCall) {
91
- throw new Error("expected parent thread system event");
92
- }
93
- expect(parentCall[0]).toBe("Replying to @Alice: Can someone investigate the latency spike?");
94
- expect(parentCall[1]?.contextKey).toContain("msteams:thread-parent:");
95
- expect(parentCall[1]?.contextKey).toContain("thread-root-123");
96
- });
97
-
98
- it("caches parent fetches across thread replies in the same session", async () => {
99
- fetchChannelMessageMock.mockResolvedValue({
100
- id: "thread-root-123",
101
- from: { user: { displayName: "Alice" } },
102
- body: { content: "Original question", contentType: "text" },
103
- });
104
- const { deps } = createMessageHandlerDeps(cfg);
105
- const handler = createMSTeamsMessageHandler(deps);
106
-
107
- await dispatchTwoThreadReplies(handler);
108
-
109
- // Parent message fetched exactly once across two replies thanks to LRU cache.
110
- expect(fetchChannelMessageMock).toHaveBeenCalledTimes(1);
111
- });
112
-
113
- it("does not re-enqueue the same parent context within the same session", async () => {
114
- fetchChannelMessageMock.mockResolvedValue({
115
- id: "thread-root-123",
116
- from: { user: { displayName: "Alice" } },
117
- body: { content: "Original question", contentType: "text" },
118
- });
119
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
120
- const handler = createMSTeamsMessageHandler(deps);
121
-
122
- await dispatchTwoThreadReplies(handler);
123
-
124
- const parentCalls = enqueueSystemEvent.mock.calls.filter(
125
- ([text]) => typeof text === "string" && text.startsWith("Replying to @"),
126
- );
127
- expect(parentCalls).toHaveLength(1);
128
- });
129
-
130
- it("does not enqueue parent context when allowlist visibility blocks the parent sender", async () => {
131
- fetchChannelMessageMock.mockResolvedValue({
132
- id: "thread-root-123",
133
- from: { user: { displayName: "Mallory", id: "mallory-aad" } },
134
- body: { content: "Blocked context", contentType: "text" },
135
- });
136
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps({
137
- channels: {
138
- msteams: {
139
- groupPolicy: "allowlist",
140
- groupAllowFrom: ["alice-aad"],
141
- contextVisibility: "allowlist",
142
- teams: {
143
- "team-1": {
144
- channels: {
145
- [channelConversationId]: { requireMention: false },
146
- },
147
- },
148
- },
149
- },
150
- },
151
- } as KlawConfig);
152
- const handler = createMSTeamsMessageHandler(deps);
153
-
154
- await handler({
155
- activity: buildChannelActivity({
156
- id: "msg-reply-1",
157
- replyToId: "thread-root-123",
158
- from: { id: "alice-id", aadObjectId: "alice-aad", name: "Alice" },
159
- }),
160
- sendActivity: vi.fn(async () => undefined),
161
- } as unknown as Parameters<typeof handler>[0]);
162
-
163
- expect(findParentSystemEventCall(enqueueSystemEvent)).toBeUndefined();
164
- });
165
-
166
- it("handles Graph failure gracefully without throwing or emitting a parent event", async () => {
167
- fetchChannelMessageMock.mockRejectedValueOnce(new Error("graph down"));
168
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
169
- const handler = createMSTeamsMessageHandler(deps);
170
-
171
- await handler({
172
- activity: buildChannelActivity({ id: "msg-reply-1", replyToId: "thread-root-123" }),
173
- sendActivity: vi.fn(async () => undefined),
174
- } as unknown as Parameters<typeof handler>[0]);
175
-
176
- const parentCall = findParentSystemEventCall(enqueueSystemEvent);
177
- expect(parentCall).toBeUndefined();
178
- // Original inbound system event still fires (best-effort parent fetch does not block).
179
- expect(enqueueSystemEvent).toHaveBeenCalled();
180
- });
181
-
182
- it("does not fetch parent for DM replyToId", async () => {
183
- fetchChannelMessageMock.mockResolvedValue({
184
- id: "x",
185
- from: { user: { displayName: "Alice" } },
186
- body: { content: "should-not-happen", contentType: "text" },
187
- });
188
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps({
189
- channels: { msteams: { allowFrom: ["*"] } },
190
- } as KlawConfig);
191
- const handler = createMSTeamsMessageHandler(deps);
192
-
193
- await handler({
194
- activity: {
195
- ...buildChannelActivity(),
196
- conversation: { id: "a:dm-conversation", conversationType: "personal" },
197
- channelData: {},
198
- replyToId: "dm-parent",
199
- entities: [],
200
- },
201
- sendActivity: vi.fn(async () => undefined),
202
- } as unknown as Parameters<typeof handler>[0]);
203
-
204
- expect(fetchChannelMessageMock).not.toHaveBeenCalled();
205
- expect(findParentSystemEventCall(enqueueSystemEvent)).toBeUndefined();
206
- });
207
-
208
- it("does not fetch parent for top-level channel messages without replyToId", async () => {
209
- fetchChannelMessageMock.mockResolvedValue({
210
- id: "x",
211
- from: { user: { displayName: "Alice" } },
212
- body: { content: "should-not-happen", contentType: "text" },
213
- });
214
- const { deps, enqueueSystemEvent } = createMessageHandlerDeps(cfg);
215
- const handler = createMSTeamsMessageHandler(deps);
216
-
217
- await handler({
218
- activity: buildChannelActivity({ id: "msg-root-1", replyToId: undefined }),
219
- sendActivity: vi.fn(async () => undefined),
220
- } as unknown as Parameters<typeof handler>[0]);
221
-
222
- expect(fetchChannelMessageMock).not.toHaveBeenCalled();
223
- expect(findParentSystemEventCall(enqueueSystemEvent)).toBeUndefined();
224
- });
225
- });
@@ -1,132 +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", () => {
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", () => {
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", () => {
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", () => {
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", () => {
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", () => {
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
-
78
- // Regression coverage for #66771 — malformed mixed thread session key from
79
- // pre-suffixed base. The handler may pass a base that has already been
80
- // thread-qualified by a prior turn (e.g. cache-miss-returned route object
81
- // mutated in-place by message-handler.ts:489). The helper must be idempotent
82
- // and re-derive from a clean base.
83
- describe("idempotency against pre-suffixed bases (#66771)", () => {
84
- it("collapses an already-thread-suffixed base when re-applied with a different thread", () => {
85
- const sessionKey = resolveMSTeamsRouteSessionKey({
86
- baseSessionKey: `${channelConversationSessionKey}:thread:old-root`,
87
- isChannel: true,
88
- conversationMessageId: "new-root",
89
- });
90
-
91
- expect(sessionKey).toBe(`${channelConversationSessionKey}:thread:new-root`);
92
- expect(sessionKey).not.toContain("old-root");
93
- // No `:thread:OLD:thread:NEW` mixed shape.
94
- expect(sessionKey.match(/:thread:/g)).toHaveLength(1);
95
- });
96
-
97
- it("collapses a doubly-thread-suffixed (already-malformed) base to a single suffix", () => {
98
- const sessionKey = resolveMSTeamsRouteSessionKey({
99
- baseSessionKey: `${channelConversationSessionKey}:thread:x:thread:y`,
100
- isChannel: true,
101
- conversationMessageId: "z",
102
- });
103
-
104
- expect(sessionKey).toBe(`${channelConversationSessionKey}:thread:z`);
105
- expect(sessionKey).not.toContain(":thread:x");
106
- expect(sessionKey).not.toContain(":thread:y");
107
- expect(sessionKey.match(/:thread:/g)).toHaveLength(1);
108
- });
109
-
110
- it("is idempotent when the base is already qualified with the same thread", () => {
111
- const sessionKey = resolveMSTeamsRouteSessionKey({
112
- baseSessionKey: `${channelConversationSessionKey}:thread:same-root`,
113
- isChannel: true,
114
- conversationMessageId: "same-root",
115
- });
116
-
117
- expect(sessionKey).toBe(`${channelConversationSessionKey}:thread:same-root`);
118
- expect(sessionKey.match(/:thread:/g)).toHaveLength(1);
119
- });
120
-
121
- it("strips a stale thread suffix when the inbound is a top-level channel message", () => {
122
- const sessionKey = resolveMSTeamsRouteSessionKey({
123
- baseSessionKey: `${channelConversationSessionKey}:thread:stale-root`,
124
- isChannel: true,
125
- replyToId: undefined,
126
- });
127
-
128
- expect(sessionKey).toBe(channelConversationSessionKey);
129
- expect(sessionKey).not.toContain("thread:");
130
- });
131
- });
132
- });