@chainlesschain/personal-data-hub 0.4.29 → 0.4.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/lib/forensics/qq-nt-collect.js +190 -0
  2. package/lib/prompt-builder.js +15 -1
  3. package/package.json +8 -3
  4. package/__tests__/adapter-guide.test.js +0 -47
  5. package/__tests__/adapter-spec.test.js +0 -78
  6. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  7. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  8. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  9. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  10. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  11. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  12. package/__tests__/adapters/apple-health.test.js +0 -95
  13. package/__tests__/adapters/bank-family.test.js +0 -125
  14. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  15. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  16. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  17. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  18. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  19. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  20. package/__tests__/adapters/doc-platforms.test.js +0 -177
  21. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  22. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  23. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  24. package/__tests__/adapters/email-adapter.test.js +0 -742
  25. package/__tests__/adapters/email-classifier.test.js +0 -347
  26. package/__tests__/adapters/email-imap-session.test.js +0 -334
  27. package/__tests__/adapters/email-parser.test.js +0 -244
  28. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  29. package/__tests__/adapters/email-providers.test.js +0 -84
  30. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  31. package/__tests__/adapters/email-templates.test.js +0 -822
  32. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  33. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  34. package/__tests__/adapters/finance-dcep.test.js +0 -74
  35. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  36. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  37. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  38. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  39. package/__tests__/adapters/git-activity.test.js +0 -222
  40. package/__tests__/adapters/gov-12123.test.js +0 -103
  41. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  42. package/__tests__/adapters/gov-tax.test.js +0 -135
  43. package/__tests__/adapters/health-meiyou.test.js +0 -125
  44. package/__tests__/adapters/local-files.test.js +0 -264
  45. package/__tests__/adapters/local-im-pc.test.js +0 -154
  46. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  47. package/__tests__/adapters/music-kugou.test.js +0 -187
  48. package/__tests__/adapters/music-qq.test.js +0 -112
  49. package/__tests__/adapters/netease-music-live.test.js +0 -244
  50. package/__tests__/adapters/netease-music.test.js +0 -74
  51. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  52. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  53. package/__tests__/adapters/reading-family.test.js +0 -108
  54. package/__tests__/adapters/recruit-boss.test.js +0 -180
  55. package/__tests__/adapters/shell-history.test.js +0 -180
  56. package/__tests__/adapters/shopping-base.test.js +0 -179
  57. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  58. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  59. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  60. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  61. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  62. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  63. package/__tests__/adapters/social-csdn.test.js +0 -175
  64. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  65. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  66. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  67. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  68. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  69. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  70. package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
  71. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
  72. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  73. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  74. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  75. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  76. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  77. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  78. package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
  79. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  80. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  81. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  82. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  83. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  84. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  85. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  86. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  87. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  88. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  89. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  90. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  91. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  92. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  93. package/__tests__/adapters/social-zhihu.test.js +0 -246
  94. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  95. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  96. package/__tests__/adapters/system-data-android.test.js +0 -519
  97. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  98. package/__tests__/adapters/travel-12306.test.js +0 -512
  99. package/__tests__/adapters/travel-amap.test.js +0 -219
  100. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  101. package/__tests__/adapters/travel-base.test.js +0 -205
  102. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  103. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  104. package/__tests__/adapters/travel-didi.test.js +0 -204
  105. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  106. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  107. package/__tests__/adapters/video-platforms.test.js +0 -152
  108. package/__tests__/adapters/video-xigua.test.js +0 -106
  109. package/__tests__/adapters/vscode.test.js +0 -299
  110. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  111. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  112. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  113. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  114. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  115. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  116. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  117. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  118. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  119. package/__tests__/adapters/weread.test.js +0 -123
  120. package/__tests__/adapters/wework-pc.test.js +0 -124
  121. package/__tests__/adapters/win-recent.test.js +0 -192
  122. package/__tests__/analysis-skills.test.js +0 -754
  123. package/__tests__/analysis.test.js +0 -1845
  124. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  125. package/__tests__/batch.test.js +0 -133
  126. package/__tests__/bridges-cc-kg.test.js +0 -231
  127. package/__tests__/bridges-cc-llm.test.js +0 -191
  128. package/__tests__/bridges-cc-rag.test.js +0 -162
  129. package/__tests__/categories.test.js +0 -92
  130. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  131. package/__tests__/e2e/full-user-journey.test.js +0 -188
  132. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  133. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  134. package/__tests__/entity-resolver-stages.test.js +0 -411
  135. package/__tests__/entity-resolver-vault.test.js +0 -249
  136. package/__tests__/entity-resolver.test.js +0 -526
  137. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  138. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  139. package/__tests__/ids.test.js +0 -45
  140. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  141. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  142. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  143. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  144. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  145. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  146. package/__tests__/key-providers.test.js +0 -126
  147. package/__tests__/kg-derive.test.js +0 -219
  148. package/__tests__/llm-client.test.js +0 -122
  149. package/__tests__/longtail-adapters.test.js +0 -281
  150. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  151. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  152. package/__tests__/mobile-extractor.test.js +0 -288
  153. package/__tests__/mock-adapter.test.js +0 -93
  154. package/__tests__/prompt-builder.test.js +0 -249
  155. package/__tests__/query-parser.test.js +0 -365
  156. package/__tests__/rag-derive.test.js +0 -169
  157. package/__tests__/registry-readiness.test.js +0 -292
  158. package/__tests__/registry.test.js +0 -420
  159. package/__tests__/salvage-ingest.test.js +0 -97
  160. package/__tests__/schemas.test.js +0 -331
  161. package/__tests__/shopping-adapters.test.js +0 -392
  162. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  163. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  164. package/__tests__/shopping-snapshot.test.js +0 -438
  165. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  166. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  167. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  168. package/__tests__/sidecar-supervisor.test.js +0 -128
  169. package/__tests__/sign-providers.test.js +0 -62
  170. package/__tests__/social-adapters.test.js +0 -280
  171. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  172. package/__tests__/social-douban-snapshot.test.js +0 -351
  173. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  174. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  175. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  176. package/__tests__/social-douyin-snapshot.test.js +0 -256
  177. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  178. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  179. package/__tests__/social-weibo-snapshot.test.js +0 -234
  180. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  181. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  182. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  183. package/__tests__/travel-adapters.test.js +0 -483
  184. package/__tests__/travel-maps-snapshot.test.js +0 -426
  185. package/__tests__/vault-driver-error.test.js +0 -74
  186. package/__tests__/vault-search-helpers.test.js +0 -104
  187. package/__tests__/vault-search.test.js +0 -423
  188. package/__tests__/vault.test.js +0 -767
  189. package/__tests__/wechat-adapter.test.js +0 -594
  190. package/__tests__/whatsapp-adapter.test.js +0 -138
  191. package/scripts/_make-fixture-all.js +0 -126
  192. package/scripts/_make-fixture-contacts.js +0 -84
  193. package/scripts/evaluate-entity-resolver.js +0 -213
  194. package/scripts/run-native-tests-sandbox.sh +0 -55
  195. package/scripts/smoke-phase-5-5.js +0 -196
  196. package/scripts/smoke-phase-5-7.js +0 -181
  197. package/scripts/smoke-system-data-contacts.js +0 -309
  198. package/scripts/smoke-system-data.js +0 -312
  199. package/vitest.config.js +0 -88
@@ -1,123 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { WeReadAdapter } = require("../../lib/adapters/weread");
6
- const { WeReadApiClient } = require("../../lib/adapters/weread/api-client");
7
- const { partitionBatch } = require("../../lib/batch");
8
-
9
- // ── stub fetch returning canned WeRead JSON by URL ──────────────────────
10
- function makeFetch(routes) {
11
- return async (url) => {
12
- for (const [pat, body] of routes) {
13
- if (url.includes(pat)) {
14
- return {
15
- ok: true,
16
- status: 200,
17
- headers: { get: () => null },
18
- json: async () => body,
19
- };
20
- }
21
- }
22
- return { ok: true, status: 200, headers: { get: () => null }, json: async () => ({}) };
23
- };
24
- }
25
-
26
- const ROUTES = [
27
- ["/user/notebooks", { books: [{ bookId: "b1", book: { title: "人类简史", author: "赫拉利", cover: "c" }, noteCount: 2, reviewCount: 1 }] }],
28
- ["/book/bookmarklist", { updated: [{ bookmarkId: "m1", bookId: "b1", markText: "认知革命", chapterTitle: "第一章", createTime: 1700000000 }] }],
29
- ["/review/list", { reviews: [{ review: { reviewId: "r1", bookId: "b1", content: "很有启发", chapterTitle: "第一章", createTime: 1700000100 } }] }],
30
- ];
31
-
32
- async function collect(iter) {
33
- const out = [];
34
- for await (const r of iter) out.push(r);
35
- return out;
36
- }
37
-
38
- describe("WeReadApiClient (cookie HTTP, stub fetch)", () => {
39
- it("parses notebooks / bookmarks / reviews defensively", async () => {
40
- const c = new WeReadApiClient({ cookie: "wr_skey=x", fetch: makeFetch(ROUTES) });
41
- const books = await c.getNotebooks();
42
- expect(books).toHaveLength(1);
43
- expect(books[0].title).toBe("人类简史");
44
- const marks = await c.getBookmarks("b1");
45
- expect(marks[0].markText).toBe("认知革命");
46
- const reviews = await c.getReviews("b1");
47
- expect(reviews[0].content).toBe("很有启发");
48
- });
49
-
50
- it("requires a cookie", () => {
51
- expect(() => new WeReadApiClient({})).toThrow(/cookie/);
52
- });
53
-
54
- it("degrades a failing endpoint to empty (no throw)", async () => {
55
- const c = new WeReadApiClient({
56
- cookie: "x",
57
- fetch: async () => { throw new Error("network down"); },
58
- });
59
- expect(await c.getNotebooks()).toEqual([]);
60
- expect(c.lastErrorCode).toBeTruthy();
61
- });
62
- });
63
-
64
- describe("WeReadAdapter — cookie mode", () => {
65
- it("readinessOnly without cookie → INVALID_COOKIE (credential)", async () => {
66
- const r = await new WeReadAdapter().authenticate({ readinessOnly: true });
67
- expect(r.reason).toBe("INVALID_COOKIE");
68
- });
69
-
70
- it("readinessOnly with cookie → configured", async () => {
71
- const r = await new WeReadAdapter({ cookie: "x" }).authenticate({ readinessOnly: true });
72
- expect(r.ok).toBe(true);
73
- expect(r.mode).toBe("configured");
74
- });
75
-
76
- it("fetches book + highlight + review and normalizes to a valid batch", async () => {
77
- const a = new WeReadAdapter();
78
- const raws = await collect(a.sync({ cookie: "wr_skey=x", fetch: makeFetch(ROUTES) }));
79
- expect(raws.map((r) => r.kind)).toEqual(["book", "highlight", "review"]);
80
- const merged = { events: [], persons: [], places: [], items: [], topics: [] };
81
- for (const r of raws) {
82
- const n = a.normalize(r);
83
- for (const k of Object.keys(merged)) merged[k].push(...n[k]);
84
- }
85
- const { valid, invalidReasons } = partitionBatch(merged);
86
- expect(invalidReasons).toHaveLength(0);
87
- expect(valid.events).toHaveLength(3); // book(browse) + highlight(other) + review(post)
88
- expect(valid.items).toHaveLength(1); // the book
89
- expect(valid.events.find((e) => e.subtype === "browse").content.title).toContain("人类简史");
90
- expect(valid.events.find((e) => e.subtype === "post").content.text).toBe("很有启发");
91
- });
92
-
93
- it("includeNotes:false yields only book events", async () => {
94
- const a = new WeReadAdapter();
95
- const raws = await collect(a.sync({ cookie: "x", fetch: makeFetch(ROUTES), includeNotes: false }));
96
- expect(raws.map((r) => r.kind)).toEqual(["book"]);
97
- });
98
- });
99
-
100
- describe("WeReadAdapter — snapshot mode", () => {
101
- const SNAP = {
102
- schemaVersion: 1,
103
- snapshottedAt: 1700000000000,
104
- events: [
105
- { kind: "book", id: "b1", bookId: "b1", title: "三体", author: "刘慈欣" },
106
- { kind: "highlight", id: "m1", bookId: "b1", bookTitle: "三体", markText: "不要回答", createTime: 1700000001 },
107
- ],
108
- };
109
- function snapAdapter(snap = SNAP, { exists = true } = {}) {
110
- const a = new WeReadAdapter();
111
- a._deps.fs = { existsSync: () => exists, readFileSync: () => JSON.stringify(snap), accessSync: () => {}, constants: { R_OK: 4 } };
112
- return a;
113
- }
114
-
115
- it("ingests snapshot events", async () => {
116
- const raws = await collect(snapAdapter().sync({ inputPath: "/x" }));
117
- expect(raws.map((r) => r.kind)).toEqual(["book", "highlight"]);
118
- });
119
-
120
- it("schemaVersion mismatch throws", async () => {
121
- await expect(collect(snapAdapter({ schemaVersion: 9, events: [] }).sync({ inputPath: "/x" }))).rejects.toThrow(/schemaVersion/);
122
- });
123
- });
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { WeWorkPcAdapter, NAME, VERSION } = require("../../lib/adapters/wework-pc");
6
- const { partitionBatch } = require("../../lib/batch");
7
-
8
- // fake driver answering sqlite_master + table_info + SELECT * by table
9
- function makeFakeDb(spec) {
10
- class FakeStmt {
11
- constructor(sql) {
12
- this.sql = sql;
13
- }
14
- all() {
15
- const s = this.sql;
16
- if (/type='table'/.test(s)) return (spec.tables || []).map((n) => ({ name: n }));
17
- const ti = s.match(/table_info\("(\w+)"\)/);
18
- if (ti) return spec.cols[ti[1]] || [];
19
- const fr = s.match(/FROM "(\w+)"/);
20
- if (fr) return spec.rows[fr[1]] || [];
21
- return [];
22
- }
23
- get() {
24
- return { n: 1 };
25
- }
26
- }
27
- return class FakeDb {
28
- // eslint-disable-next-line no-unused-vars
29
- constructor(_p, _o) {}
30
- prepare(sql) {
31
- return new FakeStmt(sql);
32
- }
33
- pragma() {}
34
- exec() {}
35
- close() {}
36
- };
37
- }
38
-
39
- // WeChat Work-ish message table: matches pattern + has time/sender/peer/content.
40
- const SPEC = {
41
- tables: ["chat_message", "session_meta", "sqlite_sequence"],
42
- cols: {
43
- chat_message: [
44
- { name: "localId" },
45
- { name: "createTime" },
46
- { name: "sender" },
47
- { name: "conversationId" },
48
- { name: "content" },
49
- ],
50
- session_meta: [{ name: "vid" }, { name: "name" }],
51
- },
52
- rows: {
53
- chat_message: [
54
- { localId: "m1", createTime: 1700000000, sender: "u1", conversationId: "c1", content: "项目周会 10 点" },
55
- { localId: "m2", createTime: 1700000010, sender: "u2", conversationId: "c1", content: "收到" },
56
- ],
57
- },
58
- };
59
-
60
- function adapter(spec, { exists = true } = {}) {
61
- const a = new WeWorkPcAdapter({ dbPath: "/fake.db" });
62
- a._deps.fs = { existsSync: () => exists, accessSync: () => {}, constants: { R_OK: 4 } };
63
- a._deps.dbDriverFactory = () => makeFakeDb(spec);
64
- return a;
65
- }
66
-
67
- async function collect(iter) {
68
- const out = [];
69
- for await (const r of iter) out.push(r);
70
- return out;
71
- }
72
-
73
- describe("WeWorkPcAdapter (企业微信 honest best-effort)", () => {
74
- it("exposes name/version", () => {
75
- expect(NAME).toBe("wework-pc");
76
- expect(VERSION).toBe("0.1.0");
77
- expect(new WeWorkPcAdapter().name).toBe("wework-pc");
78
- });
79
-
80
- it("no-arg construct + device-pull + legalGate + APP_NOT_INSTALLED readiness", async () => {
81
- const a = new WeWorkPcAdapter();
82
- a._deps.discoveryDeps = {
83
- fs: { existsSync: () => false, readdirSync: () => [], statSync: () => ({ size: 0 }), constants: { R_OK: 4 } },
84
- home: "/no-home",
85
- env: {},
86
- };
87
- expect(a.extractMode).toBe("device-pull");
88
- expect(a.dataDisclosure.legalGate).toBe(true);
89
- const r = await a.authenticate({ readinessOnly: true });
90
- expect(r.reason).toBe("APP_NOT_INSTALLED");
91
- });
92
-
93
- it("reads messages → valid events, platform=wework, raw preserved", async () => {
94
- const a = adapter(SPEC);
95
- const raws = await collect(a.sync({ dbPath: "/fake.db" }));
96
- expect(raws).toHaveLength(2);
97
- const merged = { events: [], persons: [], places: [], items: [], topics: [] };
98
- for (const r of raws) {
99
- const n = a.normalize(r);
100
- for (const k of Object.keys(merged)) merged[k].push(...n[k]);
101
- }
102
- const { valid, invalidReasons } = partitionBatch(merged);
103
- expect(invalidReasons).toHaveLength(0);
104
- expect(valid.events).toHaveLength(2);
105
- expect(valid.events[0].extra.platform).toBe("wework");
106
- expect(valid.events[0].extra.textResolved).toBe(true);
107
- expect(valid.events[0].extra.rawRow).toBeTruthy();
108
- });
109
-
110
- it("emits local-im-read progress diagnostic", async () => {
111
- const a = adapter(SPEC);
112
- const ev = [];
113
- await collect(a.sync({ dbPath: "/fake.db", onProgress: (e) => ev.push(e) }));
114
- const d = ev.find((e) => e.phase === "local-im-read");
115
- expect(d.messageTables).toContain("chat_message");
116
- expect(d.messageCount).toBe(2);
117
- });
118
-
119
- it("missing db yields nothing; unknown kind throws", async () => {
120
- const a = adapter(SPEC, { exists: false });
121
- expect(await collect(a.sync({ dbPath: "/no.db" }))).toHaveLength(0);
122
- expect(() => new WeWorkPcAdapter().normalize({ kind: "x", payload: { kind: "x" } })).toThrow(/unknown kind/);
123
- });
124
- });
@@ -1,192 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
4
- import { mkdtempSync, writeFileSync, rmSync, mkdirSync, utimesSync } from "node:fs";
5
- import { join } from "node:path";
6
- import { tmpdir } from "node:os";
7
-
8
- const {
9
- WinRecentAdapter,
10
- WIN_RECENT_NAME,
11
- WIN_RECENT_VERSION,
12
- } = require("../../lib/adapters/win-recent");
13
- const { assertAdapter } = require("../../lib/adapter-spec");
14
- const {
15
- EVENT_SUBTYPES,
16
- } = require("../../lib/constants");
17
- const { validateEvent } = require("../../lib/schemas");
18
-
19
- let tmpDir;
20
- let recentDir;
21
-
22
- function makeLnk(name, mtimeMs, body = "lnk-blob") {
23
- const p = join(recentDir, name);
24
- writeFileSync(p, body, "utf-8");
25
- if (mtimeMs != null) {
26
- utimesSync(p, mtimeMs / 1000, mtimeMs / 1000);
27
- }
28
- }
29
-
30
- beforeEach(() => {
31
- tmpDir = mkdtempSync(join(tmpdir(), "win-recent-test-"));
32
- recentDir = join(tmpDir, "Recent");
33
- mkdirSync(recentDir, { recursive: true });
34
- });
35
-
36
- afterEach(() => {
37
- rmSync(tmpDir, { recursive: true, force: true });
38
- });
39
-
40
- describe("WinRecentAdapter — contract + identity", () => {
41
- it("conforms to PersonalDataAdapter contract", () => {
42
- expect(assertAdapter(new WinRecentAdapter())).toEqual({ ok: true });
43
- });
44
-
45
- it("name + version + capabilities stable", () => {
46
- const a = new WinRecentAdapter();
47
- expect(a.name).toBe(WIN_RECENT_NAME);
48
- expect(a.name).toBe("win-recent");
49
- expect(a.version).toBe(WIN_RECENT_VERSION);
50
- expect(a.extractMode).toBe("file-import");
51
- expect(a.capabilities).toContain("sync:win-recent-shortcuts");
52
- });
53
- });
54
-
55
- describe("WinRecentAdapter.authenticate", () => {
56
- it("PLATFORM_UNSUPPORTED when no recentDir resolved (override null)", async () => {
57
- const a = new WinRecentAdapter();
58
- a._deps.defaultDir = () => null;
59
- const r = await a.authenticate({});
60
- expect(r.ok).toBe(false);
61
- expect(r.reason).toBe("PLATFORM_UNSUPPORTED");
62
- });
63
-
64
- it("RECENT_DIR_NOT_FOUND when dir doesn't exist", async () => {
65
- const a = new WinRecentAdapter({ recentDir: join(tmpDir, "bogus") });
66
- const r = await a.authenticate({});
67
- expect(r.ok).toBe(false);
68
- expect(r.reason).toBe("RECENT_DIR_NOT_FOUND");
69
- });
70
-
71
- it("succeeds when dir exists", async () => {
72
- const a = new WinRecentAdapter({ recentDir });
73
- const r = await a.authenticate({});
74
- expect(r.ok).toBe(true);
75
- expect(r.recentDir).toBe(recentDir);
76
- });
77
- });
78
-
79
- describe("WinRecentAdapter.sync", () => {
80
- it("yields one raw per .lnk, sorted mtime ascending", async () => {
81
- makeLnk("zebra.lnk", 1_700_000_003_000);
82
- makeLnk("apple.lnk", 1_700_000_001_000);
83
- makeLnk("mango.lnk", 1_700_000_002_000);
84
- const a = new WinRecentAdapter({ recentDir });
85
- const raws = [];
86
- for await (const r of a.sync()) raws.push(r);
87
- expect(raws).toHaveLength(3);
88
- expect(raws[0].payload.name).toBe("apple");
89
- expect(raws[1].payload.name).toBe("mango");
90
- expect(raws[2].payload.name).toBe("zebra");
91
- expect(raws[0].payload.mtimeMs).toBe(1_700_000_001_000);
92
- });
93
-
94
- it("skips non-.lnk files and AutomaticDestinations / CustomDestinations subdirs", async () => {
95
- makeLnk("a.lnk", 1_700_000_001_000);
96
- makeLnk("readme.txt", 1_700_000_002_000); // non-.lnk
97
- mkdirSync(join(recentDir, "AutomaticDestinations"), { recursive: true });
98
- writeFileSync(
99
- join(recentDir, "AutomaticDestinations", "deep.lnk"),
100
- "should-not-be-found",
101
- );
102
- mkdirSync(join(recentDir, "CustomDestinations"), { recursive: true });
103
- const a = new WinRecentAdapter({ recentDir });
104
- const raws = [];
105
- for await (const r of a.sync()) raws.push(r);
106
- expect(raws).toHaveLength(1);
107
- expect(raws[0].payload.name).toBe("a");
108
- });
109
-
110
- it("respects since filter (epoch ms)", async () => {
111
- makeLnk("old.lnk", 1_700_000_001_000);
112
- makeLnk("new.lnk", 1_700_000_005_000);
113
- const a = new WinRecentAdapter({ recentDir });
114
- const raws = [];
115
- for await (const r of a.sync({ since: 1_700_000_003_000 })) raws.push(r);
116
- expect(raws.map((r) => r.payload.name)).toEqual(["new"]);
117
- });
118
-
119
- it("respects limit", async () => {
120
- for (let i = 0; i < 10; i++) makeLnk(`f${i}.lnk`, 1_700_000_000_000 + i * 1000);
121
- const a = new WinRecentAdapter({ recentDir });
122
- const raws = [];
123
- for await (const r of a.sync({ limit: 4 })) raws.push(r);
124
- expect(raws).toHaveLength(4);
125
- });
126
-
127
- it("originalId folds in mtime so same file at new mtime gets a new event", async () => {
128
- makeLnk("foo.lnk", 1_700_000_001_000);
129
- const a = new WinRecentAdapter({ recentDir });
130
- const raws1 = [];
131
- for await (const r of a.sync()) raws1.push(r);
132
- const id1 = raws1[0].originalId;
133
- // Re-touch with a newer mtime
134
- makeLnk("foo.lnk", 1_700_000_009_000);
135
- const raws2 = [];
136
- for await (const r of a.sync()) raws2.push(r);
137
- const id2 = raws2[0].originalId;
138
- expect(id1).not.toBe(id2);
139
- expect(id2).toContain("1700000009000");
140
- });
141
- });
142
-
143
- describe("WinRecentAdapter.normalize", () => {
144
- it("maps recent-file to Event(OTHER) with '打开了 X' title", () => {
145
- const a = new WinRecentAdapter();
146
- const { events } = a.normalize({
147
- kind: "recent-file",
148
- originalId: "win-recent:C:\\Users\\u\\Recent\\foo.lnk:1700000001000",
149
- capturedAt: 1_700_000_005_000,
150
- payload: {
151
- name: "foo",
152
- mtimeMs: 1_700_000_001_000,
153
- size: 1024,
154
- lnkPath: "C:\\Users\\u\\Recent\\foo.lnk",
155
- },
156
- });
157
- expect(events).toHaveLength(1);
158
- const e = events[0];
159
- expect(e.subtype).toBe(EVENT_SUBTYPES.OTHER);
160
- expect(e.content.title).toBe("打开了 foo");
161
- expect(e.content.text).toBe("foo");
162
- expect(e.actor).toBe("self");
163
- expect(e.occurredAt).toBe(1_700_000_001_000);
164
- expect(e.extra.kind).toBe("recent-file");
165
- expect(e.extra.targetName).toBe("foo");
166
- expect(e.extra.source).toBe("win-recent");
167
- expect(validateEvent(e).valid).toBe(true);
168
- });
169
-
170
- it("truncates long target names in title", () => {
171
- const a = new WinRecentAdapter();
172
- const longName = "x".repeat(120);
173
- const { events } = a.normalize({
174
- kind: "recent-file",
175
- originalId: "win-recent:long",
176
- capturedAt: 1_700_000_000_000,
177
- payload: {
178
- name: longName,
179
- mtimeMs: 1_700_000_000_000,
180
- },
181
- });
182
- // Title is "打开了 " (4 chars) + name; name truncated to 70 + "…"
183
- expect(events[0].content.title.endsWith("…")).toBe(true);
184
- expect(events[0].content.text).toBe(longName); // full name preserved in text
185
- });
186
-
187
- it("throws on unknown raw.kind", () => {
188
- expect(() => new WinRecentAdapter().normalize({ kind: "bogus", payload: {} })).toThrow(
189
- /unknown raw\.kind=bogus/,
190
- );
191
- });
192
- });