@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,256 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach } from "vitest";
4
-
5
- const fs = require("node:fs");
6
- const path = require("node:path");
7
- const os = require("node:os");
8
-
9
- const {
10
- DouyinAdapter,
11
- SNAPSHOT_SCHEMA_VERSION,
12
- VALID_SNAPSHOT_KINDS,
13
- } = require("../lib/adapters/social-douyin");
14
- const { validateBatch } = require("../lib/batch");
15
-
16
- // §A8 v0.2 — Douyin snapshot mode tests, mirror of social-weibo-snapshot.
17
- //
18
- // Snapshot mode is in-APK Android cc reading JSON written by
19
- // DouyinLocalCollector (WebView cookie + 1 endpoint `passport/account/info/v2/`
20
- // that works without X-Bogus). v0.2 SURFACE = profile kind only;
21
- // history/favourite/like kinds are reserved in VALID_SNAPSHOT_KINDS for v0.3
22
- // (X-Bogus path).
23
-
24
- function writeSnapshot(dir, snapshot) {
25
- const p = path.join(dir, "social-douyin.json");
26
- fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
27
- return p;
28
- }
29
-
30
- describe("DouyinAdapter snapshot mode", () => {
31
- let tmpDir;
32
- beforeEach(() => {
33
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "douyin-snap-"));
34
- });
35
-
36
- it("exports SNAPSHOT_SCHEMA_VERSION = 1 + 6 VALID_SNAPSHOT_KINDS", () => {
37
- expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
38
- // Forward-compat list (lib index.js): profile/history/favourite/like from
39
- // v0.2/v0.3, plus message/contact added in Phase 2a (3c5126401, _im.db pull).
40
- expect(VALID_SNAPSHOT_KINDS).toEqual([
41
- "profile",
42
- "history",
43
- "favourite",
44
- "like",
45
- "message",
46
- "contact",
47
- ]);
48
- });
49
-
50
- it("authenticate(inputPath) ok when readable", async () => {
51
- const p = writeSnapshot(tmpDir, {
52
- schemaVersion: 1,
53
- snapshottedAt: Date.now(),
54
- events: [],
55
- });
56
- const a = new DouyinAdapter();
57
- const res = await a.authenticate({ inputPath: p });
58
- expect(res.ok).toBe(true);
59
- expect(res.mode).toBe("snapshot-file");
60
- });
61
-
62
- it("authenticate(inputPath) fails when path unreadable", async () => {
63
- const a = new DouyinAdapter();
64
- const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
65
- expect(res.ok).toBe(false);
66
- expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
67
- });
68
-
69
- it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
70
- const a = new DouyinAdapter();
71
- const res = await a.authenticate({});
72
- expect(res.ok).toBe(false);
73
- expect(res.reason).toBe("NO_INPUT");
74
- });
75
-
76
- it("rejects schemaVersion mismatch", async () => {
77
- const p = writeSnapshot(tmpDir, {
78
- schemaVersion: 99,
79
- snapshottedAt: Date.now(),
80
- events: [],
81
- });
82
- const a = new DouyinAdapter();
83
- let threw = null;
84
- try {
85
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
86
- } catch (err) {
87
- threw = err;
88
- }
89
- expect(threw).toBeTruthy();
90
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
91
- });
92
-
93
- it("empty events array yields nothing (no crash)", async () => {
94
- const p = writeSnapshot(tmpDir, {
95
- schemaVersion: 1,
96
- snapshottedAt: Date.now(),
97
- events: [],
98
- });
99
- const a = new DouyinAdapter();
100
- const raws = [];
101
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
102
- expect(raws.length).toBe(0);
103
- });
104
-
105
- it("profile event round-trips normalize cleanly", async () => {
106
- const now = Date.now();
107
- const p = writeSnapshot(tmpDir, {
108
- schemaVersion: 1,
109
- snapshottedAt: now,
110
- account: {
111
- secUid: "MS4wLjABAAAA_alice",
112
- shortId: "12345678",
113
- displayName: "alice",
114
- },
115
- events: [
116
- {
117
- kind: "profile",
118
- id: "profile-MS4wLjABAAAA_alice",
119
- capturedAt: now - 1000,
120
- secUid: "MS4wLjABAAAA_alice",
121
- shortId: "12345678",
122
- nickname: "alice",
123
- signature: "hello world",
124
- followingCount: 100,
125
- followerCount: 200,
126
- awemeCount: 5,
127
- favoritingCount: 30,
128
- totalFavorited: 1500,
129
- },
130
- ],
131
- });
132
- const a = new DouyinAdapter();
133
- const raws = [];
134
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
135
- expect(raws.length).toBe(1);
136
- expect(raws[0].kind).toBe("profile");
137
- expect(raws[0].originalId).toMatch(/^douyin:profile:/);
138
-
139
- const batch = a.normalize(raws[0]);
140
- expect(validateBatch(batch).valid).toBe(true);
141
- // v0.2 emits a person record (self) not an event — repeated syncs
142
- // dedupe on the same id.
143
- expect(batch.events.length).toBe(0);
144
- expect(batch.persons.length).toBe(1);
145
- const person = batch.persons[0];
146
- expect(person.id).toBe("person-douyin-MS4wLjABAAAA_alice");
147
- expect(person.subtype).toBe("self");
148
- expect(person.names).toEqual(["alice"]);
149
- expect(person.identifiers["douyin-sec-uid"]).toEqual(["MS4wLjABAAAA_alice"]);
150
- expect(person.identifiers["douyin-short-id"]).toEqual(["12345678"]);
151
- expect(person.extra.platform).toBe("douyin");
152
- expect(person.extra.signature).toBe("hello world");
153
- expect(person.extra.followerCount).toBe(200);
154
- expect(person.extra.awemeCount).toBe(5);
155
- expect(person.extra.totalFavorited).toBe(1500);
156
- expect(person.source.capturedBy).toBe("api");
157
- });
158
-
159
- it("respects per-kind include opt-out", async () => {
160
- const now = Date.now();
161
- const p = writeSnapshot(tmpDir, {
162
- schemaVersion: 1,
163
- snapshottedAt: now,
164
- events: [
165
- { kind: "profile", id: "profile-X", capturedAt: now, secUid: "X", nickname: "x" },
166
- ],
167
- });
168
- const a = new DouyinAdapter();
169
- const raws = [];
170
- for await (const r of a.sync({ inputPath: p, include: { profile: false } })) {
171
- raws.push(r);
172
- }
173
- expect(raws.length).toBe(0);
174
- });
175
-
176
- it("respects opts.limit", async () => {
177
- // v0.2 unlikely to emit more than 1 profile, but verify the gate is wired.
178
- const now = Date.now();
179
- const events = [
180
- { kind: "profile", id: "p1", capturedAt: now, secUid: "X1", nickname: "x1" },
181
- // simulate forward-compat: a v0.3 snapshot with history events
182
- { kind: "history", id: "h1", capturedAt: now - 1000, awemeId: "A1", title: "t1" },
183
- { kind: "history", id: "h2", capturedAt: now - 2000, awemeId: "A2", title: "t2" },
184
- ];
185
- const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
186
- const a = new DouyinAdapter();
187
- const raws = [];
188
- for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
189
- expect(raws.length).toBe(2);
190
- });
191
-
192
- it("filters out unknown kinds (forward compat)", async () => {
193
- const now = Date.now();
194
- const p = writeSnapshot(tmpDir, {
195
- schemaVersion: 1,
196
- snapshottedAt: now,
197
- events: [
198
- { kind: "profile", id: "p1", capturedAt: now, secUid: "X", nickname: "x" },
199
- { kind: "future-kind", id: "x", capturedAt: now },
200
- { kind: "search", id: "s", capturedAt: now }, // search is sqlite-only
201
- ],
202
- });
203
- const a = new DouyinAdapter();
204
- const raws = [];
205
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
206
- expect(raws.length).toBe(1);
207
- expect(raws[0].kind).toBe("profile");
208
- });
209
-
210
- it("snapshottedAt fallback when event capturedAt missing", async () => {
211
- const ts = 1700000000000;
212
- const p = writeSnapshot(tmpDir, {
213
- schemaVersion: 1,
214
- snapshottedAt: ts,
215
- events: [
216
- { kind: "profile", id: "p1", secUid: "X", nickname: "x" },
217
- ],
218
- });
219
- const a = new DouyinAdapter();
220
- const raws = [];
221
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
222
- expect(raws[0].capturedAt).toBe(ts);
223
- });
224
-
225
- it("v0.3 forward-compat: history events round-trip if a future snapshot ships them", async () => {
226
- // The Kotlin LocalCollector won't emit these in v0.2, but the JS adapter
227
- // already knows how to ingest them — so when v0.3 lands we won't have to
228
- // bump SNAPSHOT_SCHEMA_VERSION.
229
- const now = Date.now();
230
- const p = writeSnapshot(tmpDir, {
231
- schemaVersion: 1,
232
- snapshottedAt: now,
233
- events: [
234
- {
235
- kind: "history",
236
- id: "history-A1",
237
- capturedAt: now - 1000,
238
- awemeId: "A1",
239
- title: "future video",
240
- author: "creator",
241
- duration: 30,
242
- },
243
- ],
244
- });
245
- const a = new DouyinAdapter();
246
- const raws = [];
247
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
248
- expect(raws.length).toBe(1);
249
- expect(raws[0].kind).toBe("history");
250
- const batch = a.normalize(raws[0]);
251
- expect(validateBatch(batch).valid).toBe(true);
252
- expect(batch.events[0].subtype).toBe("browse");
253
- expect(batch.events[0].extra.awemeId).toBe("A1");
254
- expect(batch.events[0].extra.duration).toBe(30);
255
- });
256
- });
@@ -1,362 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach } from "vitest";
4
-
5
- const fs = require("node:fs");
6
- const path = require("node:path");
7
- const os = require("node:os");
8
-
9
- const {
10
- KuaishouAdapter,
11
- SNAPSHOT_SCHEMA_VERSION,
12
- VALID_SNAPSHOT_KINDS,
13
- } = require("../lib/adapters/social-kuaishou");
14
- const { validateBatch } = require("../lib/batch");
15
-
16
- // §A8 v0.2 — Kuaishou snapshot mode tests, mirror of social-toutiao-snapshot.
17
- // Snapshot mode reads JSON produced by the phone's KuaishouLocalCollector
18
- // (root + SQLCipher decrypt of /data/data/com.smile.gifmaker/databases/).
19
-
20
- function writeSnapshot(dir, snapshot) {
21
- const p = path.join(dir, "social-kuaishou.json");
22
- fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
23
- return p;
24
- }
25
-
26
- describe("KuaishouAdapter snapshot mode", () => {
27
- let tmpDir;
28
- beforeEach(() => {
29
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "kuaishou-snap-"));
30
- });
31
-
32
- it("exports SNAPSHOT_SCHEMA_VERSION = 1 + 4 VALID_SNAPSHOT_KINDS (v0.2.1 adds profile)", () => {
33
- expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
34
- expect(VALID_SNAPSHOT_KINDS).toEqual([
35
- "profile",
36
- "watch",
37
- "collect",
38
- "search",
39
- ]);
40
- });
41
-
42
- it("authenticate(inputPath) ok when readable", async () => {
43
- const p = writeSnapshot(tmpDir, {
44
- schemaVersion: 1,
45
- snapshottedAt: Date.now(),
46
- events: [],
47
- });
48
- const a = new KuaishouAdapter();
49
- const res = await a.authenticate({ inputPath: p });
50
- expect(res.ok).toBe(true);
51
- expect(res.mode).toBe("snapshot-file");
52
- });
53
-
54
- it("authenticate(inputPath) fails when path unreadable", async () => {
55
- const a = new KuaishouAdapter();
56
- const res = await a.authenticate({
57
- inputPath: path.join(tmpDir, "missing.json"),
58
- });
59
- expect(res.ok).toBe(false);
60
- expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
61
- });
62
-
63
- it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
64
- const a = new KuaishouAdapter();
65
- const res = await a.authenticate({});
66
- expect(res.ok).toBe(false);
67
- expect(res.reason).toBe("NO_INPUT");
68
- });
69
-
70
- it("authenticate() sqlite mode without account.uid returns NO_ACCOUNT_UID", async () => {
71
- const a = new KuaishouAdapter({ dbPath: "/no/such/path.db" });
72
- const res = await a.authenticate({});
73
- expect(res.ok).toBe(false);
74
- expect(res.reason).toBe("NO_ACCOUNT_UID");
75
- });
76
-
77
- it("rejects schemaVersion mismatch", async () => {
78
- const p = writeSnapshot(tmpDir, {
79
- schemaVersion: 99,
80
- snapshottedAt: Date.now(),
81
- events: [],
82
- });
83
- const a = new KuaishouAdapter();
84
- let threw = null;
85
- try {
86
- for await (const _r of a.sync({ inputPath: p })) {
87
- /* drain */
88
- }
89
- } catch (err) {
90
- threw = err;
91
- }
92
- expect(threw).toBeTruthy();
93
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
94
- });
95
-
96
- it("empty events array yields nothing (no crash)", async () => {
97
- const p = writeSnapshot(tmpDir, {
98
- schemaVersion: 1,
99
- snapshottedAt: Date.now(),
100
- events: [],
101
- });
102
- const a = new KuaishouAdapter();
103
- const raws = [];
104
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
105
- expect(raws.length).toBe(0);
106
- });
107
-
108
- it("v0.2 profile event normalizes to person-self with kuaishou-uid identifier", async () => {
109
- const now = Date.now();
110
- const p = writeSnapshot(tmpDir, {
111
- schemaVersion: 1,
112
- snapshottedAt: now,
113
- account: { uid: "77777", displayName: "alice" },
114
- events: [
115
- {
116
- kind: "profile",
117
- id: "profile-77777",
118
- capturedAt: now - 500,
119
- uid: "77777",
120
- nickname: "alice",
121
- kuaishouId: "alice_KS",
122
- avatarUrl: "https://p.kuaishou.com/u/alice.jpg",
123
- sex: "F",
124
- city: "Shanghai",
125
- constellation: "Libra",
126
- description: "hi there",
127
- },
128
- ],
129
- });
130
- const a = new KuaishouAdapter();
131
- const raws = [];
132
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
133
- expect(raws.length).toBe(1);
134
- expect(raws[0].kind).toBe("profile");
135
- expect(raws[0].originalId).toMatch(/^kuaishou:profile:/);
136
-
137
- const batch = a.normalize(raws[0]);
138
- expect(validateBatch(batch).valid).toBe(true);
139
- expect(batch.events.length).toBe(0);
140
- expect(batch.persons.length).toBe(1);
141
- const person = batch.persons[0];
142
- expect(person.id).toBe("person-kuaishou-77777");
143
- expect(person.subtype).toBe("self");
144
- expect(person.names).toEqual(["alice"]);
145
- expect(person.identifiers["kuaishou-uid"]).toEqual(["77777"]);
146
- expect(person.identifiers["kuaishou-id"]).toEqual(["alice_KS"]);
147
- expect(person.extra.platform).toBe("kuaishou");
148
- expect(person.extra.avatarUrl).toBe("https://p.kuaishou.com/u/alice.jpg");
149
- expect(person.extra.sex).toBe("F");
150
- expect(person.extra.city).toBe("Shanghai");
151
- expect(person.extra.constellation).toBe("Libra");
152
- expect(person.extra.description).toBe("hi there");
153
- expect(person.source.capturedBy).toBe("api");
154
- });
155
-
156
- it("watch event round-trips normalize cleanly (BROWSE subtype)", async () => {
157
- const now = Date.now();
158
- const p = writeSnapshot(tmpDir, {
159
- schemaVersion: 1,
160
- snapshottedAt: now,
161
- account: { uid: "67890", displayName: "alice" },
162
- events: [
163
- {
164
- kind: "watch",
165
- id: "photo-p-1",
166
- capturedAt: now - 1000,
167
- photoId: "p-1",
168
- caption: "搞笑视频",
169
- duration: 30,
170
- authorId: "u-author-1",
171
- authorName: "UpA",
172
- },
173
- ],
174
- });
175
- const a = new KuaishouAdapter();
176
- const raws = [];
177
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
178
- expect(raws.length).toBe(1);
179
- expect(raws[0].kind).toBe("watch");
180
- expect(raws[0].originalId).toMatch(/^kuaishou:watch:/);
181
-
182
- const batch = a.normalize(raws[0]);
183
- expect(validateBatch(batch).valid).toBe(true);
184
- expect(batch.events[0].subtype).toBe("browse");
185
- expect(batch.events[0].content.title).toBe("搞笑视频");
186
- expect(batch.events[0].extra.photoId).toBe("p-1");
187
- expect(batch.events[0].extra.duration).toBe(30);
188
- expect(batch.events[0].extra.authorId).toBe("u-author-1");
189
- expect(batch.events[0].extra.authorName).toBe("UpA");
190
- expect(batch.events[0].extra.platform).toBe("kuaishou");
191
- expect(batch.events[0].source.capturedBy).toBe("api");
192
- });
193
-
194
- it("collect event round-trips normalize cleanly (LIKE subtype)", async () => {
195
- const now = Date.now();
196
- const p = writeSnapshot(tmpDir, {
197
- schemaVersion: 1,
198
- snapshottedAt: now,
199
- events: [
200
- {
201
- kind: "collect",
202
- id: "collect-p-2",
203
- capturedAt: now - 2000,
204
- photoId: "p-2",
205
- caption: "美食 vlog",
206
- authorId: "u-author-2",
207
- authorName: "FoodVlogger",
208
- },
209
- ],
210
- });
211
- const a = new KuaishouAdapter();
212
- const raws = [];
213
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
214
- expect(raws.length).toBe(1);
215
-
216
- const batch = a.normalize(raws[0]);
217
- expect(validateBatch(batch).valid).toBe(true);
218
- expect(batch.events[0].subtype).toBe("like");
219
- expect(batch.events[0].content.title).toBe("美食 vlog");
220
- expect(batch.events[0].extra.photoId).toBe("p-2");
221
- expect(batch.events[0].extra.authorName).toBe("FoodVlogger");
222
- expect(batch.events[0].source.capturedBy).toBe("api");
223
- });
224
-
225
- it("search event round-trips normalize cleanly (POST subtype, keyword in title)", async () => {
226
- const now = Date.now();
227
- const p = writeSnapshot(tmpDir, {
228
- schemaVersion: 1,
229
- snapshottedAt: now,
230
- events: [
231
- {
232
- kind: "search",
233
- id: "search-square-dance:1700002000",
234
- capturedAt: now - 3000,
235
- keyword: "广场舞",
236
- },
237
- ],
238
- });
239
- const a = new KuaishouAdapter();
240
- const raws = [];
241
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
242
- expect(raws.length).toBe(1);
243
-
244
- const batch = a.normalize(raws[0]);
245
- expect(validateBatch(batch).valid).toBe(true);
246
- expect(batch.events[0].subtype).toBe("post");
247
- expect(batch.events[0].content.title).toBe("广场舞");
248
- expect(batch.events[0].extra.kind).toBe("search");
249
- expect(batch.events[0].extra.keyword).toBe("广场舞");
250
- });
251
-
252
- it("respects per-kind include opt-out", async () => {
253
- const now = Date.now();
254
- const p = writeSnapshot(tmpDir, {
255
- schemaVersion: 1,
256
- snapshottedAt: now,
257
- events: [
258
- { kind: "watch", id: "w1", capturedAt: now, photoId: "p-1", caption: "c1" },
259
- { kind: "collect", id: "c1", capturedAt: now, photoId: "p-2", caption: "c2" },
260
- { kind: "search", id: "s1", capturedAt: now, keyword: "kw" },
261
- ],
262
- });
263
- const a = new KuaishouAdapter();
264
- const raws = [];
265
- for await (const r of a.sync({
266
- inputPath: p,
267
- include: { collect: false, search: false },
268
- })) {
269
- raws.push(r);
270
- }
271
- expect(raws.length).toBe(1);
272
- expect(raws[0].kind).toBe("watch");
273
- });
274
-
275
- it("respects opts.limit", async () => {
276
- const now = Date.now();
277
- const events = [];
278
- for (let i = 0; i < 10; i++) {
279
- events.push({
280
- kind: "watch",
281
- id: `w${i}`,
282
- capturedAt: now - i * 1000,
283
- photoId: `p-${i}`,
284
- caption: `c${i}`,
285
- });
286
- }
287
- const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
288
- const a = new KuaishouAdapter();
289
- const raws = [];
290
- for await (const r of a.sync({ inputPath: p, limit: 5 })) raws.push(r);
291
- expect(raws.length).toBe(5);
292
- });
293
-
294
- it("filters out unknown kinds (forward compat)", async () => {
295
- const now = Date.now();
296
- const p = writeSnapshot(tmpDir, {
297
- schemaVersion: 1,
298
- snapshottedAt: now,
299
- events: [
300
- { kind: "watch", id: "w1", capturedAt: now, photoId: "p-1", caption: "c1" },
301
- { kind: "future-kind", id: "x", capturedAt: now },
302
- { kind: "live-watch", id: "lv-1", capturedAt: now }, // v0.3 hypothetical
303
- ],
304
- });
305
- const a = new KuaishouAdapter();
306
- const raws = [];
307
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
308
- expect(raws.length).toBe(1);
309
- expect(raws[0].kind).toBe("watch");
310
- });
311
-
312
- it("snapshottedAt fallback when event capturedAt missing", async () => {
313
- const ts = 1700000000000;
314
- const p = writeSnapshot(tmpDir, {
315
- schemaVersion: 1,
316
- snapshottedAt: ts,
317
- events: [{ kind: "watch", id: "w1", photoId: "p-1", caption: "c1" }],
318
- });
319
- const a = new KuaishouAdapter();
320
- const raws = [];
321
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
322
- expect(raws[0].capturedAt).toBe(ts);
323
- });
324
-
325
- it("sqlite mode throws when account.uid missing at sync time", async () => {
326
- const a = new KuaishouAdapter();
327
- let threw = null;
328
- try {
329
- for await (const _r of a.sync({ dbPath: "/no/such/path.db" })) {
330
- /* drain */
331
- }
332
- } catch (err) {
333
- threw = err;
334
- }
335
- expect(threw).toBeTruthy();
336
- expect(String(threw.message)).toMatch(/account\.uid required/);
337
- });
338
-
339
- it("sqlite mode gracefully exits when dbPath unreadable (with account.uid)", async () => {
340
- const a = new KuaishouAdapter({
341
- account: { uid: "u-2" },
342
- dbPath: "/no/such/path.db",
343
- });
344
- const raws = [];
345
- for await (const r of a.sync()) raws.push(r);
346
- expect(raws).toEqual([]);
347
- });
348
-
349
- it("sync() with neither inputPath nor dbPath throws", async () => {
350
- const a = new KuaishouAdapter();
351
- let threw = null;
352
- try {
353
- for await (const _r of a.sync()) {
354
- /* drain */
355
- }
356
- } catch (err) {
357
- threw = err;
358
- }
359
- expect(threw).toBeTruthy();
360
- expect(String(threw.message)).toMatch(/needs opts\.inputPath/);
361
- });
362
- });