@chainlesschain/personal-data-hub 0.4.28 → 0.4.30

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 (204) hide show
  1. package/README.md +13 -5
  2. package/lib/adapters/social-douyin-adb/usage-profile-reader.js +253 -0
  3. package/lib/adapters/social-douyin-adb/watch-history-reader.js +104 -31
  4. package/lib/adapters/social-toutiao-adb/article-reader.js +202 -0
  5. package/lib/analysis-skills/overview.js +24 -4
  6. package/lib/analysis-skills/spending.js +63 -2
  7. package/lib/analysis-skills/timeline.js +11 -6
  8. package/lib/prompt-builder.js +15 -1
  9. package/lib/query-parser.js +38 -8
  10. package/package.json +4 -1
  11. package/__tests__/adapter-guide.test.js +0 -47
  12. package/__tests__/adapter-spec.test.js +0 -78
  13. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  14. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  15. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  16. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  17. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  18. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  19. package/__tests__/adapters/apple-health.test.js +0 -95
  20. package/__tests__/adapters/bank-family.test.js +0 -125
  21. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  22. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  23. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  24. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  25. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  26. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  27. package/__tests__/adapters/doc-platforms.test.js +0 -177
  28. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  29. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  30. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  31. package/__tests__/adapters/email-adapter.test.js +0 -742
  32. package/__tests__/adapters/email-classifier.test.js +0 -347
  33. package/__tests__/adapters/email-imap-session.test.js +0 -334
  34. package/__tests__/adapters/email-parser.test.js +0 -244
  35. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  36. package/__tests__/adapters/email-providers.test.js +0 -84
  37. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  38. package/__tests__/adapters/email-templates.test.js +0 -822
  39. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  40. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  41. package/__tests__/adapters/finance-dcep.test.js +0 -74
  42. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  43. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  44. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  45. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  46. package/__tests__/adapters/git-activity.test.js +0 -222
  47. package/__tests__/adapters/gov-12123.test.js +0 -103
  48. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  49. package/__tests__/adapters/gov-tax.test.js +0 -135
  50. package/__tests__/adapters/health-meiyou.test.js +0 -125
  51. package/__tests__/adapters/local-files.test.js +0 -264
  52. package/__tests__/adapters/local-im-pc.test.js +0 -154
  53. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  54. package/__tests__/adapters/music-kugou.test.js +0 -187
  55. package/__tests__/adapters/music-qq.test.js +0 -112
  56. package/__tests__/adapters/netease-music-live.test.js +0 -244
  57. package/__tests__/adapters/netease-music.test.js +0 -74
  58. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  59. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  60. package/__tests__/adapters/reading-family.test.js +0 -108
  61. package/__tests__/adapters/recruit-boss.test.js +0 -180
  62. package/__tests__/adapters/shell-history.test.js +0 -180
  63. package/__tests__/adapters/shopping-base.test.js +0 -179
  64. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  65. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  66. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  67. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  68. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  69. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  70. package/__tests__/adapters/social-csdn.test.js +0 -175
  71. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  72. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  73. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  74. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  75. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  76. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  77. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -192
  78. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  79. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  80. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  81. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  82. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  83. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  84. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  85. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  86. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  87. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  88. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  89. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  90. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  91. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  92. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  93. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  94. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  95. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  96. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  97. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  98. package/__tests__/adapters/social-zhihu.test.js +0 -246
  99. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  100. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  101. package/__tests__/adapters/system-data-android.test.js +0 -519
  102. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  103. package/__tests__/adapters/travel-12306.test.js +0 -512
  104. package/__tests__/adapters/travel-amap.test.js +0 -219
  105. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  106. package/__tests__/adapters/travel-base.test.js +0 -205
  107. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  108. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  109. package/__tests__/adapters/travel-didi.test.js +0 -204
  110. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  111. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  112. package/__tests__/adapters/video-platforms.test.js +0 -152
  113. package/__tests__/adapters/video-xigua.test.js +0 -106
  114. package/__tests__/adapters/vscode.test.js +0 -299
  115. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  116. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  117. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  118. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  119. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  120. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  121. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  122. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  123. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  124. package/__tests__/adapters/weread.test.js +0 -123
  125. package/__tests__/adapters/wework-pc.test.js +0 -124
  126. package/__tests__/adapters/win-recent.test.js +0 -192
  127. package/__tests__/analysis-skills.test.js +0 -679
  128. package/__tests__/analysis.test.js +0 -1845
  129. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  130. package/__tests__/batch.test.js +0 -133
  131. package/__tests__/bridges-cc-kg.test.js +0 -231
  132. package/__tests__/bridges-cc-llm.test.js +0 -191
  133. package/__tests__/bridges-cc-rag.test.js +0 -162
  134. package/__tests__/categories.test.js +0 -92
  135. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  136. package/__tests__/e2e/full-user-journey.test.js +0 -188
  137. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  138. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  139. package/__tests__/entity-resolver-stages.test.js +0 -411
  140. package/__tests__/entity-resolver-vault.test.js +0 -249
  141. package/__tests__/entity-resolver.test.js +0 -526
  142. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  143. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  144. package/__tests__/ids.test.js +0 -45
  145. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  146. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  147. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  148. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  149. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  150. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  151. package/__tests__/key-providers.test.js +0 -126
  152. package/__tests__/kg-derive.test.js +0 -219
  153. package/__tests__/llm-client.test.js +0 -122
  154. package/__tests__/longtail-adapters.test.js +0 -281
  155. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  156. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  157. package/__tests__/mobile-extractor.test.js +0 -288
  158. package/__tests__/mock-adapter.test.js +0 -93
  159. package/__tests__/prompt-builder.test.js +0 -249
  160. package/__tests__/query-parser.test.js +0 -302
  161. package/__tests__/rag-derive.test.js +0 -169
  162. package/__tests__/registry-readiness.test.js +0 -292
  163. package/__tests__/registry.test.js +0 -420
  164. package/__tests__/salvage-ingest.test.js +0 -97
  165. package/__tests__/schemas.test.js +0 -331
  166. package/__tests__/shopping-adapters.test.js +0 -392
  167. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  168. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  169. package/__tests__/shopping-snapshot.test.js +0 -438
  170. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  171. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  172. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  173. package/__tests__/sidecar-supervisor.test.js +0 -128
  174. package/__tests__/sign-providers.test.js +0 -62
  175. package/__tests__/social-adapters.test.js +0 -280
  176. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  177. package/__tests__/social-douban-snapshot.test.js +0 -351
  178. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  179. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  180. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  181. package/__tests__/social-douyin-snapshot.test.js +0 -256
  182. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  183. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  184. package/__tests__/social-weibo-snapshot.test.js +0 -234
  185. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  186. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  187. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  188. package/__tests__/travel-adapters.test.js +0 -483
  189. package/__tests__/travel-maps-snapshot.test.js +0 -426
  190. package/__tests__/vault-driver-error.test.js +0 -74
  191. package/__tests__/vault-search-helpers.test.js +0 -104
  192. package/__tests__/vault-search.test.js +0 -423
  193. package/__tests__/vault.test.js +0 -767
  194. package/__tests__/wechat-adapter.test.js +0 -594
  195. package/__tests__/whatsapp-adapter.test.js +0 -138
  196. package/scripts/_make-fixture-all.js +0 -126
  197. package/scripts/_make-fixture-contacts.js +0 -84
  198. package/scripts/evaluate-entity-resolver.js +0 -213
  199. package/scripts/run-native-tests-sandbox.sh +0 -55
  200. package/scripts/smoke-phase-5-5.js +0 -196
  201. package/scripts/smoke-phase-5-7.js +0 -181
  202. package/scripts/smoke-system-data-contacts.js +0 -309
  203. package/scripts/smoke-system-data.js +0 -312
  204. package/vitest.config.js +0 -88
@@ -1,244 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { parseRawEmail } = require("../../lib/adapters/email-imap/email-parser");
6
-
7
- // ─── Fixture builders ───────────────────────────────────────────────────
8
-
9
- function plaintextEmail({
10
- from = "alice@example.com",
11
- to = "bob@example.com",
12
- subject = "Hello",
13
- body = "Hello, world!",
14
- date = "Fri, 19 May 2026 10:00:00 +0800",
15
- messageId = "<m-1@example.com>",
16
- } = {}) {
17
- return [
18
- `From: ${from}`,
19
- `To: ${to}`,
20
- `Subject: ${subject}`,
21
- `Date: ${date}`,
22
- `Message-ID: ${messageId}`,
23
- `Content-Type: text/plain; charset=utf-8`,
24
- `Content-Transfer-Encoding: 7bit`,
25
- ``,
26
- body,
27
- ].join("\r\n");
28
- }
29
-
30
- function multipartAlternative({ text = "plain version", html = "<p>html <b>version</b></p>" } = {}) {
31
- const boundary = "BOUNDARY_42";
32
- return [
33
- `From: sender@example.com`,
34
- `To: me@example.com`,
35
- `Subject: Multipart`,
36
- `MIME-Version: 1.0`,
37
- `Content-Type: multipart/alternative; boundary="${boundary}"`,
38
- ``,
39
- `--${boundary}`,
40
- `Content-Type: text/plain; charset=utf-8`,
41
- ``,
42
- text,
43
- `--${boundary}`,
44
- `Content-Type: text/html; charset=utf-8`,
45
- ``,
46
- html,
47
- `--${boundary}--`,
48
- ].join("\r\n");
49
- }
50
-
51
- function multipartWithAttachment({ filename = "report.pdf", contentType = "application/pdf", body = "%PDF-1.4\n/Encrypt placeholder\n" } = {}) {
52
- const boundary = "MIXED_99";
53
- const b64 = Buffer.from(body).toString("base64");
54
- return [
55
- `From: bank@example.com`,
56
- `To: me@example.com`,
57
- `Subject: Your statement`,
58
- `MIME-Version: 1.0`,
59
- `Content-Type: multipart/mixed; boundary="${boundary}"`,
60
- ``,
61
- `--${boundary}`,
62
- `Content-Type: text/plain`,
63
- ``,
64
- `See attached statement.`,
65
- `--${boundary}`,
66
- `Content-Type: ${contentType}; name="${filename}"`,
67
- `Content-Disposition: attachment; filename="${filename}"`,
68
- `Content-Transfer-Encoding: base64`,
69
- ``,
70
- b64,
71
- `--${boundary}--`,
72
- ].join("\r\n");
73
- }
74
-
75
- // ─── parseRawEmail ──────────────────────────────────────────────────────
76
-
77
- describe("parseRawEmail — basic shape", () => {
78
- it("rejects null/missing input", async () => {
79
- await expect(parseRawEmail(null)).rejects.toThrow(/required/);
80
- await expect(parseRawEmail()).rejects.toThrow(/required/);
81
- });
82
-
83
- it("accepts a Buffer", async () => {
84
- const buf = Buffer.from(plaintextEmail(), "utf8");
85
- const r = await parseRawEmail(buf);
86
- expect(r.subject).toBe("Hello");
87
- expect(r.textBody).toContain("Hello, world!");
88
- });
89
-
90
- it("accepts a string", async () => {
91
- const r = await parseRawEmail(plaintextEmail());
92
- expect(r.subject).toBe("Hello");
93
- });
94
-
95
- it("returns sourceBytes + contentSha256", async () => {
96
- const raw = plaintextEmail();
97
- const r = await parseRawEmail(raw);
98
- expect(r.sourceBytes).toBe(Buffer.byteLength(raw));
99
- expect(r.contentSha256).toMatch(/^[0-9a-f]{64}$/);
100
- });
101
-
102
- it("flattens headers to lowercased-keyed object", async () => {
103
- const r = await parseRawEmail(plaintextEmail());
104
- expect(r.headers["subject"]).toBe("Hello");
105
- expect(r.headers["from"]).toBeDefined();
106
- expect(r.headers["message-id"]).toBe("<m-1@example.com>");
107
- });
108
-
109
- it("parses Date header", async () => {
110
- const r = await parseRawEmail(plaintextEmail());
111
- expect(r.date).toBeInstanceOf(Date);
112
- expect(r.date.getUTCFullYear()).toBe(2026);
113
- });
114
- });
115
-
116
- describe("parseRawEmail — multipart", () => {
117
- it("multipart/alternative yields both text + html bodies", async () => {
118
- const r = await parseRawEmail(multipartAlternative());
119
- expect(r.textBody).toContain("plain version");
120
- expect(r.htmlBody).toContain("html");
121
- expect(r.htmlBody).toContain("version");
122
- });
123
-
124
- it("multipart/mixed with attachment yields attachment metadata", async () => {
125
- const r = await parseRawEmail(multipartWithAttachment());
126
- expect(r.attachments).toHaveLength(1);
127
- const a = r.attachments[0];
128
- expect(a.filename).toBe("report.pdf");
129
- expect(a.contentType).toContain("pdf");
130
- expect(a.size).toBeGreaterThan(0);
131
- expect(a.sha256).toMatch(/^[0-9a-f]{64}$/);
132
- expect(a.contentDisposition).toBe("attachment");
133
- expect(a.isInline).toBe(false);
134
- });
135
-
136
- it("flags encrypted PDFs heuristically (/Encrypt header in body)", async () => {
137
- const r = await parseRawEmail(multipartWithAttachment({
138
- filename: "encrypted.pdf",
139
- body: "%PDF-1.4\n%fake header\n/Encrypt <<\n/V 4\n>>\n",
140
- }));
141
- expect(r.attachments[0].isEncrypted).toBe(true);
142
- });
143
-
144
- it("doesn't flag plaintext PDFs as encrypted", async () => {
145
- const r = await parseRawEmail(multipartWithAttachment({
146
- body: "%PDF-1.4\nplain content no encrypt token\n",
147
- }));
148
- expect(r.attachments[0].isEncrypted).toBe(false);
149
- });
150
-
151
- it("attachment buffer is omitted by default", async () => {
152
- const r = await parseRawEmail(multipartWithAttachment());
153
- expect(r.attachments[0].buffer).toBeUndefined();
154
- });
155
-
156
- it("keepAttachmentBuffers:true attaches the decoded buffer", async () => {
157
- const r = await parseRawEmail(multipartWithAttachment(), { keepAttachmentBuffers: true });
158
- expect(Buffer.isBuffer(r.attachments[0].buffer)).toBe(true);
159
- expect(r.attachments[0].buffer.toString()).toContain("%PDF-1.4");
160
- });
161
- });
162
-
163
- describe("parseRawEmail — encoding handling", () => {
164
- it("decodes UTF-8 body correctly", async () => {
165
- const utf8Body = "妈妈生日蛋白粉 ¥288.50";
166
- const r = await parseRawEmail(plaintextEmail({ body: utf8Body }));
167
- expect(r.textBody).toContain("妈妈生日蛋白粉");
168
- expect(r.textBody).toContain("¥288.50");
169
- });
170
-
171
- it("decodes GBK-encoded body (via Content-Type charset)", async () => {
172
- // Build raw bytes: header in UTF-8, body in GBK.
173
- const headerAscii =
174
- `From: sender@example.com\r\n` +
175
- `To: me@example.com\r\n` +
176
- `Subject: 中文\r\n` +
177
- `MIME-Version: 1.0\r\n` +
178
- `Content-Type: text/plain; charset=GBK\r\n\r\n`;
179
- // GBK bytes for "妈妈生日": dc e8 dc e8 c9 fa c8 d5
180
- const gbkBody = Buffer.from([0xc2, 0xe8, 0xc2, 0xe8, 0xc9, 0xfa, 0xc8, 0xd5]);
181
- const raw = Buffer.concat([Buffer.from(headerAscii, "ascii"), gbkBody]);
182
- const r = await parseRawEmail(raw);
183
- // mailparser+iconv-lite converts GBK to UTF-8. We can't assert exact
184
- // unicode without locking in iconv tables, but we can verify the
185
- // body is non-empty + got past the GBK byte sequence (which is
186
- // invalid UTF-8 — would error if left as raw).
187
- expect(r.textBody.length).toBeGreaterThan(0);
188
- expect(r.headers["content-type"]).toBeDefined();
189
- });
190
-
191
- it("RFC 2047 encoded subject is decoded", async () => {
192
- const raw = [
193
- `From: alice@example.com`,
194
- `To: me@example.com`,
195
- // =?UTF-8?B?5aaI5aaIc/eIuOWlh+aBpQ==?= (just a sample base64)
196
- `Subject: =?UTF-8?B?5aaI5aaI?=`,
197
- `Date: Fri, 19 May 2026 10:00:00 +0800`,
198
- `Message-ID: <m@x>`,
199
- `Content-Type: text/plain; charset=utf-8`,
200
- ``,
201
- `body`,
202
- ].join("\r\n");
203
- const r = await parseRawEmail(raw);
204
- expect(r.subject).toBe("妈妈");
205
- });
206
- });
207
-
208
- describe("parseRawEmail — truncation + edge cases", () => {
209
- it("truncates bodies longer than maxBodyChars", async () => {
210
- const longBody = "X".repeat(500_000);
211
- const r = await parseRawEmail(plaintextEmail({ body: longBody }), { maxBodyChars: 1000 });
212
- expect(r.textBody.length).toBeLessThan(longBody.length);
213
- expect(r.textBody).toMatch(/truncated/);
214
- });
215
-
216
- it("returns empty bodies for emails with no payload", async () => {
217
- const raw = [
218
- `From: x@x.com`,
219
- `To: y@y.com`,
220
- `Subject: empty`,
221
- `Date: Fri, 19 May 2026 10:00:00 +0800`,
222
- `Message-ID: <m@x>`,
223
- ``,
224
- ``,
225
- ].join("\r\n");
226
- const r = await parseRawEmail(raw);
227
- expect(r.textBody).toBe("");
228
- expect(r.htmlBody).toBe("");
229
- expect(r.attachments).toEqual([]);
230
- });
231
-
232
- it("contentSha256 is deterministic for identical input", async () => {
233
- const raw = plaintextEmail();
234
- const r1 = await parseRawEmail(raw);
235
- const r2 = await parseRawEmail(raw);
236
- expect(r1.contentSha256).toBe(r2.contentSha256);
237
- });
238
-
239
- it("contentSha256 differs across different inputs", async () => {
240
- const r1 = await parseRawEmail(plaintextEmail({ body: "v1" }));
241
- const r2 = await parseRawEmail(plaintextEmail({ body: "v2" }));
242
- expect(r1.contentSha256).not.toBe(r2.contentSha256);
243
- });
244
- });