@chainlesschain/personal-data-hub 0.4.29 → 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 (198) hide show
  1. package/lib/prompt-builder.js +15 -1
  2. package/package.json +4 -1
  3. package/__tests__/adapter-guide.test.js +0 -47
  4. package/__tests__/adapter-spec.test.js +0 -78
  5. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  6. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  7. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  8. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  9. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  10. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  11. package/__tests__/adapters/apple-health.test.js +0 -95
  12. package/__tests__/adapters/bank-family.test.js +0 -125
  13. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  14. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  15. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  16. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  17. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  18. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  19. package/__tests__/adapters/doc-platforms.test.js +0 -177
  20. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  21. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  22. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  23. package/__tests__/adapters/email-adapter.test.js +0 -742
  24. package/__tests__/adapters/email-classifier.test.js +0 -347
  25. package/__tests__/adapters/email-imap-session.test.js +0 -334
  26. package/__tests__/adapters/email-parser.test.js +0 -244
  27. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  28. package/__tests__/adapters/email-providers.test.js +0 -84
  29. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  30. package/__tests__/adapters/email-templates.test.js +0 -822
  31. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  32. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  33. package/__tests__/adapters/finance-dcep.test.js +0 -74
  34. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  35. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  36. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  37. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  38. package/__tests__/adapters/git-activity.test.js +0 -222
  39. package/__tests__/adapters/gov-12123.test.js +0 -103
  40. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  41. package/__tests__/adapters/gov-tax.test.js +0 -135
  42. package/__tests__/adapters/health-meiyou.test.js +0 -125
  43. package/__tests__/adapters/local-files.test.js +0 -264
  44. package/__tests__/adapters/local-im-pc.test.js +0 -154
  45. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  46. package/__tests__/adapters/music-kugou.test.js +0 -187
  47. package/__tests__/adapters/music-qq.test.js +0 -112
  48. package/__tests__/adapters/netease-music-live.test.js +0 -244
  49. package/__tests__/adapters/netease-music.test.js +0 -74
  50. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  51. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  52. package/__tests__/adapters/reading-family.test.js +0 -108
  53. package/__tests__/adapters/recruit-boss.test.js +0 -180
  54. package/__tests__/adapters/shell-history.test.js +0 -180
  55. package/__tests__/adapters/shopping-base.test.js +0 -179
  56. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  57. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  58. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  59. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  60. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  61. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  62. package/__tests__/adapters/social-csdn.test.js +0 -175
  63. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  64. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  65. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  66. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  67. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  68. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  69. package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
  70. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
  71. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  72. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  73. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  74. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  75. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  76. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  77. package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
  78. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  79. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  80. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  81. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  82. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  83. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  84. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  85. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  86. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  87. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  88. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  89. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  90. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  91. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  92. package/__tests__/adapters/social-zhihu.test.js +0 -246
  93. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  94. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  95. package/__tests__/adapters/system-data-android.test.js +0 -519
  96. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  97. package/__tests__/adapters/travel-12306.test.js +0 -512
  98. package/__tests__/adapters/travel-amap.test.js +0 -219
  99. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  100. package/__tests__/adapters/travel-base.test.js +0 -205
  101. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  102. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  103. package/__tests__/adapters/travel-didi.test.js +0 -204
  104. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  105. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  106. package/__tests__/adapters/video-platforms.test.js +0 -152
  107. package/__tests__/adapters/video-xigua.test.js +0 -106
  108. package/__tests__/adapters/vscode.test.js +0 -299
  109. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  110. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  111. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  112. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  113. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  114. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  115. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  116. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  117. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  118. package/__tests__/adapters/weread.test.js +0 -123
  119. package/__tests__/adapters/wework-pc.test.js +0 -124
  120. package/__tests__/adapters/win-recent.test.js +0 -192
  121. package/__tests__/analysis-skills.test.js +0 -754
  122. package/__tests__/analysis.test.js +0 -1845
  123. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  124. package/__tests__/batch.test.js +0 -133
  125. package/__tests__/bridges-cc-kg.test.js +0 -231
  126. package/__tests__/bridges-cc-llm.test.js +0 -191
  127. package/__tests__/bridges-cc-rag.test.js +0 -162
  128. package/__tests__/categories.test.js +0 -92
  129. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  130. package/__tests__/e2e/full-user-journey.test.js +0 -188
  131. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  132. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  133. package/__tests__/entity-resolver-stages.test.js +0 -411
  134. package/__tests__/entity-resolver-vault.test.js +0 -249
  135. package/__tests__/entity-resolver.test.js +0 -526
  136. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  137. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  138. package/__tests__/ids.test.js +0 -45
  139. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  140. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  141. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  142. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  143. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  144. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  145. package/__tests__/key-providers.test.js +0 -126
  146. package/__tests__/kg-derive.test.js +0 -219
  147. package/__tests__/llm-client.test.js +0 -122
  148. package/__tests__/longtail-adapters.test.js +0 -281
  149. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  150. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  151. package/__tests__/mobile-extractor.test.js +0 -288
  152. package/__tests__/mock-adapter.test.js +0 -93
  153. package/__tests__/prompt-builder.test.js +0 -249
  154. package/__tests__/query-parser.test.js +0 -365
  155. package/__tests__/rag-derive.test.js +0 -169
  156. package/__tests__/registry-readiness.test.js +0 -292
  157. package/__tests__/registry.test.js +0 -420
  158. package/__tests__/salvage-ingest.test.js +0 -97
  159. package/__tests__/schemas.test.js +0 -331
  160. package/__tests__/shopping-adapters.test.js +0 -392
  161. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  162. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  163. package/__tests__/shopping-snapshot.test.js +0 -438
  164. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  165. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  166. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  167. package/__tests__/sidecar-supervisor.test.js +0 -128
  168. package/__tests__/sign-providers.test.js +0 -62
  169. package/__tests__/social-adapters.test.js +0 -280
  170. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  171. package/__tests__/social-douban-snapshot.test.js +0 -351
  172. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  173. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  174. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  175. package/__tests__/social-douyin-snapshot.test.js +0 -256
  176. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  177. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  178. package/__tests__/social-weibo-snapshot.test.js +0 -234
  179. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  180. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  181. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  182. package/__tests__/travel-adapters.test.js +0 -483
  183. package/__tests__/travel-maps-snapshot.test.js +0 -426
  184. package/__tests__/vault-driver-error.test.js +0 -74
  185. package/__tests__/vault-search-helpers.test.js +0 -104
  186. package/__tests__/vault-search.test.js +0 -423
  187. package/__tests__/vault.test.js +0 -767
  188. package/__tests__/wechat-adapter.test.js +0 -594
  189. package/__tests__/whatsapp-adapter.test.js +0 -138
  190. package/scripts/_make-fixture-all.js +0 -126
  191. package/scripts/_make-fixture-contacts.js +0 -84
  192. package/scripts/evaluate-entity-resolver.js +0 -213
  193. package/scripts/run-native-tests-sandbox.sh +0 -55
  194. package/scripts/smoke-phase-5-5.js +0 -196
  195. package/scripts/smoke-phase-5-7.js +0 -181
  196. package/scripts/smoke-system-data-contacts.js +0 -309
  197. package/scripts/smoke-system-data.js +0 -312
  198. package/vitest.config.js +0 -88
@@ -1,101 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const {
6
- WeChatKeyProvider,
7
- WeChatMD5KeyProvider,
8
- } = require("../../lib/adapters/wechat");
9
-
10
- describe("WeChatKeyProvider — base contract", () => {
11
- it("getKey throws on bare base instance (subclass must override)", async () => {
12
- const base = new WeChatKeyProvider();
13
- await expect(base.getKey()).rejects.toThrow(/must be overridden/);
14
- });
15
-
16
- it("name defaults to key-provider-base", () => {
17
- const base = new WeChatKeyProvider();
18
- expect(base.name).toBe("key-provider-base");
19
- });
20
- });
21
-
22
- describe("WeChatMD5KeyProvider — construction validation", () => {
23
- it("throws if opts missing", () => {
24
- expect(() => new WeChatMD5KeyProvider()).toThrow(/wechatDataPath/);
25
- });
26
-
27
- it("throws if wechatDataPath missing", () => {
28
- expect(() => new WeChatMD5KeyProvider({ uin: "1" })).toThrow(/wechatDataPath/);
29
- });
30
-
31
- it("name returns md5", () => {
32
- const p = new WeChatMD5KeyProvider({ wechatDataPath: "/tmp/wx" });
33
- expect(p.name).toBe("md5");
34
- });
35
- });
36
-
37
- describe("WeChatMD5KeyProvider — extractor DI happy path", () => {
38
- it("getKey returns hex when extractor yields key", async () => {
39
- const extractor = (opts) => {
40
- expect(opts.wechatDataPath).toBe("/tmp/wx");
41
- return {
42
- uin: "100200300",
43
- imei: "350123456789012",
44
- key: "abcdef1",
45
- source: "test",
46
- warnings: [],
47
- };
48
- };
49
- const p = new WeChatMD5KeyProvider({
50
- wechatDataPath: "/tmp/wx",
51
- extractor,
52
- });
53
- const key = await p.getKey();
54
- expect(key).toBe("abcdef1");
55
- expect(p.getLastResult().uin).toBe("100200300");
56
- expect(p.getLastResult().imei).toBe("350123456789012");
57
- });
58
-
59
- it("getKey passes uin/imei overrides through to extractor", async () => {
60
- let passedOpts = null;
61
- const extractor = (opts) => {
62
- passedOpts = opts;
63
- return { key: "0000000", uin: opts.uin, imei: opts.imei, warnings: [] };
64
- };
65
- const p = new WeChatMD5KeyProvider({
66
- wechatDataPath: "/tmp/wx",
67
- uin: "999",
68
- imei: "deadbeef",
69
- extractor,
70
- });
71
- await p.getKey();
72
- expect(passedOpts.uin).toBe("999");
73
- expect(passedOpts.imei).toBe("deadbeef");
74
- });
75
- });
76
-
77
- describe("WeChatMD5KeyProvider — extractor failure surfaces as throw", () => {
78
- it("throws with warnings when extractor returns no key", async () => {
79
- const extractor = () => ({
80
- uin: null,
81
- imei: null,
82
- key: null,
83
- source: "missing",
84
- warnings: ["UIN not found in shared_prefs", "IMEI not found in CompatibleInfo.cfg"],
85
- });
86
- const p = new WeChatMD5KeyProvider({
87
- wechatDataPath: "/tmp/empty",
88
- extractor,
89
- });
90
- await expect(p.getKey()).rejects.toThrow(/UIN not found/);
91
- });
92
-
93
- it("throws with generic reason when warnings empty", async () => {
94
- const extractor = () => ({ key: null, warnings: [] });
95
- const p = new WeChatMD5KeyProvider({
96
- wechatDataPath: "/tmp/empty",
97
- extractor,
98
- });
99
- await expect(p.getKey()).rejects.toThrow(/extraction returned empty/);
100
- });
101
- });
@@ -1,365 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { WeChatPcAdapter } = require("../../lib/adapters/wechat-pc");
6
- const { partitionBatch } = require("../../lib/batch");
7
-
8
- /**
9
- * WeChat **PC desktop** local-direct-read (本地直读样板, ported from Douyin).
10
- *
11
- * No native SQLite: a fake Database driver is injected via
12
- * `_deps.dbDriverFactory` (pc-db-reader accepts it as `_databaseClass`).
13
- * Covers the message/contact normalize + the MSG / Contact table read +
14
- * group-message sender-prefix parsing + key-vs-plaintext routing.
15
- */
16
-
17
- // Fake better-sqlite3-style driver answering pc-db-reader's PRAGMA + SELECTs.
18
- function makeFakeDb(spec) {
19
- class FakeStmt {
20
- constructor(sql) {
21
- this.sql = sql;
22
- }
23
- all() {
24
- const s = this.sql;
25
- if (/PRAGMA table_info\(MSG\)/.test(s)) return spec.msgCols || [];
26
- if (/FROM MSG/.test(s)) return spec.msgRows || [];
27
- if (/PRAGMA table_info\(Contact\)/.test(s)) return spec.contactCols || [];
28
- if (/FROM Contact/.test(s)) return spec.contactRows || [];
29
- return [];
30
- }
31
- get() {
32
- return { n: 1 }; // sqlite_master probe
33
- }
34
- }
35
- return class FakeDb {
36
- // eslint-disable-next-line no-unused-vars
37
- constructor(_path, _opts) {}
38
- prepare(sql) {
39
- return new FakeStmt(sql);
40
- }
41
- pragma() {}
42
- exec() {}
43
- close() {}
44
- };
45
- }
46
-
47
- const MSG_SPEC = {
48
- msgCols: [
49
- { name: "MsgSvrID" },
50
- { name: "StrTalker" },
51
- { name: "IsSender" },
52
- { name: "CreateTime" },
53
- { name: "Type" },
54
- { name: "StrContent" },
55
- ],
56
- msgRows: [
57
- { msgSvrId: "700001", talker: "wxid_bob", isSend: 0, createTime: 1700000000, type: 1, content: "你好啊" },
58
- { msgSvrId: "700002", talker: "wxid_bob", isSend: 1, createTime: 1700000010, type: 1, content: "在的" },
59
- { msgSvrId: "700003", talker: "room1@chatroom", isSend: 0, createTime: 1700000020, type: 1, content: "wxid_carol:\n大家好" },
60
- ],
61
- };
62
-
63
- const CONTACT_SPEC = {
64
- contactCols: [
65
- { name: "UserName" },
66
- { name: "Alias" },
67
- { name: "NickName" },
68
- { name: "Remark" },
69
- { name: "Type" },
70
- ],
71
- contactRows: [
72
- { wxid: "wxid_bob", alias: "bob123", nickname: "Bob", remark: "老鲍", type: 3 },
73
- { wxid: "gh_official01", alias: null, nickname: "某公众号", remark: null, type: 3 },
74
- { wxid: "room1@chatroom", alias: null, nickname: "群", remark: null, type: 2 }, // filtered
75
- ],
76
- };
77
-
78
- function freshAdapter(spec, { fsOverride } = {}) {
79
- const a = new WeChatPcAdapter({ dbPath: "/fake/MSG0.db" });
80
- a._deps.fs = fsOverride || { existsSync: () => true, accessSync: () => {}, constants: { R_OK: 4 } };
81
- a._deps.dbDriverFactory = () => makeFakeDb(spec);
82
- return a;
83
- }
84
-
85
- async function collect(iter) {
86
- const out = [];
87
- for await (const r of iter) out.push(r);
88
- return out;
89
- }
90
-
91
- describe("WeChatPcAdapter — readiness + construction", () => {
92
- // Synthetic "nothing installed" filesystem so auto-discovery is
93
- // deterministic regardless of what's on the host running the tests.
94
- const EMPTY_FS = {
95
- existsSync: () => false,
96
- readdirSync: () => [],
97
- statSync: () => ({ size: 0 }),
98
- constants: { R_OK: 4 },
99
- };
100
-
101
- it("constructs no-arg and reports APP_NOT_INSTALLED when nothing is discoverable", async () => {
102
- const a = new WeChatPcAdapter();
103
- a._deps.discoveryDeps = { fs: EMPTY_FS, home: "/no-home", env: {} };
104
- expect(a.name).toBe("wechat-pc");
105
- expect(a.extractMode).toBe("device-pull");
106
- expect(a.dataDisclosure.legalGate).toBe(true);
107
- const r = await a.authenticate({ readinessOnly: true });
108
- expect(r.ok).toBe(false);
109
- expect(r.reason).toBe("APP_NOT_INSTALLED");
110
- });
111
-
112
- it("auto-discovers an installed WeChat 4.x DB → DB_FOUND_NEEDS_KEY", async () => {
113
- // Minimal synthetic 4.x layout: ~/Documents/xwechat_files/<wxid>_N/db_storage/message/message_0.db
114
- const dirs = {
115
- "/h/Documents/xwechat_files": [{ name: "wxid_abc_1", isDirectory: () => true, isFile: () => false }],
116
- "/h/Documents/xwechat_files/wxid_abc_1/db_storage/message": [
117
- { name: "message_0.db", isDirectory: () => false, isFile: () => true },
118
- ],
119
- };
120
- const exist = new Set([
121
- "/h/Documents/xwechat_files",
122
- "/h/Documents/xwechat_files/wxid_abc_1/db_storage",
123
- "/h/Documents/xwechat_files/wxid_abc_1/db_storage/contact/contact.db",
124
- ]);
125
- const fakeFs = {
126
- existsSync: (p) => exist.has(p.replace(/\\/g, "/")),
127
- readdirSync: (p) => dirs[p.replace(/\\/g, "/")] || [],
128
- statSync: () => ({ size: 1234 }),
129
- constants: { R_OK: 4 },
130
- };
131
- const a = new WeChatPcAdapter();
132
- a._deps.discoveryDeps = { fs: fakeFs, home: "/h", env: {}, path: require("node:path").posix };
133
- const r = await a.authenticate({ readinessOnly: true });
134
- expect(r.ok).toBe(false);
135
- expect(r.reason).toBe("DB_FOUND_NEEDS_KEY");
136
- expect(r.discovered.installed).toBe(true);
137
- expect(r.discovered.primaryDb).toContain("message_0.db");
138
- });
139
-
140
- it("readinessOnly with a configured dbPath reports configured (no DB open)", async () => {
141
- const a = new WeChatPcAdapter({ dbPath: "/some/MSG0.db" });
142
- const r = await a.authenticate({ readinessOnly: true });
143
- expect(r.ok).toBe(true);
144
- expect(r.mode).toBe("configured");
145
- });
146
- });
147
-
148
- describe("WeChatPcAdapter — MSG*.db messages", () => {
149
- it("reads MSG rows → message raws with stable ids", async () => {
150
- const a = freshAdapter(MSG_SPEC);
151
- const raws = await collect(a.sync({ dbPath: "/fake/MSG0.db" }));
152
- expect(raws.map((r) => r.kind)).toEqual(["message", "message", "message"]);
153
- expect(raws.map((r) => r.originalId)).toEqual([
154
- "wechat-pc:message:700001",
155
- "wechat-pc:message:700002",
156
- "wechat-pc:message:700003",
157
- ]);
158
- });
159
-
160
- it("messages normalize to valid events (+ contact persons + group topic), 0 invalid", async () => {
161
- const a = freshAdapter(MSG_SPEC);
162
- const raws = await collect(a.sync({ dbPath: "/fake/MSG0.db" }));
163
- const merged = { events: [], persons: [], places: [], items: [], topics: [] };
164
- for (const r of raws) {
165
- const n = a.normalize(r);
166
- for (const k of Object.keys(merged)) merged[k].push(...n[k]);
167
- }
168
- const { valid, invalidReasons } = partitionBatch(merged);
169
- expect(invalidReasons).toHaveLength(0);
170
- expect(valid.events).toHaveLength(3);
171
- // bob (1-on-1) + carol (group sender)
172
- const personIds = valid.persons.map((p) => p.id).sort();
173
- expect(personIds).toContain("person-wechat-wxid_bob");
174
- expect(personIds).toContain("person-wechat-wxid_carol");
175
- // the chatroom becomes a topic
176
- expect(valid.topics.map((t) => t.id)).toContain("topic-wechat-group-room1@chatroom");
177
- });
178
-
179
- it("strips the group-message sender prefix from the text", async () => {
180
- const a = freshAdapter(MSG_SPEC);
181
- const raws = await collect(a.sync({ dbPath: "/fake/MSG0.db" }));
182
- const groupRaw = raws.find((r) => r.payload.talker === "room1@chatroom");
183
- expect(groupRaw.payload.senderWxid).toBe("wxid_carol");
184
- expect(groupRaw.payload.text).toBe("大家好");
185
- const ev = a.normalize(groupRaw).events[0];
186
- expect(ev.content.text).toBe("大家好");
187
- expect(ev.extra.isGroup).toBe(true);
188
- expect(ev.actor).toBe("person-wechat-wxid_carol");
189
- });
190
-
191
- it("CreateTime (seconds) normalizes to ms", async () => {
192
- const a = freshAdapter(MSG_SPEC);
193
- const raws = await collect(a.sync({ dbPath: "/fake/MSG0.db" }));
194
- expect(raws[0].payload.createdTimeMs).toBe(1700000000000);
195
- });
196
- });
197
-
198
- describe("WeChatPcAdapter — MicroMsg.db contacts", () => {
199
- it("reads Contact rows → contact persons; skips @chatroom; gh_ → merchant", async () => {
200
- const a = freshAdapter(CONTACT_SPEC);
201
- const raws = await collect(a.sync({ dbPath: "/fake/MicroMsg.db" }));
202
- expect(raws.map((r) => r.kind)).toEqual(["contact", "contact"]); // chatroom filtered
203
- const persons = raws.map((r) => a.normalize(r).persons[0]);
204
- const bob = persons.find((p) => p.id === "person-wechat-wxid_bob");
205
- expect(bob.subtype).toBe("contact");
206
- expect(bob.names[0]).toBe("老鲍"); // remark wins
207
- expect(bob.identifiers.wechatId).toBe("wxid_bob");
208
- const gh = persons.find((p) => p.id === "person-wechat-gh_official01");
209
- expect(gh.subtype).toBe("merchant");
210
- });
211
- });
212
-
213
- describe("WeChatPcAdapter — options + edge cases", () => {
214
- it("respects include={message:false} and limit", async () => {
215
- const a = freshAdapter(MSG_SPEC);
216
- const none = await collect(a.sync({ dbPath: "/fake/MSG0.db", include: { message: false } }));
217
- expect(none).toHaveLength(0);
218
- const capped = await collect(a.sync({ dbPath: "/fake/MSG0.db", limit: 2 }));
219
- expect(capped).toHaveLength(2);
220
- });
221
-
222
- it("emits a pc-db-read progress event with the diagnostic", async () => {
223
- const a = freshAdapter(MSG_SPEC);
224
- const events = [];
225
- await collect(a.sync({ dbPath: "/fake/MSG0.db", onProgress: (e) => events.push(e) }));
226
- const parsed = events.find((e) => e.phase === "pc-db-read");
227
- expect(parsed).toBeTruthy();
228
- expect(parsed.hadMsgTable).toBe(true);
229
- expect(parsed.messageCount).toBe(3);
230
- expect(parsed.mode).toBe("plaintext"); // no key supplied
231
- });
232
-
233
- it("missing db file yields nothing (no throw)", async () => {
234
- const a = freshAdapter(MSG_SPEC, { fsOverride: { existsSync: () => false } });
235
- const raws = await collect(a.sync({ dbPath: "/nope/MSG0.db" }));
236
- expect(raws).toHaveLength(0);
237
- });
238
-
239
- it("unknown normalize kind throws", () => {
240
- const a = new WeChatPcAdapter();
241
- expect(() => a.normalize({ kind: "weird", payload: { kind: "weird" } })).toThrow(
242
- /unknown kind/,
243
- );
244
- });
245
- });
246
-
247
- describe("WeChatPcAdapter — WeChat 4.x sidecar path", () => {
248
- function fakeCollector(result) {
249
- return async (_opts) => result;
250
- }
251
-
252
- it("opts.mode='v4' routes through the injected collector and yields messages", async () => {
253
- const a = new WeChatPcAdapter({
254
- v4Collector: fakeCollector({
255
- account: "wxid_me",
256
- messageCount: 2,
257
- dbs: [{ db: "message_0.db", messageCount: 2, hmacFailures: 0 }],
258
- messages: [
259
- {
260
- conversation: "wxid_friend",
261
- sender: "wxid_friend",
262
- type: 1,
263
- createTime: 1700000002,
264
- text: "hello from 4.0",
265
- originalId: "wechat-pc:wxid_friend:1001",
266
- },
267
- {
268
- conversation: "39354004187@chatroom",
269
- sender: "wxid_other",
270
- type: 1,
271
- createTime: 1700000003,
272
- text: "group line",
273
- originalId: "wechat-pc:39354004187@chatroom:1002",
274
- },
275
- ],
276
- }),
277
- });
278
- const raws = await collect(a.sync({ mode: "v4" }));
279
- expect(raws).toHaveLength(2);
280
- expect(raws[0].originalId).toBe("wechat-pc:wxid_friend:1001");
281
- expect(raws[0].payload.text).toBe("hello from 4.0");
282
- expect(raws[0].payload.isGroup).toBe(false);
283
- // group message: peer is the chatroom, sender preserved
284
- expect(raws[1].payload.isGroup).toBe(true);
285
- expect(raws[1].payload.senderWxid).toBe("wxid_other");
286
-
287
- // normalize reuses the 3.x path → produces a valid message event
288
- const merged = { events: [], persons: [], places: [], items: [], topics: [] };
289
- for (const r of raws) {
290
- const n = a.normalize(r);
291
- for (const k of Object.keys(merged)) if (Array.isArray(n[k])) merged[k].push(...n[k]);
292
- }
293
- const { valid } = partitionBatch(merged);
294
- expect(valid.events.length).toBe(2);
295
- const texts = valid.events.map((e) => e.content && e.content.text);
296
- expect(texts).toContain("hello from 4.0");
297
- expect(texts).toContain("group line");
298
- });
299
-
300
- it("v4 self-sent message marks isSend=1 when sender == account", async () => {
301
- const a = new WeChatPcAdapter({
302
- v4Collector: fakeCollector({
303
- account: "wxid_me",
304
- messages: [
305
- { conversation: "wxid_friend", sender: "wxid_me", type: 1, createTime: 1700000004, text: "mine", originalId: "id-3" },
306
- ],
307
- }),
308
- });
309
- const raws = await collect(a.sync({ mode: "v4" }));
310
- expect(raws[0].payload.isSend).toBe(1);
311
- });
312
-
313
- it("v4 forwards limit to the sidecar collector (sidecar owns the cap)", async () => {
314
- const msgs = Array.from({ length: 5 }, (_v, i) => ({
315
- conversation: "wxid_f", sender: "wxid_f", type: 1, createTime: 1700000000 + i, text: "m" + i, originalId: "id-" + i,
316
- }));
317
- let seenLimit = null;
318
- // Collector that honors the limit, like the real Python sidecar does.
319
- const collector = async (opts) => {
320
- seenLimit = opts.limit;
321
- return { account: "wxid_me", messages: msgs.slice(0, opts.limit || msgs.length), contacts: [] };
322
- };
323
- const a = new WeChatPcAdapter({ v4Collector: collector });
324
- const raws = await collect(a.sync({ mode: "v4", limit: 3 }));
325
- expect(seenLimit).toBe(3);
326
- expect(raws.filter((r) => r.kind === "message")).toHaveLength(3);
327
- });
328
-
329
- it("v4 yields contacts from contact.db as Person entities", async () => {
330
- const a = new WeChatPcAdapter({
331
- v4Collector: fakeCollector({
332
- account: "wxid_me",
333
- messages: [
334
- { conversation: "wxid_friend", sender: "wxid_friend", type: 1, createTime: 1700000002, text: "hi", originalId: "m-1" },
335
- ],
336
- contacts: [
337
- { wxid: "wxid_friend", nickname: "昵称", remark: "备注名", alias: "alias1", type: 3 },
338
- { wxid: "12345@chatroom", nickname: "群", remark: null, alias: null, type: 2 }, // skipped (chatroom)
339
- ],
340
- }),
341
- });
342
- const raws = await collect(a.sync({ mode: "v4" }));
343
- const contactRaws = raws.filter((r) => r.kind === "contact");
344
- expect(contactRaws).toHaveLength(1); // chatroom filtered out
345
- expect(contactRaws[0].payload.wxid).toBe("wxid_friend");
346
- expect(contactRaws[0].payload.remark).toBe("备注名");
347
-
348
- // normalize → Person entity
349
- const n = a.normalize(contactRaws[0]);
350
- expect(n.persons.length).toBeGreaterThanOrEqual(1);
351
- expect(n.persons[0].identifiers.wechatId).toBe("wxid_friend");
352
- });
353
-
354
- it("v4 can opt out of contacts via include.contact=false", async () => {
355
- const a = new WeChatPcAdapter({
356
- v4Collector: fakeCollector({
357
- account: "wxid_me",
358
- messages: [],
359
- contacts: [{ wxid: "wxid_x", nickname: "n", remark: null, alias: null, type: 3 }],
360
- }),
361
- });
362
- const raws = await collect(a.sync({ mode: "v4", include: { contact: false } }));
363
- expect(raws.filter((r) => r.kind === "contact")).toHaveLength(0);
364
- });
365
- });
@@ -1,63 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { WeChatPcAdapter } = require("../../lib/adapters/wechat-pc");
6
-
7
- // Build the raw envelope shape that WeChatPcAdapter.normalize() consumes for a
8
- // group message (the sync() generator yields { kind:"message", payload, ... }).
9
- function groupMessageRaw(payload) {
10
- return {
11
- adapter: "wechat-pc",
12
- kind: "message",
13
- originalId: "orig-1",
14
- capturedAt: 1780000000000,
15
- payload: { kind: "message", ...payload },
16
- };
17
- }
18
-
19
- describe("wechat-pc — group topic naming", () => {
20
- it("uses the resolved group display name for the topic when groupName is present", () => {
21
- const adapter = new WeChatPcAdapter();
22
- const out = adapter.normalize(groupMessageRaw({
23
- talker: "45498354778@chatroom",
24
- isGroup: true,
25
- senderWxid: "wxid_friend",
26
- groupName: "家庭群",
27
- text: "晚饭吃什么",
28
- createdTimeMs: 1780000000000,
29
- }));
30
- expect(out.topics).toHaveLength(1);
31
- // Stable id keyed on the chatroom wxid (identity unchanged)...
32
- expect(out.topics[0].id).toBe("topic-wechat-group-45498354778@chatroom");
33
- // ...but the human-readable display name is used, NOT the numeric id.
34
- expect(out.topics[0].name).toBe("家庭群");
35
- });
36
-
37
- it("falls back to the raw numeric id when no group name was resolved", () => {
38
- const adapter = new WeChatPcAdapter();
39
- const out = adapter.normalize(groupMessageRaw({
40
- talker: "45498354778@chatroom",
41
- isGroup: true,
42
- senderWxid: "wxid_friend",
43
- groupName: null,
44
- text: "hi",
45
- createdTimeMs: 1780000000000,
46
- }));
47
- expect(out.topics).toHaveLength(1);
48
- expect(out.topics[0].name).toBe("45498354778");
49
- });
50
-
51
- it("blank/whitespace group name falls back to the raw id (no empty topic name)", () => {
52
- const adapter = new WeChatPcAdapter();
53
- const out = adapter.normalize(groupMessageRaw({
54
- talker: "12345@chatroom",
55
- isGroup: true,
56
- senderWxid: "wxid_x",
57
- groupName: " ",
58
- text: "hi",
59
- createdTimeMs: 1780000000000,
60
- }));
61
- expect(out.topics[0].name).toBe("12345");
62
- });
63
- });
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { collectWeChatV4, _internals } = require("../../lib/adapters/wechat-pc/v4-sidecar");
6
-
7
- // Fake SidecarSupervisor: scripted per python exe (command[0]).
8
- function makeFactory(behaviorByPython, calls) {
9
- return (command, _cwd) => {
10
- const py = command[0];
11
- calls.push(py);
12
- const behavior = behaviorByPython[py] || { throwOn: "start", error: new Error("ENOENT spawn " + py) };
13
- return {
14
- async start() {
15
- if (behavior.throwOn === "start") throw behavior.error;
16
- },
17
- async invoke(_method, _params, _opts) {
18
- if (behavior.throwOn === "invoke") throw behavior.error;
19
- return behavior.result;
20
- },
21
- async stop() {},
22
- };
23
- };
24
- }
25
-
26
- describe("collectWeChatV4 — python fallback + error routing", () => {
27
- it("falls through to the next python when the first lacks cryptography", async () => {
28
- const calls = [];
29
- const result = await collectWeChatV4({
30
- pythonExe: "python", // tried first
31
- _supervisorFactory: makeFactory(
32
- {
33
- python: { throwOn: "invoke", error: new Error("ModuleNotFoundError: No module named 'cryptography'") },
34
- python3: { throwOn: null, result: { account: "wxid_x", messages: [{ text: "ok" }] } },
35
- },
36
- calls,
37
- ),
38
- });
39
- expect(result.account).toBe("wxid_x");
40
- expect(calls[0]).toBe("python");
41
- expect(calls).toContain("python3");
42
- });
43
-
44
- it("surfaces a WeChat data error immediately (no fallback)", async () => {
45
- const calls = [];
46
- await expect(
47
- collectWeChatV4({
48
- pythonExe: "python",
49
- _supervisorFactory: makeFactory(
50
- { python: { throwOn: "invoke", error: new Error("KEY_NOT_FOUND: key not found in Weixin.exe memory") } },
51
- calls,
52
- ),
53
- }),
54
- ).rejects.toThrow(/KEY_NOT_FOUND/);
55
- expect(calls).toEqual(["python"]); // did NOT try other pythons
56
- });
57
-
58
- it("throws SIDECAR_UNAVAILABLE when no python works", async () => {
59
- const calls = [];
60
- await expect(
61
- collectWeChatV4({
62
- _supervisorFactory: makeFactory({}, calls), // all spawn-fail
63
- }),
64
- ).rejects.toThrow(/SIDECAR_UNAVAILABLE|could not run/);
65
- });
66
-
67
- it("pythonCandidates dedupes + honors explicit/env order", () => {
68
- const list = _internals.pythonCandidates("my-python");
69
- expect(list[0]).toBe("my-python");
70
- expect(new Set(list).size).toBe(list.length);
71
- });
72
- });