@chainlesschain/personal-data-hub 0.4.28 → 0.4.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +13 -5
  2. package/lib/adapters/social-douyin-adb/usage-profile-reader.js +253 -0
  3. package/lib/adapters/social-douyin-adb/watch-history-reader.js +104 -31
  4. package/lib/adapters/social-toutiao-adb/article-reader.js +202 -0
  5. package/lib/analysis-skills/overview.js +24 -4
  6. package/lib/analysis-skills/spending.js +63 -2
  7. package/lib/analysis-skills/timeline.js +11 -6
  8. package/lib/prompt-builder.js +15 -1
  9. package/lib/query-parser.js +38 -8
  10. package/package.json +4 -1
  11. package/__tests__/adapter-guide.test.js +0 -47
  12. package/__tests__/adapter-spec.test.js +0 -78
  13. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  14. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  15. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  16. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  17. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  18. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  19. package/__tests__/adapters/apple-health.test.js +0 -95
  20. package/__tests__/adapters/bank-family.test.js +0 -125
  21. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  22. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  23. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  24. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  25. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  26. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  27. package/__tests__/adapters/doc-platforms.test.js +0 -177
  28. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  29. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  30. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  31. package/__tests__/adapters/email-adapter.test.js +0 -742
  32. package/__tests__/adapters/email-classifier.test.js +0 -347
  33. package/__tests__/adapters/email-imap-session.test.js +0 -334
  34. package/__tests__/adapters/email-parser.test.js +0 -244
  35. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  36. package/__tests__/adapters/email-providers.test.js +0 -84
  37. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  38. package/__tests__/adapters/email-templates.test.js +0 -822
  39. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  40. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  41. package/__tests__/adapters/finance-dcep.test.js +0 -74
  42. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  43. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  44. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  45. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  46. package/__tests__/adapters/git-activity.test.js +0 -222
  47. package/__tests__/adapters/gov-12123.test.js +0 -103
  48. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  49. package/__tests__/adapters/gov-tax.test.js +0 -135
  50. package/__tests__/adapters/health-meiyou.test.js +0 -125
  51. package/__tests__/adapters/local-files.test.js +0 -264
  52. package/__tests__/adapters/local-im-pc.test.js +0 -154
  53. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  54. package/__tests__/adapters/music-kugou.test.js +0 -187
  55. package/__tests__/adapters/music-qq.test.js +0 -112
  56. package/__tests__/adapters/netease-music-live.test.js +0 -244
  57. package/__tests__/adapters/netease-music.test.js +0 -74
  58. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  59. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  60. package/__tests__/adapters/reading-family.test.js +0 -108
  61. package/__tests__/adapters/recruit-boss.test.js +0 -180
  62. package/__tests__/adapters/shell-history.test.js +0 -180
  63. package/__tests__/adapters/shopping-base.test.js +0 -179
  64. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  65. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  66. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  67. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  68. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  69. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  70. package/__tests__/adapters/social-csdn.test.js +0 -175
  71. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  72. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  73. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  74. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  75. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  76. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  77. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -192
  78. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  79. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  80. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  81. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  82. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  83. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  84. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  85. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  86. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  87. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  88. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  89. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  90. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  91. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  92. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  93. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  94. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  95. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  96. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  97. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  98. package/__tests__/adapters/social-zhihu.test.js +0 -246
  99. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  100. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  101. package/__tests__/adapters/system-data-android.test.js +0 -519
  102. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  103. package/__tests__/adapters/travel-12306.test.js +0 -512
  104. package/__tests__/adapters/travel-amap.test.js +0 -219
  105. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  106. package/__tests__/adapters/travel-base.test.js +0 -205
  107. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  108. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  109. package/__tests__/adapters/travel-didi.test.js +0 -204
  110. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  111. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  112. package/__tests__/adapters/video-platforms.test.js +0 -152
  113. package/__tests__/adapters/video-xigua.test.js +0 -106
  114. package/__tests__/adapters/vscode.test.js +0 -299
  115. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  116. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  117. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  118. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  119. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  120. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  121. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  122. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  123. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  124. package/__tests__/adapters/weread.test.js +0 -123
  125. package/__tests__/adapters/wework-pc.test.js +0 -124
  126. package/__tests__/adapters/win-recent.test.js +0 -192
  127. package/__tests__/analysis-skills.test.js +0 -679
  128. package/__tests__/analysis.test.js +0 -1845
  129. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  130. package/__tests__/batch.test.js +0 -133
  131. package/__tests__/bridges-cc-kg.test.js +0 -231
  132. package/__tests__/bridges-cc-llm.test.js +0 -191
  133. package/__tests__/bridges-cc-rag.test.js +0 -162
  134. package/__tests__/categories.test.js +0 -92
  135. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  136. package/__tests__/e2e/full-user-journey.test.js +0 -188
  137. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  138. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  139. package/__tests__/entity-resolver-stages.test.js +0 -411
  140. package/__tests__/entity-resolver-vault.test.js +0 -249
  141. package/__tests__/entity-resolver.test.js +0 -526
  142. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  143. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  144. package/__tests__/ids.test.js +0 -45
  145. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  146. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  147. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  148. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  149. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  150. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  151. package/__tests__/key-providers.test.js +0 -126
  152. package/__tests__/kg-derive.test.js +0 -219
  153. package/__tests__/llm-client.test.js +0 -122
  154. package/__tests__/longtail-adapters.test.js +0 -281
  155. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  156. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  157. package/__tests__/mobile-extractor.test.js +0 -288
  158. package/__tests__/mock-adapter.test.js +0 -93
  159. package/__tests__/prompt-builder.test.js +0 -249
  160. package/__tests__/query-parser.test.js +0 -302
  161. package/__tests__/rag-derive.test.js +0 -169
  162. package/__tests__/registry-readiness.test.js +0 -292
  163. package/__tests__/registry.test.js +0 -420
  164. package/__tests__/salvage-ingest.test.js +0 -97
  165. package/__tests__/schemas.test.js +0 -331
  166. package/__tests__/shopping-adapters.test.js +0 -392
  167. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  168. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  169. package/__tests__/shopping-snapshot.test.js +0 -438
  170. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  171. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  172. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  173. package/__tests__/sidecar-supervisor.test.js +0 -128
  174. package/__tests__/sign-providers.test.js +0 -62
  175. package/__tests__/social-adapters.test.js +0 -280
  176. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  177. package/__tests__/social-douban-snapshot.test.js +0 -351
  178. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  179. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  180. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  181. package/__tests__/social-douyin-snapshot.test.js +0 -256
  182. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  183. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  184. package/__tests__/social-weibo-snapshot.test.js +0 -234
  185. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  186. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  187. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  188. package/__tests__/travel-adapters.test.js +0 -483
  189. package/__tests__/travel-maps-snapshot.test.js +0 -426
  190. package/__tests__/vault-driver-error.test.js +0 -74
  191. package/__tests__/vault-search-helpers.test.js +0 -104
  192. package/__tests__/vault-search.test.js +0 -423
  193. package/__tests__/vault.test.js +0 -767
  194. package/__tests__/wechat-adapter.test.js +0 -594
  195. package/__tests__/whatsapp-adapter.test.js +0 -138
  196. package/scripts/_make-fixture-all.js +0 -126
  197. package/scripts/_make-fixture-contacts.js +0 -84
  198. package/scripts/evaluate-entity-resolver.js +0 -213
  199. package/scripts/run-native-tests-sandbox.sh +0 -55
  200. package/scripts/smoke-phase-5-5.js +0 -196
  201. package/scripts/smoke-phase-5-7.js +0 -181
  202. package/scripts/smoke-system-data-contacts.js +0 -309
  203. package/scripts/smoke-system-data.js +0 -312
  204. package/vitest.config.js +0 -88
@@ -1,152 +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 iqiyi = require("../../lib/adapters/video-iqiyi");
10
- const tv = require("../../lib/adapters/video-tencent");
11
-
12
- function writeTmp(content) {
13
- const p = path.join(os.tmpdir(), `cc-vid-${crypto.randomUUID()}.json`);
14
- fs.writeFileSync(p, content, "utf-8");
15
- return p;
16
- }
17
- async function collect(gen) {
18
- const out = [];
19
- for await (const x of gen) out.push(x);
20
- return out;
21
- }
22
-
23
- const COOKIES = "P00001=abc; QC005=xyz";
24
-
25
- describe("video-iqiyi mappers", () => {
26
- it("name/version + mapItem (channel code → category)", () => {
27
- expect(iqiyi.NAME).toBe("video-iqiyi");
28
- const rec = iqiyi.mapItem({ tvId: "100", albumName: "庆余年", channelId: 2, videoName: "庆余年", addtime: 1716300000, videoDuration: 2700 });
29
- expect(rec).toMatchObject({ videoId: "100", title: "庆余年", category: "tv", durationSec: 2700 });
30
- expect(rec.occurredAt).toBe(1716300000000);
31
- expect(rec.url).toContain("iqiyi.com");
32
- expect(iqiyi.mapItem({ albumName: "noid" })).toBe(null);
33
- });
34
- it("extractItems tolerant", () => {
35
- expect(iqiyi.extractItems({ data: [{ tvId: 1 }] })).toHaveLength(1);
36
- expect(iqiyi.extractItems({ data: { rc: [{ tvId: 1 }] } })).toHaveLength(1);
37
- expect(iqiyi.extractItems({})).toEqual([]);
38
- });
39
- });
40
-
41
- describe("video-tencent mappers", () => {
42
- it("name/version + mapItem (typeId → category)", () => {
43
- expect(tv.NAME).toBe("video-tencent");
44
- const rec = tv.mapItem({ cid: "C9", cTitle: "三体", cTypeId: 4, viewTime: 1716310000, duration: 3000 });
45
- expect(rec).toMatchObject({ videoId: "C9", title: "三体", category: "anime", durationSec: 3000 });
46
- expect(rec.url).toContain("v.qq.com");
47
- expect(tv.mapItem({ cTitle: "noid" })).toBe(null);
48
- });
49
- });
50
-
51
- describe("IqiyiVideoAdapter (via _video-base)", () => {
52
- const SNAP = JSON.stringify({
53
- schemaVersion: 1,
54
- snapshottedAt: 1716383000000,
55
- account: { userId: "u1" },
56
- events: [
57
- { kind: "watch", id: "w1", videoId: "V1", title: "狂飙", category: "tv", episode: "第5集", durationSec: 2600, capturedAt: 1716300000000 },
58
- { kind: "favourite", id: "fa1", videoId: "V2", title: "流浪地球2", category: "movie" },
59
- ],
60
- });
61
-
62
- it("snapshot sync 2 kinds + normalize watch→media / favourite→like + media item", async () => {
63
- const p = writeTmp(SNAP);
64
- try {
65
- const a = new iqiyi.IqiyiVideoAdapter();
66
- const items = await collect(a.sync({ inputPath: p }));
67
- expect(items.map((x) => x.kind)).toEqual(["watch", "favourite"]);
68
-
69
- const watch = a.normalize(items[0]);
70
- expect(watch.events[0].subtype).toBe("media");
71
- expect(watch.events[0].content.title).toBe("观看: 狂飙 第5集");
72
- expect(watch.items[0].subtype).toBe("media");
73
- expect(watch.items[0].extra.platform).toBe("iqiyi");
74
- expect(watch.events[0].extra.itemRef).toBe(watch.items[0].id);
75
-
76
- const fav = a.normalize(items[1]);
77
- expect(fav.events[0].subtype).toBe("like");
78
- expect(fav.events[0].content.title).toBe("收藏: 流浪地球2");
79
- } finally {
80
- fs.unlinkSync(p);
81
- }
82
- });
83
-
84
- it("schema mismatch + unknown kind + include + limit", async () => {
85
- const p = writeTmp(SNAP);
86
- try {
87
- const a = new iqiyi.IqiyiVideoAdapter();
88
- expect((await collect(a.sync({ inputPath: p, include: { watch: false } }))).map((x) => x.kind)).toEqual(["favourite"]);
89
- expect(await collect(a.sync({ inputPath: p, limit: 1 }))).toHaveLength(1);
90
- expect(() => a.normalize({ payload: {} })).toThrow(/payload.record missing/);
91
- } finally {
92
- fs.unlinkSync(p);
93
- }
94
- const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
95
- try {
96
- const a = new iqiyi.IqiyiVideoAdapter();
97
- await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
98
- } finally {
99
- fs.unlinkSync(bad);
100
- }
101
- });
102
- });
103
-
104
- describe("TencentVideoAdapter cookie-api mode", () => {
105
- it("authenticate cookie (userId optional)", async () => {
106
- const a = new tv.TencentVideoAdapter({ account: { cookies: COOKIES } });
107
- expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
108
- });
109
-
110
- it("sync fetches watch+favourite, paginates, normalizes", async () => {
111
- const byUrl = (u) => (u.includes("History") ? "watch" : "favourite");
112
- const data = {
113
- watch: [{ cid: "C1", cTitle: "漫长的季节", cTypeId: 1, viewTime: 1716300000 }],
114
- favourite: [{ cid: "C2", cTitle: "繁花", cTypeId: 1 }],
115
- };
116
- const calls = [];
117
- const a = new tv.TencentVideoAdapter({
118
- account: { cookies: COOKIES, userId: "u1" },
119
- fetchFn: async ({ url, cookies, query, sign }) => {
120
- const k = byUrl(url);
121
- calls.push({ k, cookies, page: query.page, sign });
122
- return { data: { list: query.page === 1 ? data[k] : [] } };
123
- },
124
- });
125
- const items = await collect(a.sync({}));
126
- expect(items.map((x) => x.kind).sort()).toEqual(["favourite", "watch"]);
127
- expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
128
- const watch = a.normalize(items.find((x) => x.kind === "watch"));
129
- expect(watch.events[0].content.title).toBe("观看: 漫长的季节");
130
- expect(watch.items[0].extra.platform).toBe("tencent-video");
131
- });
132
-
133
- it("invokes signProvider + limit + empty + default fetch + no input", async () => {
134
- const signCalls = [];
135
- const a = new tv.TencentVideoAdapter({
136
- account: { cookies: COOKIES },
137
- fetchFn: async ({ query }) => ({ list: query.page === 1 ? [{ cid: "C1", cTitle: "x" }, { cid: "C2", cTitle: "y" }] : [] }),
138
- signProvider: async (ctx) => { signCalls.push(ctx); return "sig"; },
139
- });
140
- expect(await collect(a.sync({ limit: 1, include: { favourite: false } }))).toHaveLength(1);
141
- expect(signCalls.length).toBeGreaterThan(0);
142
-
143
- const a2 = new tv.TencentVideoAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
144
- expect(await collect(a2.sync({}))).toEqual([]);
145
-
146
- const a3 = new tv.TencentVideoAdapter({ account: { cookies: COOKIES } });
147
- await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
148
-
149
- const a4 = new tv.TencentVideoAdapter();
150
- await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
151
- });
152
- });
@@ -1,106 +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 { XiguaVideoAdapter, extractItems, mapItem, NAME, VERSION } = require("../../lib/adapters/video-xigua");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-xig-${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 = "sid_tt=abc; ttwid=xyz";
23
-
24
- describe("video-xigua mappers", () => {
25
- it("name/version", () => {
26
- expect(NAME).toBe("video-xigua");
27
- expect(VERSION).toBe("0.1.0");
28
- });
29
- it("mapItem reads nested article + bytedance fields", () => {
30
- const rec = mapItem({ behot_time: 1716300000, article: { group_id: "G1", title: "城市骑行 vlog", video_duration: 620, user_name: "骑行小王" } });
31
- expect(rec).toMatchObject({ videoId: "G1", title: "城市骑行 vlog", durationSec: 620, channel: "骑行小王" });
32
- expect(rec.occurredAt).toBe(1716300000000);
33
- expect(rec.url).toContain("ixigua.com");
34
- expect(mapItem({ article: { title: "noid" } })).toBe(null);
35
- });
36
- it("mapItem reads flat item too", () => {
37
- const rec = mapItem({ group_id: "G2", title: "测评", duration: 300, create_time: 1716310000 });
38
- expect(rec).toMatchObject({ videoId: "G2", title: "测评", durationSec: 300 });
39
- });
40
- it("extractItems tolerant", () => {
41
- expect(extractItems({ data: { history: [{ group_id: 1 }] } })).toHaveLength(1);
42
- expect(extractItems({ data: { favorites: [{ group_id: 1 }] } })).toHaveLength(1);
43
- expect(extractItems({})).toEqual([]);
44
- });
45
- });
46
-
47
- describe("XiguaVideoAdapter (via _video-base)", () => {
48
- const SNAP = JSON.stringify({
49
- schemaVersion: 1,
50
- snapshottedAt: 1716383000000,
51
- account: { userId: "u1" },
52
- events: [
53
- { kind: "watch", id: "w1", videoId: "V1", title: "纪录片:长江", category: "documentary", durationSec: 3600, capturedAt: 1716300000000 },
54
- { kind: "favourite", id: "fa1", videoId: "V2", title: "搞笑合集" },
55
- ],
56
- });
57
-
58
- it("snapshot sync 2 kinds + normalize watch→media / favourite→like", async () => {
59
- const p = writeTmp(SNAP);
60
- try {
61
- const a = new XiguaVideoAdapter();
62
- const items = await collect(a.sync({ inputPath: p }));
63
- expect(items.map((x) => x.kind)).toEqual(["watch", "favourite"]);
64
- const w = a.normalize(items[0]);
65
- expect(w.events[0].subtype).toBe("media");
66
- expect(w.events[0].content.title).toBe("观看: 纪录片:长江");
67
- expect(w.items[0].subtype).toBe("media");
68
- expect(w.items[0].extra.platform).toBe("xigua");
69
- const fav = a.normalize(items[1]);
70
- expect(fav.events[0].subtype).toBe("like");
71
- expect(fav.events[0].content.title).toBe("收藏: 搞笑合集");
72
- } finally {
73
- fs.unlinkSync(p);
74
- }
75
- });
76
-
77
- it("cookie-api fetch + normalize", async () => {
78
- const byUrl = (u) => (u.includes("history") ? "watch" : "favourite");
79
- const data = {
80
- watch: [{ behot_time: 1716300000, article: { group_id: "C1", title: "汽车评测", video_duration: 500 } }],
81
- favourite: [{ group_id: "C2", title: "美食教程" }],
82
- };
83
- const calls = [];
84
- const a = new XiguaVideoAdapter({
85
- account: { cookies: COOKIES, userId: "u1" },
86
- fetchFn: async ({ url, cookies, query, sign }) => {
87
- const k = byUrl(url);
88
- calls.push({ k, cookies, page: query.page, sign });
89
- return { data: { list: query.page === 1 ? data[k] : [] } };
90
- },
91
- });
92
- expect(await a.authenticate()).toEqual({ ok: true, account: "u1", mode: "cookie" });
93
- const items = await collect(a.sync({}));
94
- expect(items.map((x) => x.kind).sort()).toEqual(["favourite", "watch"]);
95
- expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
96
- const w = a.normalize(items.find((x) => x.kind === "watch"));
97
- expect(w.events[0].content.title).toBe("观看: 汽车评测");
98
- });
99
-
100
- it("default fetch throws; no input throws", async () => {
101
- const a = new XiguaVideoAdapter({ account: { cookies: COOKIES } });
102
- await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
103
- const b = new XiguaVideoAdapter();
104
- await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
105
- });
106
- });
@@ -1,299 +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
- import Database from "better-sqlite3";
8
-
9
- const {
10
- VSCodeAdapter,
11
- VSCODE_NAME,
12
- VSCODE_VERSION,
13
- decodeFileUri,
14
- } = require("../../lib/adapters/vscode");
15
- const { assertAdapter } = require("../../lib/adapter-spec");
16
- const {
17
- ENTITY_TYPES,
18
- EVENT_SUBTYPES,
19
- ITEM_SUBTYPES,
20
- } = require("../../lib/constants");
21
- const { validateEvent, validateItem } = require("../../lib/schemas");
22
-
23
- let tmpDir;
24
- let vscodeRoot;
25
- let wsRoot;
26
- let stateDbPath;
27
-
28
- function makeWorkspace(hash, folderUri, opts = {}) {
29
- const d = join(wsRoot, hash);
30
- mkdirSync(d, { recursive: true });
31
- const wsFile = join(d, "workspace.json");
32
- writeFileSync(wsFile, JSON.stringify({ folder: folderUri }), "utf-8");
33
- if (opts.mtimeMs) {
34
- const ms = opts.mtimeMs;
35
- utimesSync(wsFile, ms / 1000, ms / 1000);
36
- }
37
- }
38
-
39
- function makeTerminalHistoryDb({ commands = [], dirs = [], cmdTs = null, dirTs = null }) {
40
- mkdirSync(join(vscodeRoot, "User", "globalStorage"), { recursive: true });
41
- const db = new Database(stateDbPath);
42
- db.exec("CREATE TABLE ItemTable(key TEXT PRIMARY KEY, value BLOB)");
43
- const put = db.prepare("INSERT OR REPLACE INTO ItemTable(key, value) VALUES(?, ?)");
44
- put.run(
45
- "terminal.history.entries.commands",
46
- JSON.stringify({
47
- entries: commands.map((c) => ({ key: c, value: { shellType: "pwsh" } })),
48
- }),
49
- );
50
- put.run(
51
- "terminal.history.entries.dirs",
52
- JSON.stringify({
53
- entries: dirs.map((d) => ({ key: d, value: { shellType: "pwsh" } })),
54
- }),
55
- );
56
- if (cmdTs != null) put.run("terminal.history.timestamp.commands", String(cmdTs));
57
- if (dirTs != null) put.run("terminal.history.timestamp.dirs", String(dirTs));
58
- db.close();
59
- }
60
-
61
- beforeEach(() => {
62
- tmpDir = mkdtempSync(join(tmpdir(), "vscode-adapter-test-"));
63
- vscodeRoot = join(tmpDir, "Code");
64
- wsRoot = join(vscodeRoot, "User", "workspaceStorage");
65
- stateDbPath = join(vscodeRoot, "User", "globalStorage", "state.vscdb");
66
- mkdirSync(wsRoot, { recursive: true });
67
- });
68
-
69
- afterEach(() => {
70
- rmSync(tmpDir, { recursive: true, force: true });
71
- });
72
-
73
- describe("VSCodeAdapter — contract + identity", () => {
74
- it("conforms to PersonalDataAdapter contract", () => {
75
- expect(assertAdapter(new VSCodeAdapter())).toEqual({ ok: true });
76
- });
77
-
78
- it("name/version/capabilities are stable", () => {
79
- const a = new VSCodeAdapter();
80
- expect(a.name).toBe(VSCODE_NAME);
81
- expect(a.name).toBe("vscode");
82
- expect(a.version).toBe(VSCODE_VERSION);
83
- expect(a.extractMode).toBe("file-import");
84
- expect(a.capabilities).toContain("sync:vscode-workspace-storage");
85
- expect(a.capabilities).toContain("sync:vscode-globalstorage-sqlite");
86
- });
87
- });
88
-
89
- describe("VSCodeAdapter.authenticate", () => {
90
- it("VSCODE_NOT_FOUND when neither workspaceStorage nor state.vscdb exist", async () => {
91
- rmSync(wsRoot, { recursive: true, force: true });
92
- const a = new VSCodeAdapter({ vscodeRoot });
93
- const r = await a.authenticate({});
94
- expect(r.ok).toBe(false);
95
- expect(r.reason).toBe("VSCODE_NOT_FOUND");
96
- });
97
-
98
- it("succeeds when only workspaceStorage exists", async () => {
99
- const a = new VSCodeAdapter({ vscodeRoot });
100
- const r = await a.authenticate({});
101
- expect(r.ok).toBe(true);
102
- expect(r.hasWorkspaces).toBe(true);
103
- expect(r.hasTerminalHistory).toBe(false);
104
- });
105
-
106
- it("succeeds when only state.vscdb exists", async () => {
107
- rmSync(wsRoot, { recursive: true, force: true });
108
- makeTerminalHistoryDb({ commands: ["ls"], cmdTs: 1_700_000_000_000 });
109
- const a = new VSCodeAdapter({ vscodeRoot });
110
- const r = await a.authenticate({});
111
- expect(r.ok).toBe(true);
112
- expect(r.hasWorkspaces).toBe(false);
113
- expect(r.hasTerminalHistory).toBe(true);
114
- });
115
- });
116
-
117
- describe("VSCodeAdapter.sync — workspaces", () => {
118
- it("yields one raw per workspace.json with folderPath decoded", async () => {
119
- makeWorkspace("hash-a", "file:///c%3A/code/foo", { mtimeMs: 1_700_000_001_000 });
120
- makeWorkspace("hash-b", "file:///c%3A/code/bar", { mtimeMs: 1_700_000_002_000 });
121
- const a = new VSCodeAdapter({ vscodeRoot });
122
- const raws = [];
123
- for await (const r of a.sync()) raws.push(r);
124
- const wss = raws.filter((r) => r.kind === "workspace");
125
- expect(wss).toHaveLength(2);
126
- const byHash = Object.fromEntries(wss.map((r) => [r.payload.hash, r.payload]));
127
- expect(byHash["hash-a"].folderUri).toBe("file:///c%3A/code/foo");
128
- expect(byHash["hash-a"].folderPath).toMatch(/foo$/);
129
- expect(byHash["hash-a"].lastOpenedMs).toBe(1_700_000_001_000);
130
- });
131
-
132
- it("filters workspaces by since (uses workspace.json mtime)", async () => {
133
- makeWorkspace("old", "file:///c%3A/old", { mtimeMs: 1_700_000_000_000 });
134
- makeWorkspace("new", "file:///c%3A/new", { mtimeMs: 1_700_000_005_000 });
135
- const a = new VSCodeAdapter({ vscodeRoot });
136
- const raws = [];
137
- for await (const r of a.sync({ since: 1_700_000_003_000 })) raws.push(r);
138
- const hashes = raws.filter((r) => r.kind === "workspace").map((r) => r.payload.hash);
139
- expect(hashes).toEqual(["new"]);
140
- });
141
-
142
- it("skips workspaces with no folder/workspace key", async () => {
143
- const d = join(wsRoot, "empty");
144
- mkdirSync(d, { recursive: true });
145
- writeFileSync(join(d, "workspace.json"), JSON.stringify({}), "utf-8");
146
- const a = new VSCodeAdapter({ vscodeRoot });
147
- const raws = [];
148
- for await (const r of a.sync()) raws.push(r);
149
- expect(raws.filter((r) => r.kind === "workspace")).toHaveLength(0);
150
- });
151
- });
152
-
153
- describe("VSCodeAdapter.sync — terminal history", () => {
154
- it("yields one raw per command + per dir, anchored to snapshot ts", async () => {
155
- makeTerminalHistoryDb({
156
- commands: ["ls", "git status", "npm test"],
157
- dirs: ["/c/code/foo", "/c/code/bar"],
158
- cmdTs: 1_700_000_010_000,
159
- dirTs: 1_700_000_020_000,
160
- });
161
- const a = new VSCodeAdapter({ vscodeRoot });
162
- const raws = [];
163
- for await (const r of a.sync()) raws.push(r);
164
- const cmds = raws.filter((r) => r.kind === "terminal-command");
165
- const dirs = raws.filter((r) => r.kind === "terminal-dir");
166
- expect(cmds).toHaveLength(3);
167
- expect(dirs).toHaveLength(2);
168
- expect(cmds[0].payload.value).toBe("ls");
169
- expect(cmds[0].payload.snapshotTs).toBe(1_700_000_010_000);
170
- expect(dirs[0].payload.snapshotTs).toBe(1_700_000_020_000);
171
- });
172
-
173
- it("originalId disambiguates duplicate commands by sourceIndex", async () => {
174
- makeTerminalHistoryDb({
175
- commands: ["ls", "ls"], // duplicate value
176
- cmdTs: 1_700_000_010_000,
177
- });
178
- const a = new VSCodeAdapter({ vscodeRoot });
179
- const raws = [];
180
- for await (const r of a.sync()) raws.push(r);
181
- const ids = raws.filter((r) => r.kind === "terminal-command").map((r) => r.originalId);
182
- expect(new Set(ids).size).toBe(2);
183
- });
184
-
185
- it("respects include.terminal=false", async () => {
186
- makeWorkspace("h", "file:///c%3A/p", { mtimeMs: 1_700_000_001_000 });
187
- makeTerminalHistoryDb({ commands: ["ls"], cmdTs: 1_700_000_010_000 });
188
- const a = new VSCodeAdapter({ vscodeRoot });
189
- const raws = [];
190
- for await (const r of a.sync({ include: { terminal: false } })) raws.push(r);
191
- expect(raws.every((r) => r.kind === "workspace")).toBe(true);
192
- expect(raws.length).toBe(1);
193
- });
194
-
195
- it("respects include.workspaces=false", async () => {
196
- makeWorkspace("h", "file:///c%3A/p", { mtimeMs: 1_700_000_001_000 });
197
- makeTerminalHistoryDb({ commands: ["ls"], cmdTs: 1_700_000_010_000 });
198
- const a = new VSCodeAdapter({ vscodeRoot });
199
- const raws = [];
200
- for await (const r of a.sync({ include: { workspaces: false } })) raws.push(r);
201
- expect(raws.every((r) => r.kind !== "workspace")).toBe(true);
202
- });
203
- });
204
-
205
- describe("VSCodeAdapter.normalize", () => {
206
- it("maps a workspace to Item(LINK) with code-project category", () => {
207
- const a = new VSCodeAdapter();
208
- const { items } = a.normalize({
209
- kind: "workspace",
210
- capturedAt: 1_700_000_000_000,
211
- payload: {
212
- hash: "h1",
213
- folderUri: "file:///c%3A/code/chainlesschain",
214
- folderPath: "c:\\code\\chainlesschain",
215
- lastOpenedMs: 1_700_000_001_000,
216
- },
217
- });
218
- expect(items).toHaveLength(1);
219
- expect(items[0].subtype).toBe(ITEM_SUBTYPES.LINK);
220
- expect(items[0].category).toBe("code-project");
221
- expect(items[0].name).toBe("chainlesschain");
222
- expect(items[0].extra.editor).toBe("vscode");
223
- expect(items[0].extra.folderUri).toBe("file:///c%3A/code/chainlesschain");
224
- expect(validateItem(items[0]).valid).toBe(true);
225
- });
226
-
227
- it("maps terminal-command to Event(OTHER) with cmd in content", () => {
228
- const a = new VSCodeAdapter();
229
- const { events } = a.normalize({
230
- kind: "terminal-command",
231
- capturedAt: 1_700_000_000_000,
232
- originalId: "vscode-terminal-cmd:0:abc",
233
- payload: {
234
- value: "git status",
235
- shellType: "pwsh",
236
- sourceIndex: 0,
237
- snapshotTs: 1_700_000_010_000,
238
- },
239
- });
240
- expect(events).toHaveLength(1);
241
- expect(events[0].subtype).toBe(EVENT_SUBTYPES.OTHER);
242
- expect(events[0].content.title).toBe("git status");
243
- expect(events[0].content.text).toBe("git status");
244
- expect(events[0].extra.kind).toBe("terminal-command");
245
- expect(events[0].extra.shellType).toBe("pwsh");
246
- expect(events[0].occurredAt).toBe(1_700_000_010_000);
247
- expect(validateEvent(events[0]).valid).toBe(true);
248
- });
249
-
250
- it("maps terminal-dir to Event(OTHER) with 'cd <dir>' title", () => {
251
- const a = new VSCodeAdapter();
252
- const { events } = a.normalize({
253
- kind: "terminal-dir",
254
- capturedAt: 1_700_000_000_000,
255
- originalId: "vscode-terminal-dir:0:xyz",
256
- payload: {
257
- value: "/c/code/foo",
258
- sourceIndex: 0,
259
- snapshotTs: 1_700_000_020_000,
260
- },
261
- });
262
- expect(events[0].content.title).toBe("cd /c/code/foo");
263
- expect(events[0].extra.kind).toBe("terminal-dir");
264
- expect(validateEvent(events[0]).valid).toBe(true);
265
- });
266
-
267
- it("truncates >80 char command titles to ellipsis", () => {
268
- const a = new VSCodeAdapter();
269
- const longCmd = "echo " + "a".repeat(200);
270
- const { events } = a.normalize({
271
- kind: "terminal-command",
272
- capturedAt: 1_700_000_000_000,
273
- originalId: "vscode-terminal-cmd:0:long",
274
- payload: { value: longCmd, sourceIndex: 0, snapshotTs: 1_700_000_010_000 },
275
- });
276
- expect(events[0].content.title.length).toBeLessThanOrEqual(81);
277
- expect(events[0].content.title.endsWith("…")).toBe(true);
278
- expect(events[0].content.text).toBe(longCmd);
279
- });
280
-
281
- it("throws on unknown raw.kind", () => {
282
- expect(() => new VSCodeAdapter().normalize({ kind: "bogus", payload: {} })).toThrow(
283
- /unknown raw\.kind=bogus/,
284
- );
285
- });
286
- });
287
-
288
- describe("decodeFileUri helper", () => {
289
- it("decodes Windows file URI to backslash path", () => {
290
- if (process.platform !== "win32") return;
291
- expect(decodeFileUri("file:///c%3A/code/foo")).toBe("c:\\code\\foo");
292
- });
293
-
294
- it("returns null for non-file:// schemes", () => {
295
- expect(decodeFileUri("vscode-remote://ssh-remote+host/foo")).toBe(null);
296
- expect(decodeFileUri(null)).toBe(null);
297
- expect(decodeFileUri(undefined)).toBe(null);
298
- });
299
- });