@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,289 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
-
9
- const {
10
- WhatsAppAdapter,
11
- NAME,
12
- VERSION,
13
- } = require("../../lib/adapters/messaging-whatsapp");
14
-
15
- function writeTmpDb() {
16
- const p = path.join(
17
- os.tmpdir(),
18
- `cc-whatsapp-test-${crypto.randomUUID()}.db`,
19
- );
20
- fs.writeFileSync(p, "fake");
21
- return p;
22
- }
23
-
24
- async function collect(gen) {
25
- const out = [];
26
- for await (const x of gen) out.push(x);
27
- return out;
28
- }
29
-
30
- function makeFakeDriverFactory(tables, log = {}) {
31
- return () =>
32
- class FakeDb {
33
- constructor(dbPath, opts) {
34
- log.opened = { dbPath, opts };
35
- }
36
- prepare(sql) {
37
- for (const [needle, rows] of Object.entries(tables)) {
38
- if (sql.includes(needle)) return { all: () => rows };
39
- }
40
- throw new Error(`no such table in: ${sql}`);
41
- }
42
- close() {
43
- log.closed = true;
44
- }
45
- };
46
- }
47
-
48
- describe("constants", () => {
49
- it("exposes name/version + high sensitivity & legal gate", () => {
50
- expect(NAME).toBe("messaging-whatsapp");
51
- expect(VERSION).toBe("0.6.0");
52
- const a = new WhatsAppAdapter();
53
- expect(a.dataDisclosure.sensitivity).toBe("high");
54
- expect(a.dataDisclosure.legalGate).toBe(true);
55
- });
56
- });
57
-
58
- describe("authenticate", () => {
59
- it("fails DB_NOT_PULLED without a real db file", async () => {
60
- const a = new WhatsAppAdapter();
61
- const r = await a.authenticate({});
62
- expect(r.ok).toBe(false);
63
- expect(r.reason).toBe("DB_NOT_PULLED");
64
- });
65
-
66
- it("ok when dbPath exists (inputPath alias too)", async () => {
67
- const p = writeTmpDb();
68
- try {
69
- const a = new WhatsAppAdapter({ account: { phone: "8613800138000" } });
70
- expect(await a.authenticate({ inputPath: p })).toEqual({
71
- ok: true,
72
- account: "8613800138000",
73
- mode: "snapshot-file",
74
- });
75
- } finally {
76
- fs.unlinkSync(p);
77
- }
78
- });
79
- });
80
-
81
- describe("sync — fake sqlite driver", () => {
82
- const JID_ROW = {
83
- _id: 1,
84
- user: "8613800138000",
85
- raw_string: "8613800138000@s.whatsapp.net",
86
- display_name: "Alice",
87
- };
88
- const CHAT_ROW = { _id: 2, subject: "Family group" };
89
- const MSG_ROW = {
90
- _id: 3,
91
- key_remote_jid: "8613800138000@s.whatsapp.net",
92
- from_me: 1,
93
- text_data: "hello",
94
- timestamp: 1716383021, // seconds
95
- };
96
- const CALL_ROW = {
97
- _id: 4,
98
- jid_row_id: 1,
99
- from_me: 0,
100
- video_call: 1,
101
- duration: 65,
102
- timestamp: 1716383021000,
103
- };
104
-
105
- it("yields contact/chat/message/call rows with kind tags, closes db", async () => {
106
- const p = writeTmpDb();
107
- const log = {};
108
- try {
109
- const a = new WhatsAppAdapter({
110
- dbPath: p,
111
- dbDriverFactory: makeFakeDriverFactory(
112
- {
113
- "FROM jid": [JID_ROW],
114
- "FROM chat": [CHAT_ROW],
115
- "FROM message ": [MSG_ROW],
116
- "FROM call_log": [CALL_ROW],
117
- },
118
- log,
119
- ),
120
- });
121
- const items = await collect(a.sync({}));
122
- expect(items.map((i) => i.originalId)).toEqual([
123
- "jid-1",
124
- "chat-2",
125
- "msg-3",
126
- "call-4",
127
- ]);
128
- expect(items.map((i) => i.payload.kind)).toEqual([
129
- "contact",
130
- "chat",
131
- "message",
132
- "call",
133
- ]);
134
- // message timestamp seconds → ms
135
- expect(items[2].capturedAt).toBe(1716383021 * 1000);
136
- expect(log.opened.opts).toEqual({ readonly: true });
137
- expect(log.closed).toBe(true);
138
- } finally {
139
- fs.unlinkSync(p);
140
- }
141
- });
142
-
143
- it("falls back to legacy `messages` table when `message` missing", async () => {
144
- const p = writeTmpDb();
145
- try {
146
- const a = new WhatsAppAdapter({
147
- dbPath: p,
148
- dbDriverFactory: makeFakeDriverFactory({
149
- "FROM jid": [],
150
- "FROM chat": [],
151
- "FROM messages ": [MSG_ROW],
152
- "FROM call_log": [],
153
- }),
154
- });
155
- const items = await collect(a.sync({}));
156
- expect(items).toHaveLength(1);
157
- expect(items[0].payload.kind).toBe("message");
158
- } finally {
159
- fs.unlinkSync(p);
160
- }
161
- });
162
-
163
- it("returns silently when db file missing", async () => {
164
- const a = new WhatsAppAdapter({
165
- dbPath: path.join(os.tmpdir(), "nonexistent-wa.db"),
166
- dbDriverFactory: makeFakeDriverFactory({}),
167
- });
168
- expect(await collect(a.sync({}))).toEqual([]);
169
- });
170
- });
171
-
172
- describe("normalize", () => {
173
- const a = new WhatsAppAdapter();
174
-
175
- it("personal jid → contact person with digits-only phone identifier", () => {
176
- const batch = a.normalize({
177
- originalId: "jid-1",
178
- payload: {
179
- kind: "contact",
180
- row: {
181
- _id: 1,
182
- user: "+86 138-0013-8000",
183
- raw_string: "8613800138000@s.whatsapp.net",
184
- display_name: "Alice",
185
- },
186
- },
187
- });
188
- const person = batch.persons[0];
189
- expect(person.subtype).toBe("contact");
190
- expect(person.names).toEqual(["Alice", "+86 138-0013-8000"]);
191
- expect(person.identifiers).toEqual({ phone: ["8613800138000"] });
192
- expect(batch.topics).toEqual([]);
193
- });
194
-
195
- it("group jid (@g.us) → topic, not person", () => {
196
- const batch = a.normalize({
197
- originalId: "jid-9",
198
- payload: {
199
- kind: "contact",
200
- row: {
201
- _id: 9,
202
- raw_string: "1234-5678@g.us",
203
- display_name: "Family group",
204
- },
205
- },
206
- });
207
- expect(batch.persons).toEqual([]);
208
- expect(batch.topics[0]).toMatchObject({
209
- id: "topic-whatsapp-1234-5678@g.us",
210
- name: "Family group",
211
- });
212
- });
213
-
214
- it("chat row → topic named by subject", () => {
215
- const batch = a.normalize({
216
- originalId: "chat-2",
217
- payload: { kind: "chat", row: { _id: 2, subject: "Work chat" } },
218
- });
219
- expect(batch.topics[0]).toMatchObject({
220
- id: "topic-whatsapp-chat-2",
221
- name: "Work chat",
222
- });
223
- });
224
-
225
- it("outgoing message → message event from person-self, title truncated to 80", () => {
226
- const longText = "x".repeat(200);
227
- const batch = a.normalize({
228
- originalId: "msg-3",
229
- payload: {
230
- kind: "message",
231
- row: {
232
- _id: 3,
233
- key_remote_jid: "8613800138000@s.whatsapp.net",
234
- from_me: 1,
235
- text_data: longText,
236
- timestamp: 1716383021000,
237
- },
238
- },
239
- });
240
- const ev = batch.events[0];
241
- expect(ev.subtype).toBe("message");
242
- expect(ev.actor).toBe("person-self");
243
- expect(ev.occurredAt).toBe(1716383021000);
244
- expect(ev.content.title).toHaveLength(80);
245
- expect(ev.content.text).toHaveLength(200);
246
- expect(ev.extra.isOutgoing).toBe(true);
247
- });
248
-
249
- it("incoming empty message → '(空)' title, actor from jid", () => {
250
- const batch = a.normalize({
251
- originalId: "msg-4",
252
- payload: {
253
- kind: "message",
254
- row: {
255
- _id: 4,
256
- key_remote_jid: "86139@s.whatsapp.net",
257
- from_me: 0,
258
- timestamp: 1716383021000,
259
- },
260
- },
261
- });
262
- const ev = batch.events[0];
263
- expect(ev.content.title).toBe("(空)");
264
- expect(ev.actor).toBe("person-whatsapp-86139@s.whatsapp.net");
265
- expect(ev.extra.isOutgoing).toBe(false);
266
- });
267
-
268
- it("incoming video call → call event with duration/isVideo extras", () => {
269
- const batch = a.normalize({
270
- originalId: "call-5",
271
- payload: {
272
- kind: "call",
273
- row: {
274
- _id: 5,
275
- jid_row_id: 1,
276
- from_me: 0,
277
- video_call: 1,
278
- duration: 65,
279
- timestamp: 1716383021000,
280
- },
281
- },
282
- });
283
- const ev = batch.events[0];
284
- expect(ev.subtype).toBe("call");
285
- expect(ev.content.title).toBe("WhatsApp call (video)");
286
- expect(ev.actor).toBe("person-whatsapp-1");
287
- expect(ev.extra).toMatchObject({ duration: 65, isVideo: true, fromMe: false });
288
- });
289
- });
@@ -1,187 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
-
9
- const {
10
- KugouMusicAdapter,
11
- extractList,
12
- songItemToRecord,
13
- playlistItemToRecord,
14
- NAME,
15
- VERSION,
16
- SNAPSHOT_SCHEMA_VERSION,
17
- } = require("../../lib/adapters/music-kugou");
18
-
19
- function writeTmp(content) {
20
- const p = path.join(os.tmpdir(), `cc-kg-${crypto.randomUUID()}.json`);
21
- fs.writeFileSync(p, content, "utf-8");
22
- return p;
23
- }
24
- async function collect(gen) {
25
- const out = [];
26
- for await (const x of gen) out.push(x);
27
- return out;
28
- }
29
-
30
- const COOKIES = "KuGoo=abc; kg_mid=xyz";
31
-
32
- const SNAP = JSON.stringify({
33
- schemaVersion: 1,
34
- snapshottedAt: 1716383000000,
35
- account: { userId: "u1" },
36
- events: [
37
- { kind: "play", id: "p1", songId: "S1", song: "晴天", artist: "周杰伦", album: "叶惠美", playCount: 12, capturedAt: 1716300000000 },
38
- { kind: "favorite", id: "f1", songId: "S2", song: "稻香", artist: "周杰伦" },
39
- { kind: "playlist", id: "pl1", playlistId: "L1", name: "华语经典", trackCount: 88, creator: "我" },
40
- ],
41
- });
42
-
43
- describe("constants + item mappers", () => {
44
- it("name/version", () => {
45
- expect(NAME).toBe("music-kugou");
46
- expect(VERSION).toBe("0.1.0");
47
- expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
48
- });
49
- it("songItemToRecord: discrete fields + filename split fallback", () => {
50
- const r1 = songItemToRecord({ hash: "H1", songname: "夜曲", singername: "周杰伦", album_name: "十一月的萧邦", addtime: 1716300000 });
51
- expect(r1).toMatchObject({ id: "H1", song: "夜曲", artist: "周杰伦", album: "十一月的萧邦" });
52
- expect(r1.occurredAt).toBe(1716300000000);
53
- const r2 = songItemToRecord({ mixsongid: 9, filename: "林俊杰 - 江南" });
54
- expect(r2).toMatchObject({ song: "江南", artist: "林俊杰" });
55
- expect(songItemToRecord({ songname: "noid" })).toBe(null);
56
- });
57
- it("playlistItemToRecord", () => {
58
- const r = playlistItemToRecord({ listid: "L9", name: "睡前", count: 30, nickname: "我" });
59
- expect(r).toMatchObject({ id: "L9", playlistId: "L9", name: "睡前", trackCount: 30, creator: "我" });
60
- });
61
- it("extractList tolerant", () => {
62
- expect(extractList({ list: [{ hash: 1 }] })).toHaveLength(1);
63
- expect(extractList({ data: { info: [{ hash: 1 }] } })).toHaveLength(1);
64
- expect(extractList({})).toEqual([]);
65
- });
66
- });
67
-
68
- describe("KugouMusicAdapter snapshot mode", () => {
69
- it("authenticate validates inputPath", async () => {
70
- const p = writeTmp(SNAP);
71
- try {
72
- const a = new KugouMusicAdapter();
73
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
74
- expect((await a.authenticate({ inputPath: path.join(os.tmpdir(), "no-kg.json") })).reason).toBe("INPUT_PATH_UNREADABLE");
75
- } finally {
76
- fs.unlinkSync(p);
77
- }
78
- });
79
-
80
- it("sync 3 kinds + normalize play→media+item / favorite→like / playlist→topic", async () => {
81
- const p = writeTmp(SNAP);
82
- try {
83
- const a = new KugouMusicAdapter();
84
- const items = await collect(a.sync({ inputPath: p }));
85
- expect(items.map((x) => x.kind)).toEqual(["play", "favorite", "playlist"]);
86
-
87
- const play = a.normalize(items[0]);
88
- expect(play.events[0].subtype).toBe("media");
89
- expect(play.events[0].content.title).toBe("听了: 晴天 - 周杰伦");
90
- expect(play.items[0].subtype).toBe("media");
91
- expect(play.items[0].extra.platform).toBe("kugou");
92
- expect(play.events[0].extra.itemRef).toBe(play.items[0].id);
93
-
94
- const fav = a.normalize(items[1]);
95
- expect(fav.events[0].subtype).toBe("like");
96
- expect(fav.events[0].content.title).toBe("收藏: 稻香 - 周杰伦");
97
-
98
- const pl = a.normalize(items[2]);
99
- expect(pl.topics[0].name).toBe("华语经典");
100
- expect(pl.topics[0].extra.trackCount).toBe(88);
101
- } finally {
102
- fs.unlinkSync(p);
103
- }
104
- });
105
-
106
- it("include + limit + schema mismatch + unknown kind", async () => {
107
- const p = writeTmp(SNAP);
108
- try {
109
- const a = new KugouMusicAdapter();
110
- expect((await collect(a.sync({ inputPath: p, include: { play: false, favorite: false } }))).map((x) => x.kind)).toEqual(["playlist"]);
111
- expect(await collect(a.sync({ inputPath: p, limit: 1 }))).toHaveLength(1);
112
- expect(() => a.normalize({ kind: "bogus", payload: {} })).toThrow(/unknown kind/);
113
- } finally {
114
- fs.unlinkSync(p);
115
- }
116
- const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
117
- try {
118
- const a = new KugouMusicAdapter();
119
- await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
120
- } finally {
121
- fs.unlinkSync(bad);
122
- }
123
- });
124
- });
125
-
126
- describe("KugouMusicAdapter cookie-api mode", () => {
127
- it("authenticate cookie mode (userId optional)", async () => {
128
- const a = new KugouMusicAdapter({ account: { cookies: COOKIES } });
129
- expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
130
- });
131
-
132
- it("sync fetches plays/favorites/playlists, normalizes", async () => {
133
- const byUrl = (u) => (u.includes("listen") ? "play" : u.includes("favorite") ? "favorite" : "playlist");
134
- const data = {
135
- play: [{ hash: "H1", songname: "七里香", singername: "周杰伦", addtime: 1716300000 }],
136
- favorite: [{ hash: "H2", filename: "陈奕迅 - 浮夸" }],
137
- playlist: [{ listid: "L1", name: "粤语", count: 50 }],
138
- };
139
- const calls = [];
140
- const a = new KugouMusicAdapter({
141
- account: { cookies: COOKIES, userId: "u1" },
142
- fetchFn: async ({ url, cookies, query, sign }) => {
143
- const k = byUrl(url);
144
- calls.push({ k, cookies, page: query.page, sign });
145
- return { data: { list: query.page === 1 ? data[k] : [] } };
146
- },
147
- });
148
- const items = await collect(a.sync({}));
149
- expect(items.map((x) => x.kind).sort()).toEqual(["favorite", "play", "playlist"]);
150
- expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
151
- const play = a.normalize(items.find((x) => x.kind === "play"));
152
- expect(play.events[0].content.title).toBe("听了: 七里香 - 周杰伦");
153
- const fav = a.normalize(items.find((x) => x.kind === "favorite"));
154
- expect(fav.events[0].content.title).toBe("收藏: 浮夸 - 陈奕迅"); // filename split
155
- const pl = a.normalize(items.find((x) => x.kind === "playlist"));
156
- expect(pl.topics[0].name).toBe("粤语");
157
- });
158
-
159
- it("invokes signProvider", async () => {
160
- const signCalls = [];
161
- const a = new KugouMusicAdapter({
162
- account: { cookies: COOKIES },
163
- fetchFn: async ({ query }) => ({ list: query.page === 1 ? [{ hash: "H1", songname: "x" }] : [] }),
164
- signProvider: async (ctx) => { signCalls.push(ctx); return "sig"; },
165
- });
166
- const items = await collect(a.sync({ include: { favorite: false, playlist: false } }));
167
- expect(items.length).toBeGreaterThan(0);
168
- expect(signCalls[0].cookies).toBe(COOKIES);
169
- });
170
-
171
- it("limit + empty/login + default fetch + no input", async () => {
172
- const a1 = new KugouMusicAdapter({
173
- account: { cookies: COOKIES },
174
- fetchFn: async ({ query }) => ({ list: query.page === 1 ? [{ hash: "H1", songname: "a" }, { hash: "H2", songname: "b" }] : [] }),
175
- });
176
- expect(await collect(a1.sync({ limit: 1 }))).toHaveLength(1);
177
-
178
- const a2 = new KugouMusicAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
179
- expect(await collect(a2.sync({}))).toEqual([]);
180
-
181
- const a3 = new KugouMusicAdapter({ account: { cookies: COOKIES } });
182
- await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
183
-
184
- const a4 = new KugouMusicAdapter();
185
- await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
186
- });
187
- });
@@ -1,112 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
-
9
- const qm = require("../../lib/adapters/music-qq");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-qqm-${crypto.randomUUID()}.json`);
13
- fs.writeFileSync(p, content, "utf-8");
14
- return p;
15
- }
16
- async function collect(gen) {
17
- const out = [];
18
- for await (const x of gen) out.push(x);
19
- return out;
20
- }
21
- const COOKIES = "qqmusic_key=abc; uin=123";
22
-
23
- describe("music-qq mappers", () => {
24
- it("name/version", () => {
25
- expect(qm.NAME).toBe("music-qq");
26
- expect(qm.VERSION).toBe("0.1.0");
27
- });
28
- it("flattenSinger handles array / string / object", () => {
29
- expect(qm.flattenSinger([{ name: "周杰伦" }, { name: "费玉清" }])).toBe("周杰伦/费玉清");
30
- expect(qm.flattenSinger("林俊杰")).toBe("林俊杰");
31
- expect(qm.flattenSinger({ name: "邓紫棋" })).toBe("邓紫棋");
32
- expect(qm.flattenSinger(null)).toBe("");
33
- });
34
- it("songItemToRecord (QQ fields: songmid, singer array, album.name)", () => {
35
- const r = qm.songItemToRecord({ songmid: "S1", songname: "晴天", singer: [{ name: "周杰伦" }], album: { name: "叶惠美" }, time: 1716383000 });
36
- expect(r).toMatchObject({ songId: "S1", song: "晴天", artist: "周杰伦", album: "叶惠美" });
37
- expect(r.occurredAt).toBe(1716383000000);
38
- expect(qm.songItemToRecord({ songname: "x" })).toBe(null);
39
- });
40
- it("playlistItemToRecord (dissid/dissname/songnum)", () => {
41
- const r = qm.playlistItemToRecord({ dissid: "P1", dissname: "我喜欢", songnum: 42, creator: { name: "我" } });
42
- expect(r).toMatchObject({ playlistId: "P1", name: "我喜欢", trackCount: 42, creator: "我" });
43
- expect(qm.playlistItemToRecord({ dissname: "x" })).toBe(null);
44
- });
45
- it("extractList tolerant (list / data.songlist)", () => {
46
- expect(qm.extractList({ list: [{ songmid: 1 }] })).toHaveLength(1);
47
- expect(qm.extractList({ data: { songlist: [{ songmid: 1 }] } })).toHaveLength(1);
48
- expect(qm.extractList({})).toEqual([]);
49
- });
50
- });
51
-
52
- describe("QQMusicAdapter (snapshot + cookie-api)", () => {
53
- const SNAP = JSON.stringify({
54
- schemaVersion: 1,
55
- snapshottedAt: 1716383000000,
56
- account: { userId: "u1" },
57
- events: [
58
- { kind: "play", id: "play-S1", songId: "S1", song: "晴天", artist: "周杰伦", album: "叶惠美" },
59
- { kind: "favorite", id: "fav-S2", songId: "S2", song: "稻香", artist: "周杰伦" },
60
- { kind: "playlist", id: "pl-P1", playlistId: "P1", name: "我喜欢", trackCount: 42 },
61
- ],
62
- });
63
-
64
- it("snapshot → play(MEDIA)/favorite(LIKE) events + playlist topic", async () => {
65
- const p = writeTmp(SNAP);
66
- try {
67
- const a = new qm.QQMusicAdapter();
68
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
69
- const items = await collect(a.sync({ inputPath: p }));
70
- expect(items).toHaveLength(3);
71
- const play = a.normalize(items[0]);
72
- expect(play.events[0].subtype).toBe("media");
73
- expect(play.events[0].content.title).toContain("听了: 晴天");
74
- expect(play.items[0].subtype).toBe("media");
75
- expect(play.items[0].extra.platform).toBe("qqmusic");
76
- expect(items[0].originalId).toBe("qqmusic:play:play-S1"); // snapshot uses ev.id (mirrors kugou)
77
- const fav = a.normalize(items[1]);
78
- expect(fav.events[0].subtype).toBe("like");
79
- const pl = a.normalize(items[2]);
80
- expect(pl.topics[0].name).toBe("我喜欢");
81
- expect(pl.topics[0].id).toBe("topic-qqmusic-playlist-P1");
82
- } finally {
83
- fs.unlinkSync(p);
84
- }
85
- });
86
-
87
- it("cookie-api: fetch 3 kinds + sign seam", async () => {
88
- let signed = 0;
89
- const a = new qm.QQMusicAdapter({
90
- account: { cookies: COOKIES, userId: "u1" },
91
- signProvider: async () => { signed += 1; return "sig"; },
92
- fetchFn: async ({ url, query }) => {
93
- if (query.page > 1) return { list: [] };
94
- if (url.includes("/listen")) return { list: [{ songmid: "A", songname: "歌1", singer: [{ name: "歌手" }], time: 1716383000 }] };
95
- if (url.includes("/favorite")) return { data: { songlist: [{ songmid: "B", songname: "歌2", singer: "歌手2" }] } };
96
- return { data: { list: [{ dissid: "C", dissname: "歌单", songnum: 5 }] } };
97
- },
98
- });
99
- expect(await a.authenticate()).toEqual({ ok: true, account: "u1", mode: "cookie" });
100
- const items = await collect(a.sync({}));
101
- expect(items).toHaveLength(3);
102
- expect(items.map((i) => i.originalId).sort()).toEqual(["qqmusic:favorite:B", "qqmusic:play:A", "qqmusic:playlist:C"]);
103
- expect(signed).toBeGreaterThan(0);
104
- });
105
-
106
- it("low sensitivity (consumer music); default fetch / no input throw", async () => {
107
- expect(new qm.QQMusicAdapter().dataDisclosure.sensitivity).toBe("low");
108
- expect(new qm.QQMusicAdapter().dataDisclosure.legalGate).toBe(false);
109
- await expect(collect(new qm.QQMusicAdapter({ account: { cookies: COOKIES } }).sync({}))).rejects.toThrow(/no fetchFn/);
110
- await expect(collect(new qm.QQMusicAdapter().sync({}))).rejects.toThrow(/needs opts.inputPath/);
111
- });
112
- });