@openclaw/feishu 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.
- package/dist/accounts-Ba3-WP1z.js +423 -0
- package/dist/api.js +2280 -0
- package/dist/app-registration-B8qc1MCM.js +184 -0
- package/dist/audio-preflight.runtime-BPlzkO3l.js +7 -0
- package/dist/card-interaction-BfRLgvw_.js +96 -0
- package/dist/channel-CSD_Jt8I.js +1668 -0
- package/dist/channel-entry.js +22 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-DYsXcD36.js +700 -0
- package/dist/client-DBVoQL5w.js +157 -0
- package/dist/contract-api.js +9 -0
- package/dist/conversation-id-DWS3Ep2A.js +139 -0
- package/dist/directory.static-f3EeoRJd.js +44 -0
- package/dist/drive-C5eJLJr7.js +883 -0
- package/dist/index.js +68 -0
- package/dist/monitor-CT189QfR.js +60 -0
- package/dist/monitor.account-dJV2jO8C.js +4990 -0
- package/dist/monitor.state-DYM02ipp.js +100 -0
- package/dist/policy-D6c-wMPl.js +118 -0
- package/dist/probe-BNzzU_uR.js +149 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/runtime-CG0DuRCy.js +8 -0
- package/dist/runtime-api.js +14 -0
- package/dist/secret-contract-Dm4Z_zQN.js +119 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/security-audit-DqJdocrN.js +11 -0
- package/dist/security-audit-shared-ByuMx9cJ.js +38 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-DowxxbpH.js +1218 -0
- package/dist/session-conversation-B4nrW-vo.js +27 -0
- package/dist/session-key-api.js +2 -0
- package/dist/setup-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/subagent-hooks-C3UhPVLV.js +227 -0
- package/dist/subagent-hooks-api.js +23 -0
- package/dist/targets-JMFJRKSe.js +48 -0
- package/dist/thread-bindings-BmS6TLes.js +222 -0
- package/package.json +15 -6
- package/api.ts +0 -31
- package/channel-entry.ts +0 -20
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -16
- package/index.ts +0 -82
- package/runtime-api.ts +0 -55
- package/secret-contract-api.ts +0 -5
- package/security-contract-api.ts +0 -1
- package/session-key-api.ts +0 -1
- package/setup-api.ts +0 -3
- package/setup-entry.test.ts +0 -14
- package/setup-entry.ts +0 -13
- package/src/accounts.test.ts +0 -459
- package/src/accounts.ts +0 -326
- package/src/app-registration.ts +0 -331
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -25
- package/src/async.test.ts +0 -35
- package/src/async.ts +0 -104
- package/src/audio-preflight.runtime.ts +0 -9
- package/src/bitable.test.ts +0 -131
- package/src/bitable.ts +0 -762
- package/src/bot-content.ts +0 -474
- package/src/bot-group-name.test.ts +0 -108
- package/src/bot-runtime-api.ts +0 -12
- package/src/bot-sender-name.ts +0 -125
- package/src/bot.broadcast.test.ts +0 -463
- package/src/bot.card-action.test.ts +0 -577
- package/src/bot.checkBotMentioned.test.ts +0 -265
- package/src/bot.helpers.test.ts +0 -118
- package/src/bot.stripBotMention.test.ts +0 -126
- package/src/bot.test.ts +0 -3040
- package/src/bot.ts +0 -1559
- package/src/card-action.ts +0 -447
- package/src/card-interaction.test.ts +0 -129
- package/src/card-interaction.ts +0 -159
- package/src/card-test-helpers.ts +0 -47
- package/src/card-ux-approval.ts +0 -65
- package/src/card-ux-launcher.test.ts +0 -99
- package/src/card-ux-launcher.ts +0 -121
- package/src/card-ux-shared.ts +0 -33
- package/src/channel-runtime-api.ts +0 -16
- package/src/channel.runtime.ts +0 -47
- package/src/channel.test.ts +0 -959
- package/src/channel.ts +0 -1313
- package/src/chat-schema.ts +0 -25
- package/src/chat.test.ts +0 -196
- package/src/chat.ts +0 -188
- package/src/client.test.ts +0 -433
- package/src/client.ts +0 -290
- package/src/comment-dispatcher-runtime-api.ts +0 -6
- package/src/comment-dispatcher.test.ts +0 -169
- package/src/comment-dispatcher.ts +0 -107
- package/src/comment-handler-runtime-api.ts +0 -3
- package/src/comment-handler.test.ts +0 -486
- package/src/comment-handler.ts +0 -309
- package/src/comment-reaction.test.ts +0 -166
- package/src/comment-reaction.ts +0 -259
- package/src/comment-shared.test.ts +0 -182
- package/src/comment-shared.ts +0 -406
- package/src/comment-target.ts +0 -44
- package/src/config-schema.test.ts +0 -309
- package/src/config-schema.ts +0 -333
- package/src/conversation-id.test.ts +0 -18
- package/src/conversation-id.ts +0 -199
- package/src/dedup-runtime-api.ts +0 -1
- package/src/dedup.ts +0 -141
- package/src/directory.static.ts +0 -61
- package/src/directory.test.ts +0 -136
- package/src/directory.ts +0 -124
- package/src/doc-schema.ts +0 -182
- package/src/docx-batch-insert.test.ts +0 -91
- package/src/docx-batch-insert.ts +0 -223
- package/src/docx-color-text.ts +0 -154
- package/src/docx-table-ops.test.ts +0 -53
- package/src/docx-table-ops.ts +0 -316
- package/src/docx-types.ts +0 -38
- package/src/docx.account-selection.test.ts +0 -79
- package/src/docx.test.ts +0 -685
- package/src/docx.ts +0 -1616
- package/src/drive-schema.ts +0 -92
- package/src/drive.test.ts +0 -1219
- package/src/drive.ts +0 -829
- package/src/dynamic-agent.ts +0 -137
- package/src/event-types.ts +0 -45
- package/src/external-keys.test.ts +0 -20
- package/src/external-keys.ts +0 -19
- package/src/lifecycle.test-support.ts +0 -220
- package/src/media.test.ts +0 -900
- package/src/media.ts +0 -861
- package/src/mention-target.types.ts +0 -5
- package/src/mention.ts +0 -114
- package/src/message-action-contract.ts +0 -13
- package/src/monitor-state-runtime-api.ts +0 -7
- package/src/monitor-transport-runtime-api.ts +0 -7
- package/src/monitor.account.ts +0 -468
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
- package/src/monitor.bot-identity.ts +0 -86
- package/src/monitor.bot-menu-handler.ts +0 -165
- package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
- package/src/monitor.bot-menu.test.ts +0 -178
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
- package/src/monitor.card-action.lifecycle.test-support.ts +0 -373
- package/src/monitor.cleanup.test.ts +0 -376
- package/src/monitor.comment-notice-handler.ts +0 -105
- package/src/monitor.comment.test.ts +0 -937
- package/src/monitor.comment.ts +0 -1386
- package/src/monitor.lifecycle.test.ts +0 -4
- package/src/monitor.message-handler.ts +0 -339
- package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
- package/src/monitor.reaction.test.ts +0 -713
- package/src/monitor.startup.test.ts +0 -192
- package/src/monitor.startup.ts +0 -74
- package/src/monitor.state.defaults.test.ts +0 -46
- package/src/monitor.state.ts +0 -170
- package/src/monitor.synthetic-error.ts +0 -18
- package/src/monitor.test-mocks.ts +0 -45
- package/src/monitor.transport.ts +0 -424
- package/src/monitor.ts +0 -100
- package/src/monitor.webhook-e2e.test.ts +0 -272
- package/src/monitor.webhook-security.test.ts +0 -264
- package/src/monitor.webhook.test-helpers.ts +0 -116
- package/src/outbound-runtime-api.ts +0 -1
- package/src/outbound.test.ts +0 -935
- package/src/outbound.ts +0 -718
- package/src/perm-schema.ts +0 -52
- package/src/perm.ts +0 -170
- package/src/pins.ts +0 -108
- package/src/policy.test.ts +0 -334
- package/src/policy.ts +0 -236
- package/src/post.test.ts +0 -105
- package/src/post.ts +0 -275
- package/src/probe.test.ts +0 -275
- package/src/probe.ts +0 -166
- package/src/processing-claims.ts +0 -59
- package/src/qr-terminal.ts +0 -1
- package/src/reactions.ts +0 -123
- package/src/reasoning-preview.test.ts +0 -59
- package/src/reasoning-preview.ts +0 -20
- package/src/reply-dispatcher-runtime-api.ts +0 -7
- package/src/reply-dispatcher.test.ts +0 -1144
- package/src/reply-dispatcher.ts +0 -650
- package/src/runtime.ts +0 -9
- package/src/secret-contract.ts +0 -145
- package/src/secret-input.ts +0 -1
- package/src/security-audit-shared.ts +0 -69
- package/src/security-audit.test.ts +0 -61
- package/src/security-audit.ts +0 -1
- package/src/send-result.ts +0 -29
- package/src/send-target.test.ts +0 -80
- package/src/send-target.ts +0 -35
- package/src/send.reply-fallback.test.ts +0 -292
- package/src/send.test.ts +0 -550
- package/src/send.ts +0 -800
- package/src/sequential-key.test.ts +0 -72
- package/src/sequential-key.ts +0 -28
- package/src/sequential-queue.test.ts +0 -92
- package/src/sequential-queue.ts +0 -16
- package/src/session-conversation.ts +0 -42
- package/src/session-route.ts +0 -48
- package/src/setup-core.ts +0 -51
- package/src/setup-surface.test.ts +0 -174
- package/src/setup-surface.ts +0 -581
- package/src/streaming-card.test.ts +0 -190
- package/src/streaming-card.ts +0 -490
- package/src/subagent-hooks.test.ts +0 -603
- package/src/subagent-hooks.ts +0 -397
- package/src/targets.ts +0 -97
- package/src/test-support/lifecycle-test-support.ts +0 -453
- package/src/thread-bindings.test.ts +0 -143
- package/src/thread-bindings.ts +0 -330
- package/src/tool-account-routing.test.ts +0 -187
- package/src/tool-account.test.ts +0 -44
- package/src/tool-account.ts +0 -93
- package/src/tool-factory-test-harness.ts +0 -79
- package/src/tool-result.test.ts +0 -32
- package/src/tool-result.ts +0 -16
- package/src/tools-config.test.ts +0 -21
- package/src/tools-config.ts +0 -22
- package/src/types.ts +0 -104
- package/src/typing.test.ts +0 -144
- package/src/typing.ts +0 -214
- package/src/wiki-schema.ts +0 -55
- package/src/wiki.ts +0 -227
- package/subagent-hooks-api.ts +0 -31
- package/tsconfig.json +0 -16
package/src/media.test.ts
DELETED
|
@@ -1,900 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
|
|
4
|
-
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
import type { ClawdbotConfig } from "../runtime-api.js";
|
|
6
|
-
|
|
7
|
-
const createFeishuClientMock = vi.hoisted(() => vi.fn());
|
|
8
|
-
const resolveFeishuAccountMock = vi.hoisted(() => vi.fn());
|
|
9
|
-
const normalizeFeishuTargetMock = vi.hoisted(() => vi.fn());
|
|
10
|
-
const resolveReceiveIdTypeMock = vi.hoisted(() => vi.fn());
|
|
11
|
-
const loadWebMediaMock = vi.hoisted(() => vi.fn());
|
|
12
|
-
const runFfmpegMock = vi.hoisted(() => vi.fn());
|
|
13
|
-
|
|
14
|
-
const fileCreateMock = vi.hoisted(() => vi.fn());
|
|
15
|
-
const imageCreateMock = vi.hoisted(() => vi.fn());
|
|
16
|
-
const imageGetMock = vi.hoisted(() => vi.fn());
|
|
17
|
-
const messageCreateMock = vi.hoisted(() => vi.fn());
|
|
18
|
-
const messageResourceGetMock = vi.hoisted(() => vi.fn());
|
|
19
|
-
const messageReplyMock = vi.hoisted(() => vi.fn());
|
|
20
|
-
|
|
21
|
-
const FEISHU_MEDIA_HTTP_TIMEOUT_MS = 120_000;
|
|
22
|
-
const emptyConfig: ClawdbotConfig = {};
|
|
23
|
-
|
|
24
|
-
vi.mock("./client.js", () => ({
|
|
25
|
-
createFeishuClient: createFeishuClientMock,
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
vi.mock("./accounts.js", () => ({
|
|
29
|
-
resolveFeishuAccount: resolveFeishuAccountMock,
|
|
30
|
-
resolveFeishuRuntimeAccount: resolveFeishuAccountMock,
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
vi.mock("./targets.js", () => ({
|
|
34
|
-
normalizeFeishuTarget: normalizeFeishuTargetMock,
|
|
35
|
-
resolveReceiveIdType: resolveReceiveIdTypeMock,
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
vi.mock("./runtime.js", () => ({
|
|
39
|
-
getFeishuRuntime: () => ({
|
|
40
|
-
media: {
|
|
41
|
-
loadWebMedia: loadWebMediaMock,
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
vi.mock("openclaw/plugin-sdk/media-runtime", async (importOriginal) => {
|
|
47
|
-
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/media-runtime")>();
|
|
48
|
-
return {
|
|
49
|
-
...actual,
|
|
50
|
-
runFfmpeg: runFfmpegMock,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
let downloadImageFeishu: typeof import("./media.js").downloadImageFeishu;
|
|
55
|
-
let downloadMessageResourceFeishu: typeof import("./media.js").downloadMessageResourceFeishu;
|
|
56
|
-
let sanitizeFileNameForUpload: typeof import("./media.js").sanitizeFileNameForUpload;
|
|
57
|
-
let sendMediaFeishu: typeof import("./media.js").sendMediaFeishu;
|
|
58
|
-
|
|
59
|
-
function expectPathIsolatedToTmpRoot(pathValue: string, key: string): void {
|
|
60
|
-
expect(pathValue).not.toContain(key);
|
|
61
|
-
expect(pathValue).not.toContain("..");
|
|
62
|
-
|
|
63
|
-
const tmpRoot = path.resolve(resolvePreferredOpenClawTmpDir());
|
|
64
|
-
const resolved = path.resolve(pathValue);
|
|
65
|
-
const rel = path.relative(tmpRoot, resolved);
|
|
66
|
-
expect(rel === ".." || rel.startsWith(`..${path.sep}`)).toBe(false);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function expectMediaTimeoutClientConfigured(): void {
|
|
70
|
-
expect(createFeishuClientMock).toHaveBeenCalledWith(
|
|
71
|
-
expect.objectContaining({
|
|
72
|
-
httpTimeoutMs: FEISHU_MEDIA_HTTP_TIMEOUT_MS,
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function mockResolvedFeishuAccount() {
|
|
78
|
-
resolveFeishuAccountMock.mockReturnValue({
|
|
79
|
-
configured: true,
|
|
80
|
-
accountId: "main",
|
|
81
|
-
config: {},
|
|
82
|
-
appId: "app_id",
|
|
83
|
-
appSecret: "app_secret",
|
|
84
|
-
domain: "feishu",
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
describe("sendMediaFeishu msg_type routing", () => {
|
|
89
|
-
beforeAll(async () => {
|
|
90
|
-
({
|
|
91
|
-
downloadImageFeishu,
|
|
92
|
-
downloadMessageResourceFeishu,
|
|
93
|
-
sanitizeFileNameForUpload,
|
|
94
|
-
sendMediaFeishu,
|
|
95
|
-
} = await import("./media.js"));
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
beforeEach(() => {
|
|
99
|
-
vi.clearAllMocks();
|
|
100
|
-
mockResolvedFeishuAccount();
|
|
101
|
-
|
|
102
|
-
normalizeFeishuTargetMock.mockReturnValue("ou_target");
|
|
103
|
-
resolveReceiveIdTypeMock.mockReturnValue("open_id");
|
|
104
|
-
|
|
105
|
-
createFeishuClientMock.mockReturnValue({
|
|
106
|
-
im: {
|
|
107
|
-
file: {
|
|
108
|
-
create: fileCreateMock,
|
|
109
|
-
},
|
|
110
|
-
image: {
|
|
111
|
-
create: imageCreateMock,
|
|
112
|
-
get: imageGetMock,
|
|
113
|
-
},
|
|
114
|
-
message: {
|
|
115
|
-
create: messageCreateMock,
|
|
116
|
-
reply: messageReplyMock,
|
|
117
|
-
},
|
|
118
|
-
messageResource: {
|
|
119
|
-
get: messageResourceGetMock,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
fileCreateMock.mockResolvedValue({
|
|
125
|
-
code: 0,
|
|
126
|
-
data: { file_key: "file_key_1" },
|
|
127
|
-
});
|
|
128
|
-
imageCreateMock.mockResolvedValue({
|
|
129
|
-
code: 0,
|
|
130
|
-
data: { image_key: "image_key_1" },
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
messageCreateMock.mockResolvedValue({
|
|
134
|
-
code: 0,
|
|
135
|
-
data: { message_id: "msg_1" },
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
messageReplyMock.mockResolvedValue({
|
|
139
|
-
code: 0,
|
|
140
|
-
data: { message_id: "reply_1" },
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
loadWebMediaMock.mockResolvedValue({
|
|
144
|
-
buffer: Buffer.from("remote-audio"),
|
|
145
|
-
fileName: "remote.opus",
|
|
146
|
-
kind: "audio",
|
|
147
|
-
contentType: "audio/ogg",
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
imageGetMock.mockResolvedValue(Buffer.from("image-bytes"));
|
|
151
|
-
messageResourceGetMock.mockResolvedValue(Buffer.from("resource-bytes"));
|
|
152
|
-
runFfmpegMock.mockImplementation(async (args: string[]) => {
|
|
153
|
-
await fs.writeFile(args.at(-1) ?? "", Buffer.from("opus-output"));
|
|
154
|
-
return "";
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("uses msg_type=media for mp4 video", async () => {
|
|
159
|
-
await sendMediaFeishu({
|
|
160
|
-
cfg: emptyConfig,
|
|
161
|
-
to: "user:ou_target",
|
|
162
|
-
mediaBuffer: Buffer.from("video"),
|
|
163
|
-
fileName: "clip.mp4",
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
167
|
-
expect.objectContaining({
|
|
168
|
-
data: expect.objectContaining({ file_type: "mp4" }),
|
|
169
|
-
}),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
173
|
-
expect.objectContaining({
|
|
174
|
-
data: expect.objectContaining({ msg_type: "media" }),
|
|
175
|
-
}),
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("uses msg_type=audio for opus", async () => {
|
|
180
|
-
await sendMediaFeishu({
|
|
181
|
-
cfg: emptyConfig,
|
|
182
|
-
to: "user:ou_target",
|
|
183
|
-
mediaBuffer: Buffer.from("audio"),
|
|
184
|
-
fileName: "voice.opus",
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
188
|
-
expect.objectContaining({
|
|
189
|
-
data: expect.objectContaining({ file_type: "opus" }),
|
|
190
|
-
}),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
194
|
-
expect.objectContaining({
|
|
195
|
-
data: expect.objectContaining({ msg_type: "audio" }),
|
|
196
|
-
}),
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("uses msg_type=file for documents", async () => {
|
|
201
|
-
await sendMediaFeishu({
|
|
202
|
-
cfg: emptyConfig,
|
|
203
|
-
to: "user:ou_target",
|
|
204
|
-
mediaBuffer: Buffer.from("doc"),
|
|
205
|
-
fileName: "paper.pdf",
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
209
|
-
expect.objectContaining({
|
|
210
|
-
data: expect.objectContaining({ file_type: "pdf" }),
|
|
211
|
-
}),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
215
|
-
expect.objectContaining({
|
|
216
|
-
data: expect.objectContaining({ msg_type: "file" }),
|
|
217
|
-
}),
|
|
218
|
-
);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("uses msg_type=media for remote mp4 content even when the filename is generic", async () => {
|
|
222
|
-
loadWebMediaMock.mockResolvedValueOnce({
|
|
223
|
-
buffer: Buffer.from("remote-video"),
|
|
224
|
-
fileName: "download",
|
|
225
|
-
kind: "video",
|
|
226
|
-
contentType: "video/mp4",
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
await sendMediaFeishu({
|
|
230
|
-
cfg: emptyConfig,
|
|
231
|
-
to: "user:ou_target",
|
|
232
|
-
mediaUrl: "https://example.com/video",
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
236
|
-
expect.objectContaining({
|
|
237
|
-
data: expect.objectContaining({ file_type: "mp4" }),
|
|
238
|
-
}),
|
|
239
|
-
);
|
|
240
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
241
|
-
expect.objectContaining({
|
|
242
|
-
data: expect.objectContaining({ msg_type: "media" }),
|
|
243
|
-
}),
|
|
244
|
-
);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("falls back to generic file for unsupported audio formats", async () => {
|
|
248
|
-
loadWebMediaMock.mockResolvedValueOnce({
|
|
249
|
-
buffer: Buffer.from("remote-mp3"),
|
|
250
|
-
fileName: "song.mp3",
|
|
251
|
-
kind: "audio",
|
|
252
|
-
contentType: "audio/mpeg",
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
await sendMediaFeishu({
|
|
256
|
-
cfg: emptyConfig,
|
|
257
|
-
to: "user:ou_target",
|
|
258
|
-
mediaUrl: "https://example.com/song.mp3",
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
262
|
-
expect.objectContaining({
|
|
263
|
-
data: expect.objectContaining({ file_type: "stream" }),
|
|
264
|
-
}),
|
|
265
|
-
);
|
|
266
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
267
|
-
expect.objectContaining({
|
|
268
|
-
data: expect.objectContaining({ msg_type: "file" }),
|
|
269
|
-
}),
|
|
270
|
-
);
|
|
271
|
-
expect(runFfmpegMock).not.toHaveBeenCalled();
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it("transcodes voice-intent mp3 to msg_type=audio", async () => {
|
|
275
|
-
loadWebMediaMock.mockResolvedValueOnce({
|
|
276
|
-
buffer: Buffer.from("remote-mp3"),
|
|
277
|
-
fileName: "reply.mp3",
|
|
278
|
-
kind: "audio",
|
|
279
|
-
contentType: "audio/mpeg",
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
await sendMediaFeishu({
|
|
283
|
-
cfg: emptyConfig,
|
|
284
|
-
to: "user:ou_target",
|
|
285
|
-
mediaUrl: "https://example.com/reply.mp3",
|
|
286
|
-
audioAsVoice: true,
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
expect(runFfmpegMock).toHaveBeenCalledWith(
|
|
290
|
-
expect.arrayContaining(["-c:a", "libopus", "-ar", "48000", "-b:a", "64k"]),
|
|
291
|
-
);
|
|
292
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
293
|
-
expect.objectContaining({
|
|
294
|
-
data: expect.objectContaining({
|
|
295
|
-
file_type: "opus",
|
|
296
|
-
file_name: "voice.ogg",
|
|
297
|
-
file: Buffer.from("opus-output"),
|
|
298
|
-
}),
|
|
299
|
-
}),
|
|
300
|
-
);
|
|
301
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
302
|
-
expect.objectContaining({
|
|
303
|
-
data: expect.objectContaining({ msg_type: "audio" }),
|
|
304
|
-
}),
|
|
305
|
-
);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it("leaves native voice audio unchanged when audioAsVoice is true", async () => {
|
|
309
|
-
await sendMediaFeishu({
|
|
310
|
-
cfg: emptyConfig,
|
|
311
|
-
to: "user:ou_target",
|
|
312
|
-
mediaBuffer: Buffer.from("opus"),
|
|
313
|
-
fileName: "reply.ogg",
|
|
314
|
-
audioAsVoice: true,
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
expect(runFfmpegMock).not.toHaveBeenCalled();
|
|
318
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
319
|
-
expect.objectContaining({
|
|
320
|
-
data: expect.objectContaining({
|
|
321
|
-
file_type: "opus",
|
|
322
|
-
file_name: "reply.ogg",
|
|
323
|
-
}),
|
|
324
|
-
}),
|
|
325
|
-
);
|
|
326
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
327
|
-
expect.objectContaining({
|
|
328
|
-
data: expect.objectContaining({ msg_type: "audio" }),
|
|
329
|
-
}),
|
|
330
|
-
);
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it("falls back to file when voice-intent audio cannot be transcoded", async () => {
|
|
334
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
335
|
-
runFfmpegMock.mockRejectedValueOnce(new Error("ffmpeg missing"));
|
|
336
|
-
loadWebMediaMock.mockResolvedValueOnce({
|
|
337
|
-
buffer: Buffer.from("remote-mp3"),
|
|
338
|
-
fileName: "reply.mp3",
|
|
339
|
-
kind: "audio",
|
|
340
|
-
contentType: "audio/mpeg",
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
await sendMediaFeishu({
|
|
344
|
-
cfg: emptyConfig,
|
|
345
|
-
to: "user:ou_target",
|
|
346
|
-
mediaUrl: "https://example.com/reply.mp3",
|
|
347
|
-
audioAsVoice: true,
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
expect(fileCreateMock).toHaveBeenCalledWith(
|
|
351
|
-
expect.objectContaining({
|
|
352
|
-
data: expect.objectContaining({
|
|
353
|
-
file_type: "stream",
|
|
354
|
-
file_name: "reply.mp3",
|
|
355
|
-
file: Buffer.from("remote-mp3"),
|
|
356
|
-
}),
|
|
357
|
-
}),
|
|
358
|
-
);
|
|
359
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
360
|
-
expect.objectContaining({
|
|
361
|
-
data: expect.objectContaining({ msg_type: "file" }),
|
|
362
|
-
}),
|
|
363
|
-
);
|
|
364
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
365
|
-
expect.stringContaining("audioAsVoice transcode failed"),
|
|
366
|
-
expect.any(Error),
|
|
367
|
-
);
|
|
368
|
-
warnSpy.mockRestore();
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it("configures the media client timeout for image uploads", async () => {
|
|
372
|
-
await sendMediaFeishu({
|
|
373
|
-
cfg: emptyConfig,
|
|
374
|
-
to: "user:ou_target",
|
|
375
|
-
mediaBuffer: Buffer.from("image"),
|
|
376
|
-
fileName: "photo.png",
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
expectMediaTimeoutClientConfigured();
|
|
380
|
-
expect(messageCreateMock).toHaveBeenCalledWith(
|
|
381
|
-
expect.objectContaining({
|
|
382
|
-
data: expect.objectContaining({ msg_type: "image" }),
|
|
383
|
-
}),
|
|
384
|
-
);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it("preserves Feishu diagnostics when media sends reject before response checks", async () => {
|
|
388
|
-
messageCreateMock.mockRejectedValueOnce(
|
|
389
|
-
Object.assign(new Error("Request failed with status code 400"), {
|
|
390
|
-
response: {
|
|
391
|
-
status: 400,
|
|
392
|
-
data: {
|
|
393
|
-
code: 9499,
|
|
394
|
-
msg: "Bad Request",
|
|
395
|
-
error: {
|
|
396
|
-
log_id: "20260429124731MEDIA",
|
|
397
|
-
troubleshooter: "https://open.feishu.cn/search?log_id=20260429124731MEDIA",
|
|
398
|
-
},
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
}),
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
const send = sendMediaFeishu({
|
|
405
|
-
cfg: emptyConfig,
|
|
406
|
-
to: "user:ou_target",
|
|
407
|
-
mediaBuffer: Buffer.from("image"),
|
|
408
|
-
fileName: "photo.png",
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
await expect(send).rejects.toThrow(/Feishu image send failed: .*"feishu_code":9499/);
|
|
412
|
-
await expect(send).rejects.toThrow(/"feishu_log_id":"20260429124731MEDIA"/);
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it("uses msg_type=media when replying with mp4", async () => {
|
|
416
|
-
await sendMediaFeishu({
|
|
417
|
-
cfg: emptyConfig,
|
|
418
|
-
to: "user:ou_target",
|
|
419
|
-
mediaBuffer: Buffer.from("video"),
|
|
420
|
-
fileName: "reply.mp4",
|
|
421
|
-
replyToMessageId: "om_parent",
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
expect(messageReplyMock).toHaveBeenCalledWith(
|
|
425
|
-
expect.objectContaining({
|
|
426
|
-
path: { message_id: "om_parent" },
|
|
427
|
-
data: expect.objectContaining({ msg_type: "media" }),
|
|
428
|
-
}),
|
|
429
|
-
);
|
|
430
|
-
|
|
431
|
-
expect(messageCreateMock).not.toHaveBeenCalled();
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
it("passes reply_in_thread when replyInThread is true", async () => {
|
|
435
|
-
await sendMediaFeishu({
|
|
436
|
-
cfg: emptyConfig,
|
|
437
|
-
to: "user:ou_target",
|
|
438
|
-
mediaBuffer: Buffer.from("video"),
|
|
439
|
-
fileName: "reply.mp4",
|
|
440
|
-
replyToMessageId: "om_parent",
|
|
441
|
-
replyInThread: true,
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
expect(messageReplyMock).toHaveBeenCalledWith(
|
|
445
|
-
expect.objectContaining({
|
|
446
|
-
path: { message_id: "om_parent" },
|
|
447
|
-
data: expect.objectContaining({
|
|
448
|
-
msg_type: "media",
|
|
449
|
-
reply_in_thread: true,
|
|
450
|
-
}),
|
|
451
|
-
}),
|
|
452
|
-
);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it("omits reply_in_thread when replyInThread is false", async () => {
|
|
456
|
-
await sendMediaFeishu({
|
|
457
|
-
cfg: emptyConfig,
|
|
458
|
-
to: "user:ou_target",
|
|
459
|
-
mediaBuffer: Buffer.from("video"),
|
|
460
|
-
fileName: "reply.mp4",
|
|
461
|
-
replyToMessageId: "om_parent",
|
|
462
|
-
replyInThread: false,
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
const callData = messageReplyMock.mock.calls[0][0].data;
|
|
466
|
-
expect(callData).not.toHaveProperty("reply_in_thread");
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it("passes mediaLocalRoots as localRoots to loadWebMedia for local paths (#27884)", async () => {
|
|
470
|
-
loadWebMediaMock.mockResolvedValue({
|
|
471
|
-
buffer: Buffer.from("local-file"),
|
|
472
|
-
fileName: "doc.pdf",
|
|
473
|
-
kind: "document",
|
|
474
|
-
contentType: "application/pdf",
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
const roots = ["/allowed/workspace", "/tmp/openclaw"];
|
|
478
|
-
await sendMediaFeishu({
|
|
479
|
-
cfg: emptyConfig,
|
|
480
|
-
to: "user:ou_target",
|
|
481
|
-
mediaUrl: "/allowed/workspace/file.pdf",
|
|
482
|
-
mediaLocalRoots: roots,
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
expect(loadWebMediaMock).toHaveBeenCalledWith(
|
|
486
|
-
"/allowed/workspace/file.pdf",
|
|
487
|
-
expect.objectContaining({
|
|
488
|
-
maxBytes: expect.any(Number),
|
|
489
|
-
optimizeImages: false,
|
|
490
|
-
localRoots: roots,
|
|
491
|
-
}),
|
|
492
|
-
);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it("fails closed when media URL fetch is blocked", async () => {
|
|
496
|
-
loadWebMediaMock.mockRejectedValueOnce(
|
|
497
|
-
new Error("Blocked: resolves to private/internal IP address"),
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
await expect(
|
|
501
|
-
sendMediaFeishu({
|
|
502
|
-
cfg: emptyConfig,
|
|
503
|
-
to: "user:ou_target",
|
|
504
|
-
mediaUrl: "https://x/img",
|
|
505
|
-
fileName: "voice.opus",
|
|
506
|
-
}),
|
|
507
|
-
).rejects.toThrow(/private\/internal/i);
|
|
508
|
-
|
|
509
|
-
expect(fileCreateMock).not.toHaveBeenCalled();
|
|
510
|
-
expect(messageCreateMock).not.toHaveBeenCalled();
|
|
511
|
-
expect(messageReplyMock).not.toHaveBeenCalled();
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
it("uses isolated temp paths for image downloads", async () => {
|
|
515
|
-
const imageKey = "img_v3_01abc123";
|
|
516
|
-
let capturedPath: string | undefined;
|
|
517
|
-
|
|
518
|
-
imageGetMock.mockResolvedValueOnce({
|
|
519
|
-
writeFile: async (tmpPath: string) => {
|
|
520
|
-
capturedPath = tmpPath;
|
|
521
|
-
await fs.writeFile(tmpPath, Buffer.from("image-data"));
|
|
522
|
-
},
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
const result = await downloadImageFeishu({
|
|
526
|
-
cfg: emptyConfig,
|
|
527
|
-
imageKey,
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
expect(imageGetMock).toHaveBeenCalledWith(
|
|
531
|
-
expect.objectContaining({
|
|
532
|
-
path: { image_key: imageKey },
|
|
533
|
-
}),
|
|
534
|
-
);
|
|
535
|
-
expectMediaTimeoutClientConfigured();
|
|
536
|
-
expect(result.buffer).toEqual(Buffer.from("image-data"));
|
|
537
|
-
expect(capturedPath).toBeDefined();
|
|
538
|
-
expectPathIsolatedToTmpRoot(capturedPath as string, imageKey);
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
it("uses isolated temp paths for message resource downloads", async () => {
|
|
542
|
-
const fileKey = "file_v3_01abc123";
|
|
543
|
-
let capturedPath: string | undefined;
|
|
544
|
-
|
|
545
|
-
messageResourceGetMock.mockResolvedValueOnce({
|
|
546
|
-
writeFile: async (tmpPath: string) => {
|
|
547
|
-
capturedPath = tmpPath;
|
|
548
|
-
await fs.writeFile(tmpPath, Buffer.from("resource-data"));
|
|
549
|
-
},
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
const result = await downloadMessageResourceFeishu({
|
|
553
|
-
cfg: emptyConfig,
|
|
554
|
-
messageId: "om_123",
|
|
555
|
-
fileKey,
|
|
556
|
-
type: "image",
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
expect(result.buffer).toEqual(Buffer.from("resource-data"));
|
|
560
|
-
expect(capturedPath).toBeDefined();
|
|
561
|
-
expectPathIsolatedToTmpRoot(capturedPath as string, fileKey);
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
it("rejects invalid image keys before calling feishu api", async () => {
|
|
565
|
-
await expect(
|
|
566
|
-
downloadImageFeishu({
|
|
567
|
-
cfg: emptyConfig,
|
|
568
|
-
imageKey: "a/../../bad",
|
|
569
|
-
}),
|
|
570
|
-
).rejects.toThrow("invalid image_key");
|
|
571
|
-
|
|
572
|
-
expect(imageGetMock).not.toHaveBeenCalled();
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
it("rejects invalid file keys before calling feishu api", async () => {
|
|
576
|
-
await expect(
|
|
577
|
-
downloadMessageResourceFeishu({
|
|
578
|
-
cfg: emptyConfig,
|
|
579
|
-
messageId: "om_123",
|
|
580
|
-
fileKey: "x/../../bad",
|
|
581
|
-
type: "file",
|
|
582
|
-
}),
|
|
583
|
-
).rejects.toThrow("invalid file_key");
|
|
584
|
-
|
|
585
|
-
expect(messageResourceGetMock).not.toHaveBeenCalled();
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
it("preserves Chinese filenames for file uploads", async () => {
|
|
589
|
-
await sendMediaFeishu({
|
|
590
|
-
cfg: emptyConfig,
|
|
591
|
-
to: "user:ou_target",
|
|
592
|
-
mediaBuffer: Buffer.from("doc"),
|
|
593
|
-
fileName: "测试文档.pdf",
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
const createCall = fileCreateMock.mock.calls[0][0];
|
|
597
|
-
expect(createCall.data.file_name).toBe("测试文档.pdf");
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
it("preserves ASCII filenames unchanged for file uploads", async () => {
|
|
601
|
-
await sendMediaFeishu({
|
|
602
|
-
cfg: emptyConfig,
|
|
603
|
-
to: "user:ou_target",
|
|
604
|
-
mediaBuffer: Buffer.from("doc"),
|
|
605
|
-
fileName: "report-2026.pdf",
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
const createCall = fileCreateMock.mock.calls[0][0];
|
|
609
|
-
expect(createCall.data.file_name).toBe("report-2026.pdf");
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
it("preserves special Unicode characters (em-dash, full-width brackets) in filenames", async () => {
|
|
613
|
-
await sendMediaFeishu({
|
|
614
|
-
cfg: emptyConfig,
|
|
615
|
-
to: "user:ou_target",
|
|
616
|
-
mediaBuffer: Buffer.from("doc"),
|
|
617
|
-
fileName: "报告—详情(2026).md",
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
const createCall = fileCreateMock.mock.calls[0][0];
|
|
621
|
-
expect(createCall.data.file_name).toBe("报告—详情(2026).md");
|
|
622
|
-
});
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
describe("sanitizeFileNameForUpload", () => {
|
|
626
|
-
it("returns ASCII filenames unchanged", () => {
|
|
627
|
-
expect(sanitizeFileNameForUpload("report.pdf")).toBe("report.pdf");
|
|
628
|
-
expect(sanitizeFileNameForUpload("my-file_v2.txt")).toBe("my-file_v2.txt");
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
it("preserves Chinese characters", () => {
|
|
632
|
-
expect(sanitizeFileNameForUpload("测试文件.md")).toBe("测试文件.md");
|
|
633
|
-
expect(sanitizeFileNameForUpload("武汉15座山登山信息汇总.csv")).toBe(
|
|
634
|
-
"武汉15座山登山信息汇总.csv",
|
|
635
|
-
);
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
it("preserves em-dash and full-width brackets", () => {
|
|
639
|
-
expect(sanitizeFileNameForUpload("文件—说明(v2).pdf")).toBe("文件—说明(v2).pdf");
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
it("preserves single quotes and parentheses", () => {
|
|
643
|
-
expect(sanitizeFileNameForUpload("文件'(test).txt")).toBe("文件'(test).txt");
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
it("preserves filenames without extension", () => {
|
|
647
|
-
expect(sanitizeFileNameForUpload("测试文件")).toBe("测试文件");
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
it("preserves mixed ASCII and non-ASCII", () => {
|
|
651
|
-
expect(sanitizeFileNameForUpload("Report_报告_2026.xlsx")).toBe("Report_报告_2026.xlsx");
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it("preserves emoji filenames", () => {
|
|
655
|
-
expect(sanitizeFileNameForUpload("report_😀.txt")).toBe("report_😀.txt");
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
it("strips control characters", () => {
|
|
659
|
-
expect(sanitizeFileNameForUpload("bad\x00file.txt")).toBe("bad_file.txt");
|
|
660
|
-
expect(sanitizeFileNameForUpload("inject\r\nheader.txt")).toBe("inject__header.txt");
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
it("strips quotes and backslashes to prevent header injection", () => {
|
|
664
|
-
expect(sanitizeFileNameForUpload('file"name.txt')).toBe("file_name.txt");
|
|
665
|
-
expect(sanitizeFileNameForUpload("file\\name.txt")).toBe("file_name.txt");
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
describe("downloadMessageResourceFeishu", () => {
|
|
670
|
-
function httpStatusError(status: number): Error & { response: { status: number } } {
|
|
671
|
-
return Object.assign(new Error(`Request failed with status code ${status}`), {
|
|
672
|
-
response: { status },
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
beforeEach(() => {
|
|
677
|
-
vi.clearAllMocks();
|
|
678
|
-
mockResolvedFeishuAccount();
|
|
679
|
-
|
|
680
|
-
createFeishuClientMock.mockReturnValue({
|
|
681
|
-
im: {
|
|
682
|
-
messageResource: {
|
|
683
|
-
get: messageResourceGetMock,
|
|
684
|
-
},
|
|
685
|
-
},
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
messageResourceGetMock.mockResolvedValue(Buffer.from("fake-audio-data"));
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
// Regression: Feishu API only supports type=image|file for messageResource.get.
|
|
692
|
-
// Audio/video resources must use type=file, not type=audio (#8746).
|
|
693
|
-
it("forwards provided type=file for non-image resources", async () => {
|
|
694
|
-
const result = await downloadMessageResourceFeishu({
|
|
695
|
-
cfg: emptyConfig,
|
|
696
|
-
messageId: "om_audio_msg",
|
|
697
|
-
fileKey: "file_key_audio",
|
|
698
|
-
type: "file",
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
expect(messageResourceGetMock).toHaveBeenCalledWith(
|
|
702
|
-
expect.objectContaining({
|
|
703
|
-
path: { message_id: "om_audio_msg", file_key: "file_key_audio" },
|
|
704
|
-
params: { type: "file" },
|
|
705
|
-
}),
|
|
706
|
-
);
|
|
707
|
-
expectMediaTimeoutClientConfigured();
|
|
708
|
-
expect(result.buffer).toBeInstanceOf(Buffer);
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
it("image uses type=image", async () => {
|
|
712
|
-
messageResourceGetMock.mockResolvedValue(Buffer.from("fake-image-data"));
|
|
713
|
-
|
|
714
|
-
const result = await downloadMessageResourceFeishu({
|
|
715
|
-
cfg: emptyConfig,
|
|
716
|
-
messageId: "om_img_msg",
|
|
717
|
-
fileKey: "img_key_1",
|
|
718
|
-
type: "image",
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
expect(messageResourceGetMock).toHaveBeenCalledWith(
|
|
722
|
-
expect.objectContaining({
|
|
723
|
-
path: { message_id: "om_img_msg", file_key: "img_key_1" },
|
|
724
|
-
params: { type: "image" },
|
|
725
|
-
}),
|
|
726
|
-
);
|
|
727
|
-
expectMediaTimeoutClientConfigured();
|
|
728
|
-
expect(result.buffer).toBeInstanceOf(Buffer);
|
|
729
|
-
});
|
|
730
|
-
|
|
731
|
-
it("extracts content-type and filename metadata from download headers", async () => {
|
|
732
|
-
messageResourceGetMock.mockResolvedValueOnce({
|
|
733
|
-
data: Buffer.from("fake-video-data"),
|
|
734
|
-
headers: {
|
|
735
|
-
"content-type": "video/mp4",
|
|
736
|
-
"content-disposition": `attachment; filename="clip.mp4"`,
|
|
737
|
-
},
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
const result = await downloadMessageResourceFeishu({
|
|
741
|
-
cfg: emptyConfig,
|
|
742
|
-
messageId: "om_video_msg",
|
|
743
|
-
fileKey: "file_key_video",
|
|
744
|
-
type: "file",
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
expect(result).toMatchObject({
|
|
748
|
-
buffer: Buffer.from("fake-video-data"),
|
|
749
|
-
contentType: "video/mp4",
|
|
750
|
-
fileName: "clip.mp4",
|
|
751
|
-
});
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
it("retries file resources as media after HTTP 502", async () => {
|
|
755
|
-
const originalError = httpStatusError(502);
|
|
756
|
-
messageResourceGetMock.mockRejectedValueOnce(originalError).mockResolvedValueOnce({
|
|
757
|
-
data: Buffer.from("fake-ios-video-data"),
|
|
758
|
-
headers: {
|
|
759
|
-
"content-type": "video/mp4",
|
|
760
|
-
"content-disposition": `attachment; filename="ios-video.mp4"`,
|
|
761
|
-
},
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
const result = await downloadMessageResourceFeishu({
|
|
765
|
-
cfg: emptyConfig,
|
|
766
|
-
messageId: "om_ios_video_msg",
|
|
767
|
-
fileKey: "file_key_ios_video",
|
|
768
|
-
type: "file",
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
expect(messageResourceGetMock).toHaveBeenNthCalledWith(
|
|
772
|
-
1,
|
|
773
|
-
expect.objectContaining({
|
|
774
|
-
path: { message_id: "om_ios_video_msg", file_key: "file_key_ios_video" },
|
|
775
|
-
params: { type: "file" },
|
|
776
|
-
}),
|
|
777
|
-
);
|
|
778
|
-
expect(messageResourceGetMock).toHaveBeenNthCalledWith(
|
|
779
|
-
2,
|
|
780
|
-
expect.objectContaining({
|
|
781
|
-
path: { message_id: "om_ios_video_msg", file_key: "file_key_ios_video" },
|
|
782
|
-
params: { type: "media" },
|
|
783
|
-
}),
|
|
784
|
-
);
|
|
785
|
-
expect(result).toMatchObject({
|
|
786
|
-
buffer: Buffer.from("fake-ios-video-data"),
|
|
787
|
-
contentType: "video/mp4",
|
|
788
|
-
fileName: "ios-video.mp4",
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
it("rethrows the original HTTP 502 when the media retry fails", async () => {
|
|
793
|
-
const originalError = httpStatusError(502);
|
|
794
|
-
messageResourceGetMock
|
|
795
|
-
.mockRejectedValueOnce(originalError)
|
|
796
|
-
.mockRejectedValueOnce(new Error("media retry failed"));
|
|
797
|
-
|
|
798
|
-
await expect(
|
|
799
|
-
downloadMessageResourceFeishu({
|
|
800
|
-
cfg: emptyConfig,
|
|
801
|
-
messageId: "om_ios_video_msg",
|
|
802
|
-
fileKey: "file_key_ios_video",
|
|
803
|
-
type: "file",
|
|
804
|
-
}),
|
|
805
|
-
).rejects.toBe(originalError);
|
|
806
|
-
|
|
807
|
-
expect(messageResourceGetMock).toHaveBeenNthCalledWith(
|
|
808
|
-
1,
|
|
809
|
-
expect.objectContaining({ params: { type: "file" } }),
|
|
810
|
-
);
|
|
811
|
-
expect(messageResourceGetMock).toHaveBeenNthCalledWith(
|
|
812
|
-
2,
|
|
813
|
-
expect.objectContaining({ params: { type: "media" } }),
|
|
814
|
-
);
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
it("does not retry non-fallback download failures", async () => {
|
|
818
|
-
for (const scenario of [
|
|
819
|
-
{ messageId: "om_image_msg", fileKey: "img_key_502", type: "image" as const, status: 502 },
|
|
820
|
-
{ messageId: "om_file_msg", fileKey: "file_key_500", type: "file" as const, status: 500 },
|
|
821
|
-
]) {
|
|
822
|
-
const originalError = httpStatusError(scenario.status);
|
|
823
|
-
messageResourceGetMock.mockClear();
|
|
824
|
-
messageResourceGetMock.mockRejectedValueOnce(originalError);
|
|
825
|
-
|
|
826
|
-
await expect(
|
|
827
|
-
downloadMessageResourceFeishu({
|
|
828
|
-
cfg: emptyConfig,
|
|
829
|
-
messageId: scenario.messageId,
|
|
830
|
-
fileKey: scenario.fileKey,
|
|
831
|
-
type: scenario.type,
|
|
832
|
-
}),
|
|
833
|
-
).rejects.toBe(originalError);
|
|
834
|
-
|
|
835
|
-
expect(messageResourceGetMock).toHaveBeenCalledTimes(1);
|
|
836
|
-
expect(messageResourceGetMock).toHaveBeenCalledWith(
|
|
837
|
-
expect.objectContaining({
|
|
838
|
-
path: { message_id: scenario.messageId, file_key: scenario.fileKey },
|
|
839
|
-
params: { type: scenario.type },
|
|
840
|
-
}),
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
it("recovers CJK filenames from plain Content-Disposition headers decoded as Latin-1", async () => {
|
|
846
|
-
const fileName = "武汉15座山登山信息汇总.csv";
|
|
847
|
-
const latin1HeaderFileName = Buffer.from(fileName, "utf8").toString("latin1");
|
|
848
|
-
messageResourceGetMock.mockResolvedValueOnce({
|
|
849
|
-
data: Buffer.from("fake-file-data"),
|
|
850
|
-
headers: {
|
|
851
|
-
"content-disposition": `attachment; filename="${latin1HeaderFileName}"`,
|
|
852
|
-
},
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
const result = await downloadMessageResourceFeishu({
|
|
856
|
-
cfg: emptyConfig,
|
|
857
|
-
messageId: "om_file_msg",
|
|
858
|
-
fileKey: "file_key_csv",
|
|
859
|
-
type: "file",
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
expect(result.fileName).toBe(fileName);
|
|
863
|
-
});
|
|
864
|
-
|
|
865
|
-
it("keeps valid Latin-1 filenames from plain Content-Disposition headers unchanged", async () => {
|
|
866
|
-
messageResourceGetMock.mockResolvedValueOnce({
|
|
867
|
-
data: Buffer.from("fake-file-data"),
|
|
868
|
-
headers: {
|
|
869
|
-
"content-disposition": `attachment; filename="café-©.txt"`,
|
|
870
|
-
},
|
|
871
|
-
});
|
|
872
|
-
|
|
873
|
-
const result = await downloadMessageResourceFeishu({
|
|
874
|
-
cfg: emptyConfig,
|
|
875
|
-
messageId: "om_latin1_msg",
|
|
876
|
-
fileKey: "file_key_latin1",
|
|
877
|
-
type: "file",
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
expect(result.fileName).toBe("café-©.txt");
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
it("keeps JSON-derived file_name metadata unchanged", async () => {
|
|
884
|
-
const fileName = "武汉15座山登山信息汇总.csv";
|
|
885
|
-
const latin1LookingFileName = Buffer.from(fileName, "utf8").toString("latin1");
|
|
886
|
-
messageResourceGetMock.mockResolvedValueOnce({
|
|
887
|
-
data: Buffer.from("fake-file-data"),
|
|
888
|
-
file_name: latin1LookingFileName,
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
const result = await downloadMessageResourceFeishu({
|
|
892
|
-
cfg: emptyConfig,
|
|
893
|
-
messageId: "om_json_file_msg",
|
|
894
|
-
fileKey: "file_key_json",
|
|
895
|
-
type: "file",
|
|
896
|
-
});
|
|
897
|
-
|
|
898
|
-
expect(result.fileName).toBe(latin1LookingFileName);
|
|
899
|
-
});
|
|
900
|
-
});
|