@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,125 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
-
9
- const my = require("../../lib/adapters/health-meiyou");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-my-${crypto.randomUUID()}.json`);
13
- fs.writeFileSync(p, content, "utf-8");
14
- return p;
15
- }
16
- async function collect(gen) {
17
- const out = [];
18
- for await (const x of gen) out.push(x);
19
- return out;
20
- }
21
-
22
- const COOKIES = "myclient_id=abc; sid=xyz";
23
-
24
- describe("health-meiyou mappers", () => {
25
- it("name/version", () => {
26
- expect(my.NAME).toBe("health-meiyou");
27
- expect(my.VERSION).toBe("0.1.0");
28
- });
29
- it("mapPeriod / mapRecord field aliases; no id → null", () => {
30
- const p = my.mapPeriod({ record_id: "P1", start_date: 1716383000, end_date: 1716800000, cycle_length: 28, period_length: 5 });
31
- expect(p).toMatchObject({ recordId: "P1", cycleLength: 28, periodLength: 5 });
32
- expect(p.startMs).toBe(1716383000000);
33
- expect(my.mapPeriod({})).toBe(null);
34
- const r = my.mapRecord({ id: "R1", record_type: "mood", date: 1716383000, value: "开心", remark: "今天不错" });
35
- expect(r).toMatchObject({ recordId: "R1", recordType: "mood", value: "开心", note: "今天不错" });
36
- expect(my.mapRecord({ note: "noid" })).toBe(null);
37
- });
38
- it("extractList tolerant", () => {
39
- expect(my.extractList({ list: [{ id: 1 }] })).toHaveLength(1);
40
- expect(my.extractList({ data: { calendar: [{ id: 1 }] } })).toHaveLength(1);
41
- expect(my.extractList({})).toEqual([]);
42
- });
43
- });
44
-
45
- describe("MeiyouAdapter (snapshot + cookie-api)", () => {
46
- const SNAP = JSON.stringify({
47
- schemaVersion: 1,
48
- snapshottedAt: 1716383000000,
49
- account: { userId: "u1" },
50
- events: [
51
- { kind: "period", id: "p-P1", recordId: "P1", startDate: 1716383000, endDate: 1716800000, cycleLength: 28, periodLength: 5 },
52
- { kind: "record", id: "r-R1", recordId: "R1", recordType: "mood", date: 1716383000, value: "开心" },
53
- ],
54
- });
55
-
56
- it("snapshot sync + normalize → period + record events", async () => {
57
- const p = writeTmp(SNAP);
58
- try {
59
- const a = new my.MeiyouAdapter();
60
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
61
- const items = await collect(a.sync({ inputPath: p }));
62
- expect(items).toHaveLength(2);
63
- const period = a.normalize(items[0]);
64
- expect(period.events[0].subtype).toBe("other");
65
- expect(period.events[0].content.title).toBe("经期记录");
66
- expect(period.events[0].extra.cycleLength).toBe(28);
67
- expect(items[0].originalId).toBe("meiyou:period:P1");
68
- const record = a.normalize(items[1]);
69
- expect(record.events[0].extra.recordType).toBe("mood");
70
- expect(record.events[0].extra.value).toBe("开心");
71
- expect(items[1].originalId).toBe("meiyou:record:R1");
72
- } finally {
73
- fs.unlinkSync(p);
74
- }
75
- });
76
-
77
- it("dataDisclosure: high sensitivity + legalGate (reproductive health)", () => {
78
- const a = new my.MeiyouAdapter();
79
- expect(a.dataDisclosure.sensitivity).toBe("high");
80
- expect(a.dataDisclosure.legalGate).toBe(true);
81
- });
82
-
83
- it("include filter can exclude a kind", async () => {
84
- const p = writeTmp(SNAP);
85
- try {
86
- const a = new my.MeiyouAdapter();
87
- const items = await collect(a.sync({ inputPath: p, include: { record: false } }));
88
- expect(items).toHaveLength(1);
89
- expect(items[0].kind).toBe("period");
90
- } finally {
91
- fs.unlinkSync(p);
92
- }
93
- });
94
-
95
- it("cookie-api: best-effort fetch both kinds + unverified flag + sign seam", async () => {
96
- const calls = [];
97
- let signed = 0;
98
- const a = new my.MeiyouAdapter({
99
- account: { cookies: COOKIES, userId: "u1" },
100
- signProvider: async () => {
101
- signed += 1;
102
- return "sig";
103
- },
104
- fetchFn: async ({ url, query }) => {
105
- calls.push({ url, page: query.page });
106
- if (query.page > 1) return { list: [] };
107
- if (url.includes("/period")) return { list: [{ recordId: "P9", startDate: 1716383000, cycleLength: 30 }] };
108
- return { list: [{ recordId: "R9", recordType: "weight", date: 1716383000, value: 55 }] };
109
- },
110
- });
111
- const auth = await a.authenticate();
112
- expect(auth).toMatchObject({ ok: true, mode: "cookie", unverified: true });
113
- const items = await collect(a.sync({}));
114
- expect(items).toHaveLength(2);
115
- expect(items.map((i) => i.originalId).sort()).toEqual(["meiyou:period:P9", "meiyou:record:R9"]);
116
- expect(signed).toBeGreaterThan(0);
117
- });
118
-
119
- it("default fetch throws; no input throws", async () => {
120
- const a = new my.MeiyouAdapter({ account: { cookies: COOKIES } });
121
- await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
122
- const b = new my.MeiyouAdapter();
123
- await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
124
- });
125
- });
@@ -1,264 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
4
- import { mkdtempSync, rmSync, mkdirSync, writeFileSync, utimesSync } from "node:fs";
5
- import { join } from "node:path";
6
- import { tmpdir } from "node:os";
7
-
8
- const {
9
- LocalFilesAdapter,
10
- LOCAL_FILES_NAME,
11
- LOCAL_FILES_VERSION,
12
- } = require("../../lib/adapters/local-files");
13
- const { assertAdapter } = require("../../lib/adapter-spec");
14
- const { EVENT_SUBTYPES } = require("../../lib/constants");
15
- const { validateEvent } = require("../../lib/schemas");
16
-
17
- let tmpDir;
18
-
19
- function makeFile(rel, content, mtimeMs) {
20
- const p = join(tmpDir, rel);
21
- mkdirSync(join(tmpDir, rel, ".."), { recursive: true });
22
- writeFileSync(p, content, "utf-8");
23
- if (mtimeMs) utimesSync(p, mtimeMs / 1000, mtimeMs / 1000);
24
- return p;
25
- }
26
-
27
- beforeEach(() => {
28
- tmpDir = mkdtempSync(join(tmpdir(), "local-files-test-"));
29
- });
30
-
31
- afterEach(() => {
32
- rmSync(tmpDir, { recursive: true, force: true });
33
- });
34
-
35
- describe("LocalFilesAdapter — contract + identity", () => {
36
- it("conforms to PersonalDataAdapter contract", () => {
37
- expect(assertAdapter(new LocalFilesAdapter())).toEqual({ ok: true });
38
- });
39
-
40
- it("identifies as local-files with sync:local-file-walk capability", () => {
41
- const a = new LocalFilesAdapter();
42
- expect(a.name).toBe(LOCAL_FILES_NAME);
43
- expect(a.name).toBe("local-files");
44
- expect(a.version).toBe(LOCAL_FILES_VERSION);
45
- expect(a.capabilities).toContain("sync:local-file-walk");
46
- });
47
- });
48
-
49
- describe("LocalFilesAdapter.sync", () => {
50
- it("yields one row per file across multiple roots", async () => {
51
- const r1 = join(tmpDir, "root1");
52
- const r2 = join(tmpDir, "root2");
53
- mkdirSync(r1);
54
- mkdirSync(r2);
55
- makeFile("root1/a.txt", "a", 1_700_000_001_000);
56
- makeFile("root1/b.md", "b", 1_700_000_002_000);
57
- makeFile("root2/c.pdf", "c", 1_700_000_003_000);
58
- const a = new LocalFilesAdapter({ roots: [r1, r2] });
59
- const raws = [];
60
- for await (const r of a.sync()) raws.push(r);
61
- expect(raws).toHaveLength(3);
62
- expect(raws.every((r) => r.kind === "local-file")).toBe(true);
63
- const names = raws.map((r) => r.payload.name).sort();
64
- expect(names).toEqual(["a.txt", "b.md", "c.pdf"]);
65
- });
66
-
67
- it("walks subdirectories within maxDepth", async () => {
68
- const r = join(tmpDir, "r");
69
- mkdirSync(r);
70
- makeFile("r/sub/nested/deep.txt", "x", 1_700_000_001_000);
71
- const a = new LocalFilesAdapter({ roots: [r] });
72
- const raws = [];
73
- for await (const x of a.sync()) raws.push(x);
74
- expect(raws).toHaveLength(1);
75
- expect(raws[0].payload.name).toBe("deep.txt");
76
- });
77
-
78
- it("excludes xwechat_files / WXWork / node_modules / .git by default", async () => {
79
- const r = join(tmpDir, "r");
80
- mkdirSync(r);
81
- makeFile("r/normal.txt", "ok", 1_700_000_001_000);
82
- makeFile("r/xwechat_files/x.txt", "skip", 1_700_000_001_000);
83
- makeFile("r/WXWork/y.txt", "skip", 1_700_000_001_000);
84
- makeFile("r/node_modules/lib/index.js", "skip", 1_700_000_001_000);
85
- makeFile("r/.git/config", "skip", 1_700_000_001_000);
86
- const a = new LocalFilesAdapter({ roots: [r] });
87
- const raws = [];
88
- for await (const x of a.sync()) raws.push(x);
89
- expect(raws.map((r) => r.payload.name)).toEqual(["normal.txt"]);
90
- });
91
-
92
- it("custom excludes override defaults", async () => {
93
- const r = join(tmpDir, "r");
94
- mkdirSync(r);
95
- makeFile("r/.git/config", "kept-now", 1_700_000_001_000);
96
- makeFile("r/build/out.txt", "skipped-now", 1_700_000_001_000);
97
- const a = new LocalFilesAdapter({ roots: [r], excludes: ["build"] });
98
- const raws = [];
99
- for await (const x of a.sync()) raws.push(x);
100
- // .git is hidden (leading '.') so still skipped even without default rule
101
- expect(raws.map((r) => r.payload.name)).toEqual([]);
102
- });
103
-
104
- it("skips hidden files / dirs (leading '.')", async () => {
105
- const r = join(tmpDir, "r");
106
- mkdirSync(r);
107
- makeFile("r/.hidden", "skip", 1_700_000_001_000);
108
- makeFile("r/.cache/sub.txt", "skip", 1_700_000_001_000);
109
- makeFile("r/visible.txt", "ok", 1_700_000_001_000);
110
- const a = new LocalFilesAdapter({ roots: [r] });
111
- const raws = [];
112
- for await (const x of a.sync()) raws.push(x);
113
- expect(raws.map((r) => r.payload.name)).toEqual(["visible.txt"]);
114
- });
115
-
116
- it("respects since filter (file mtime granularity)", async () => {
117
- const r = join(tmpDir, "r");
118
- mkdirSync(r);
119
- makeFile("r/old.txt", "x", 1_700_000_001_000);
120
- makeFile("r/new.txt", "x", 1_700_000_005_000);
121
- const a = new LocalFilesAdapter({ roots: [r] });
122
- const raws = [];
123
- for await (const x of a.sync({ since: 1_700_000_003_000 })) raws.push(x);
124
- expect(raws.map((r) => r.payload.name)).toEqual(["new.txt"]);
125
- });
126
-
127
- it("respects limit", async () => {
128
- const r = join(tmpDir, "r");
129
- mkdirSync(r);
130
- for (let i = 0; i < 5; i++) makeFile(`r/f${i}.txt`, "x", 1_700_000_001_000);
131
- const a = new LocalFilesAdapter({ roots: [r] });
132
- const raws = [];
133
- for await (const x of a.sync({ limit: 2 })) raws.push(x);
134
- expect(raws).toHaveLength(2);
135
- });
136
-
137
- it("missing roots silently produce nothing", async () => {
138
- const a = new LocalFilesAdapter({ roots: [join(tmpDir, "nonexistent")] });
139
- const raws = [];
140
- for await (const x of a.sync()) raws.push(x);
141
- expect(raws).toHaveLength(0);
142
- });
143
-
144
- it("originalId encodes path + mtime so re-saved files dedupe per mtime", async () => {
145
- const r = join(tmpDir, "r");
146
- mkdirSync(r);
147
- const p = makeFile("r/a.txt", "x", 1_700_000_001_000);
148
- const a = new LocalFilesAdapter({ roots: [r] });
149
- const first = [];
150
- for await (const x of a.sync()) first.push(x);
151
- expect(first[0].originalId).toBe(`local-file:${p}:1700000001000`);
152
- // change mtime -> new originalId so adapter does not collapse history
153
- utimesSync(p, 1_700_000_009 / 1000, 1_700_000_009);
154
- const second = [];
155
- for await (const x of a.sync()) second.push(x);
156
- expect(second[0].originalId).not.toBe(first[0].originalId);
157
- });
158
- });
159
-
160
- describe("LocalFilesAdapter.authenticate + healthCheck", () => {
161
- it("authenticate returns ok=true with resolved roots when defaults exist", async () => {
162
- const r = join(tmpDir, "r");
163
- mkdirSync(r);
164
- const a = new LocalFilesAdapter({ roots: [r] });
165
- const result = await a.authenticate();
166
- expect(result.ok).toBe(true);
167
- expect(result.mode).toBe("file-import");
168
- expect(result.roots).toEqual([r]);
169
- });
170
-
171
- it("authenticate returns NO_DATA_ROOTS when roots is empty", async () => {
172
- const a = new LocalFilesAdapter({ roots: [] });
173
- // Constructor coerces empty array to override=null, so defaults kick in.
174
- // Force empty roots via context arg path is not exposed; verify the
175
- // adapter at least returns ok when defaults present. This test verifies
176
- // the no-roots branch by stubbing defaultRoots to return [].
177
- a._deps.defaultRoots = () => [];
178
- const result = await a.authenticate();
179
- expect(result.ok).toBe(false);
180
- expect(result.reason).toBe("NO_DATA_ROOTS");
181
- });
182
-
183
- it("healthCheck always returns ok=true (file-import adapter has no live dep)", async () => {
184
- const a = new LocalFilesAdapter();
185
- const r = await a.healthCheck();
186
- expect(r.ok).toBe(true);
187
- expect(typeof r.lastChecked).toBe("number");
188
- });
189
- });
190
-
191
- describe("LocalFilesAdapter.normalize", () => {
192
- it("maps local-file → Event(OTHER) with [file] title prefix", () => {
193
- const a = new LocalFilesAdapter();
194
- const { events } = a.normalize({
195
- kind: "local-file",
196
- originalId: "local-file:/home/u/Documents/report.pdf:1700000005000",
197
- capturedAt: 1_700_000_010_000,
198
- payload: {
199
- path: "/home/u/Documents/report.pdf",
200
- name: "report.pdf",
201
- ext: "pdf",
202
- size: 4096,
203
- mtimeMs: 1_700_000_005_000,
204
- root: "/home/u/Documents",
205
- },
206
- });
207
- expect(events).toHaveLength(1);
208
- const e = events[0];
209
- expect(e.subtype).toBe(EVENT_SUBTYPES.OTHER);
210
- expect(e.actor).toBe("self");
211
- expect(e.content.title).toBe("[file] report.pdf");
212
- expect(e.content.text).toBe("/home/u/Documents/report.pdf");
213
- expect(e.occurredAt).toBe(1_700_000_005_000);
214
- expect(e.extra.kind).toBe("local-file");
215
- expect(e.extra.ext).toBe("pdf");
216
- expect(e.extra.size).toBe(4096);
217
- expect(validateEvent(e).valid).toBe(true);
218
- });
219
-
220
- it("truncates long filenames in title (keeps full path in text)", () => {
221
- const a = new LocalFilesAdapter();
222
- const longName = "x".repeat(300) + ".txt";
223
- const { events } = a.normalize({
224
- kind: "local-file",
225
- originalId: "local-file:/r/big.txt:1700000000000",
226
- capturedAt: 1_700_000_000_000,
227
- payload: {
228
- path: "/r/" + longName,
229
- name: longName,
230
- ext: "txt",
231
- size: 0,
232
- mtimeMs: 1_700_000_000_000,
233
- root: "/r",
234
- },
235
- });
236
- expect(events[0].content.title.length).toBeLessThanOrEqual(101);
237
- expect(events[0].content.title.endsWith("…")).toBe(true);
238
- expect(events[0].content.text).toContain(longName);
239
- });
240
-
241
- it("uses '(无名)' for empty filename", () => {
242
- const a = new LocalFilesAdapter();
243
- const { events } = a.normalize({
244
- kind: "local-file",
245
- originalId: "local-file::1700000000000",
246
- capturedAt: 1_700_000_000_000,
247
- payload: {
248
- path: "",
249
- name: "",
250
- ext: "",
251
- size: 0,
252
- mtimeMs: 1_700_000_000_000,
253
- root: "",
254
- },
255
- });
256
- expect(events[0].content.title).toBe("[file] (无名)");
257
- });
258
-
259
- it("throws on unknown raw.kind", () => {
260
- expect(() => new LocalFilesAdapter().normalize({ kind: "bogus" })).toThrow(
261
- /unknown raw\.kind=bogus/,
262
- );
263
- });
264
- });
@@ -1,154 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
-
5
- const { DingTalkPcAdapter } = require("../../lib/adapters/dingtalk-pc");
6
- const { FeishuPcAdapter } = require("../../lib/adapters/feishu-pc");
7
- const { readLocalImDb } = require("../../lib/adapters/_local-im-db-reader");
8
- const { partitionBatch } = require("../../lib/batch");
9
-
10
- // fake driver answering sqlite_master + table_info + SELECT * by table
11
- function makeFakeDb(spec) {
12
- class FakeStmt {
13
- constructor(sql) {
14
- this.sql = sql;
15
- }
16
- all() {
17
- const s = this.sql;
18
- if (/type='table'/.test(s)) return (spec.tables || []).map((n) => ({ name: n }));
19
- const ti = s.match(/table_info\("(\w+)"\)/);
20
- if (ti) return spec.cols[ti[1]] || [];
21
- const fr = s.match(/FROM "(\w+)"/);
22
- if (fr) return spec.rows[fr[1]] || [];
23
- return [];
24
- }
25
- get() {
26
- return { n: 1 };
27
- }
28
- }
29
- return class FakeDb {
30
- // eslint-disable-next-line no-unused-vars
31
- constructor(_p, _o) {}
32
- prepare(sql) {
33
- return new FakeStmt(sql);
34
- }
35
- pragma() {}
36
- exec() {}
37
- close() {}
38
- };
39
- }
40
-
41
- const SPEC = {
42
- // msg_table matches + has time/content → ingested
43
- // msg_meta matches pattern but no time/content → skipped (loud diagnostic)
44
- // contact_meta doesn't match pattern → not scanned
45
- // sqlite_sequence → filtered (sqlite_*)
46
- tables: ["msg_table", "msg_meta", "contact_meta", "sqlite_sequence"],
47
- cols: {
48
- msg_table: [
49
- { name: "msgId" },
50
- { name: "createTime" },
51
- { name: "senderId" },
52
- { name: "conversationId" },
53
- { name: "content" },
54
- ],
55
- msg_meta: [{ name: "uid" }, { name: "name" }],
56
- contact_meta: [{ name: "uid" }, { name: "name" }],
57
- },
58
- rows: {
59
- msg_table: [
60
- { msgId: "m1", createTime: 1700000000, senderId: "u1", conversationId: "c1", content: "开会通知" },
61
- { msgId: "m2", createTime: 1700000010, senderId: "u2", conversationId: "c1", content: "收到" },
62
- ],
63
- },
64
- };
65
-
66
- // opaque schema — time resolves, but body is a BLOB → text null, raw kept
67
- const OPAQUE_SPEC = {
68
- tables: ["chat_msg"],
69
- cols: { chat_msg: [{ name: "id" }, { name: "timestamp" }, { name: "body" }] },
70
- rows: { chat_msg: [{ id: 7, timestamp: 1700000000, body: Buffer.from([1, 2]) }] },
71
- };
72
-
73
- function adapter(Cls, spec, { exists = true } = {}) {
74
- const a = new Cls({ dbPath: "/fake.db" });
75
- a._deps.fs = { existsSync: () => exists, accessSync: () => {}, constants: { R_OK: 4 } };
76
- a._deps.dbDriverFactory = () => makeFakeDb(spec);
77
- return a;
78
- }
79
-
80
- async function collect(iter) {
81
- const out = [];
82
- for await (const r of iter) out.push(r);
83
- return out;
84
- }
85
-
86
- describe("readLocalImDb (generic honest reader)", () => {
87
- it("discovers message tables, skips metadata + sqlite_*", () => {
88
- const { messages, diagnostic } = readLocalImDb("/x", { _databaseClass: makeFakeDb(SPEC) });
89
- expect(diagnostic.messageTables).toEqual(["msg_table"]);
90
- expect(diagnostic.skippedTables).toEqual(["msg_meta"]);
91
- expect(messages).toHaveLength(2);
92
- expect(messages[0].text).toBe("开会通知");
93
- expect(messages[0].createdTimeMs).toBe(1700000000000);
94
- });
95
-
96
- it("opaque body → text null but rawRow preserved + loud diagnostic", () => {
97
- const { messages, diagnostic } = readLocalImDb("/x", { _databaseClass: makeFakeDb(OPAQUE_SPEC) });
98
- expect(messages).toHaveLength(1);
99
- expect(messages[0].text).toBeNull();
100
- expect(messages[0].rawRow).toBeTruthy();
101
- expect(diagnostic.textCount).toBe(0);
102
- expect(diagnostic.messageTables).toEqual(["chat_msg"]);
103
- });
104
- });
105
-
106
- describe.each([
107
- ["DingTalkPcAdapter", DingTalkPcAdapter, "dingtalk"],
108
- ["FeishuPcAdapter", FeishuPcAdapter, "feishu"],
109
- ])("%s (honest best-effort)", (_label, Cls, platform) => {
110
- it("no-arg construct + APP_NOT_INSTALLED when nothing discoverable + legalGate", async () => {
111
- const a = new Cls();
112
- a._deps.discoveryDeps = {
113
- fs: { existsSync: () => false, readdirSync: () => [], statSync: () => ({ size: 0 }), constants: { R_OK: 4 } },
114
- home: "/no-home",
115
- env: {},
116
- };
117
- expect(a.extractMode).toBe("device-pull");
118
- expect(a.dataDisclosure.legalGate).toBe(true);
119
- const r = await a.authenticate({ readinessOnly: true });
120
- expect(r.reason).toBe("APP_NOT_INSTALLED");
121
- });
122
-
123
- it("reads messages → valid events, platform tag, raw preserved", async () => {
124
- const a = adapter(Cls, SPEC);
125
- const raws = await collect(a.sync({ dbPath: "/fake.db" }));
126
- expect(raws).toHaveLength(2);
127
- const merged = { events: [], persons: [], places: [], items: [], topics: [] };
128
- for (const r of raws) {
129
- const n = a.normalize(r);
130
- for (const k of Object.keys(merged)) merged[k].push(...n[k]);
131
- }
132
- const { valid, invalidReasons } = partitionBatch(merged);
133
- expect(invalidReasons).toHaveLength(0);
134
- expect(valid.events).toHaveLength(2);
135
- expect(valid.events[0].extra.platform).toBe(platform);
136
- expect(valid.events[0].extra.textResolved).toBe(true);
137
- expect(valid.events[0].extra.rawRow).toBeTruthy();
138
- });
139
-
140
- it("emits local-im-read progress diagnostic", async () => {
141
- const a = adapter(Cls, SPEC);
142
- const ev = [];
143
- await collect(a.sync({ dbPath: "/fake.db", onProgress: (e) => ev.push(e) }));
144
- const d = ev.find((e) => e.phase === "local-im-read");
145
- expect(d.messageTables).toContain("msg_table");
146
- expect(d.messageCount).toBe(2);
147
- });
148
-
149
- it("missing db yields nothing; unknown kind throws", async () => {
150
- const a = adapter(Cls, SPEC, { exists: false });
151
- expect(await collect(a.sync({ dbPath: "/no.db" }))).toHaveLength(0);
152
- expect(() => new Cls().normalize({ kind: "x", payload: { kind: "x" } })).toThrow(/unknown kind/);
153
- });
154
- });