@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,175 +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 {
10
- CsdnAdapter,
11
- extractList,
12
- NAME,
13
- VERSION,
14
- SNAPSHOT_SCHEMA_VERSION,
15
- } = require("../../lib/adapters/social-csdn");
16
-
17
- function writeTmp(content) {
18
- const p = path.join(os.tmpdir(), `cc-csdn-${crypto.randomUUID()}.json`);
19
- fs.writeFileSync(p, content, "utf-8");
20
- return p;
21
- }
22
- async function collect(gen) {
23
- const out = [];
24
- for await (const x of gen) out.push(x);
25
- return out;
26
- }
27
-
28
- const COOKIES = "UserName=alice; UserToken=xyz";
29
-
30
- const SNAP = JSON.stringify({
31
- schemaVersion: 1,
32
- snapshottedAt: 1716383000000,
33
- account: { username: "alice", name: "Alice" },
34
- events: [
35
- { kind: "article", id: "article-101", articleId: "101", title: "<p>Vue 源码解析</p>", viewCount: 999, collectCount: 50, createdTime: 1716300000, url: "https://blog.csdn.net/alice/article/details/101" },
36
- { kind: "favourite", id: "fav-202", itemId: "202", title: "Rust 入门", url: "https://x/202", source: "blog", capturedAt: 1716310000000 },
37
- { kind: "follow", id: "follow-bob", username: "bob", name: "Bob", capturedAt: 1716320000000 },
38
- ],
39
- });
40
-
41
- describe("constants + extractList", () => {
42
- it("name/version/schema", () => {
43
- expect(NAME).toBe("social-csdn");
44
- expect(VERSION).toBe("0.1.0");
45
- expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
46
- });
47
- it("extractList tolerant", () => {
48
- expect(extractList({ list: [{ id: 1 }] })).toHaveLength(1);
49
- expect(extractList({ data: { list: [{ id: 1 }] } })).toHaveLength(1);
50
- expect(extractList({ data: { records: [{ id: 1 }] } })).toHaveLength(1);
51
- expect(extractList({})).toEqual([]);
52
- });
53
- });
54
-
55
- describe("CsdnAdapter snapshot mode", () => {
56
- it("authenticate validates inputPath", async () => {
57
- const p = writeTmp(SNAP);
58
- try {
59
- const a = new CsdnAdapter();
60
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
61
- expect((await a.authenticate({ inputPath: path.join(os.tmpdir(), "no-csdn.json") })).reason).toBe("INPUT_PATH_UNREADABLE");
62
- } finally {
63
- fs.unlinkSync(p);
64
- }
65
- });
66
-
67
- it("sync 3 kinds + normalize article→post(html-stripped)/favourite→like/follow→person", async () => {
68
- const p = writeTmp(SNAP);
69
- try {
70
- const a = new CsdnAdapter();
71
- const items = await collect(a.sync({ inputPath: p }));
72
- expect(items.map((x) => x.kind)).toEqual(["article", "favourite", "follow"]);
73
-
74
- const art = a.normalize(items[0]);
75
- expect(art.events[0].subtype).toBe("post");
76
- expect(art.events[0].content.text).toBe("Vue 源码解析"); // html stripped
77
- expect(art.events[0].extra.viewCount).toBe(999);
78
- expect(art.events[0].extra.collectCount).toBe(50);
79
-
80
- const fav = a.normalize(items[1]);
81
- expect(fav.events[0].subtype).toBe("like");
82
- expect(fav.events[0].content.title).toBe("Rust 入门");
83
-
84
- const fol = a.normalize(items[2]);
85
- expect(fol.persons[0].subtype).toBe("contact");
86
- expect(fol.persons[0].names).toEqual(["Bob"]);
87
- expect(fol.persons[0].identifiers["csdn-username"]).toEqual(["bob"]);
88
- } finally {
89
- fs.unlinkSync(p);
90
- }
91
- });
92
-
93
- it("include filter + limit + schema mismatch + unknown kind", async () => {
94
- const p = writeTmp(SNAP);
95
- try {
96
- const a = new CsdnAdapter();
97
- expect((await collect(a.sync({ inputPath: p, include: { article: false, follow: false } }))).map((x) => x.kind)).toEqual(["favourite"]);
98
- expect(await collect(a.sync({ inputPath: p, limit: 2 }))).toHaveLength(2);
99
- expect(() => a.normalize({ kind: "bogus", payload: {} })).toThrow(/unknown kind/);
100
- } finally {
101
- fs.unlinkSync(p);
102
- }
103
- const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
104
- try {
105
- const a = new CsdnAdapter();
106
- await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
107
- } finally {
108
- fs.unlinkSync(bad);
109
- }
110
- });
111
- });
112
-
113
- describe("CsdnAdapter cookie-api mode", () => {
114
- it("authenticate requires username", async () => {
115
- const noU = new CsdnAdapter({ account: { cookies: COOKIES } });
116
- expect((await noU.authenticate()).reason).toBe("NO_ACCOUNT_USERNAME");
117
- const ok = new CsdnAdapter({ account: { cookies: COOKIES, username: "alice" } });
118
- expect(await ok.authenticate()).toEqual({ ok: true, account: "alice", mode: "cookie" });
119
- });
120
-
121
- it("sync fetches articles/favourites/followees, normalizes", async () => {
122
- const byUrl = (u) => (u.includes("get-business-list") ? "articles" : u.includes("favorite") ? "favourites" : "followees");
123
- const data = {
124
- articles: [{ articleId: "A1", title: "Go 并发", viewCount: 10, createdTime: 1716300000 }],
125
- favourites: [{ id: "F1", title: "K8s 实践", source: "blog", created_at: 1716310000 }],
126
- followees: [{ username: "carol", name: "Carol" }],
127
- };
128
- const calls = [];
129
- const a = new CsdnAdapter({
130
- account: { cookies: COOKIES, username: "alice" },
131
- fetchFn: async ({ url, cookies, query, sign }) => {
132
- const k = byUrl(url);
133
- calls.push({ k, cookies, page: query.page, sign });
134
- return { data: { list: query.page === 1 ? data[k] : [] } };
135
- },
136
- });
137
- const items = await collect(a.sync({}));
138
- expect(items.map((x) => x.kind).sort()).toEqual(["article", "favourite", "follow"]);
139
- expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
140
- const art = a.normalize(items.find((x) => x.kind === "article"));
141
- expect(art.events[0].content.title).toBe("Go 并发");
142
- const fol = a.normalize(items.find((x) => x.kind === "follow"));
143
- expect(fol.persons[0].names).toEqual(["Carol"]);
144
- });
145
-
146
- it("invokes signProvider", async () => {
147
- const signCalls = [];
148
- const a = new CsdnAdapter({
149
- account: { cookies: COOKIES, username: "alice" },
150
- fetchFn: async ({ query }) => ({ list: query.page === 1 ? [{ articleId: "A1", title: "x" }] : [] }),
151
- signProvider: async (ctx) => { signCalls.push(ctx); return "sig"; },
152
- });
153
- const items = await collect(a.sync({ include: { favourite: false, follow: false } }));
154
- expect(items.length).toBeGreaterThan(0);
155
- expect(signCalls.length).toBeGreaterThan(0);
156
- expect(signCalls[0].cookies).toBe(COOKIES);
157
- });
158
-
159
- it("limit + empty/login + default fetch + no input", async () => {
160
- const a1 = new CsdnAdapter({
161
- account: { cookies: COOKIES, username: "alice" },
162
- fetchFn: async ({ query }) => ({ list: query.page === 1 ? [{ articleId: "A1", title: "a" }, { articleId: "A2", title: "b" }] : [] }),
163
- });
164
- expect(await collect(a1.sync({ limit: 1 }))).toHaveLength(1);
165
-
166
- const a2 = new CsdnAdapter({ account: { cookies: COOKIES, username: "alice" }, fetchFn: async () => "<html>login</html>" });
167
- expect(await collect(a2.sync({}))).toEqual([]);
168
-
169
- const a3 = new CsdnAdapter({ account: { cookies: COOKIES, username: "alice" } });
170
- await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
171
-
172
- const a4 = new CsdnAdapter();
173
- await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
174
- });
175
- });
@@ -1,165 +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 {
10
- DongchediAdapter,
11
- extractData,
12
- isEnd,
13
- NAME,
14
- VERSION,
15
- SNAPSHOT_SCHEMA_VERSION,
16
- } = require("../../lib/adapters/social-dongchedi");
17
-
18
- function writeTmp(content) {
19
- const p = path.join(os.tmpdir(), `cc-dcd-${crypto.randomUUID()}.json`);
20
- fs.writeFileSync(p, content, "utf-8");
21
- return p;
22
- }
23
- async function collect(gen) {
24
- const out = [];
25
- for await (const x of gen) out.push(x);
26
- return out;
27
- }
28
-
29
- const COOKIES = "tt_webid=abc; sessionid=xyz";
30
-
31
- const SNAP = JSON.stringify({
32
- schemaVersion: 1,
33
- snapshottedAt: 1716383000000,
34
- account: { userId: "u1" },
35
- events: [
36
- { kind: "favourite", id: "fav-1", itemId: "G1", title: "2026 新能源车横评", contentType: "article", url: "https://x/G1", capturedAt: 1716300000000 },
37
- { kind: "follow", id: "follow-S1", followId: "S1", name: "理想 L 系列", followType: "series", capturedAt: 1716320000000 },
38
- ],
39
- });
40
-
41
- describe("constants + helpers", () => {
42
- it("name/version/schema", () => {
43
- expect(NAME).toBe("social-dongchedi");
44
- expect(VERSION).toBe("0.1.0");
45
- expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
46
- });
47
- it("extractData tolerant", () => {
48
- expect(extractData({ data: [{ id: 1 }] })).toHaveLength(1);
49
- expect(extractData({ data: { favorite_list: [{ id: 1 }] } })).toHaveLength(1);
50
- expect(extractData({ data: { follow_list: [{ id: 1 }] } })).toHaveLength(1);
51
- expect(extractData({})).toEqual([]);
52
- });
53
- it("isEnd reads has_more", () => {
54
- expect(isEnd({ data: { has_more: false } })).toBe(true);
55
- expect(isEnd({ has_more: 0 })).toBe(true);
56
- expect(isEnd({ data: { has_more: true } })).toBe(false);
57
- });
58
- });
59
-
60
- describe("DongchediAdapter snapshot mode", () => {
61
- it("authenticate validates inputPath", async () => {
62
- const p = writeTmp(SNAP);
63
- try {
64
- const a = new DongchediAdapter();
65
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
66
- expect((await a.authenticate({ inputPath: path.join(os.tmpdir(), "no-dcd.json") })).reason).toBe("INPUT_PATH_UNREADABLE");
67
- } finally {
68
- fs.unlinkSync(p);
69
- }
70
- });
71
-
72
- it("sync 2 kinds + normalize favourite→like / follow→person", async () => {
73
- const p = writeTmp(SNAP);
74
- try {
75
- const a = new DongchediAdapter();
76
- const items = await collect(a.sync({ inputPath: p }));
77
- expect(items.map((x) => x.kind)).toEqual(["favourite", "follow"]);
78
-
79
- const fav = a.normalize(items[0]);
80
- expect(fav.events[0].subtype).toBe("like");
81
- expect(fav.events[0].content.title).toBe("收藏: 2026 新能源车横评");
82
- expect(fav.events[0].extra.contentType).toBe("article");
83
-
84
- const fol = a.normalize(items[1]);
85
- expect(fol.persons[0].subtype).toBe("contact");
86
- expect(fol.persons[0].names).toEqual(["理想 L 系列"]);
87
- expect(fol.persons[0].identifiers["dongchedi-id"]).toEqual(["S1"]);
88
- expect(fol.persons[0].extra.followType).toBe("series");
89
- } finally {
90
- fs.unlinkSync(p);
91
- }
92
- });
93
-
94
- it("include + limit + schema mismatch + unknown kind", async () => {
95
- const p = writeTmp(SNAP);
96
- try {
97
- const a = new DongchediAdapter();
98
- expect((await collect(a.sync({ inputPath: p, include: { favourite: false } }))).map((x) => x.kind)).toEqual(["follow"]);
99
- expect(await collect(a.sync({ inputPath: p, limit: 1 }))).toHaveLength(1);
100
- expect(() => a.normalize({ kind: "bogus", payload: {} })).toThrow(/unknown kind/);
101
- } finally {
102
- fs.unlinkSync(p);
103
- }
104
- const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
105
- try {
106
- const a = new DongchediAdapter();
107
- await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
108
- } finally {
109
- fs.unlinkSync(bad);
110
- }
111
- });
112
- });
113
-
114
- describe("DongchediAdapter cookie-api mode", () => {
115
- it("authenticate cookie (userId optional)", async () => {
116
- const a = new DongchediAdapter({ account: { cookies: COOKIES } });
117
- expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
118
- });
119
-
120
- it("sync fetches favourites + follows, normalizes", async () => {
121
- const byUrl = (u) => (u.includes("favorite") ? "favourite" : "follow");
122
- const data = {
123
- favourite: [{ group_id: "G1", title: "试驾视频", content_type: "video", create_time: 1716300000 }],
124
- follow: [{ series_id: "S9", series_name: "比亚迪汉", follow_time: 1716320000 }],
125
- };
126
- const calls = [];
127
- const a = new DongchediAdapter({
128
- account: { cookies: COOKIES, userId: "u1" },
129
- fetchFn: async ({ url, cookies, query, sign }) => {
130
- const k = byUrl(url);
131
- calls.push({ k, cookies, offset: query.offset, sign });
132
- return { data: { list: query.offset === 0 ? data[k] : [], has_more: false } };
133
- },
134
- });
135
- const items = await collect(a.sync({}));
136
- expect(items.map((x) => x.kind).sort()).toEqual(["favourite", "follow"]);
137
- expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
138
- const fav = a.normalize(items.find((x) => x.kind === "favourite"));
139
- expect(fav.events[0].content.title).toBe("收藏: 试驾视频");
140
- const fol = a.normalize(items.find((x) => x.kind === "follow"));
141
- expect(fol.persons[0].names).toEqual(["比亚迪汉"]);
142
- expect(fol.persons[0].extra.followType).toBe("series");
143
- });
144
-
145
- it("invokes signProvider + limit + empty + default fetch + no input", async () => {
146
- const signCalls = [];
147
- const a = new DongchediAdapter({
148
- account: { cookies: COOKIES },
149
- fetchFn: async ({ query }) => ({ data: { list: query.offset === 0 ? [{ group_id: "G1", title: "x" }, { group_id: "G2", title: "y" }] : [], has_more: false } }),
150
- signProvider: async (ctx) => { signCalls.push(ctx); return "x-bogus"; },
151
- });
152
- expect(await collect(a.sync({ limit: 1, include: { follow: false } }))).toHaveLength(1);
153
- expect(signCalls.length).toBeGreaterThan(0);
154
- expect(signCalls[0].cookies).toBe(COOKIES);
155
-
156
- const a2 = new DongchediAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
157
- expect(await collect(a2.sync({}))).toEqual([]);
158
-
159
- const a3 = new DongchediAdapter({ account: { cookies: COOKIES } });
160
- await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
161
-
162
- const a4 = new DongchediAdapter();
163
- await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
164
- });
165
- });
@@ -1,165 +0,0 @@
1
- /**
2
- * Douyin aweme-detail title resolver tests (real-device-driven 2026-06-11:
3
- * web detail endpoint returns aweme_detail{desc,author,duration} with no signing).
4
- * fetch injected — no network.
5
- */
6
- "use strict";
7
-
8
- import { describe, it, expect, vi } from "vitest";
9
-
10
- const {
11
- AwemeDetailClient,
12
- } = require("../../lib/adapters/social-douyin-adb/aweme-detail-client");
13
- const {
14
- collectWatchHistory,
15
- } = require("../../lib/adapters/social-douyin-adb/collector");
16
- const { DouyinAdapter } = require("../../lib/adapters/social-douyin");
17
- const { partitionBatch } = require("../../lib/batch");
18
-
19
- function makeFetch(byAid) {
20
- return async (url) => {
21
- const m = /aweme_id=(\d+)/.exec(url);
22
- const aid = m && m[1];
23
- const payload = byAid[aid];
24
- if (payload === undefined) return { ok: false, status: 404, text: async () => "nf" };
25
- return {
26
- ok: payload.status ? payload.status >= 200 && payload.status < 300 : true,
27
- status: payload.status || 200,
28
- text: async () => (typeof payload.body === "string" ? payload.body : JSON.stringify(payload.body)),
29
- };
30
- };
31
- }
32
- const noSleep = () => Promise.resolve();
33
-
34
- describe("AwemeDetailClient.fetchDetail", () => {
35
- it("parses aweme_detail → {desc, author, durationMs, createTime}; sends aweme_id + webapp params", async () => {
36
- let seenUrl;
37
- const fetch = async (url) => {
38
- seenUrl = url;
39
- return { ok: true, status: 200, text: async () => JSON.stringify({
40
- status_code: 0,
41
- aweme_detail: { desc: "洋气婆婆和她的土狗儿媳", author: { nickname: "任集" }, duration: 9200, create_time: 1780112750 },
42
- }) };
43
- };
44
- const c = new AwemeDetailClient({ fetch, sleep: noSleep });
45
- const d = await c.fetchDetail("7645526043227334246");
46
- expect(d).toEqual({ awemeId: "7645526043227334246", desc: "洋气婆婆和她的土狗儿媳", author: "任集", durationMs: 9200, createTime: 1780112750 });
47
- expect(seenUrl).toContain("aweme_id=7645526043227334246");
48
- expect(seenUrl).toContain("device_platform=webapp");
49
- expect(seenUrl).toContain("aid=6383");
50
- });
51
-
52
- it("status_code != 0 → null + lastError", async () => {
53
- const fetch = makeFetch({ 1: { body: { status_code: 8, status_msg: "risk" } } });
54
- const c = new AwemeDetailClient({ fetch, sleep: noSleep });
55
- expect(await c.fetchDetail("1")).toBe(null);
56
- expect(c.lastErrorCode).toBe(8);
57
- });
58
-
59
- it("missing aweme_detail (deleted/private) → null -5", async () => {
60
- const fetch = makeFetch({ 1: { body: { status_code: 0 } } });
61
- const c = new AwemeDetailClient({ fetch, sleep: noSleep });
62
- expect(await c.fetchDetail("1")).toBe(null);
63
- expect(c.lastErrorCode).toBe(-5);
64
- });
65
-
66
- it("HTTP non-2xx → null with status", async () => {
67
- const fetch = makeFetch({ 1: { status: 444, body: "blocked" } });
68
- const c = new AwemeDetailClient({ fetch, sleep: noSleep });
69
- expect(await c.fetchDetail("1")).toBe(null);
70
- expect(c.lastErrorCode).toBe(444);
71
- });
72
- });
73
-
74
- describe("AwemeDetailClient.resolveMany", () => {
75
- it("dedups ids, caps at limit, skips per-id failures", async () => {
76
- const calls = [];
77
- const fetch = async (url) => {
78
- const aid = /aweme_id=(\d+)/.exec(url)[1];
79
- calls.push(aid);
80
- const ok = { 11: true, 22: true }[aid];
81
- return { ok: true, status: 200, text: async () => JSON.stringify(
82
- ok ? { status_code: 0, aweme_detail: { desc: "d" + aid, author: { nickname: "a" } } }
83
- : { status_code: 0 }, // 33 → no aweme_detail → skipped
84
- ) };
85
- };
86
- const c = new AwemeDetailClient({ fetch, sleep: noSleep });
87
- const map = await c.resolveMany(["11", "11", "22", "33"], { limit: 10 });
88
- expect(calls).toEqual(["11", "22", "33"]); // deduped (one 11)
89
- expect([...map.keys()].sort()).toEqual(["11", "22"]); // 33 skipped
90
- expect(map.get("11").desc).toBe("d11");
91
- });
92
-
93
- it("respects limit (stops early)", async () => {
94
- const calls = [];
95
- const fetch = async (url) => {
96
- calls.push(/aweme_id=(\d+)/.exec(url)[1]);
97
- return { ok: true, status: 200, text: async () => JSON.stringify({ status_code: 0, aweme_detail: { desc: "x" } }) };
98
- };
99
- const c = new AwemeDetailClient({ fetch, sleep: noSleep });
100
- await c.resolveMany(["1", "2", "3", "4", "5"], { limit: 2 });
101
- expect(calls).toEqual(["1", "2"]);
102
- });
103
- });
104
-
105
- describe("collectWatchHistory --resolve-titles integration", () => {
106
- it("attaches title/author/duration → normalizeHistory shows real content", async () => {
107
- const fs = require("node:fs");
108
- const os = require("node:os");
109
- const bridge = {
110
- invoke: vi.fn(async (m) =>
111
- m === "douyin.watch-history"
112
- ? {
113
- uid: "92585448288",
114
- records: [
115
- { awemeId: "7645526043227334246", capturedAt: 1780112750000, enterFrom: "homepage_hot" },
116
- ],
117
- }
118
- : (() => { throw new Error("unknown " + m); })(),
119
- ),
120
- };
121
- const detailClient = new AwemeDetailClient({
122
- sleep: () => Promise.resolve(),
123
- fetch: makeFetch({
124
- "7645526043227334246": { body: { status_code: 0, aweme_detail: { desc: "洋气婆婆和她的土狗儿媳", author: { nickname: "任集" }, duration: 9200 } } },
125
- }),
126
- });
127
- const r = await collectWatchHistory(bridge, {
128
- stagingDir: os.tmpdir(),
129
- now: () => 1781000000000,
130
- resolveTitles: true,
131
- _detailClient: detailClient,
132
- });
133
- expect(r.titlesResolved).toBe(1);
134
- const snap = JSON.parse(fs.readFileSync(r.snapshotPath, "utf-8"));
135
- try {
136
- expect(snap.events[0].title).toBe("洋气婆婆和她的土狗儿媳");
137
- const a = new DouyinAdapter();
138
- const batch = a.normalize({
139
- adapter: "social-douyin",
140
- kind: "history",
141
- originalId: "douyin:history:1",
142
- capturedAt: 1780112750000,
143
- payload: { ...snap.events[0], account: snap.account },
144
- });
145
- expect(partitionBatch(batch).invalidReasons).toHaveLength(0);
146
- expect(batch.events[0].content.title).toBe("洋气婆婆和她的土狗儿媳");
147
- expect(batch.events[0].extra.author).toBe("任集");
148
- expect(batch.events[0].extra.duration).toBe(9200);
149
- expect(batch.events[0].extra.enterFrom).toBe("homepage_hot");
150
- } finally {
151
- fs.unlinkSync(r.snapshotPath);
152
- }
153
- });
154
-
155
- it("without resolveTitles, no network + title stays unresolved", async () => {
156
- const os = require("node:os");
157
- const fs = require("node:fs");
158
- const bridge = { invoke: vi.fn(async () => ({ uid: "1", records: [{ awemeId: "999", capturedAt: 1, enterFrom: "x" }] })) };
159
- const r = await collectWatchHistory(bridge, { stagingDir: os.tmpdir(), now: () => 1, resolveTitles: false });
160
- expect(r.titlesResolved).toBe(0);
161
- const snap = JSON.parse(fs.readFileSync(r.snapshotPath, "utf-8"));
162
- fs.unlinkSync(r.snapshotPath);
163
- expect(snap.events[0].title).toBeUndefined();
164
- });
165
- });