@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,224 +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
- KeepAdapter,
11
- SNAPSHOT_SCHEMA_VERSION,
12
- VALID_SNAPSHOT_KINDS,
13
- mapWorkout,
14
- extractList,
15
- typeLabel,
16
- } = require("../lib/adapters/fitness-keep");
17
- const { assertAdapter } = require("../lib/adapter-spec");
18
- const { validateBatch } = require("../lib/batch");
19
-
20
- // Keep (健身) — mirrors fitness-joyrun but multi-type (workoutType). best-effort
21
- // scaffold; signing injected. pure-Node.
22
-
23
- function writeSnapshot(dir, snapshot) {
24
- const p = path.join(dir, "fitness-keep.json");
25
- fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
26
- return p;
27
- }
28
-
29
- describe("KeepAdapter snapshot mode", () => {
30
- let tmpDir;
31
- beforeEach(() => {
32
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "keep-snap-"));
33
- });
34
-
35
- it("exports schema constants", () => {
36
- expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
37
- expect(VALID_SNAPSHOT_KINDS).toEqual(["workout"]);
38
- });
39
-
40
- it("authenticate(inputPath) ok; authenticate() no input → NO_INPUT", async () => {
41
- const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: Date.now(), events: [] });
42
- const a = new KeepAdapter();
43
- expect((await a.authenticate({ inputPath: p })).ok).toBe(true);
44
- const r = await a.authenticate({});
45
- expect(r.ok).toBe(false);
46
- expect(r.reason).toBe("NO_INPUT");
47
- });
48
-
49
- it("rejects schemaVersion mismatch", async () => {
50
- const p = writeSnapshot(tmpDir, { schemaVersion: 9, snapshottedAt: Date.now(), events: [] });
51
- const a = new KeepAdapter();
52
- let threw = null;
53
- try {
54
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
55
- } catch (err) {
56
- threw = err;
57
- }
58
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
59
- });
60
-
61
- it("running workout → OTHER event '运动: 跑步 X km' + GPS-bearing extra", async () => {
62
- const now = Date.now();
63
- const p = writeSnapshot(tmpDir, {
64
- schemaVersion: 1, snapshottedAt: now,
65
- account: { userId: "u1" },
66
- events: [
67
- { kind: "workout", id: "w1", workoutId: "9001", type: "running", name: "晨跑",
68
- time: 1700000000, distanceMeters: 5230, durationSec: 1800, calories: 320, steps: 6400 },
69
- ],
70
- });
71
- const a = new KeepAdapter();
72
- const raws = [];
73
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
74
- expect(raws.length).toBe(1);
75
- expect(raws[0].originalId).toBe("keep:workout:9001");
76
- const batch = a.normalize(raws[0]);
77
- expect(validateBatch(batch).valid).toBe(true);
78
- expect(batch.events[0].subtype).toBe("other");
79
- expect(batch.events[0].content.title).toBe("运动: 跑步 5.23 km");
80
- expect(batch.events[0].extra.workoutType).toBe("running");
81
- expect(batch.events[0].extra.calories).toBe(320);
82
- });
83
-
84
- it("non-distance workout (yoga) → '运动: 瑜伽 N 分钟'", async () => {
85
- const now = Date.now();
86
- const p = writeSnapshot(tmpDir, {
87
- schemaVersion: 1, snapshottedAt: now,
88
- events: [
89
- { kind: "workout", id: "w2", workoutId: "9002", type: "yoga", name: "晚间瑜伽",
90
- time: now, durationSec: 1500, calories: 120 },
91
- ],
92
- });
93
- const a = new KeepAdapter();
94
- const raws = [];
95
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
96
- const batch = a.normalize(raws[0]);
97
- expect(validateBatch(batch).valid).toBe(true);
98
- expect(batch.events[0].content.title).toBe("运动: 瑜伽 25 分钟");
99
- });
100
-
101
- it("unknown type falls back to raw token; no metrics → bare '运动: <type>'", async () => {
102
- const now = Date.now();
103
- const p = writeSnapshot(tmpDir, {
104
- schemaVersion: 1, snapshottedAt: now,
105
- events: [{ kind: "workout", id: "w3", workoutId: "9003", type: "parkour", time: now }],
106
- });
107
- const a = new KeepAdapter();
108
- const raws = [];
109
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
110
- const batch = a.normalize(raws[0]);
111
- expect(batch.events[0].content.title).toBe("运动: parkour");
112
- });
113
-
114
- it("respects include opt-out + limit", async () => {
115
- const now = Date.now();
116
- const events = Array.from({ length: 4 }, (_, i) => ({
117
- kind: "workout", id: `w${i}`, workoutId: String(100 + i), type: "running",
118
- time: now - i * 1000, distanceMeters: 3000,
119
- }));
120
- const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
121
- const a = new KeepAdapter();
122
- let raws = [];
123
- for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
124
- expect(raws.length).toBe(2);
125
- raws = [];
126
- for await (const r of a.sync({ inputPath: p, include: { workout: false } })) raws.push(r);
127
- expect(raws.length).toBe(0);
128
- });
129
-
130
- it("advertises capabilities + passes assertAdapter", () => {
131
- const a = new KeepAdapter();
132
- expect(a.capabilities).toContain("sync:snapshot");
133
- expect(a.capabilities).toContain("sync:cookie-api");
134
- expect(assertAdapter(a).ok).toBe(true);
135
- });
136
- });
137
-
138
- describe("KeepAdapter cookie-api mode", () => {
139
- it("authenticate(cookie) returns unverified:true (best-effort scaffold)", async () => {
140
- const a = new KeepAdapter({ account: { cookies: "token=ok" } });
141
- const res = await a.authenticate();
142
- expect(res.ok).toBe(true);
143
- expect(res.mode).toBe("cookie");
144
- expect(res.unverified).toBe(true);
145
- });
146
-
147
- it("fetches workouts via fetchFn and normalizes (km vs meters heuristic)", async () => {
148
- const fetchFn = async () => ({
149
- data: {
150
- records: [
151
- { workoutId: 555, type: "cycling", name: "骑行", doneDate: 1700000000, distance: 12.5, duration: 2400, kcal: 410 },
152
- ],
153
- },
154
- });
155
- const a = new KeepAdapter({ account: { userId: "u1", cookies: "token=ok" }, fetchFn });
156
- const raws = [];
157
- for await (const r of a.sync({})) raws.push(r);
158
- expect(raws.length).toBe(1);
159
- const batch = a.normalize(raws[0]);
160
- expect(validateBatch(batch).valid).toBe(true);
161
- // distance 12.5 (looks like km, no meter field) → 12500 m → 12.50 km
162
- expect(batch.events[0].content.title).toBe("运动: 骑行 12.50 km");
163
- expect(batch.events[0].extra.calories).toBe(410);
164
- });
165
-
166
- it("invokes signProvider, passes sign to fetchFn", async () => {
167
- let seen = null;
168
- const signProvider = async () => "SIG";
169
- const fetchFn = async (opts) => {
170
- seen = opts.sign;
171
- return { list: [] };
172
- };
173
- const a = new KeepAdapter({ account: { cookies: "x=1" }, fetchFn, signProvider });
174
- for await (const _r of a.sync({})) { /* drain */ }
175
- expect(seen).toBe("SIG");
176
- });
177
-
178
- it("paginates until short page", async () => {
179
- const all = Array.from({ length: 45 }, (_, i) => ({ workoutId: i + 1, type: "running", time: 1700000000, distanceMeters: 3000 }));
180
- const seenPages = [];
181
- const fetchFn = async (opts) => {
182
- const page = opts.query.page;
183
- seenPages.push(page);
184
- return { list: all.slice((page - 1) * 30, page * 30) };
185
- };
186
- const a = new KeepAdapter({ account: { cookies: "x=1" }, fetchFn });
187
- const raws = [];
188
- for await (const r of a.sync({})) raws.push(r);
189
- expect(raws.length).toBe(45);
190
- expect(seenPages).toEqual([1, 2]);
191
- });
192
-
193
- it("mapWorkout / extractList / typeLabel helpers", () => {
194
- expect(mapWorkout({ workoutId: 7, type: "running", distanceMeters: 5000 }).distanceMeters).toBe(5000);
195
- expect(mapWorkout({})).toBe(null);
196
- expect(extractList({ data: { logs: [1] } })).toEqual([1]);
197
- expect(extractList(null)).toEqual([]);
198
- expect(typeLabel("yoga")).toBe("瑜伽");
199
- expect(typeLabel("xyz")).toBe("xyz");
200
- expect(typeLabel(null)).toBe("运动");
201
- });
202
-
203
- it("uses opts.listUrl override", async () => {
204
- let seenUrl = null;
205
- const fetchFn = async (opts) => {
206
- seenUrl = opts.url;
207
- return { list: [] };
208
- };
209
- const a = new KeepAdapter({ account: { cookies: "x=1" }, fetchFn, listUrl: "https://x/w" });
210
- for await (const _r of a.sync({})) { /* drain */ }
211
- expect(seenUrl).toBe("https://x/w");
212
- });
213
-
214
- it("default fetchFn throws legible error", async () => {
215
- const a = new KeepAdapter({ account: { cookies: "x=1" } });
216
- let threw = null;
217
- try {
218
- for await (const _r of a.sync({})) { /* drain */ }
219
- } catch (err) {
220
- threw = err;
221
- }
222
- expect(String(threw.message)).toMatch(/no fetchFn configured/);
223
- });
224
- });
@@ -1,96 +0,0 @@
1
- {
2
- "schema": 1,
3
- "description": "Mock 200-pair labeled set for Phase 8 EntityResolver evaluation. Synthetic data (no real PII). 100 'same' positives + 100 'different' negatives across Email/Alipay/WeChat-style profiles. Real 200-pair set lives in user vault and is gitignored (see design doc §7.3).",
4
- "generatedAt": "2026-05-20",
5
- "categories": {
6
- "cross-source-same-identifier": "Same email/phone/wechatId across two adapters; rule stage should catch",
7
- "cross-source-same-name-different-adapter": "Same 中文 name only; needs embedding+LLM",
8
- "cross-source-different-identifier": "Clearly distinct identifiers; should be 'different'",
9
- "same-adapter-same-name": "Same adapter, different originalId, shared name (adapter internal dup)",
10
- "homonym-trap": "Same common 中文 name but different people (different identifiers)"
11
- },
12
- "pairs": [
13
- {
14
- "id": "p001",
15
- "category": "cross-source-same-identifier",
16
- "groundTruth": "same",
17
- "a": { "id": "p-email-mom-001", "type": "person", "names": ["妈"], "identifiers": { "email": ["mom001@163.com"] }, "source": { "adapter": "email", "originalId": "1" } },
18
- "b": { "id": "p-alipay-001", "type": "person", "names": ["陈XX"], "identifiers": { "email": ["mom001@163.com"] }, "source": { "adapter": "alipay-bill", "originalId": "2" } }
19
- },
20
- {
21
- "id": "p002",
22
- "category": "cross-source-same-identifier",
23
- "groundTruth": "same",
24
- "a": { "id": "p-email-dad-002", "type": "person", "names": ["爸"], "identifiers": { "phone": ["13800001111"] }, "source": { "adapter": "email", "originalId": "1" } },
25
- "b": { "id": "p-alipay-002", "type": "person", "names": ["陈父亲"], "identifiers": { "phone": ["+86 138 0000 1111"] }, "source": { "adapter": "alipay-bill", "originalId": "2" } }
26
- },
27
- {
28
- "id": "p003",
29
- "category": "cross-source-different-identifier",
30
- "groundTruth": "different",
31
- "a": { "id": "p-email-alice-003", "type": "person", "names": ["Alice"], "identifiers": { "email": ["alice@x.com"] }, "source": { "adapter": "email", "originalId": "1" } },
32
- "b": { "id": "p-alipay-003", "type": "person", "names": ["Bob"], "identifiers": { "phone": ["13900001234"] }, "source": { "adapter": "alipay-bill", "originalId": "2" } }
33
- },
34
- {
35
- "id": "p004",
36
- "category": "cross-source-same-name-different-adapter",
37
- "groundTruth": "same",
38
- "a": { "id": "p-email-zs-004", "type": "person", "names": ["张三"], "identifiers": { "email": ["zs@x.com"] }, "source": { "adapter": "email", "originalId": "1" } },
39
- "b": { "id": "p-alipay-004", "type": "person", "names": ["张三"], "identifiers": {}, "source": { "adapter": "alipay-bill", "originalId": "2" } }
40
- },
41
- {
42
- "id": "p005",
43
- "category": "homonym-trap",
44
- "groundTruth": "different",
45
- "a": { "id": "p-email-zs1-005", "type": "person", "names": ["张三"], "identifiers": { "email": ["zhang1@a.com"], "phone": ["13800001111"] }, "source": { "adapter": "email", "originalId": "1" } },
46
- "b": { "id": "p-email-zs2-005", "type": "person", "names": ["张三"], "identifiers": { "email": ["zhang2@b.com"], "phone": ["13900002222"] }, "source": { "adapter": "email", "originalId": "2" } }
47
- },
48
- {
49
- "id": "p006",
50
- "category": "same-adapter-same-name",
51
- "groundTruth": "same",
52
- "a": { "id": "p-email-li-006a", "type": "person", "names": ["李四"], "identifiers": {}, "source": { "adapter": "email", "originalId": "1" } },
53
- "b": { "id": "p-email-li-006b", "type": "person", "names": ["李四"], "identifiers": {}, "source": { "adapter": "email", "originalId": "2" } }
54
- },
55
- {
56
- "id": "p007",
57
- "category": "cross-source-same-identifier",
58
- "groundTruth": "same",
59
- "a": { "id": "p-wechat-007", "type": "person", "names": ["王五"], "identifiers": { "wechatId": "wxid_wangwu" }, "source": { "adapter": "wechat", "originalId": "1" } },
60
- "b": { "id": "p-alipay-007", "type": "person", "names": ["王XX"], "identifiers": { "wechatId": "wxid_wangwu" }, "source": { "adapter": "alipay-bill", "originalId": "2" } }
61
- },
62
- {
63
- "id": "p008",
64
- "category": "cross-source-different-identifier",
65
- "groundTruth": "different",
66
- "a": { "id": "p-email-ceo-008", "type": "person", "names": ["陈总"], "identifiers": { "email": ["ceo@bigco.com"] }, "source": { "adapter": "email", "originalId": "1" } },
67
- "b": { "id": "p-email-ceo2-008", "type": "person", "names": ["陈总"], "identifiers": { "email": ["chen@xiaobu.com"] }, "source": { "adapter": "email", "originalId": "2" } }
68
- },
69
- {
70
- "id": "p009",
71
- "category": "cross-source-same-name-different-adapter",
72
- "groundTruth": "same",
73
- "a": { "id": "p-wechat-009", "type": "person", "names": ["小明"], "identifiers": {}, "source": { "adapter": "wechat", "originalId": "1" } },
74
- "b": { "id": "p-alipay-009", "type": "person", "names": ["小明"], "identifiers": {}, "source": { "adapter": "alipay-bill", "originalId": "2" } }
75
- },
76
- {
77
- "id": "p010",
78
- "category": "homonym-trap",
79
- "groundTruth": "different",
80
- "a": { "id": "p-email-lijun1-010", "type": "person", "names": ["李军"], "identifiers": { "email": ["lijun.eng@coA.com"] }, "source": { "adapter": "email", "originalId": "1" } },
81
- "b": { "id": "p-email-lijun2-010", "type": "person", "names": ["李军"], "identifiers": { "email": ["lijun.sales@coB.com"] }, "source": { "adapter": "email", "originalId": "2" } }
82
- }
83
- ],
84
- "summary": {
85
- "totalPairs": 10,
86
- "byGroundTruth": { "same": 5, "different": 5 },
87
- "byCategory": {
88
- "cross-source-same-identifier": 3,
89
- "cross-source-same-name-different-adapter": 2,
90
- "cross-source-different-identifier": 2,
91
- "same-adapter-same-name": 1,
92
- "homonym-trap": 2
93
- },
94
- "note": "This is a 10-pair smoke fixture (committed to git, synthetic). The real 200-pair set lives at __tests__/fixtures/entity-resolver-200.json which is gitignored — generated from user vault via scripts/gen-entity-resolver-fixture.js."
95
- }
96
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { newId, timestampFromId } = require("../lib/ids");
6
-
7
- describe("ids", () => {
8
- it("newId returns a 36-char UUID v7 string", () => {
9
- const id = newId();
10
- expect(typeof id).toBe("string");
11
- expect(id.length).toBe(36);
12
- expect(id.charAt(14)).toBe("7"); // version nibble
13
- });
14
-
15
- it("newId generates unique IDs", () => {
16
- const ids = new Set();
17
- for (let i = 0; i < 1000; i++) ids.add(newId());
18
- expect(ids.size).toBe(1000);
19
- });
20
-
21
- it("newId generates time-ordered IDs (sortable by string compare)", async () => {
22
- const a = newId();
23
- // Wait > 1ms so the embedded timestamp definitely advances.
24
- await new Promise((r) => setTimeout(r, 5));
25
- const b = newId();
26
- expect(a < b).toBe(true);
27
- });
28
-
29
- it("timestampFromId returns a recent unix ms timestamp for v7 IDs", () => {
30
- const now = Date.now();
31
- const id = newId();
32
- const ts = timestampFromId(id);
33
- expect(ts).not.toBeNull();
34
- // Embedded timestamp should be within 2s of now (allow CI jitter).
35
- expect(Math.abs(ts - now)).toBeLessThan(2000);
36
- });
37
-
38
- it("timestampFromId returns null for non-v7 input", () => {
39
- // A canonical v4 UUID has version nibble "4"
40
- const v4 = "550e8400-e29b-41d4-a716-446655440000";
41
- expect(timestampFromId(v4)).toBeNull();
42
- expect(timestampFromId("not-a-uuid")).toBeNull();
43
- expect(timestampFromId(undefined)).toBeNull();
44
- });
45
- });
@@ -1,228 +0,0 @@
1
- "use strict";
2
-
3
- // Integration — AIChatHistoryAdapter end-to-end through AdapterRegistry.
4
- // Verifies the full chain: register → syncAdapter → real vendor HTTP →
5
- // raw archive → normalize → partition → vault put → watermark advance →
6
- // audit log.
7
-
8
- import { describe, it, expect, afterEach } from "vitest";
9
-
10
- const fs = require("node:fs");
11
- const path = require("node:path");
12
- const os = require("node:os");
13
-
14
- const {
15
- LocalVault, generateKeyHex, AdapterRegistry,
16
- } = require("../../lib");
17
- const {
18
- AIChatHistoryAdapter, CookieAuthSession, DEFAULT_VENDOR_SPECS,
19
- } = require("../../lib/adapters/ai-chat-history");
20
-
21
- function makeRig() {
22
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-aichat-int-"));
23
- const vault = new LocalVault({ path: path.join(dir, "v.db"), key: generateKeyHex() });
24
- vault.open();
25
- const registry = new AdapterRegistry({ vault });
26
- return { vault, registry, dir };
27
- }
28
-
29
- function cleanup({ vault, dir }) {
30
- try { vault.close(); } catch (_e) {}
31
- try { fs.rmSync(dir, { recursive: true, force: true }); } catch (_e) {}
32
- }
33
-
34
- function makeResponse({ status = 200, body = {} } = {}) {
35
- return {
36
- status,
37
- ok: status >= 200 && status < 300,
38
- headers: { get: () => null },
39
- async json() { return body; },
40
- async text() { return JSON.stringify(body); },
41
- };
42
- }
43
-
44
- function makeRoutedFetch(routes) {
45
- const calls = [];
46
- return {
47
- calls,
48
- async fetch(url, init) {
49
- calls.push({ url, init });
50
- for (const [pattern, response] of routes) {
51
- if (typeof pattern === "string" ? url.includes(pattern) : pattern.test(url)) {
52
- if (typeof response === "function") return response(url, init);
53
- return response;
54
- }
55
- }
56
- return makeResponse({ status: 404, body: { error: "no route" } });
57
- },
58
- };
59
- }
60
-
61
- function makeClock() {
62
- let t = 1700000000_000;
63
- return {
64
- now: () => t,
65
- sleep: async (ms) => { t += ms; },
66
- };
67
- }
68
-
69
- function deepseekFixtures() {
70
- return [
71
- ["/get_user_info", makeResponse({ body: { code: 0, data: { biz_data: { user_id: "ds-u1" } } } })],
72
- [/fetch_page.*before=/, makeResponse({ body: { data: { biz_data: { chat_sessions: [] } } } })],
73
- ["/chat_session/fetch_page", makeResponse({ body: { data: { biz_data: { chat_sessions: [
74
- { id: "ds-c1", title: "test ds chat", model: "deepseek-r1", inserted_at: 1700000100, updated_at: 1700000200 },
75
- ] } } } })],
76
- ["/chat/history_messages", makeResponse({ body: { data: { biz_data: { chat_messages: [
77
- { id: "ds-m1", role: "USER", content: "hi deepseek", inserted_at: 1700000100 },
78
- { id: "ds-m2", role: "ASSISTANT", content: "hi back", inserted_at: 1700000110, model: "deepseek-r1" },
79
- ] } } } })],
80
- ];
81
- }
82
-
83
- function kimiFixtures() {
84
- return [
85
- ["/api/user", makeResponse({ body: { id: "km-u1" } })],
86
- [/list\?offset=30/, makeResponse({ body: { items: [], total: 1 } })],
87
- [/list\?offset=0/, makeResponse({ body: { items: [
88
- { id: "km-c1", name: "test kimi", created_at: 1700000300, updated_at: 1700000400, message_count: 1 },
89
- ], total: 1 } })],
90
- [/segment\/scroll/, async (_url, init) => {
91
- const body = JSON.parse(init.body);
92
- if (body.last === "0") {
93
- return makeResponse({ body: {
94
- items: [{ id: "km-msg-1", role: "user", content: "hi kimi", created_at: 1700000300 }],
95
- has_more: false,
96
- } });
97
- }
98
- return makeResponse({ body: { items: [], has_more: false } });
99
- }],
100
- ];
101
- }
102
-
103
- // ─── tests ───────────────────────────────────────────────────────────────
104
-
105
- describe("Integration — AIChatHistoryAdapter through AdapterRegistry", () => {
106
- let rig;
107
- afterEach(() => cleanup(rig));
108
-
109
- it("registers without contract errors (adapter passes assertAdapter)", () => {
110
- rig = makeRig();
111
- const a = new AIChatHistoryAdapter();
112
- expect(() => rig.registry.register(a)).not.toThrow();
113
- });
114
-
115
- it("two-vendor sync writes events to vault with proper raw_events archive", async () => {
116
- rig = makeRig();
117
- const clk = makeClock();
118
- const fetched = makeRoutedFetch([...deepseekFixtures(), ...kimiFixtures()]);
119
- const a = new AIChatHistoryAdapter({
120
- fetch: fetched.fetch,
121
- sleep: clk.sleep,
122
- now: clk.now,
123
- });
124
- a.setSession("deepseek", new CookieAuthSession({ vendor: "deepseek", cookies: [{ name: "userToken", value: "x" }] }));
125
- a.setSession("kimi", new CookieAuthSession({ vendor: "kimi", cookies: [{ name: "sess", value: "y" }] }));
126
- rig.registry.register(a);
127
-
128
- const report = await rig.registry.syncAdapter("ai-chat-history");
129
- expect(report.status).toBe("ok");
130
- expect(report.invalidCount).toBe(0); // adapter must yield valid registry envelopes
131
-
132
- // Each vendor yields: 1 conv + N msgs (deepseek=2, kimi=1) = 5 raws across both
133
- expect(report.rawCount).toBeGreaterThanOrEqual(5);
134
-
135
- // Vault has events (2 deepseek msgs + 1 kimi msg)
136
- const allEvents = rig.vault.queryEvents({ adapter: "ai-chat-history", limit: 1000 });
137
- expect(allEvents.length).toBeGreaterThanOrEqual(3);
138
- const vendors = new Set(allEvents.map((e) => e.extra && e.extra.vendor).filter(Boolean));
139
- expect(vendors.has("deepseek")).toBe(true);
140
- expect(vendors.has("kimi")).toBe(true);
141
-
142
- // Vendor Person dedup via raw SQL: only 1 DeepSeek Person + 1 Kimi Person
143
- const aiAgentCount = rig.vault.db
144
- .prepare("SELECT COUNT(*) AS n FROM persons WHERE subtype = 'ai-agent'")
145
- .get().n;
146
- expect(aiAgentCount).toBe(2);
147
-
148
- // Topics: 1 conversation Topic per vendor (extra.kind = 'ai-conversation')
149
- const topicCount = rig.vault.db
150
- .prepare("SELECT COUNT(*) AS n FROM topics WHERE json_extract(extra, '$.kind') = 'ai-conversation'")
151
- .get().n;
152
- expect(topicCount).toBe(2);
153
- });
154
-
155
- it("watermark advances after successful sync; second sync is idempotent", async () => {
156
- rig = makeRig();
157
- const clk = makeClock();
158
- const fetched = makeRoutedFetch(deepseekFixtures());
159
- const a = new AIChatHistoryAdapter({ fetch: fetched.fetch, sleep: clk.sleep, now: clk.now });
160
- a.setSession("deepseek", new CookieAuthSession({ vendor: "deepseek", cookies: [{ name: "userToken", value: "x" }] }));
161
- rig.registry.register(a);
162
-
163
- const r1 = await rig.registry.syncAdapter("ai-chat-history");
164
- expect(r1.status).toBe("ok");
165
- const firstWatermark = r1.watermark;
166
- expect(firstWatermark).toBeTruthy();
167
-
168
- const eventsAfterFirst = rig.vault.queryEvents({ adapter: "ai-chat-history", limit: 100 }).length;
169
- expect(eventsAfterFirst).toBeGreaterThanOrEqual(2);
170
-
171
- // Re-sync same fixtures — should be idempotent (no duplicate events).
172
- const r2 = await rig.registry.syncAdapter("ai-chat-history");
173
- expect(r2.status).toBe("ok");
174
-
175
- // Vault doesn't double-insert thanks to events table PK (id is UUIDv7 so different each time
176
- // but source.originalId dedup via findBySource semantics applies). At minimum, both syncs
177
- // succeeded without errors and the watermark moved forward.
178
- expect(Number(r2.watermark)).toBeGreaterThanOrEqual(Number(firstWatermark));
179
- });
180
-
181
- it("vendor-cookie-expired sentinel does not abort the whole sync", async () => {
182
- rig = makeRig();
183
- const clk = makeClock();
184
- // deepseek returns 401, kimi works.
185
- const fetched = makeRoutedFetch([
186
- [/chat_session\/fetch_page/, makeResponse({ status: 401 })],
187
- ...kimiFixtures(),
188
- ]);
189
- const a = new AIChatHistoryAdapter({ fetch: fetched.fetch, sleep: clk.sleep, now: clk.now });
190
- a.setSession("deepseek", new CookieAuthSession({ vendor: "deepseek", cookies: [] }));
191
- a.setSession("kimi", new CookieAuthSession({ vendor: "kimi", cookies: [] }));
192
- rig.registry.register(a);
193
-
194
- const report = await rig.registry.syncAdapter("ai-chat-history");
195
- expect(report.status).toBe("ok"); // partial success is still ok
196
-
197
- // Kimi events made it in despite deepseek failure.
198
- const allEvents = rig.vault.queryEvents({ adapter: "ai-chat-history", limit: 100 });
199
- const kimiEvents = allEvents.filter((e) => e.extra && e.extra.vendor === "kimi");
200
- expect(kimiEvents.length).toBeGreaterThan(0);
201
- });
202
-
203
- it("no sessions configured → zero events ingested, no error", async () => {
204
- rig = makeRig();
205
- const a = new AIChatHistoryAdapter();
206
- rig.registry.register(a);
207
-
208
- const report = await rig.registry.syncAdapter("ai-chat-history");
209
- expect(report.status).toBe("ok");
210
- expect(report.rawCount).toBe(0);
211
- expect(rig.vault.queryEvents({ adapter: "ai-chat-history", limit: 10 }).length).toBe(0);
212
- });
213
-
214
- it("audit log captures sync.ok with adapter name + scope", async () => {
215
- rig = makeRig();
216
- const clk = makeClock();
217
- const fetched = makeRoutedFetch(deepseekFixtures());
218
- const a = new AIChatHistoryAdapter({ fetch: fetched.fetch, sleep: clk.sleep, now: clk.now });
219
- a.setSession("deepseek", new CookieAuthSession({ vendor: "deepseek", cookies: [] }));
220
- rig.registry.register(a);
221
-
222
- await rig.registry.syncAdapter("ai-chat-history");
223
-
224
- const audit = rig.vault.queryAudit({ adapter: "ai-chat-history", limit: 50 });
225
- const okEntries = audit.filter((a) => a.action === "adapter.sync.ok");
226
- expect(okEntries.length).toBeGreaterThan(0);
227
- });
228
- });