@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,188 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * E2E — full Personal Data Hub user journey.
5
- *
6
- * Simulates a user from zero to "ask a question and get an answer":
7
- * 1. Initialize fresh vault
8
- * 2. Register + sync EmailAdapter (mocked IMAP session)
9
- * 3. Register + import Alipay CSV
10
- * 4. EntityResolver auto-merges same-email persons
11
- * 5. Worker drains uncertain pairs (rule-stage only, no LLM needed)
12
- * 6. SpendingSkill answers "how much did I spend?" with combined totals
13
- * 7. TimelineSkill weaves events into chronological story
14
- * 8. EventDetail surfaces the source raw row for a citation
15
- *
16
- * Avoids real network / real LLM / real device — every external boundary
17
- * is mocked via DI seams (sessionFactory, csvParser, embeddingStage).
18
- */
19
-
20
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
21
-
22
- const fs = require("node:fs");
23
- const path = require("node:path");
24
- const os = require("node:os");
25
-
26
- const {
27
- LocalVault, generateKeyHex, AdapterRegistry,
28
- EntityResolver,
29
- EmailAdapter, AlipayBillAdapter,
30
- SpendingSkill, TimelineSkill, RelationsSkill,
31
- } = require("../../lib");
32
-
33
- describe("E2E — full Personal Data Hub user journey", () => {
34
- let dir, vault, registry, resolver;
35
-
36
- beforeEach(() => {
37
- dir = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-e2e-"));
38
- vault = new LocalVault({ path: path.join(dir, "v.db"), key: generateKeyHex() });
39
- vault.open();
40
- resolver = new EntityResolver({ vault });
41
- registry = new AdapterRegistry({ vault, entityResolver: resolver });
42
- });
43
-
44
- afterEach(() => {
45
- try { vault.close(); } catch (_e) {}
46
- try { fs.rmSync(dir, { recursive: true, force: true }); } catch (_e) {}
47
- });
48
-
49
- it("zero → email + alipay → entity merge → spending answer", async () => {
50
- // ─── Step 1-2: Register + sync EmailAdapter with mocked IMAP ───
51
- const emailEnv = {
52
- uid: 1, internalDate: new Date("2026-05-15T10:00:00Z"),
53
- flags: ["\\Seen"], messageId: "<msg-1@x>",
54
- subject: "招商银行 11 月对账单",
55
- from: [{ name: "招商银行", address: "ebank@cmbchina.com" }],
56
- to: [{ address: "me@example.com" }], cc: [],
57
- date: new Date("2026-05-15T10:00:00Z"), size: 1024,
58
- source: Buffer.from("RAW", "utf-8"),
59
- };
60
- const emailSessionFactory = () => ({
61
- async connect() {},
62
- async openMailbox() { return { uidValidity: 1, uidNext: 9999, exists: 1 }; },
63
- async *fetchFullSince() { yield emailEnv; },
64
- async close() {},
65
- });
66
- const emailAdapter = new EmailAdapter({
67
- account: { provider: "qq", email: "me@example.com", authCode: "x", folders: ["INBOX"] },
68
- sessionFactory: emailSessionFactory,
69
- parser: async () => ({
70
- textBody: "尊敬的客户:\n您的招商银行信用卡 应还金额 ¥3,256.78 元",
71
- attachments: [],
72
- }),
73
- });
74
- registry.register(emailAdapter);
75
- const emailReport = await registry.syncAdapter("email-imap");
76
- expect(emailReport.status).toBe("ok");
77
- expect(emailReport.entityCounts.events).toBeGreaterThanOrEqual(1);
78
-
79
- // ─── Step 3: Register + import Alipay CSV ───
80
- const alipayCsv = [
81
- "支付宝交易记录明细查询",
82
- "账号:[me@example.com]",
83
- "起始日期:[2026-05-01 00:00:00] 终止日期:[2026-05-31 00:00:00]",
84
- "---------------------------------交易记录明细列表------------------------------",
85
- "交易号,商家订单号,交易创建时间,付款时间,最近修改时间,交易来源地,类型,交易对方,商品名称,金额(元),收/支,交易状态,服务费(元),成功退款(元),备注,资金状态",
86
- "2026051022001112345001,T1,2026-05-10 14:00:00,2026-05-10 14:00:02,2026-05-10 14:00:02,客户端,即时到账交易,美团,美团外卖订单,38.50,支出,交易成功,0.00,0.00,,已支出",
87
- "2026051522001112345002,T2,2026-05-15 09:00:00,2026-05-15 09:00:05,2026-05-15 09:00:05,客户端,即时到账交易,淘宝,运动鞋,299.00,支出,交易成功,0.00,0.00,,已支出",
88
- "2026052022001112345003,,2026-05-20 12:00:00,2026-05-20 12:00:02,2026-05-20 12:00:02,客户端,转账,张三,生日礼物,500.00,支出,交易成功,0.00,0.00,生日快乐,已支出",
89
- "---------------------------------交易记录明细列表结束------------------------------",
90
- ].join("\n");
91
- const csvPath = path.join(dir, "alipay.csv");
92
- fs.writeFileSync(csvPath, alipayCsv, "utf-8");
93
-
94
- const alipayAdapter = new AlipayBillAdapter({
95
- account: { email: "me@example.com" },
96
- });
97
- registry.register(alipayAdapter);
98
- const alipayReport = await registry.syncAdapter("alipay-bill", { csvPath });
99
- expect(alipayReport.status).toBe("ok");
100
- expect(alipayReport.entityCounts.events).toBe(3);
101
-
102
- // ─── Step 4-5: EntityResolver drained (rule stage only) ───
103
- // Email's sender person (招商银行) is a separate identity; Alipay's
104
- // 美团/淘宝/张三 are 3 new persons. None should auto-merge unless
105
- // they share identifiers. The resolver should record decisions.
106
- const queueStatsBefore = vault.resolveQueueStats();
107
- expect(queueStatsBefore.pending + queueStatsBefore.done).toBeGreaterThanOrEqual(0);
108
-
109
- // ─── Step 6: SpendingSkill answers "how much did I spend?" ───
110
- const spendingSkill = new SpendingSkill({ vault });
111
- const spending = await spendingSkill.run({});
112
- expect(spending.summary.totalSpend).toBeCloseTo(38.50 + 299 + 500, 2);
113
- expect(spending.summary.eventCount).toBeGreaterThanOrEqual(3);
114
- expect(spending.breakdown.length).toBeGreaterThanOrEqual(3);
115
- expect(spending.breakdown[0].key).toBe("张三"); // biggest
116
-
117
- // ─── Step 7: TimelineSkill weaves into story ───
118
- const timelineSkill = new TimelineSkill({ vault });
119
- const timeline = await timelineSkill.run({
120
- since: Date.parse("2026-05-01T00:00:00Z"),
121
- until: Date.parse("2026-06-01T00:00:00Z"),
122
- });
123
- expect(timeline.entries.length).toBeGreaterThanOrEqual(4); // email + 3 alipay
124
- expect(timeline.summary.byAdapter["email-imap"]).toBeGreaterThanOrEqual(1);
125
- expect(timeline.summary.byAdapter["alipay-bill"]).toBe(3);
126
- // Chronological: 5/10 first, 5/15 next, 5/20 last
127
- expect(timeline.entries[0].occurredAt).toBeLessThan(timeline.entries[timeline.entries.length - 1].occurredAt);
128
-
129
- // ─── Step 8: RelationsSkill (ranked mode) ───
130
- const relationsSkill = new RelationsSkill({ vault });
131
- const relations = await relationsSkill.run({}); // ranked mode
132
- expect(relations.ranked.length).toBeGreaterThanOrEqual(3);
133
- // Top should be 张三 (biggest transfer)
134
- const zhangsan = relations.ranked.find((p) => p.name === "张三");
135
- expect(zhangsan).toBeDefined();
136
- expect(zhangsan.totalSpend).toBe(500);
137
-
138
- // ─── Step 9: event-detail deep-link works ───
139
- // Pull one event and verify the source row is recoverable
140
- const events = vault.queryEvents({ adapter: "alipay-bill", limit: 10 });
141
- expect(events.length).toBe(3);
142
- // Find the Taobao transaction by counterparty (title is item name, e.g. "运动鞋")
143
- const tx = events.find((e) => e.extra && e.extra.counterparty === "淘宝");
144
- expect(tx).toBeDefined();
145
- expect(tx.source.adapter).toBe("alipay-bill");
146
- expect(tx.extra.counterpartyKind).toBe("merchant");
147
- });
148
-
149
- it("idempotent re-sync — same alipay CSV produces 0 duplicate events", async () => {
150
- const alipayCsv = [
151
- "支付宝交易记录明细查询",
152
- "账号:[me@example.com]",
153
- "---------------------------------交易记录明细列表------------------------------",
154
- "交易号,商家订单号,交易创建时间,付款时间,最近修改时间,交易来源地,类型,交易对方,商品名称,金额(元),收/支,交易状态,服务费(元),成功退款(元),备注,资金状态",
155
- "2026051022001112345001,T1,2026-05-10 14:00:00,2026-05-10 14:00:02,2026-05-10 14:00:02,客户端,即时到账交易,美团,外卖,38.50,支出,交易成功,0.00,0.00,,已支出",
156
- ].join("\n");
157
- const csvPath = path.join(dir, "alipay.csv");
158
- fs.writeFileSync(csvPath, alipayCsv, "utf-8");
159
-
160
- const adapter = new AlipayBillAdapter({ account: { email: "me@example.com" } });
161
- registry.register(adapter);
162
- await registry.syncAdapter("alipay-bill", { csvPath });
163
- await registry.syncAdapter("alipay-bill", { csvPath });
164
-
165
- const events = vault.queryEvents({ adapter: "alipay-bill", limit: 100 });
166
- expect(events.length).toBe(1); // dedup by originalId
167
- });
168
-
169
- it("vault stats reflect post-sync entity counts", async () => {
170
- const csvPath = path.join(dir, "alipay.csv");
171
- fs.writeFileSync(csvPath, [
172
- "支付宝交易记录明细查询",
173
- "账号:[me@example.com]",
174
- "---------------------------------交易记录明细列表------------------------------",
175
- "交易号,商家订单号,交易创建时间,付款时间,最近修改时间,交易来源地,类型,交易对方,商品名称,金额(元),收/支,交易状态,服务费(元),成功退款(元),备注,资金状态",
176
- "2026051022001112345001,T1,2026-05-10 14:00:00,2026-05-10 14:00:02,2026-05-10 14:00:02,客户端,即时到账交易,美团,外卖,38.50,支出,交易成功,0.00,0.00,,已支出",
177
- ].join("\n"), "utf-8");
178
-
179
- const adapter = new AlipayBillAdapter({ account: { email: "me@example.com" } });
180
- registry.register(adapter);
181
- await registry.syncAdapter("alipay-bill", { csvPath });
182
-
183
- const stats = vault.stats();
184
- expect(stats.events).toBe(1);
185
- expect(stats.persons).toBe(1); // 美团 merchant
186
- expect(stats.rawEvents).toBeGreaterThanOrEqual(1);
187
- });
188
- });
@@ -1,146 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * E2E — spawn the cc CLI and exercise the real `hub list-adapters` +
5
- * `hub sync-adapter` commands against a sandboxed APPDATA dir. Validates
6
- * the entire path PDH wiring → registry → CLI gateway → JSON stdout for
7
- * the 4 new Phase 17 adapters.
8
- *
9
- * Same bs3mc-on-Win caveat as the integration test: skip when LocalVault
10
- * cannot open. CI Linux runs the real chain.
11
- *
12
- * Strategy: redirect APPDATA / XDG_CONFIG_HOME / HOME to a tmpdir so the
13
- * CLI's getElectronUserDataDir() resolves to that tmpdir and we don't
14
- * touch the user's real chainlesschain-desktop-vue/.chainlesschain dir.
15
- */
16
-
17
- import { describe, it, expect, beforeAll, afterAll } from "vitest";
18
-
19
- const fs = require("node:fs");
20
- const path = require("node:path");
21
- const os = require("node:os");
22
- const { spawnSync } = require("node:child_process");
23
-
24
- // Probe bs3mc once — same gate as the integration test.
25
- let bs3mcAvailable = true;
26
- let bs3mcSkipReason = "";
27
- try {
28
- const probeDir = fs.mkdtempSync(path.join(os.tmpdir(), "bs3mc-e2e-probe-"));
29
- const { LocalVault: PV, generateKeyHex: PK } = require("../../lib");
30
- const v = new PV({ path: path.join(probeDir, "p.db"), key: PK() });
31
- v.open();
32
- v.close();
33
- fs.rmSync(probeDir, { recursive: true, force: true });
34
- } catch (e) {
35
- bs3mcAvailable = false;
36
- bs3mcSkipReason = e && e.message ? e.message : String(e);
37
- }
38
- // Resolve the CLI entry — we run it through node directly (avoids cc
39
- // PATH lookup hassles + the workspace symlink resolves to current source).
40
- // In the FTS5 sandbox runner (lib/ + __tests__/ copied to $TMPDIR) the
41
- // relative ../../../cli path resolves outside the repo and is missing;
42
- // gate the tests so they skip cleanly when the CLI binary is absent.
43
- const CLI_BIN = path.resolve(__dirname, "..", "..", "..", "cli", "bin", "chainlesschain.js");
44
- const cliBinAvailable = fs.existsSync(CLI_BIN);
45
-
46
- const itOrSkip = bs3mcAvailable && cliBinAvailable ? it : it.skip;
47
-
48
- let sandboxAppData;
49
-
50
- function runCli(args, { timeoutMs = 60_000 } = {}) {
51
- const env = {
52
- ...process.env,
53
- // Override the platform user-data dir lookup so initHub() builds its
54
- // vault inside our sandbox instead of the real user profile.
55
- APPDATA: sandboxAppData,
56
- XDG_CONFIG_HOME: sandboxAppData,
57
- HOME: sandboxAppData,
58
- USERPROFILE: sandboxAppData,
59
- // Prevent CC from launching the auto-update probe / telemetry pings
60
- // mid-test (those can hang the spawn).
61
- CC_DISABLE_TELEMETRY: "1",
62
- CC_DISABLE_AUTOUPDATE: "1",
63
- NO_COLOR: "1",
64
- };
65
- const res = spawnSync(process.execPath, [CLI_BIN, ...args], {
66
- env,
67
- encoding: "utf-8",
68
- timeout: timeoutMs,
69
- windowsHide: true,
70
- });
71
- return {
72
- code: res.status,
73
- stdout: res.stdout || "",
74
- stderr: res.stderr || "",
75
- signal: res.signal,
76
- error: res.error,
77
- };
78
- }
79
-
80
- beforeAll(() => {
81
- if (!bs3mcAvailable) return;
82
- sandboxAppData = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-e2e-appdata-"));
83
- });
84
-
85
- afterAll(() => {
86
- if (sandboxAppData) {
87
- try {
88
- fs.rmSync(sandboxAppData, { recursive: true, force: true });
89
- } catch (_e) {
90
- /* noop */
91
- }
92
- }
93
- });
94
-
95
- describe("cc hub list-adapters — 4 Phase 17 adapters registered", () => {
96
- itOrSkip("lists browser-history-chrome / -edge / vscode / win-recent", () => {
97
- const r = runCli(["hub", "list-adapters", "--json"]);
98
- // Stderr may carry deprecation noise; we only assert on the JSON stdout.
99
- expect(r.code).toBe(0);
100
- let parsed;
101
- try {
102
- parsed = JSON.parse(r.stdout);
103
- } catch (_e) {
104
- throw new Error(
105
- `list-adapters did not emit JSON (code=${r.code}, signal=${r.signal})\n--- stdout ---\n${r.stdout}\n--- stderr ---\n${r.stderr}`,
106
- );
107
- }
108
- const names = parsed.map((a) => a.name);
109
- for (const expected of [
110
- "browser-history-chrome",
111
- "browser-history-edge",
112
- "vscode",
113
- "win-recent",
114
- ]) {
115
- expect(names).toContain(expected);
116
- }
117
- });
118
- });
119
-
120
- describe("cc hub sync-adapter — drives one adapter end-to-end", () => {
121
- itOrSkip("win-recent sync against an empty Recent dir returns ok with 0 events", () => {
122
- // win-recent will fall through authenticate() PLATFORM_UNSUPPORTED on
123
- // Linux CI. To make this assertion stable across both Win and Linux
124
- // CI runners, we touch a sandbox Recent dir and point the adapter at
125
- // it via env var — but the adapter doesn't read env, only opts. So
126
- // this test simply validates the CLI gateway can invoke and surface
127
- // either an "ok empty" report (Win) or an "unhealthy" report (Linux
128
- // where the default dir doesn't exist). Both prove the gateway works.
129
- const r = runCli(["hub", "sync-adapter", "win-recent", "--json"]);
130
- // The CLI exits 0 for both ok and adapter-reported-error reports; it
131
- // exits non-zero only for hard exceptions. We accept either.
132
- let parsed;
133
- try {
134
- parsed = JSON.parse(r.stdout);
135
- } catch (_e) {
136
- throw new Error(
137
- `sync-adapter did not emit JSON (code=${r.code})\nstdout: ${r.stdout.slice(0, 400)}\nstderr: ${r.stderr.slice(0, 400)}`,
138
- );
139
- }
140
- expect(parsed).toBeDefined();
141
- // status is one of: ok / auth_expired / unhealthy / error
142
- expect(["ok", "auth_expired", "unhealthy", "error"]).toContain(parsed.status);
143
- expect(typeof parsed.rawCount).toBe("number");
144
- expect(parsed.entityCounts).toBeDefined();
145
- });
146
- });
@@ -1,177 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
4
-
5
- const path = require("node:path");
6
- const fs = require("node:fs");
7
- const os = require("node:os");
8
- const { LocalVault } = require("../lib/vault");
9
- const { generateKeyHex } = require("../lib/key-providers");
10
- const { AdapterRegistry } = require("../lib/registry");
11
- const { EntityResolver } = require("../lib/entity-resolver");
12
-
13
- // Minimal adapter that yields raw rows then normalizes to UnifiedSchema
14
- class FakeAdapter {
15
- constructor(name, persons) {
16
- this.name = name;
17
- this.version = "0.1.0";
18
- this.capabilities = ["sync:test"];
19
- this.rateLimits = {};
20
- this.dataDisclosure = { fields: [], sensitivity: "low", legalGate: false };
21
- this._persons = persons;
22
- }
23
- async authenticate() { return { ok: true }; }
24
- async healthCheck() { return { ok: true, lastChecked: Date.now() }; }
25
- async *sync() {
26
- for (const p of this._persons) {
27
- yield { adapter: this.name, originalId: p.id, capturedAt: Date.now(), payload: { person: p } };
28
- }
29
- }
30
- normalize(raw) {
31
- const p = raw.payload.person;
32
- const now = Date.now();
33
- const source = {
34
- adapter: this.name, adapterVersion: this.version,
35
- originalId: raw.originalId, capturedAt: raw.capturedAt, capturedBy: "api",
36
- };
37
- return {
38
- events: [{
39
- id: `evt-${raw.originalId}`,
40
- type: "event",
41
- subtype: "interaction",
42
- occurredAt: now,
43
- actor: p.id,
44
- ingestedAt: now,
45
- source,
46
- }],
47
- persons: [{
48
- id: p.id,
49
- type: "person",
50
- subtype: "contact",
51
- names: p.names || [],
52
- identifiers: p.identifiers || {},
53
- ingestedAt: now,
54
- source,
55
- }],
56
- places: [], items: [], topics: [],
57
- };
58
- }
59
- }
60
-
61
- function makeRig() {
62
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "er-hook-"));
63
- const vault = new LocalVault({ path: path.join(dir, "v.db"), key: generateKeyHex() });
64
- vault.open();
65
- const resolver = new EntityResolver({ vault });
66
- const registry = new AdapterRegistry({ vault, entityResolver: resolver });
67
- return { vault, resolver, registry, dir };
68
- }
69
-
70
- function cleanup({ vault, dir }) {
71
- try { vault.close(); } catch (_e) {}
72
- try { fs.rmSync(dir, { recursive: true, force: true }); } catch (_e) {}
73
- }
74
-
75
- // ─── tests ────────────────────────────────────────────────────────────────
76
-
77
- describe("Phase 8.6 — registry → entity resolver ingest hook", () => {
78
- let rig;
79
- afterEach(() => cleanup(rig));
80
-
81
- it("registry.syncAdapter fires resolveOnIngest with new Persons", async () => {
82
- rig = makeRig();
83
- const adapter = new FakeAdapter("a1", [
84
- { id: "p-1", names: ["Alice"], identifiers: { email: ["alice@x.com"] } },
85
- { id: "p-2", names: ["Bob"], identifiers: { email: ["bob@x.com"] } },
86
- ]);
87
- rig.registry.register(adapter);
88
- const report = await rig.registry.syncAdapter("a1");
89
- expect(report.status).toBe("ok");
90
- expect(report.entityResolver).toBeDefined();
91
- expect(report.entityResolver.newPersons).toBe(2);
92
- });
93
-
94
- it("cross-adapter R1 match: same email → auto-merged", async () => {
95
- rig = makeRig();
96
- // Adapter 1 imports Alice via email
97
- rig.registry.register(new FakeAdapter("email", [
98
- { id: "p-email-alice", names: ["Alice"], identifiers: { email: ["alice@x.com"] } },
99
- ]));
100
- await rig.registry.syncAdapter("email");
101
-
102
- // Adapter 2 imports same Alice via different name + same email
103
- rig.registry.register(new FakeAdapter("alipay", [
104
- { id: "p-alipay-alice-X", names: ["A. Alice"], identifiers: { email: ["alice@x.com"] } },
105
- ]));
106
- const report = await rig.registry.syncAdapter("alipay");
107
- expect(report.entityResolver.sameImmediate).toBeGreaterThanOrEqual(1);
108
-
109
- // Verify merge group exists
110
- const members = rig.vault.getMergeGroupMembers("p-email-alice").sort();
111
- expect(members).toEqual(["p-alipay-alice-X", "p-email-alice"]);
112
- });
113
-
114
- it("uncertain pairs (name overlap only) → enqueued for async", async () => {
115
- rig = makeRig();
116
- rig.registry.register(new FakeAdapter("email", [
117
- { id: "p-1", names: ["张三"] }, // no identifiers
118
- ]));
119
- await rig.registry.syncAdapter("email");
120
-
121
- rig.registry.register(new FakeAdapter("alipay", [
122
- { id: "p-2", names: ["张三"] },
123
- ]));
124
- const report = await rig.registry.syncAdapter("alipay");
125
- expect(report.entityResolver.enqueued).toBeGreaterThanOrEqual(1);
126
- expect(rig.vault.resolveQueueStats().pending).toBeGreaterThanOrEqual(1);
127
- });
128
-
129
- it("zero-overlap pair → no merge, no resolver decisions, person still ingested", async () => {
130
- rig = makeRig();
131
- rig.registry.register(new FakeAdapter("email", [
132
- { id: "p-1", names: ["Alice"], identifiers: { email: ["a@x.com"] } },
133
- ]));
134
- await rig.registry.syncAdapter("email");
135
-
136
- rig.registry.register(new FakeAdapter("alipay", [
137
- { id: "p-2", names: ["Bob"], identifiers: { phone: ["13999998888"] } },
138
- ]));
139
- const report = await rig.registry.syncAdapter("alipay");
140
- expect(report.status).toBe("ok");
141
- expect(rig.vault.stats().mergeGroups).toBe(0);
142
- });
143
-
144
- it("resolver failure does NOT break ingest (audit-logged)", async () => {
145
- rig = makeRig();
146
- // Mock resolver that throws on resolveOnIngest
147
- rig.registry.entityResolver = {
148
- resolveOnIngest: () => { throw new Error("resolver boom"); },
149
- };
150
- rig.registry.register(new FakeAdapter("a1", [
151
- { id: "p-1", names: ["Alice"], identifiers: { email: ["alice@x.com"] } },
152
- ]));
153
- const report = await rig.registry.syncAdapter("a1");
154
- expect(report.status).toBe("ok"); // sync completes
155
- expect(report.entityCounts.persons).toBe(1); // person still ingested
156
- const audits = rig.vault.queryAudit({ action: "adapter.sync.entity_resolver_failed", limit: 5 });
157
- expect(audits.length).toBeGreaterThanOrEqual(1);
158
- });
159
-
160
- it("no entityResolver = registry works as before (backward-compat)", async () => {
161
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "er-hook-"));
162
- const vault = new LocalVault({ path: path.join(dir, "v.db"), key: generateKeyHex() });
163
- vault.open();
164
- try {
165
- const registry = new AdapterRegistry({ vault }); // no entityResolver
166
- registry.register(new FakeAdapter("a1", [
167
- { id: "p-1", names: ["x"], identifiers: { email: ["a@x.com"] } },
168
- ]));
169
- const report = await registry.syncAdapter("a1");
170
- expect(report.status).toBe("ok");
171
- expect(report.entityResolver).toBeUndefined();
172
- } finally {
173
- vault.close();
174
- fs.rmSync(dir, { recursive: true, force: true });
175
- }
176
- });
177
- });