@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,443 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
- import type { PluginRuntime } from "../runtime-api.js";
6
- import { respondToMSTeamsFileConsentInvoke } from "./file-consent-invoke.js";
7
- import { getPendingUploadFs, storePendingUploadFs } from "./pending-uploads-fs.js";
8
- import { clearPendingUploads, getPendingUpload, storePendingUpload } from "./pending-uploads.js";
9
- import { setMSTeamsRuntime } from "./runtime.js";
10
- import type { MSTeamsTurnContext } from "./sdk-types.js";
11
-
12
- const fileConsentMockState = vi.hoisted(() => ({
13
- uploadToConsentUrl: vi.fn(),
14
- }));
15
-
16
- vi.mock("./monitor-handler/message-handler.js", () => ({
17
- createMSTeamsMessageHandler: () => async () => {},
18
- }));
19
-
20
- vi.mock("./monitor-handler/reaction-handler.js", () => ({
21
- createMSTeamsReactionHandler: () => async () => {},
22
- }));
23
-
24
- vi.mock("./file-consent.js", async () => {
25
- const actual = await vi.importActual<typeof import("./file-consent.js")>("./file-consent.js");
26
- return {
27
- ...actual,
28
- uploadToConsentUrl: fileConsentMockState.uploadToConsentUrl,
29
- };
30
- });
31
-
32
- function createRuntimeStub(stateDir?: string): PluginRuntime {
33
- return {
34
- logging: {
35
- shouldLogVerbose: () => false,
36
- },
37
- channel: {
38
- debounce: {
39
- resolveInboundDebounceMs: () => 0,
40
- createInboundDebouncer: () => ({
41
- enqueue: async () => {},
42
- flushKey: async () => {},
43
- cancelKey: () => false,
44
- }),
45
- },
46
- },
47
- state: {
48
- resolveStateDir: (env?: NodeJS.ProcessEnv) => {
49
- const override = env?.KLAW_STATE_DIR?.trim();
50
- if (override) {
51
- return override;
52
- }
53
- return stateDir ?? path.join(os.homedir(), ".klaw");
54
- },
55
- },
56
- } as unknown as PluginRuntime;
57
- }
58
-
59
- const runtimeStub: PluginRuntime = createRuntimeStub();
60
-
61
- const log = {
62
- debug: vi.fn(),
63
- info: vi.fn(),
64
- error: vi.fn(),
65
- };
66
-
67
- function createInvokeContext(params: {
68
- conversationId: string;
69
- uploadId: string;
70
- action: "accept" | "decline";
71
- }): {
72
- context: MSTeamsTurnContext;
73
- sendActivity: ReturnType<typeof vi.fn>;
74
- updateActivity: ReturnType<typeof vi.fn>;
75
- } {
76
- const sendActivity = vi.fn(async () => ({ id: "activity-id" }));
77
- const updateActivity = vi.fn(async () => ({ id: "activity-id" }));
78
- const uploadInfo =
79
- params.action === "accept"
80
- ? {
81
- name: "secret.txt",
82
- uploadUrl: "https://upload.example.com/put",
83
- contentUrl: "https://content.example.com/file",
84
- uniqueId: "unique-id",
85
- fileType: "txt",
86
- }
87
- : undefined;
88
- return {
89
- context: {
90
- activity: {
91
- type: "invoke",
92
- name: "fileConsent/invoke",
93
- conversation: { id: params.conversationId },
94
- value: {
95
- type: "fileUpload",
96
- action: params.action,
97
- uploadInfo,
98
- context: { uploadId: params.uploadId },
99
- },
100
- },
101
- sendActivity,
102
- sendActivities: async () => [],
103
- updateActivity,
104
- } as unknown as MSTeamsTurnContext,
105
- sendActivity,
106
- updateActivity,
107
- };
108
- }
109
-
110
- function createConsentInvokeHarness(params: {
111
- pendingConversationId?: string;
112
- invokeConversationId: string;
113
- action: "accept" | "decline";
114
- consentCardActivityId?: string;
115
- }) {
116
- const uploadId = storePendingUpload({
117
- buffer: Buffer.from("TOP_SECRET_VICTIM_FILE\n"),
118
- filename: "secret.txt",
119
- contentType: "text/plain",
120
- conversationId: params.pendingConversationId ?? "19:victim@thread.v2",
121
- consentCardActivityId: params.consentCardActivityId,
122
- });
123
- const { context, sendActivity, updateActivity } = createInvokeContext({
124
- conversationId: params.invokeConversationId,
125
- uploadId,
126
- action: params.action,
127
- });
128
- return { uploadId, context, sendActivity, updateActivity };
129
- }
130
-
131
- function requirePendingUpload(uploadId: string) {
132
- const upload = getPendingUpload(uploadId);
133
- if (!upload) {
134
- throw new Error(`expected pending upload ${uploadId}`);
135
- }
136
- return upload;
137
- }
138
-
139
- function expectInvokeResponse(sendActivity: ReturnType<typeof vi.fn>): void {
140
- expect(
141
- sendActivity.mock.calls.some(
142
- ([activity]) =>
143
- typeof activity === "object" &&
144
- activity !== null &&
145
- (activity as { type?: unknown }).type === "invokeResponse",
146
- ),
147
- ).toBe(true);
148
- }
149
-
150
- function expectPendingUploadFields(uploadId: string): void {
151
- const upload = requirePendingUpload(uploadId);
152
- expect(upload.conversationId).toBe("19:victim@thread.v2");
153
- expect(upload.filename).toBe("secret.txt");
154
- expect(upload.contentType).toBe("text/plain");
155
- }
156
-
157
- function expectUploadUrlCall(url: string): void {
158
- const [call] = fileConsentMockState.uploadToConsentUrl.mock.calls;
159
- if (!call) {
160
- throw new Error("expected uploadToConsentUrl call");
161
- }
162
- const [payload] = call;
163
- if (!payload || typeof payload !== "object" || !("url" in payload)) {
164
- throw new Error("expected uploadToConsentUrl payload");
165
- }
166
- expect(payload.url).toBe(url);
167
- }
168
-
169
- function readUpdatedActivity(updateActivity: ReturnType<typeof vi.fn>): {
170
- id?: unknown;
171
- type?: unknown;
172
- attachments?: Array<{ contentType?: unknown }>;
173
- } {
174
- const [call] = updateActivity.mock.calls;
175
- if (!call) {
176
- throw new Error("expected updateActivity call");
177
- }
178
- const [activity] = call;
179
- if (!activity || typeof activity !== "object") {
180
- throw new Error("expected updated activity payload");
181
- }
182
- return activity as {
183
- id?: unknown;
184
- type?: unknown;
185
- attachments?: Array<{ contentType?: unknown }>;
186
- };
187
- }
188
-
189
- describe("msteams file consent invoke authz", () => {
190
- beforeEach(() => {
191
- setMSTeamsRuntime(runtimeStub);
192
- clearPendingUploads();
193
- vi.clearAllMocks();
194
- fileConsentMockState.uploadToConsentUrl.mockReset();
195
- fileConsentMockState.uploadToConsentUrl.mockResolvedValue(undefined);
196
- });
197
-
198
- it("uploads when invoke conversation matches pending upload conversation", async () => {
199
- const { uploadId, context, sendActivity } = createConsentInvokeHarness({
200
- invokeConversationId: "19:victim@thread.v2;messageid=abc123",
201
- action: "accept",
202
- });
203
-
204
- await respondToMSTeamsFileConsentInvoke(context, log);
205
-
206
- // invokeResponse should be sent immediately
207
- expectInvokeResponse(sendActivity);
208
-
209
- expect(fileConsentMockState.uploadToConsentUrl).toHaveBeenCalledTimes(1);
210
- expectUploadUrlCall("https://upload.example.com/put");
211
- expect(getPendingUpload(uploadId)).toBeUndefined();
212
- });
213
-
214
- it("calls updateActivity to replace the consent card when consentCardActivityId is set", async () => {
215
- const { context, sendActivity, updateActivity } = createConsentInvokeHarness({
216
- invokeConversationId: "19:victim@thread.v2;messageid=abc123",
217
- action: "accept",
218
- consentCardActivityId: "consent-card-activity-id-123",
219
- });
220
-
221
- await respondToMSTeamsFileConsentInvoke(context, log);
222
-
223
- expectInvokeResponse(sendActivity);
224
- expect(fileConsentMockState.uploadToConsentUrl).toHaveBeenCalledTimes(1);
225
-
226
- // Should replace the original consent card with the file info card
227
- expect(updateActivity).toHaveBeenCalledTimes(1);
228
- const updatedActivity = readUpdatedActivity(updateActivity);
229
- expect(updatedActivity.id).toBe("consent-card-activity-id-123");
230
- expect(updatedActivity.type).toBe("message");
231
- expect(
232
- updatedActivity.attachments?.some(
233
- (attachment) => attachment.contentType === "application/vnd.microsoft.teams.card.file.info",
234
- ),
235
- ).toBe(true);
236
- });
237
-
238
- it("does not send file info card via sendActivity when updateActivity succeeds", async () => {
239
- const { context, sendActivity, updateActivity } = createConsentInvokeHarness({
240
- invokeConversationId: "19:victim@thread.v2;messageid=abc123",
241
- action: "accept",
242
- consentCardActivityId: "consent-card-activity-id-happy",
243
- });
244
-
245
- await respondToMSTeamsFileConsentInvoke(context, log);
246
-
247
- // updateActivity should replace the consent card in-place
248
- expect(updateActivity).toHaveBeenCalledTimes(1);
249
-
250
- // sendActivity should only be called once for the invokeResponse, NOT for the file info card
251
- expect(sendActivity).toHaveBeenCalledTimes(1);
252
- expectInvokeResponse(sendActivity);
253
-
254
- // Explicitly verify no file info card was sent via sendActivity
255
- for (const call of sendActivity.mock.calls) {
256
- const arg = call[0] as Record<string, unknown>;
257
- if (typeof arg === "object" && arg !== null && "attachments" in arg) {
258
- const attachments = arg.attachments as Array<{ contentType?: string }>;
259
- for (const att of attachments) {
260
- expect(att.contentType).not.toBe("application/vnd.microsoft.teams.card.file.info");
261
- }
262
- }
263
- }
264
- });
265
-
266
- it("does not call updateActivity when no consentCardActivityId is stored", async () => {
267
- const { context, updateActivity } = createConsentInvokeHarness({
268
- invokeConversationId: "19:victim@thread.v2;messageid=abc123",
269
- action: "accept",
270
- // no consentCardActivityId
271
- });
272
-
273
- await respondToMSTeamsFileConsentInvoke(context, log);
274
-
275
- expect(fileConsentMockState.uploadToConsentUrl).toHaveBeenCalledTimes(1);
276
- expect(updateActivity).not.toHaveBeenCalled();
277
- });
278
-
279
- it("still completes upload if updateActivity throws", async () => {
280
- const { uploadId, context, updateActivity } = createConsentInvokeHarness({
281
- invokeConversationId: "19:victim@thread.v2;messageid=abc123",
282
- action: "accept",
283
- consentCardActivityId: "consent-card-activity-id-fail",
284
- });
285
- updateActivity.mockRejectedValueOnce(new Error("Teams API error"));
286
-
287
- await respondToMSTeamsFileConsentInvoke(context, log);
288
-
289
- // Upload should have completed despite updateActivity failure
290
- expect(fileConsentMockState.uploadToConsentUrl).toHaveBeenCalledTimes(1);
291
- expect(getPendingUpload(uploadId)).toBeUndefined();
292
- expect(updateActivity).toHaveBeenCalledTimes(1);
293
- });
294
-
295
- it("rejects cross-conversation accept invoke and keeps pending upload", async () => {
296
- const { uploadId, context, sendActivity } = createConsentInvokeHarness({
297
- invokeConversationId: "19:attacker@thread.v2",
298
- action: "accept",
299
- });
300
-
301
- await respondToMSTeamsFileConsentInvoke(context, log);
302
-
303
- // invokeResponse should be sent immediately
304
- expectInvokeResponse(sendActivity);
305
-
306
- expect(sendActivity).toHaveBeenCalledWith(
307
- "The file upload request has expired. Please try sending the file again.",
308
- );
309
-
310
- expect(fileConsentMockState.uploadToConsentUrl).not.toHaveBeenCalled();
311
- expectPendingUploadFields(uploadId);
312
- });
313
-
314
- it("ignores cross-conversation decline invoke and keeps pending upload", async () => {
315
- const { uploadId, context, sendActivity } = createConsentInvokeHarness({
316
- invokeConversationId: "19:attacker@thread.v2",
317
- action: "decline",
318
- });
319
-
320
- await respondToMSTeamsFileConsentInvoke(context, log);
321
-
322
- // invokeResponse should be sent immediately
323
- expectInvokeResponse(sendActivity);
324
-
325
- expect(fileConsentMockState.uploadToConsentUrl).not.toHaveBeenCalled();
326
- expectPendingUploadFields(uploadId);
327
- expect(sendActivity).toHaveBeenCalledTimes(1);
328
- });
329
- });
330
-
331
- describe("msteams file consent invoke FS fallback", () => {
332
- let tmpDir: string;
333
- let originalStateDir: string | undefined;
334
-
335
- beforeEach(async () => {
336
- originalStateDir = process.env.KLAW_STATE_DIR;
337
- tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "klaw-msteams-invoke-"));
338
- process.env.KLAW_STATE_DIR = tmpDir;
339
- setMSTeamsRuntime(createRuntimeStub(tmpDir));
340
- clearPendingUploads();
341
- vi.clearAllMocks();
342
- fileConsentMockState.uploadToConsentUrl.mockReset();
343
- fileConsentMockState.uploadToConsentUrl.mockResolvedValue(undefined);
344
- });
345
-
346
- afterEach(async () => {
347
- if (originalStateDir === undefined) {
348
- delete process.env.KLAW_STATE_DIR;
349
- } else {
350
- process.env.KLAW_STATE_DIR = originalStateDir;
351
- }
352
- try {
353
- await fs.promises.rm(tmpDir, { recursive: true, force: true });
354
- } catch {
355
- // tmp dir may already be gone
356
- }
357
- });
358
-
359
- it("reads pending upload from FS store when in-memory store is empty (cross-process CLI path)", async () => {
360
- // Simulate the CLI process writing to the FS store before exiting; the
361
- // in-memory store in this (monitor) process is empty.
362
- const uploadId = "cli-upload-id-123";
363
- const conversationId = "19:victim@thread.v2";
364
- await storePendingUploadFs({
365
- id: uploadId,
366
- buffer: Buffer.from("CLI PAYLOAD"),
367
- filename: "cli.bin",
368
- contentType: "application/octet-stream",
369
- conversationId,
370
- });
371
-
372
- expect(getPendingUpload(uploadId)).toBeUndefined();
373
-
374
- const sendActivity = vi.fn(async () => ({ id: "activity-id" }));
375
- const updateActivity = vi.fn(async () => ({ id: "activity-id" }));
376
- const context = {
377
- activity: {
378
- type: "invoke",
379
- name: "fileConsent/invoke",
380
- conversation: { id: `${conversationId};messageid=abc123` },
381
- value: {
382
- type: "fileUpload",
383
- action: "accept",
384
- uploadInfo: {
385
- name: "cli.bin",
386
- uploadUrl: "https://upload.example.com/put",
387
- contentUrl: "https://content.example.com/cli.bin",
388
- uniqueId: "unique-cli",
389
- fileType: "bin",
390
- },
391
- context: { uploadId },
392
- },
393
- },
394
- sendActivity,
395
- sendActivities: async () => [],
396
- updateActivity,
397
- } as unknown as MSTeamsTurnContext;
398
-
399
- await respondToMSTeamsFileConsentInvoke(context, log);
400
-
401
- // The upload should have run using the FS-loaded buffer
402
- expect(fileConsentMockState.uploadToConsentUrl).toHaveBeenCalledTimes(1);
403
- expectUploadUrlCall("https://upload.example.com/put");
404
-
405
- // FS entry should have been cleaned up after successful upload
406
- expect(await getPendingUploadFs(uploadId)).toBeUndefined();
407
- });
408
-
409
- it("cleans up FS entry on decline even when in-memory store is empty", async () => {
410
- const uploadId = "cli-decline-id";
411
- const conversationId = "19:victim@thread.v2";
412
- await storePendingUploadFs({
413
- id: uploadId,
414
- buffer: Buffer.from("DECLINED"),
415
- filename: "decline.txt",
416
- contentType: "text/plain",
417
- conversationId,
418
- });
419
-
420
- const sendActivity = vi.fn(async () => ({ id: "activity-id" }));
421
- const updateActivity = vi.fn(async () => ({ id: "activity-id" }));
422
- const context = {
423
- activity: {
424
- type: "invoke",
425
- name: "fileConsent/invoke",
426
- conversation: { id: `${conversationId};messageid=abc123` },
427
- value: {
428
- type: "fileUpload",
429
- action: "decline",
430
- context: { uploadId },
431
- },
432
- },
433
- sendActivity,
434
- sendActivities: async () => [],
435
- updateActivity,
436
- } as unknown as MSTeamsTurnContext;
437
-
438
- await respondToMSTeamsFileConsentInvoke(context, log);
439
-
440
- expect(fileConsentMockState.uploadToConsentUrl).not.toHaveBeenCalled();
441
- expect(await getPendingUploadFs(uploadId)).toBeUndefined();
442
- });
443
- });