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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/dist/api.js +646 -0
  2. package/dist/approval-cg0SVahb.js +94 -0
  3. package/dist/channel-N6Y_Rcjp.js +551 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.setup-ByCRAe5H.js +25 -0
  6. package/dist/config-D6545NkC.js +94 -0
  7. package/dist/config-schema-DFcjQw73.js +309 -0
  8. package/dist/exec-approvals-COUsM6wZ.js +138 -0
  9. package/dist/gateway-CmSUJKSt.js +6726 -0
  10. package/dist/handler-runtime-Bqm6N0WG.js +120 -0
  11. package/dist/index.js +29 -0
  12. package/dist/narrowing-BoieBTIU.js +25 -0
  13. package/dist/outbound-BJfhwrPg.js +1357 -0
  14. package/dist/request-context-DXtpwWui.js +921 -0
  15. package/dist/resolve-D_06fV6-.js +284 -0
  16. package/dist/runtime-BJAS3eXW.js +18 -0
  17. package/dist/runtime-api.js +2 -0
  18. package/dist/secret-contract-api.js +56 -0
  19. package/dist/sender-p-B14eLG.js +1987 -0
  20. package/dist/setup-entry.js +15 -0
  21. package/dist/setup-plugin-api.js +2 -0
  22. package/dist/string-normalize-Ci6NM5DE.js +98 -0
  23. package/dist/target-parser-Y0prnrXD.js +245 -0
  24. package/package.json +15 -6
  25. package/api.ts +0 -56
  26. package/channel-plugin-api.ts +0 -1
  27. package/index.ts +0 -29
  28. package/runtime-api.ts +0 -9
  29. package/setup-entry.ts +0 -9
  30. package/setup-plugin-api.ts +0 -3
  31. package/src/bridge/approval/capability.ts +0 -237
  32. package/src/bridge/approval/handler-runtime.ts +0 -204
  33. package/src/bridge/bootstrap.ts +0 -135
  34. package/src/bridge/channel-entry.ts +0 -18
  35. package/src/bridge/commands/framework-context-adapter.ts +0 -60
  36. package/src/bridge/commands/framework-registration.ts +0 -47
  37. package/src/bridge/commands/from-parser.test.ts +0 -86
  38. package/src/bridge/commands/from-parser.ts +0 -60
  39. package/src/bridge/commands/result-dispatcher.ts +0 -76
  40. package/src/bridge/config-shared.ts +0 -132
  41. package/src/bridge/config.ts +0 -111
  42. package/src/bridge/gateway.ts +0 -174
  43. package/src/bridge/logger.ts +0 -31
  44. package/src/bridge/narrowing.ts +0 -31
  45. package/src/bridge/plugin-version.test.ts +0 -146
  46. package/src/bridge/plugin-version.ts +0 -102
  47. package/src/bridge/runtime.ts +0 -25
  48. package/src/bridge/sdk-adapter.ts +0 -131
  49. package/src/bridge/setup/finalize.ts +0 -144
  50. package/src/bridge/setup/surface.ts +0 -34
  51. package/src/bridge/tools/channel.ts +0 -58
  52. package/src/bridge/tools/index.ts +0 -15
  53. package/src/bridge/tools/remind.test.ts +0 -124
  54. package/src/bridge/tools/remind.ts +0 -91
  55. package/src/channel.setup.ts +0 -33
  56. package/src/channel.ts +0 -288
  57. package/src/command-auth.test.ts +0 -62
  58. package/src/config-schema.ts +0 -84
  59. package/src/config.test.ts +0 -364
  60. package/src/engine/access/access-control.test.ts +0 -198
  61. package/src/engine/access/access-control.ts +0 -226
  62. package/src/engine/access/index.ts +0 -16
  63. package/src/engine/access/resolve-policy.test.ts +0 -59
  64. package/src/engine/access/resolve-policy.ts +0 -57
  65. package/src/engine/access/sender-match.test.ts +0 -60
  66. package/src/engine/access/sender-match.ts +0 -55
  67. package/src/engine/access/types.ts +0 -53
  68. package/src/engine/adapter/audio.port.ts +0 -27
  69. package/src/engine/adapter/commands.port.ts +0 -22
  70. package/src/engine/adapter/history.port.ts +0 -52
  71. package/src/engine/adapter/index.ts +0 -139
  72. package/src/engine/adapter/mention-gate.port.ts +0 -50
  73. package/src/engine/adapter/types.ts +0 -38
  74. package/src/engine/api/api-client.ts +0 -212
  75. package/src/engine/api/media-chunked.test.ts +0 -336
  76. package/src/engine/api/media-chunked.ts +0 -622
  77. package/src/engine/api/media.ts +0 -218
  78. package/src/engine/api/messages.ts +0 -293
  79. package/src/engine/api/retry.ts +0 -217
  80. package/src/engine/api/routes.ts +0 -95
  81. package/src/engine/api/token.ts +0 -271
  82. package/src/engine/approval/index.test.ts +0 -22
  83. package/src/engine/approval/index.ts +0 -224
  84. package/src/engine/commands/builtin/log-helpers.ts +0 -319
  85. package/src/engine/commands/builtin/register-all.ts +0 -17
  86. package/src/engine/commands/builtin/register-approve.ts +0 -201
  87. package/src/engine/commands/builtin/register-basic.ts +0 -95
  88. package/src/engine/commands/builtin/register-clear-storage.ts +0 -187
  89. package/src/engine/commands/builtin/register-logs.ts +0 -20
  90. package/src/engine/commands/builtin/register-streaming.ts +0 -137
  91. package/src/engine/commands/builtin/state.ts +0 -31
  92. package/src/engine/commands/slash-command-auth.ts +0 -48
  93. package/src/engine/commands/slash-command-handler.ts +0 -146
  94. package/src/engine/commands/slash-commands-impl.test.ts +0 -8
  95. package/src/engine/commands/slash-commands-impl.ts +0 -61
  96. package/src/engine/commands/slash-commands.ts +0 -199
  97. package/src/engine/config/credential-backup.test.ts +0 -88
  98. package/src/engine/config/credential-backup.ts +0 -107
  99. package/src/engine/config/credentials.ts +0 -76
  100. package/src/engine/config/group.test.ts +0 -234
  101. package/src/engine/config/group.ts +0 -299
  102. package/src/engine/config/resolve.test.ts +0 -152
  103. package/src/engine/config/resolve.ts +0 -283
  104. package/src/engine/config/setup-logic.ts +0 -84
  105. package/src/engine/engine-import-boundary.test.ts +0 -73
  106. package/src/engine/gateway/codec.ts +0 -47
  107. package/src/engine/gateway/constants.ts +0 -117
  108. package/src/engine/gateway/event-dispatcher.ts +0 -177
  109. package/src/engine/gateway/gateway-connection.ts +0 -371
  110. package/src/engine/gateway/gateway.ts +0 -291
  111. package/src/engine/gateway/inbound-attachments.test.ts +0 -126
  112. package/src/engine/gateway/inbound-attachments.ts +0 -360
  113. package/src/engine/gateway/inbound-context.ts +0 -195
  114. package/src/engine/gateway/inbound-pipeline.self-echo.test.ts +0 -218
  115. package/src/engine/gateway/inbound-pipeline.ts +0 -235
  116. package/src/engine/gateway/interaction-handler.ts +0 -220
  117. package/src/engine/gateway/message-queue.test.ts +0 -282
  118. package/src/engine/gateway/message-queue.ts +0 -499
  119. package/src/engine/gateway/outbound-dispatch.test.ts +0 -231
  120. package/src/engine/gateway/outbound-dispatch.ts +0 -575
  121. package/src/engine/gateway/reconnect.ts +0 -199
  122. package/src/engine/gateway/stages/access-stage.ts +0 -132
  123. package/src/engine/gateway/stages/assembly-stage.ts +0 -156
  124. package/src/engine/gateway/stages/content-stage.test.ts +0 -77
  125. package/src/engine/gateway/stages/content-stage.ts +0 -77
  126. package/src/engine/gateway/stages/envelope-stage.test.ts +0 -152
  127. package/src/engine/gateway/stages/envelope-stage.ts +0 -144
  128. package/src/engine/gateway/stages/group-gate-stage.ts +0 -292
  129. package/src/engine/gateway/stages/index.ts +0 -18
  130. package/src/engine/gateway/stages/quote-stage.ts +0 -113
  131. package/src/engine/gateway/stages/refidx-stage.ts +0 -62
  132. package/src/engine/gateway/stages/stub-contexts.ts +0 -116
  133. package/src/engine/gateway/types.ts +0 -264
  134. package/src/engine/gateway/typing-keepalive.ts +0 -79
  135. package/src/engine/group/activation.test.ts +0 -114
  136. package/src/engine/group/activation.ts +0 -147
  137. package/src/engine/group/history.test.ts +0 -314
  138. package/src/engine/group/history.ts +0 -321
  139. package/src/engine/group/mention.test.ts +0 -141
  140. package/src/engine/group/mention.ts +0 -197
  141. package/src/engine/group/message-gating.test.ts +0 -188
  142. package/src/engine/group/message-gating.ts +0 -216
  143. package/src/engine/messaging/decode-media-path.ts +0 -82
  144. package/src/engine/messaging/media-source.ts +0 -215
  145. package/src/engine/messaging/media-type-detect.ts +0 -37
  146. package/src/engine/messaging/outbound-audio-port.ts +0 -38
  147. package/src/engine/messaging/outbound-deliver.ts +0 -810
  148. package/src/engine/messaging/outbound-media-send.ts +0 -702
  149. package/src/engine/messaging/outbound-reply.ts +0 -27
  150. package/src/engine/messaging/outbound-result-helpers.ts +0 -54
  151. package/src/engine/messaging/outbound-types.ts +0 -45
  152. package/src/engine/messaging/outbound.ts +0 -485
  153. package/src/engine/messaging/reply-dispatcher.ts +0 -597
  154. package/src/engine/messaging/reply-limiter.ts +0 -164
  155. package/src/engine/messaging/sender.ts +0 -729
  156. package/src/engine/messaging/streaming-c2c.ts +0 -1192
  157. package/src/engine/messaging/streaming-media-send.ts +0 -544
  158. package/src/engine/messaging/target-parser.ts +0 -104
  159. package/src/engine/ref/format-message-ref.ts +0 -142
  160. package/src/engine/ref/format-ref-entry.test.ts +0 -60
  161. package/src/engine/ref/format-ref-entry.ts +0 -27
  162. package/src/engine/ref/store.ts +0 -208
  163. package/src/engine/ref/types.ts +0 -27
  164. package/src/engine/session/known-users.ts +0 -137
  165. package/src/engine/session/session-store.ts +0 -204
  166. package/src/engine/tools/channel-api.ts +0 -244
  167. package/src/engine/tools/remind-logic.test.ts +0 -280
  168. package/src/engine/tools/remind-logic.ts +0 -377
  169. package/src/engine/types.ts +0 -313
  170. package/src/engine/utils/attachment-tags.test.ts +0 -186
  171. package/src/engine/utils/attachment-tags.ts +0 -174
  172. package/src/engine/utils/audio.test.ts +0 -250
  173. package/src/engine/utils/audio.ts +0 -585
  174. package/src/engine/utils/data-paths.ts +0 -38
  175. package/src/engine/utils/diagnostics.ts +0 -109
  176. package/src/engine/utils/file-utils.test.ts +0 -72
  177. package/src/engine/utils/file-utils.ts +0 -225
  178. package/src/engine/utils/format.test.ts +0 -68
  179. package/src/engine/utils/format.ts +0 -70
  180. package/src/engine/utils/image-size.test.ts +0 -158
  181. package/src/engine/utils/image-size.ts +0 -249
  182. package/src/engine/utils/log.test.ts +0 -28
  183. package/src/engine/utils/log.ts +0 -61
  184. package/src/engine/utils/media-tags.test.ts +0 -32
  185. package/src/engine/utils/media-tags.ts +0 -177
  186. package/src/engine/utils/payload.test.ts +0 -68
  187. package/src/engine/utils/payload.ts +0 -145
  188. package/src/engine/utils/platform-storage-laziness.test.ts +0 -63
  189. package/src/engine/utils/platform.test.ts +0 -148
  190. package/src/engine/utils/platform.ts +0 -343
  191. package/src/engine/utils/request-context.ts +0 -60
  192. package/src/engine/utils/string-normalize.ts +0 -91
  193. package/src/engine/utils/stt.test.ts +0 -104
  194. package/src/engine/utils/stt.ts +0 -100
  195. package/src/engine/utils/text-parsing.test.ts +0 -29
  196. package/src/engine/utils/text-parsing.ts +0 -155
  197. package/src/engine/utils/upload-cache.ts +0 -96
  198. package/src/engine/utils/voice-text.ts +0 -15
  199. package/src/exec-approvals.ts +0 -218
  200. package/src/manifest-schema.test.ts +0 -56
  201. package/src/qqbot-test-support.ts +0 -29
  202. package/src/types.ts +0 -210
  203. package/tsconfig.json +0 -16
@@ -1,336 +0,0 @@
1
- import * as crypto from "node:crypto";
2
- import * as fs from "node:fs";
3
- import * as os from "node:os";
4
- import * as path from "node:path";
5
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
- import {
7
- ApiError,
8
- MediaFileType,
9
- type UploadMediaResponse,
10
- type UploadPrepareResponse,
11
- } from "../types.js";
12
- import type { ApiClient } from "./api-client.js";
13
- import {
14
- ChunkedMediaApi,
15
- UploadDailyLimitExceededError,
16
- isChunkedUploadImplemented,
17
- } from "./media-chunked.js";
18
- import type { UploadCacheAdapter } from "./media.js";
19
- import { UPLOAD_PREPARE_FALLBACK_CODE } from "./retry.js";
20
- import type { TokenManager } from "./token.js";
21
-
22
- // ============ Test doubles ============
23
-
24
- /** Build a minimal ApiClient stub whose `request` is fully mockable. */
25
- function mockApiClient(): ApiClient & { request: ReturnType<typeof vi.fn> } {
26
- return {
27
- request: vi.fn(),
28
- } as unknown as ApiClient & { request: ReturnType<typeof vi.fn> };
29
- }
30
-
31
- /** Minimal TokenManager stub returning a static token. */
32
- function mockTokenManager(token = "test-token"): TokenManager {
33
- return {
34
- getAccessToken: vi.fn().mockResolvedValue(token),
35
- } as unknown as TokenManager;
36
- }
37
-
38
- /** In-memory upload-cache adapter. */
39
- function inMemoryCache(): UploadCacheAdapter & {
40
- getSpy: ReturnType<typeof vi.fn>;
41
- setSpy: ReturnType<typeof vi.fn>;
42
- } {
43
- const store = new Map<string, string>();
44
- const getSpy = vi.fn(
45
- (hash: string, scope: string, targetId: string, fileType: number) =>
46
- store.get(`${hash}:${scope}:${targetId}:${fileType}`) ?? null,
47
- );
48
- const setSpy = vi.fn(
49
- (hash: string, scope: string, targetId: string, fileType: number, fileInfo: string) => {
50
- store.set(`${hash}:${scope}:${targetId}:${fileType}`, fileInfo);
51
- },
52
- );
53
- return {
54
- computeHash: (data: string | Uint8Array) => crypto.createHash("md5").update(data).digest("hex"),
55
- get: getSpy,
56
- set: setSpy,
57
- getSpy,
58
- setSpy,
59
- };
60
- }
61
-
62
- /** Build a canned upload_prepare response with `parts` presigned URLs. */
63
- function makePrepareResponse(uploadId: string, parts: number): UploadPrepareResponse {
64
- return {
65
- upload_id: uploadId,
66
- block_size: 8,
67
- parts: Array.from({ length: parts }, (_, i) => ({
68
- index: i + 1,
69
- presigned_url: `https://cos.example.com/part-${i + 1}`,
70
- })),
71
- concurrency: 2,
72
- retry_timeout: 60,
73
- };
74
- }
75
-
76
- /** Fixture: a 20-byte buffer that spans 3 parts at block_size=8. */
77
- const FIXTURE_BUFFER = Buffer.from("0123456789abcdefghij"); // 20 bytes
78
-
79
- // ============ fetch stub for COS PUT ============
80
-
81
- let originalFetch: typeof globalThis.fetch;
82
-
83
- function stubFetchOk(): ReturnType<typeof vi.fn> {
84
- const spy = vi.fn(
85
- async () =>
86
- new Response("", {
87
- status: 200,
88
- headers: {
89
- ETag: '"etag-value"',
90
- "x-cos-request-id": "req-id",
91
- },
92
- }),
93
- );
94
- globalThis.fetch = spy as unknown as typeof globalThis.fetch;
95
- return spy;
96
- }
97
-
98
- // ============ Tests ============
99
-
100
- describe("media-chunked: UploadDailyLimitExceededError", () => {
101
- it("captures filePath / fileSize / message", () => {
102
- const err = new UploadDailyLimitExceededError("/tmp/x.mp4", 123, "quota exceeded");
103
- expect(err).toBeInstanceOf(Error);
104
- expect(err.name).toBe("UploadDailyLimitExceededError");
105
- expect(err.filePath).toBe("/tmp/x.mp4");
106
- expect(err.fileSize).toBe(123);
107
- expect(err.message).toBe("quota exceeded");
108
- });
109
- });
110
-
111
- describe("media-chunked: isChunkedUploadImplemented", () => {
112
- it("returns true for the filled-in module", () => {
113
- expect(isChunkedUploadImplemented()).toBe(true);
114
- });
115
- });
116
-
117
- describe("media-chunked: ChunkedMediaApi.uploadChunked", () => {
118
- beforeEach(() => {
119
- originalFetch = globalThis.fetch;
120
- });
121
-
122
- afterEach(() => {
123
- globalThis.fetch = originalFetch;
124
- vi.restoreAllMocks();
125
- });
126
-
127
- it("rejects url / base64 sources up-front", async () => {
128
- const client = mockApiClient();
129
- const tm = mockTokenManager();
130
- const api = new ChunkedMediaApi(client, tm);
131
-
132
- await expect(
133
- api.uploadChunked({
134
- scope: "c2c",
135
- targetId: "u1",
136
- fileType: MediaFileType.IMAGE,
137
- source: { kind: "url", url: "https://x" },
138
- creds: { appId: "a", clientSecret: "s" },
139
- }),
140
- ).rejects.toThrow(/unsupported source kind 'url'/);
141
-
142
- await expect(
143
- api.uploadChunked({
144
- scope: "c2c",
145
- targetId: "u1",
146
- fileType: MediaFileType.IMAGE,
147
- source: { kind: "base64", data: "AA==" },
148
- creds: { appId: "a", clientSecret: "s" },
149
- }),
150
- ).rejects.toThrow(/unsupported source kind 'base64'/);
151
-
152
- expect(client.request).not.toHaveBeenCalled();
153
- });
154
-
155
- it("takes the cache fast path and skips upload_prepare on hit", async () => {
156
- const client = mockApiClient();
157
- const tm = mockTokenManager();
158
- const cache = inMemoryCache();
159
-
160
- // Seed cache with the md5 that uploadChunked will compute.
161
- const md5 = crypto.createHash("md5").update(FIXTURE_BUFFER).digest("hex");
162
- cache.set(md5, "c2c", "u1", MediaFileType.IMAGE, "cached-file-info", "uuid", 999);
163
-
164
- const api = new ChunkedMediaApi(client, tm, { uploadCache: cache });
165
-
166
- const result = await api.uploadChunked({
167
- scope: "c2c",
168
- targetId: "u1",
169
- fileType: MediaFileType.IMAGE,
170
- source: { kind: "buffer", buffer: FIXTURE_BUFFER },
171
- creds: { appId: "a", clientSecret: "s" },
172
- });
173
-
174
- expect(result.file_info).toBe("cached-file-info");
175
- expect(client.request).not.toHaveBeenCalled();
176
- expect(cache.getSpy).toHaveBeenCalledWith(md5, "c2c", "u1", MediaFileType.IMAGE);
177
- });
178
-
179
- it("runs prepare → COS PUT → part_finish → complete for a buffer source", async () => {
180
- const client = mockApiClient();
181
- const tm = mockTokenManager();
182
- const cache = inMemoryCache();
183
- const fetchSpy = stubFetchOk();
184
-
185
- const prepareResp = makePrepareResponse("uid-1", 3);
186
- const completeResp: UploadMediaResponse = {
187
- file_uuid: "uuid-final",
188
- file_info: "final-file-info",
189
- ttl: 3600,
190
- };
191
-
192
- // First request: upload_prepare; three follow-ups: upload_part_finish ×3
193
- // plus one complete. Because concurrency=2 the order of part_finish is
194
- // not strictly deterministic, so match on path + payload key.
195
- client.request.mockImplementation(
196
- async (_token: string, _method: string, path: string, body: Record<string, unknown>) => {
197
- if (path.endsWith("/upload_prepare")) {
198
- expect(body.file_type).toBe(MediaFileType.FILE);
199
- expect(typeof body.md5).toBe("string");
200
- expect(typeof body.sha1).toBe("string");
201
- expect(typeof body.md5_10m).toBe("string");
202
- expect(body.file_size).toBe(FIXTURE_BUFFER.length);
203
- return prepareResp;
204
- }
205
- if (path.endsWith("/upload_part_finish")) {
206
- expect(body.upload_id).toBe("uid-1");
207
- expect(typeof body.part_index).toBe("number");
208
- return {};
209
- }
210
- if (path.endsWith("/files")) {
211
- expect(body.upload_id).toBe("uid-1");
212
- return completeResp;
213
- }
214
- throw new Error(`unexpected path ${path}`);
215
- },
216
- );
217
-
218
- const api = new ChunkedMediaApi(client, tm, { uploadCache: cache });
219
- const onProgress = vi.fn();
220
-
221
- const result = await api.uploadChunked({
222
- scope: "group",
223
- targetId: "g1",
224
- fileType: MediaFileType.FILE,
225
- source: { kind: "buffer", buffer: FIXTURE_BUFFER, fileName: "blob.bin" },
226
- creds: { appId: "a", clientSecret: "s" },
227
- onProgress,
228
- });
229
-
230
- expect(result).toEqual(completeResp);
231
-
232
- // One prepare + 3 part_finish + 1 complete = 5 client requests.
233
- expect(client.request).toHaveBeenCalledTimes(5);
234
-
235
- // 3 COS PUTs, one per part, each to the presigned URL.
236
- expect(fetchSpy).toHaveBeenCalledTimes(3);
237
- const putUrls = fetchSpy.mock.calls.map((c) => c[0]);
238
- expect(putUrls).toEqual(
239
- expect.arrayContaining([
240
- "https://cos.example.com/part-1",
241
- "https://cos.example.com/part-2",
242
- "https://cos.example.com/part-3",
243
- ]),
244
- );
245
-
246
- // Cache populated with the complete result.
247
- const expectedMd5 = crypto.createHash("md5").update(FIXTURE_BUFFER).digest("hex");
248
- expect(cache.setSpy).toHaveBeenCalledWith(
249
- expectedMd5,
250
- "group",
251
- "g1",
252
- MediaFileType.FILE,
253
- "final-file-info",
254
- "uuid-final",
255
- 3600,
256
- );
257
-
258
- // Progress callback hit 3 times with monotonically-increasing counts.
259
- expect(onProgress).toHaveBeenCalledTimes(3);
260
- const last = onProgress.mock.calls[2][0];
261
- expect(last.completedParts).toBe(3);
262
- expect(last.totalParts).toBe(3);
263
- expect(last.uploadedBytes).toBe(FIXTURE_BUFFER.length);
264
- expect(last.totalBytes).toBe(FIXTURE_BUFFER.length);
265
- });
266
-
267
- it("maps UPLOAD_PREPARE_FALLBACK_CODE to UploadDailyLimitExceededError", async () => {
268
- const client = mockApiClient();
269
- const tm = mockTokenManager();
270
- client.request.mockRejectedValueOnce(
271
- new ApiError(
272
- "daily limit exceeded",
273
- 200,
274
- "/v2/users/u1/upload_prepare",
275
- UPLOAD_PREPARE_FALLBACK_CODE,
276
- "quota",
277
- ),
278
- );
279
-
280
- const api = new ChunkedMediaApi(client, tm);
281
- await expect(
282
- api.uploadChunked({
283
- scope: "c2c",
284
- targetId: "u1",
285
- fileType: MediaFileType.FILE,
286
- source: { kind: "buffer", buffer: FIXTURE_BUFFER, fileName: "big.bin" },
287
- creds: { appId: "a", clientSecret: "s" },
288
- }),
289
- ).rejects.toBeInstanceOf(UploadDailyLimitExceededError);
290
- });
291
-
292
- it("streams hashes from a localPath source", async () => {
293
- const tmp = await fs.promises.mkdtemp(path.join(os.tmpdir(), "chunked-"));
294
- const filePath = path.join(tmp, "fixture.bin");
295
- await fs.promises.writeFile(filePath, FIXTURE_BUFFER);
296
- try {
297
- const client = mockApiClient();
298
- const tm = mockTokenManager();
299
- stubFetchOk();
300
-
301
- client.request.mockImplementation(async (_t, _m, p) => {
302
- if (p.endsWith("/upload_prepare")) {
303
- return makePrepareResponse("uid-2", 3);
304
- }
305
- if (p.endsWith("/upload_part_finish")) {
306
- return {};
307
- }
308
- if (p.endsWith("/files")) {
309
- return { file_uuid: "u", file_info: "fi", ttl: 10 } satisfies UploadMediaResponse;
310
- }
311
- throw new Error(`unexpected ${p}`);
312
- });
313
-
314
- const api = new ChunkedMediaApi(client, tm);
315
- const result = await api.uploadChunked({
316
- scope: "c2c",
317
- targetId: "u1",
318
- fileType: MediaFileType.VIDEO,
319
- source: { kind: "localPath", path: filePath, size: FIXTURE_BUFFER.length },
320
- creds: { appId: "a", clientSecret: "s" },
321
- });
322
-
323
- expect(result.file_info).toBe("fi");
324
-
325
- // Verify prepare received the md5 of the on-disk bytes.
326
- const prepareCall = client.request.mock.calls.find((c) =>
327
- String(c[2]).endsWith("/upload_prepare"),
328
- )!;
329
- const prepareBody = prepareCall[3] as { md5: string; file_name: string };
330
- expect(prepareBody.md5).toBe(crypto.createHash("md5").update(FIXTURE_BUFFER).digest("hex"));
331
- expect(prepareBody.file_name).toBe("fixture.bin");
332
- } finally {
333
- await fs.promises.rm(tmp, { recursive: true, force: true });
334
- }
335
- });
336
- });