@chainlesschain/personal-data-hub 0.4.29 → 0.4.31

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 (199) hide show
  1. package/lib/forensics/qq-nt-collect.js +190 -0
  2. package/lib/prompt-builder.js +15 -1
  3. package/package.json +8 -3
  4. package/__tests__/adapter-guide.test.js +0 -47
  5. package/__tests__/adapter-spec.test.js +0 -78
  6. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  7. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  8. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  9. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  10. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  11. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  12. package/__tests__/adapters/apple-health.test.js +0 -95
  13. package/__tests__/adapters/bank-family.test.js +0 -125
  14. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  15. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  16. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  17. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  18. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  19. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  20. package/__tests__/adapters/doc-platforms.test.js +0 -177
  21. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  22. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  23. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  24. package/__tests__/adapters/email-adapter.test.js +0 -742
  25. package/__tests__/adapters/email-classifier.test.js +0 -347
  26. package/__tests__/adapters/email-imap-session.test.js +0 -334
  27. package/__tests__/adapters/email-parser.test.js +0 -244
  28. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  29. package/__tests__/adapters/email-providers.test.js +0 -84
  30. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  31. package/__tests__/adapters/email-templates.test.js +0 -822
  32. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  33. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  34. package/__tests__/adapters/finance-dcep.test.js +0 -74
  35. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  36. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  37. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  38. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  39. package/__tests__/adapters/git-activity.test.js +0 -222
  40. package/__tests__/adapters/gov-12123.test.js +0 -103
  41. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  42. package/__tests__/adapters/gov-tax.test.js +0 -135
  43. package/__tests__/adapters/health-meiyou.test.js +0 -125
  44. package/__tests__/adapters/local-files.test.js +0 -264
  45. package/__tests__/adapters/local-im-pc.test.js +0 -154
  46. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  47. package/__tests__/adapters/music-kugou.test.js +0 -187
  48. package/__tests__/adapters/music-qq.test.js +0 -112
  49. package/__tests__/adapters/netease-music-live.test.js +0 -244
  50. package/__tests__/adapters/netease-music.test.js +0 -74
  51. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  52. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  53. package/__tests__/adapters/reading-family.test.js +0 -108
  54. package/__tests__/adapters/recruit-boss.test.js +0 -180
  55. package/__tests__/adapters/shell-history.test.js +0 -180
  56. package/__tests__/adapters/shopping-base.test.js +0 -179
  57. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  58. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  59. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  60. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  61. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  62. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  63. package/__tests__/adapters/social-csdn.test.js +0 -175
  64. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  65. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  66. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  67. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  68. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  69. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  70. package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
  71. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
  72. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  73. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  74. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  75. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  76. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  77. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  78. package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
  79. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  80. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  81. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  82. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  83. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  84. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  85. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  86. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  87. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  88. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  89. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  90. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  91. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  92. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  93. package/__tests__/adapters/social-zhihu.test.js +0 -246
  94. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  95. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  96. package/__tests__/adapters/system-data-android.test.js +0 -519
  97. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  98. package/__tests__/adapters/travel-12306.test.js +0 -512
  99. package/__tests__/adapters/travel-amap.test.js +0 -219
  100. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  101. package/__tests__/adapters/travel-base.test.js +0 -205
  102. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  103. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  104. package/__tests__/adapters/travel-didi.test.js +0 -204
  105. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  106. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  107. package/__tests__/adapters/video-platforms.test.js +0 -152
  108. package/__tests__/adapters/video-xigua.test.js +0 -106
  109. package/__tests__/adapters/vscode.test.js +0 -299
  110. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  111. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  112. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  113. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  114. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  115. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  116. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  117. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  118. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  119. package/__tests__/adapters/weread.test.js +0 -123
  120. package/__tests__/adapters/wework-pc.test.js +0 -124
  121. package/__tests__/adapters/win-recent.test.js +0 -192
  122. package/__tests__/analysis-skills.test.js +0 -754
  123. package/__tests__/analysis.test.js +0 -1845
  124. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  125. package/__tests__/batch.test.js +0 -133
  126. package/__tests__/bridges-cc-kg.test.js +0 -231
  127. package/__tests__/bridges-cc-llm.test.js +0 -191
  128. package/__tests__/bridges-cc-rag.test.js +0 -162
  129. package/__tests__/categories.test.js +0 -92
  130. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  131. package/__tests__/e2e/full-user-journey.test.js +0 -188
  132. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  133. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  134. package/__tests__/entity-resolver-stages.test.js +0 -411
  135. package/__tests__/entity-resolver-vault.test.js +0 -249
  136. package/__tests__/entity-resolver.test.js +0 -526
  137. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  138. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  139. package/__tests__/ids.test.js +0 -45
  140. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  141. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  142. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  143. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  144. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  145. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  146. package/__tests__/key-providers.test.js +0 -126
  147. package/__tests__/kg-derive.test.js +0 -219
  148. package/__tests__/llm-client.test.js +0 -122
  149. package/__tests__/longtail-adapters.test.js +0 -281
  150. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  151. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  152. package/__tests__/mobile-extractor.test.js +0 -288
  153. package/__tests__/mock-adapter.test.js +0 -93
  154. package/__tests__/prompt-builder.test.js +0 -249
  155. package/__tests__/query-parser.test.js +0 -365
  156. package/__tests__/rag-derive.test.js +0 -169
  157. package/__tests__/registry-readiness.test.js +0 -292
  158. package/__tests__/registry.test.js +0 -420
  159. package/__tests__/salvage-ingest.test.js +0 -97
  160. package/__tests__/schemas.test.js +0 -331
  161. package/__tests__/shopping-adapters.test.js +0 -392
  162. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  163. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  164. package/__tests__/shopping-snapshot.test.js +0 -438
  165. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  166. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  167. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  168. package/__tests__/sidecar-supervisor.test.js +0 -128
  169. package/__tests__/sign-providers.test.js +0 -62
  170. package/__tests__/social-adapters.test.js +0 -280
  171. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  172. package/__tests__/social-douban-snapshot.test.js +0 -351
  173. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  174. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  175. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  176. package/__tests__/social-douyin-snapshot.test.js +0 -256
  177. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  178. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  179. package/__tests__/social-weibo-snapshot.test.js +0 -234
  180. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  181. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  182. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  183. package/__tests__/travel-adapters.test.js +0 -483
  184. package/__tests__/travel-maps-snapshot.test.js +0 -426
  185. package/__tests__/vault-driver-error.test.js +0 -74
  186. package/__tests__/vault-search-helpers.test.js +0 -104
  187. package/__tests__/vault-search.test.js +0 -423
  188. package/__tests__/vault.test.js +0 -767
  189. package/__tests__/wechat-adapter.test.js +0 -594
  190. package/__tests__/whatsapp-adapter.test.js +0 -138
  191. package/scripts/_make-fixture-all.js +0 -126
  192. package/scripts/_make-fixture-contacts.js +0 -84
  193. package/scripts/evaluate-entity-resolver.js +0 -213
  194. package/scripts/run-native-tests-sandbox.sh +0 -55
  195. package/scripts/smoke-phase-5-5.js +0 -196
  196. package/scripts/smoke-phase-5-7.js +0 -181
  197. package/scripts/smoke-system-data-contacts.js +0 -309
  198. package/scripts/smoke-system-data.js +0 -312
  199. 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
- });