@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,426 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach } from "vitest";
4
-
5
- const fs = require("node:fs");
6
- const path = require("node:path");
7
- const os = require("node:os");
8
-
9
- const {
10
- BaiduMapAdapter,
11
- SNAPSHOT_SCHEMA_VERSION: BAIDU_VERSION,
12
- } = require("../lib/adapters/travel-baidu-map");
13
- const {
14
- TencentMapAdapter,
15
- SNAPSHOT_SCHEMA_VERSION: TENCENT_VERSION,
16
- } = require("../lib/adapters/travel-tencent-map");
17
- const { validateBatch } = require("../lib/batch");
18
-
19
- // §2.5b 地图三联 v0.2 — snapshot-mode tests, mirror of social-weibo-snapshot
20
- // & social-bilibili-snapshot patterns.
21
- //
22
- // Snapshot mode is in-APK Android cc reading JSON written by the
23
- // {Baidu,Tencent}MapLocalCollector (WebView cookie scrape). Sqlite/device-pull
24
- // tests remain in travel-adapters.test.js. Three kinds: favourite / search /
25
- // route — all 3 reuse normalizeTravelRecord via on-the-fly TravelRecord build.
26
-
27
- function writeSnapshot(dir, fileName, snapshot) {
28
- const p = path.join(dir, fileName);
29
- fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
30
- return p;
31
- }
32
-
33
- describe("BaiduMapAdapter snapshot mode", () => {
34
- let tmpDir;
35
- beforeEach(() => {
36
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "baidu-map-snap-"));
37
- });
38
-
39
- it("exports SNAPSHOT_SCHEMA_VERSION = 1", () => {
40
- expect(BAIDU_VERSION).toBe(1);
41
- });
42
-
43
- it("authenticate(inputPath) ok when readable + mode=snapshot-file", async () => {
44
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
45
- schemaVersion: 1,
46
- snapshottedAt: Date.now(),
47
- events: [],
48
- });
49
- const a = new BaiduMapAdapter();
50
- const res = await a.authenticate({ inputPath: p });
51
- expect(res.ok).toBe(true);
52
- expect(res.mode).toBe("snapshot-file");
53
- });
54
-
55
- it("authenticate(inputPath) fails when path unreadable", async () => {
56
- const a = new BaiduMapAdapter();
57
- const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
58
- expect(res.ok).toBe(false);
59
- expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
60
- });
61
-
62
- it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
63
- const a = new BaiduMapAdapter();
64
- const res = await a.authenticate({});
65
- expect(res.ok).toBe(false);
66
- expect(res.reason).toBe("NO_INPUT");
67
- });
68
-
69
- it("authenticate(dbPath) without account.deviceId returns NO_ACCOUNT_DEVICE_ID", async () => {
70
- const a = new BaiduMapAdapter({ dbPath: path.join(tmpDir, "fake.db") });
71
- const res = await a.authenticate({});
72
- expect(res.ok).toBe(false);
73
- expect(res.reason).toBe("NO_ACCOUNT_DEVICE_ID");
74
- });
75
-
76
- it("rejects schemaVersion mismatch", async () => {
77
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
78
- schemaVersion: 99,
79
- snapshottedAt: Date.now(),
80
- events: [],
81
- });
82
- const a = new BaiduMapAdapter();
83
- let threw = null;
84
- try {
85
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
86
- } catch (err) {
87
- threw = err;
88
- }
89
- expect(threw).toBeTruthy();
90
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
91
- });
92
-
93
- it("empty events array yields nothing (no crash)", async () => {
94
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
95
- schemaVersion: 1,
96
- snapshottedAt: Date.now(),
97
- events: [],
98
- });
99
- const a = new BaiduMapAdapter();
100
- const raws = [];
101
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
102
- expect(raws.length).toBe(0);
103
- });
104
-
105
- it("favourite + search + route round-trip normalize cleanly", async () => {
106
- const now = Date.now();
107
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
108
- schemaVersion: 1,
109
- snapshottedAt: now,
110
- vendor: "baidu-map",
111
- account: { uid: "12345", displayName: "alice" },
112
- events: [
113
- {
114
- kind: "favourite",
115
- id: "fav-R1",
116
- capturedAt: now - 1000,
117
- name: "公司",
118
- address: "厦门市象屿路 93 号",
119
- lat: 24.4781,
120
- lng: 118.0894,
121
- category: "company",
122
- },
123
- {
124
- kind: "search",
125
- id: "search-S1",
126
- capturedAt: now - 2000,
127
- query: "鼓浪屿",
128
- city: "厦门",
129
- },
130
- {
131
- kind: "route",
132
- id: "route-RT1",
133
- capturedAt: now - 3000,
134
- from: { name: "厦门北站", lat: 24.6, lng: 118.0 },
135
- to: { name: "厦门大学", lat: 24.43, lng: 118.09 },
136
- mode: "drive",
137
- },
138
- ],
139
- });
140
- const a = new BaiduMapAdapter();
141
- const raws = [];
142
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
143
- expect(raws.length).toBe(3);
144
-
145
- const kinds = raws.map((r) => r.kind);
146
- expect(kinds).toEqual(["favourite", "search", "route"]);
147
-
148
- // Each originalId namespaced under baidu-map:<kind>:<id>
149
- expect(raws[0].originalId).toMatch(/^baidu-map:favourite:/);
150
- expect(raws[1].originalId).toMatch(/^baidu-map:search:/);
151
- expect(raws[2].originalId).toMatch(/^baidu-map:route:/);
152
-
153
- // Normalize each + validate
154
- for (const raw of raws) {
155
- const batch = a.normalize(raw);
156
- expect(validateBatch(batch).valid).toBe(true);
157
- }
158
-
159
- // Favourite: visit-type trip event + 1 place (to) + carrier merchant
160
- const favBatch = a.normalize(raws[0]);
161
- expect(favBatch.events.length).toBe(1);
162
- expect(favBatch.events[0].subtype).toBe("trip");
163
- // The to-place name flows through as the trip's destination
164
- // (Place uses singular `name`; aliases array for redundant labels)
165
- const favToPlace = favBatch.places.find(
166
- (pl) => pl.name === "公司" || (pl.aliases && pl.aliases.includes("公司")),
167
- );
168
- expect(favToPlace).toBeTruthy();
169
-
170
- // Route: from/to places (2) + carrier merchant
171
- const routeBatch = a.normalize(raws[2]);
172
- expect(routeBatch.places.length).toBeGreaterThanOrEqual(2);
173
-
174
- // Carrier always "百度地图"
175
- const allBatches = raws.map((r) => a.normalize(r));
176
- const carriers = allBatches.flatMap((b) =>
177
- b.persons.filter((p) => p.names.includes("百度地图")),
178
- );
179
- expect(carriers.length).toBe(3);
180
- });
181
-
182
- it("respects per-kind include opt-out", async () => {
183
- const now = Date.now();
184
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
185
- schemaVersion: 1,
186
- snapshottedAt: now,
187
- events: [
188
- { kind: "favourite", id: "f1", capturedAt: now, name: "家", lat: 24, lng: 118 },
189
- { kind: "search", id: "s1", capturedAt: now, query: "餐厅" },
190
- { kind: "route", id: "r1", capturedAt: now, from: { name: "A" }, to: { name: "B" }, mode: "walk" },
191
- ],
192
- });
193
- const a = new BaiduMapAdapter();
194
- const raws = [];
195
- for await (const r of a.sync({ inputPath: p, include: { search: false } })) {
196
- raws.push(r);
197
- }
198
- const kinds = raws.map((r) => r.kind);
199
- expect(kinds).toEqual(["favourite", "route"]);
200
- });
201
-
202
- it("respects opts.limit", async () => {
203
- const now = Date.now();
204
- const events = Array.from({ length: 5 }, (_, i) => ({
205
- kind: "favourite",
206
- id: `f${i}`,
207
- capturedAt: now - i * 100,
208
- name: `place-${i}`,
209
- lat: 24,
210
- lng: 118,
211
- }));
212
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
213
- schemaVersion: 1,
214
- snapshottedAt: now,
215
- events,
216
- });
217
- const a = new BaiduMapAdapter();
218
- const raws = [];
219
- for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
220
- expect(raws.length).toBe(2);
221
- });
222
-
223
- it("filters out unknown kinds (forward compat)", async () => {
224
- const now = Date.now();
225
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
226
- schemaVersion: 1,
227
- snapshottedAt: now,
228
- events: [
229
- { kind: "favourite", id: "f1", capturedAt: now, name: "ok", lat: 1, lng: 2 },
230
- { kind: "future-kind", id: "x", capturedAt: now },
231
- { kind: "trip-summary", id: "ts", capturedAt: now }, // hypothetical future
232
- ],
233
- });
234
- const a = new BaiduMapAdapter();
235
- const raws = [];
236
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
237
- expect(raws.length).toBe(1);
238
- expect(raws[0].kind).toBe("favourite");
239
- });
240
-
241
- it("snapshottedAt fallback when event capturedAt missing", async () => {
242
- const ts = 1700000000000;
243
- const p = writeSnapshot(tmpDir, "travel-baidu-map.json", {
244
- schemaVersion: 1,
245
- snapshottedAt: ts,
246
- events: [
247
- { kind: "favourite", id: "f1", name: "no time", lat: 1, lng: 2 },
248
- ],
249
- });
250
- const a = new BaiduMapAdapter();
251
- const raws = [];
252
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
253
- expect(raws[0].capturedAt).toBe(ts);
254
- });
255
-
256
- it("sync() without inputPath OR dbPath throws", async () => {
257
- const a = new BaiduMapAdapter();
258
- let threw = null;
259
- try {
260
- for await (const _r of a.sync({})) { /* drain */ }
261
- } catch (err) {
262
- threw = err;
263
- }
264
- expect(threw).toBeTruthy();
265
- expect(String(threw.message)).toMatch(/needs opts.inputPath/);
266
- });
267
-
268
- it("snapshot mode does NOT require account.deviceId at construction", () => {
269
- // The whole point of snapshot mode: stateless adapter, account from snapshot
270
- expect(() => new BaiduMapAdapter()).not.toThrow();
271
- expect(() => new BaiduMapAdapter({})).not.toThrow();
272
- });
273
- });
274
-
275
- describe("TencentMapAdapter snapshot mode", () => {
276
- let tmpDir;
277
- beforeEach(() => {
278
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "tencent-map-snap-"));
279
- });
280
-
281
- it("exports SNAPSHOT_SCHEMA_VERSION = 1", () => {
282
- expect(TENCENT_VERSION).toBe(1);
283
- });
284
-
285
- it("constructor allows missing account (stateless snapshot mode)", () => {
286
- expect(() => new TencentMapAdapter()).not.toThrow();
287
- expect(() => new TencentMapAdapter({})).not.toThrow();
288
- });
289
-
290
- it("authenticate(inputPath) ok", async () => {
291
- const p = writeSnapshot(tmpDir, "travel-tencent-map.json", {
292
- schemaVersion: 1,
293
- snapshottedAt: Date.now(),
294
- events: [],
295
- });
296
- const a = new TencentMapAdapter();
297
- const res = await a.authenticate({ inputPath: p });
298
- expect(res.ok).toBe(true);
299
- expect(res.mode).toBe("snapshot-file");
300
- });
301
-
302
- it("authenticate(dbPath) without deviceId returns NO_ACCOUNT_DEVICE_ID", async () => {
303
- const a = new TencentMapAdapter({ dbPath: "/tmp/fake.db" });
304
- const res = await a.authenticate({});
305
- expect(res.ok).toBe(false);
306
- expect(res.reason).toBe("NO_ACCOUNT_DEVICE_ID");
307
- });
308
-
309
- it("rejects schemaVersion mismatch", async () => {
310
- const p = writeSnapshot(tmpDir, "travel-tencent-map.json", {
311
- schemaVersion: 99,
312
- snapshottedAt: Date.now(),
313
- events: [],
314
- });
315
- const a = new TencentMapAdapter();
316
- let threw = null;
317
- try {
318
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
319
- } catch (err) {
320
- threw = err;
321
- }
322
- expect(threw).toBeTruthy();
323
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
324
- });
325
-
326
- it("favourite + route normalize cleanly with carrier=腾讯地图", async () => {
327
- const now = Date.now();
328
- const p = writeSnapshot(tmpDir, "travel-tencent-map.json", {
329
- schemaVersion: 1,
330
- snapshottedAt: now,
331
- vendor: "tencent-map",
332
- account: { uid: "qq-12345", displayName: "alice" },
333
- events: [
334
- {
335
- kind: "favourite",
336
- id: "fav-T1",
337
- capturedAt: now - 1000,
338
- name: "公司",
339
- address: "广州市天河区珠江新城",
340
- lat: 23.12,
341
- lng: 113.32,
342
- category: "company",
343
- },
344
- {
345
- kind: "route",
346
- id: "route-T1",
347
- capturedAt: now - 2000,
348
- from: { name: "广州南站", lat: 22.99, lng: 113.27 },
349
- to: { name: "天河客运站", lat: 23.16, lng: 113.36 },
350
- mode: "transit",
351
- },
352
- ],
353
- });
354
- const a = new TencentMapAdapter();
355
- const raws = [];
356
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
357
- expect(raws.length).toBe(2);
358
-
359
- expect(raws[0].originalId).toMatch(/^tencent-map:favourite:/);
360
- expect(raws[1].originalId).toMatch(/^tencent-map:route:/);
361
-
362
- for (const raw of raws) {
363
- const batch = a.normalize(raw);
364
- expect(validateBatch(batch).valid).toBe(true);
365
- }
366
-
367
- // Carrier must be 腾讯地图 (not 百度地图 or 高德地图 — paranoid catch
368
- // copy-paste regression)
369
- const allBatches = raws.map((r) => a.normalize(r));
370
- for (const b of allBatches) {
371
- const tencentCarrier = b.persons.find((p) => p.names.includes("腾讯地图"));
372
- expect(tencentCarrier).toBeTruthy();
373
- expect(b.persons.find((p) => p.names.includes("百度地图"))).toBeFalsy();
374
- expect(b.persons.find((p) => p.names.includes("高德地图"))).toBeFalsy();
375
- }
376
-
377
- // Route mode "transit" maps to bus
378
- const routeBatch = a.normalize(raws[1]);
379
- const tripEvent = routeBatch.events[0];
380
- expect(tripEvent.extra.vehicleType).toBe("bus");
381
- });
382
-
383
- it("empty events array yields nothing", async () => {
384
- const p = writeSnapshot(tmpDir, "travel-tencent-map.json", {
385
- schemaVersion: 1,
386
- snapshottedAt: Date.now(),
387
- events: [],
388
- });
389
- const a = new TencentMapAdapter();
390
- const raws = [];
391
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
392
- expect(raws.length).toBe(0);
393
- });
394
-
395
- it("filters unknown kinds", async () => {
396
- const now = Date.now();
397
- const p = writeSnapshot(tmpDir, "travel-tencent-map.json", {
398
- schemaVersion: 1,
399
- snapshottedAt: now,
400
- events: [
401
- { kind: "favourite", id: "f1", capturedAt: now, name: "ok", lat: 1, lng: 2 },
402
- { kind: "speculative-future", id: "x", capturedAt: now },
403
- ],
404
- });
405
- const a = new TencentMapAdapter();
406
- const raws = [];
407
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
408
- expect(raws.length).toBe(1);
409
- expect(raws[0].kind).toBe("favourite");
410
- });
411
-
412
- it("snapshottedAt fallback when event capturedAt missing", async () => {
413
- const ts = 1700000000000;
414
- const p = writeSnapshot(tmpDir, "travel-tencent-map.json", {
415
- schemaVersion: 1,
416
- snapshottedAt: ts,
417
- events: [
418
- { kind: "favourite", id: "f1", name: "no time", lat: 1, lng: 2 },
419
- ],
420
- });
421
- const a = new TencentMapAdapter();
422
- const raws = [];
423
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
424
- expect(raws[0].capturedAt).toBe(ts);
425
- });
426
- });
@@ -1,74 +0,0 @@
1
- /**
2
- * Unit tests for formatDriverLoadError — the pure error-translation helper
3
- * sitting in front of `require("better-sqlite3-multiple-ciphers")`.
4
- *
5
- * Why this matters: bs3mc upstream only ships prebuilds for Node LTS ABIs
6
- * (108/115/127). Running cc / PDH on Node 23/24/25 throws a cryptic
7
- * "NODE_MODULE_VERSION X / requires NODE_MODULE_VERSION Y" stack that
8
- * buries the real fix (use Node 22 LTS). This helper translates that into
9
- * actionable Chinese guidance. See memory `node_23_native_dep_trap.md`.
10
- */
11
-
12
- "use strict";
13
-
14
- import { describe, it, expect } from "vitest";
15
-
16
- const {
17
- _internal: { formatDriverLoadError },
18
- } = require("../lib/vault");
19
-
20
- describe("formatDriverLoadError", () => {
21
- it("detects ABI mismatch and emits actionable Chinese guidance", () => {
22
- const original = new Error(
23
- "The module '\\\\?\\C:\\code\\chainlesschain\\node_modules\\better-sqlite3-multiple-ciphers\\build\\Release\\better_sqlite3.node'\n" +
24
- "was compiled against a different Node.js version using\n" +
25
- "NODE_MODULE_VERSION 140. This version of Node.js requires\n" +
26
- "NODE_MODULE_VERSION 127. Please try re-compiling or re-installing\n" +
27
- "the module (for instance, using `npm rebuild` or `npm install`).",
28
- );
29
- const wrapped = formatDriverLoadError(original, "v24.0.1");
30
- expect(wrapped.code).toBe("BS3MC_ABI_MISMATCH");
31
- expect(wrapped.cause).toBe(original);
32
- expect(wrapped.message).toMatch(/Node v24\.0\.1 has ABI 127/);
33
- expect(wrapped.message).toMatch(/bs3mc prebuild is ABI 140/);
34
- expect(wrapped.message).toMatch(/切 Node 22 LTS/);
35
- expect(wrapped.message).toMatch(/nvm install 22\.12\.0/);
36
- expect(wrapped.message).toMatch(/npm rebuild better-sqlite3-multiple-ciphers/);
37
- });
38
-
39
- it("falls back to generic message when error is not ABI-related", () => {
40
- const original = new Error("ENOENT: no such file or directory");
41
- const wrapped = formatDriverLoadError(original, "v22.12.0");
42
- expect(wrapped.code).toBeUndefined();
43
- expect(wrapped.cause).toBe(original);
44
- expect(wrapped.message).toMatch(/Failed to load better-sqlite3-multiple-ciphers/);
45
- expect(wrapped.message).toMatch(/ENOENT: no such file or directory/);
46
- });
47
-
48
- it("handles non-Error throw values (string / null)", () => {
49
- const wrapped1 = formatDriverLoadError("plain string", "v22.12.0");
50
- expect(wrapped1.message).toMatch(/Original error: plain string/);
51
-
52
- const wrapped2 = formatDriverLoadError(null, "v22.12.0");
53
- expect(wrapped2.message).toMatch(/Original error: null/);
54
- });
55
-
56
- it("uses process.versions.node when nodeVer omitted", () => {
57
- const original = new Error(
58
- "NODE_MODULE_VERSION 200. requires NODE_MODULE_VERSION 127.",
59
- );
60
- const wrapped = formatDriverLoadError(original);
61
- expect(wrapped.code).toBe("BS3MC_ABI_MISMATCH");
62
- expect(wrapped.message).toContain(process.versions.node);
63
- });
64
-
65
- it("preserves ABI numbers from the original error message in the rewritten body", () => {
66
- const original = new Error(
67
- "NODE_MODULE_VERSION 137. requires NODE_MODULE_VERSION 131.",
68
- );
69
- const wrapped = formatDriverLoadError(original, "v23.7.0");
70
- expect(wrapped.message).toContain("ABI 131");
71
- expect(wrapped.message).toContain("ABI 137");
72
- expect(wrapped.message).toContain("v23.7.0");
73
- });
74
- });
@@ -1,104 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Pure-JS unit tests for the search SQL fragment builders in vault.js.
5
- * Runs without the native bs3mc binding so it works on any Node ABI
6
- * (the integration-level tests in vault-search.test.js need a working
7
- * native binding and only run in CI).
8
- */
9
-
10
- import { describe, it, expect } from "vitest";
11
-
12
- const { _searchHelpers } = require("../lib/vault");
13
- const { _categoryToWhere, _quoteFtsQuery, FTS5_MIN_QUERY_LEN } = _searchHelpers;
14
-
15
- describe("_quoteFtsQuery", () => {
16
- it("wraps a plain string in FTS5 phrase quotes", () => {
17
- expect(_quoteFtsQuery("hello")).toBe('"hello"');
18
- });
19
-
20
- it("doubles embedded double quotes (FTS5 escape rule)", () => {
21
- expect(_quoteFtsQuery('he said "hi"')).toBe('"he said ""hi"""');
22
- });
23
-
24
- it("preserves CJK as-is", () => {
25
- expect(_quoteFtsQuery("支付宝订单")).toBe('"支付宝订单"');
26
- });
27
-
28
- it("does not interpret FTS5 operators (OR/AND/NEAR — they're inside quotes)", () => {
29
- // The whole input is wrapped in phrase quotes, so OR is literal text
30
- expect(_quoteFtsQuery("a OR b")).toBe('"a OR b"');
31
- });
32
-
33
- it("FTS5_MIN_QUERY_LEN matches trigram tokenizer requirement", () => {
34
- expect(FTS5_MIN_QUERY_LEN).toBe(3);
35
- });
36
- });
37
-
38
- describe("_categoryToWhere", () => {
39
- it("returns sql=null for empty/null category (caller skips filter)", () => {
40
- expect(_categoryToWhere(null)).toEqual({ sql: null, params: {} });
41
- expect(_categoryToWhere("")).toEqual({ sql: null, params: {} });
42
- expect(_categoryToWhere(undefined)).toEqual({ sql: null, params: {} });
43
- });
44
-
45
- it("returns '0=1' for unknown category (no rules match)", () => {
46
- const r = _categoryToWhere("not-a-real-category");
47
- expect(r.sql).toBe("0=1");
48
- expect(r.params).toEqual({});
49
- });
50
-
51
- it("translates 'chat' to wechat-exact + messaging-prefix OR", () => {
52
- const r = _categoryToWhere("chat");
53
- expect(r.sql).toMatch(/source_adapter = @cat\d/);
54
- expect(r.sql).toMatch(/source_adapter LIKE @cat\d/);
55
- expect(Object.values(r.params)).toEqual(
56
- expect.arrayContaining(["wechat", "messaging-%"])
57
- );
58
- });
59
-
60
- it("translates 'social' to a single LIKE 'social-%' condition", () => {
61
- const r = _categoryToWhere("social");
62
- expect(r.sql).toMatch(/source_adapter LIKE @cat0/);
63
- expect(r.params).toEqual({ cat0: "social-%" });
64
- });
65
-
66
- it("translates 'shopping' to shopping-% OR alipay-%", () => {
67
- const r = _categoryToWhere("shopping");
68
- const vals = Object.values(r.params).sort();
69
- expect(vals).toEqual(["alipay-%", "shopping-%"]);
70
- expect(r.sql).toMatch(/OR/);
71
- });
72
-
73
- it("translates 'system' to system-data + browser-history + local-source adapters", () => {
74
- const r = _categoryToWhere("system");
75
- // 7 rules currently map to "system" (see lib/categories.js PREFIX_RULES):
76
- // prefix wildcards: system-data*, browser-*
77
- // exact names: vscode, win-recent, git-activity, shell-history, local-files
78
- // If a future adapter joins this bucket, append it here.
79
- const vals = Object.values(r.params).sort();
80
- expect(vals).toEqual([
81
- "browser-%",
82
- "git-activity",
83
- "local-files",
84
- "shell-history",
85
- "system-data%",
86
- "vscode",
87
- "win-recent",
88
- ]);
89
- expect(r.sql).toContain("OR");
90
- });
91
-
92
- it("translates 'other' to NOT-IN-any-prefix (negation form)", () => {
93
- const r = _categoryToWhere("other");
94
- expect(r.sql).toMatch(/NOT LIKE @cat\d/);
95
- expect(r.sql).toMatch(/AND/);
96
- // Should reference every prefix rule
97
- expect(Object.keys(r.params).length).toBeGreaterThan(5);
98
- });
99
-
100
- it("supports custom param prefix to avoid collisions in compound queries", () => {
101
- const r = _categoryToWhere("social", "xx");
102
- expect(Object.keys(r.params)[0]).toMatch(/^xx/);
103
- });
104
- });