@chainlesschain/personal-data-hub 0.2.1 → 0.2.3
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.
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +58 -16
- package/__tests__/adapters/wechat-frida-agent.test.js +132 -1
- package/__tests__/integration/social-bilibili-pipeline.test.js +261 -0
- package/__tests__/longtail-adapters.test.js +60 -14
- package/__tests__/messaging-qq-snapshot.test.js +294 -0
- package/__tests__/shopping-pinduoduo-snapshot.test.js +302 -0
- package/__tests__/shopping-snapshot.test.js +438 -0
- package/__tests__/social-adapters.test.js +91 -17
- package/__tests__/social-bilibili-snapshot.test.js +278 -0
- package/__tests__/social-douyin-snapshot.test.js +253 -0
- package/__tests__/social-kuaishou-snapshot.test.js +309 -0
- package/__tests__/social-toutiao-snapshot.test.js +314 -0
- package/__tests__/social-weibo-snapshot.test.js +234 -0
- package/__tests__/social-xiaohongshu-snapshot.test.js +232 -0
- package/__tests__/travel-maps-snapshot.test.js +426 -0
- package/__tests__/vault-driver-error.test.js +74 -0
- package/__tests__/wechat-adapter.test.js +118 -0
- package/lib/adapters/messaging-qq/index.js +498 -92
- package/lib/adapters/shopping-jd/index.js +228 -25
- package/lib/adapters/shopping-meituan/index.js +222 -26
- package/lib/adapters/shopping-pinduoduo/index.js +275 -0
- package/lib/adapters/social-bilibili/adapter.js +500 -0
- package/lib/adapters/social-bilibili/index.js +21 -169
- package/lib/adapters/social-douyin/index.js +454 -63
- package/lib/adapters/social-kuaishou/index.js +379 -127
- package/lib/adapters/social-toutiao/index.js +400 -130
- package/lib/adapters/social-weibo/index.js +393 -95
- package/lib/adapters/social-xiaohongshu/index.js +389 -49
- package/lib/adapters/travel-baidu-map/index.js +286 -26
- package/lib/adapters/travel-tencent-map/index.js +414 -0
- package/lib/adapters/wechat/content-parser.js +11 -2
- package/lib/adapters/wechat/db-reader.js +88 -10
- package/lib/adapters/wechat/frida-agent/loader.js +7 -0
- package/lib/adapters/wechat/frida-agent/wechat-key-hook.js +140 -18
- package/lib/adapters/wechat/key-providers/frida-key-provider.js +8 -0
- package/lib/adapters/wechat/normalize.js +12 -3
- package/lib/index.js +5 -1
- package/lib/vault.js +60 -8
- package/package.json +2 -1
|
@@ -0,0 +1,234 @@
|
|
|
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
|
+
WeiboAdapter,
|
|
11
|
+
SNAPSHOT_SCHEMA_VERSION,
|
|
12
|
+
VALID_SNAPSHOT_KINDS,
|
|
13
|
+
} = require("../lib/adapters/social-weibo");
|
|
14
|
+
const { validateBatch } = require("../lib/batch");
|
|
15
|
+
|
|
16
|
+
// §A8 v0.2 — snapshot-mode tests, mirror of social-bilibili-snapshot.test.js.
|
|
17
|
+
//
|
|
18
|
+
// Snapshot mode is in-APK Android cc reading JSON written by WeiboLocalCollector
|
|
19
|
+
// (WebView + OkHttp). Sqlite/device-pull tests stay in social-adapters.test.js.
|
|
20
|
+
|
|
21
|
+
function writeSnapshot(dir, snapshot) {
|
|
22
|
+
const p = path.join(dir, "social-weibo.json");
|
|
23
|
+
fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
|
|
24
|
+
return p;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("WeiboAdapter snapshot mode", () => {
|
|
28
|
+
let tmpDir;
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "weibo-snap-"));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("exports SNAPSHOT_SCHEMA_VERSION = 1 + 3 VALID_SNAPSHOT_KINDS", () => {
|
|
34
|
+
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
35
|
+
expect(VALID_SNAPSHOT_KINDS).toEqual(["post", "favourite", "follow"]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("authenticate(inputPath) ok when readable", async () => {
|
|
39
|
+
const p = writeSnapshot(tmpDir, {
|
|
40
|
+
schemaVersion: 1,
|
|
41
|
+
snapshottedAt: Date.now(),
|
|
42
|
+
events: [],
|
|
43
|
+
});
|
|
44
|
+
const a = new WeiboAdapter();
|
|
45
|
+
const res = await a.authenticate({ inputPath: p });
|
|
46
|
+
expect(res.ok).toBe(true);
|
|
47
|
+
expect(res.mode).toBe("snapshot-file");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("authenticate(inputPath) fails when path unreadable", async () => {
|
|
51
|
+
const a = new WeiboAdapter();
|
|
52
|
+
const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
|
|
53
|
+
expect(res.ok).toBe(false);
|
|
54
|
+
expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
|
|
58
|
+
const a = new WeiboAdapter();
|
|
59
|
+
const res = await a.authenticate({});
|
|
60
|
+
expect(res.ok).toBe(false);
|
|
61
|
+
expect(res.reason).toBe("NO_INPUT");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("rejects schemaVersion mismatch", async () => {
|
|
65
|
+
const p = writeSnapshot(tmpDir, {
|
|
66
|
+
schemaVersion: 99,
|
|
67
|
+
snapshottedAt: Date.now(),
|
|
68
|
+
events: [],
|
|
69
|
+
});
|
|
70
|
+
const a = new WeiboAdapter();
|
|
71
|
+
let threw = null;
|
|
72
|
+
try {
|
|
73
|
+
for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
|
|
74
|
+
} catch (err) {
|
|
75
|
+
threw = err;
|
|
76
|
+
}
|
|
77
|
+
expect(threw).toBeTruthy();
|
|
78
|
+
expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("empty events array yields nothing (no crash)", async () => {
|
|
82
|
+
const p = writeSnapshot(tmpDir, {
|
|
83
|
+
schemaVersion: 1,
|
|
84
|
+
snapshottedAt: Date.now(),
|
|
85
|
+
events: [],
|
|
86
|
+
});
|
|
87
|
+
const a = new WeiboAdapter();
|
|
88
|
+
const raws = [];
|
|
89
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
90
|
+
expect(raws.length).toBe(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("post + favourite + follow round-trip normalize cleanly", async () => {
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
const p = writeSnapshot(tmpDir, {
|
|
96
|
+
schemaVersion: 1,
|
|
97
|
+
snapshottedAt: now,
|
|
98
|
+
account: { uid: "12345", displayName: "alice" },
|
|
99
|
+
events: [
|
|
100
|
+
{
|
|
101
|
+
kind: "post",
|
|
102
|
+
id: "post-M1",
|
|
103
|
+
capturedAt: now - 1000,
|
|
104
|
+
text: "今天天气真好",
|
|
105
|
+
mid: "M1",
|
|
106
|
+
source: "iPhone",
|
|
107
|
+
repostsCount: 5,
|
|
108
|
+
commentsCount: 3,
|
|
109
|
+
likesCount: 10,
|
|
110
|
+
picCount: 1,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
kind: "favourite",
|
|
114
|
+
id: "fav-M2",
|
|
115
|
+
capturedAt: now - 2000,
|
|
116
|
+
text: "收藏的微博",
|
|
117
|
+
mid: "M2",
|
|
118
|
+
authorScreenName: "bob",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
kind: "follow",
|
|
122
|
+
id: "follow-99",
|
|
123
|
+
capturedAt: now - 3000,
|
|
124
|
+
uid: 99,
|
|
125
|
+
screenName: "carol",
|
|
126
|
+
description: "hello",
|
|
127
|
+
avatarUrl: "https://example.com/c.jpg",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
const a = new WeiboAdapter();
|
|
132
|
+
const raws = [];
|
|
133
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
134
|
+
expect(raws.length).toBe(3);
|
|
135
|
+
|
|
136
|
+
const kinds = raws.map((r) => r.kind);
|
|
137
|
+
expect(kinds).toEqual(["post", "favourite", "follow"]);
|
|
138
|
+
|
|
139
|
+
// Each originalId namespaced under weibo:<kind>:<id>
|
|
140
|
+
expect(raws[0].originalId).toMatch(/^weibo:post:/);
|
|
141
|
+
expect(raws[1].originalId).toMatch(/^weibo:favourite:/);
|
|
142
|
+
expect(raws[2].originalId).toMatch(/^weibo:follow:/);
|
|
143
|
+
|
|
144
|
+
// Normalize each + validate
|
|
145
|
+
for (const raw of raws) {
|
|
146
|
+
const batch = a.normalize(raw);
|
|
147
|
+
expect(validateBatch(batch).valid).toBe(true);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const postBatch = a.normalize(raws[0]);
|
|
151
|
+
expect(postBatch.events[0].subtype).toBe("post");
|
|
152
|
+
expect(postBatch.events[0].extra.weiboMid).toBe("M1");
|
|
153
|
+
expect(postBatch.events[0].extra.repostsCount).toBe(5);
|
|
154
|
+
expect(postBatch.events[0].extra.commentsCount).toBe(3);
|
|
155
|
+
expect(postBatch.events[0].extra.likesCount).toBe(10);
|
|
156
|
+
expect(postBatch.events[0].extra.picCount).toBe(1);
|
|
157
|
+
expect(postBatch.events[0].source.capturedBy).toBe("api");
|
|
158
|
+
|
|
159
|
+
const favBatch = a.normalize(raws[1]);
|
|
160
|
+
expect(favBatch.events[0].subtype).toBe("like");
|
|
161
|
+
expect(favBatch.events[0].extra.authorScreenName).toBe("bob");
|
|
162
|
+
|
|
163
|
+
const followBatch = a.normalize(raws[2]);
|
|
164
|
+
expect(followBatch.events.length).toBe(0);
|
|
165
|
+
expect(followBatch.persons.length).toBe(1);
|
|
166
|
+
expect(followBatch.persons[0].names).toEqual(["carol"]);
|
|
167
|
+
expect(followBatch.persons[0].identifiers["weibo-uid"]).toEqual(["99"]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("respects per-kind include opt-out", async () => {
|
|
171
|
+
const now = Date.now();
|
|
172
|
+
const p = writeSnapshot(tmpDir, {
|
|
173
|
+
schemaVersion: 1,
|
|
174
|
+
snapshottedAt: now,
|
|
175
|
+
events: [
|
|
176
|
+
{ kind: "post", id: "p1", capturedAt: now, text: "p1", mid: "M1" },
|
|
177
|
+
{ kind: "favourite", id: "f1", capturedAt: now, text: "f1", mid: "M2" },
|
|
178
|
+
{ kind: "follow", id: "fl1", capturedAt: now, uid: 99, screenName: "x" },
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
const a = new WeiboAdapter();
|
|
182
|
+
const raws = [];
|
|
183
|
+
for await (const r of a.sync({ inputPath: p, include: { favourite: false } })) {
|
|
184
|
+
raws.push(r);
|
|
185
|
+
}
|
|
186
|
+
const kinds = raws.map((r) => r.kind);
|
|
187
|
+
expect(kinds).toEqual(["post", "follow"]);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("respects opts.limit", async () => {
|
|
191
|
+
const now = Date.now();
|
|
192
|
+
const events = Array.from({ length: 5 }, (_, i) => ({
|
|
193
|
+
kind: "post", id: `p${i}`, capturedAt: now - i * 100, text: `t${i}`, mid: `M${i}`,
|
|
194
|
+
}));
|
|
195
|
+
const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
|
|
196
|
+
const a = new WeiboAdapter();
|
|
197
|
+
const raws = [];
|
|
198
|
+
for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
|
|
199
|
+
expect(raws.length).toBe(2);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("filters out unknown kinds (forward compat)", async () => {
|
|
203
|
+
const now = Date.now();
|
|
204
|
+
const p = writeSnapshot(tmpDir, {
|
|
205
|
+
schemaVersion: 1,
|
|
206
|
+
snapshottedAt: now,
|
|
207
|
+
events: [
|
|
208
|
+
{ kind: "post", id: "p1", capturedAt: now, text: "ok", mid: "M1" },
|
|
209
|
+
{ kind: "future-kind", id: "x", capturedAt: now },
|
|
210
|
+
{ kind: "search", id: "s", capturedAt: now }, // search is sqlite-only
|
|
211
|
+
],
|
|
212
|
+
});
|
|
213
|
+
const a = new WeiboAdapter();
|
|
214
|
+
const raws = [];
|
|
215
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
216
|
+
expect(raws.length).toBe(1);
|
|
217
|
+
expect(raws[0].kind).toBe("post");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("snapshottedAt fallback when event capturedAt missing", async () => {
|
|
221
|
+
const ts = 1700000000000;
|
|
222
|
+
const p = writeSnapshot(tmpDir, {
|
|
223
|
+
schemaVersion: 1,
|
|
224
|
+
snapshottedAt: ts,
|
|
225
|
+
events: [
|
|
226
|
+
{ kind: "post", id: "p1", text: "no time", mid: "M1" },
|
|
227
|
+
],
|
|
228
|
+
});
|
|
229
|
+
const a = new WeiboAdapter();
|
|
230
|
+
const raws = [];
|
|
231
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
232
|
+
expect(raws[0].capturedAt).toBe(ts);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
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
|
+
XiaohongshuAdapter,
|
|
11
|
+
SNAPSHOT_SCHEMA_VERSION,
|
|
12
|
+
VALID_SNAPSHOT_KINDS,
|
|
13
|
+
} = require("../lib/adapters/social-xiaohongshu");
|
|
14
|
+
const { validateBatch } = require("../lib/batch");
|
|
15
|
+
|
|
16
|
+
// §A8 v0.2 — snapshot-mode tests, mirror of social-weibo-snapshot.test.js.
|
|
17
|
+
//
|
|
18
|
+
// Snapshot mode is in-APK Android cc reading JSON written by XhsLocalCollector
|
|
19
|
+
// (WebView + OkHttp + X-S signed requests). Sqlite/device-pull tests stay in
|
|
20
|
+
// longtail-adapters.test.js (legacy Phase 13.4 path).
|
|
21
|
+
|
|
22
|
+
function writeSnapshot(dir, snapshot) {
|
|
23
|
+
const p = path.join(dir, "social-xiaohongshu.json");
|
|
24
|
+
fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
|
|
25
|
+
return p;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("XiaohongshuAdapter snapshot mode", () => {
|
|
29
|
+
let tmpDir;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "xhs-snap-"));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("exports SNAPSHOT_SCHEMA_VERSION = 1 + 3 VALID_SNAPSHOT_KINDS", () => {
|
|
35
|
+
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
36
|
+
expect(VALID_SNAPSHOT_KINDS).toEqual(["note", "liked", "follow"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("authenticate(inputPath) ok when readable", async () => {
|
|
40
|
+
const p = writeSnapshot(tmpDir, {
|
|
41
|
+
schemaVersion: 1,
|
|
42
|
+
snapshottedAt: Date.now(),
|
|
43
|
+
events: [],
|
|
44
|
+
});
|
|
45
|
+
const a = new XiaohongshuAdapter();
|
|
46
|
+
const res = await a.authenticate({ inputPath: p });
|
|
47
|
+
expect(res.ok).toBe(true);
|
|
48
|
+
expect(res.mode).toBe("snapshot-file");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("authenticate(inputPath) fails when path unreadable", async () => {
|
|
52
|
+
const a = new XiaohongshuAdapter();
|
|
53
|
+
const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
|
|
54
|
+
expect(res.ok).toBe(false);
|
|
55
|
+
expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
|
|
59
|
+
const a = new XiaohongshuAdapter();
|
|
60
|
+
const res = await a.authenticate({});
|
|
61
|
+
expect(res.ok).toBe(false);
|
|
62
|
+
expect(res.reason).toBe("NO_INPUT");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("rejects schemaVersion mismatch", async () => {
|
|
66
|
+
const p = writeSnapshot(tmpDir, {
|
|
67
|
+
schemaVersion: 99,
|
|
68
|
+
snapshottedAt: Date.now(),
|
|
69
|
+
events: [],
|
|
70
|
+
});
|
|
71
|
+
const a = new XiaohongshuAdapter();
|
|
72
|
+
let threw = null;
|
|
73
|
+
try {
|
|
74
|
+
for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
|
|
75
|
+
} catch (err) {
|
|
76
|
+
threw = err;
|
|
77
|
+
}
|
|
78
|
+
expect(threw).toBeTruthy();
|
|
79
|
+
expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("empty events array yields nothing (no crash)", async () => {
|
|
83
|
+
const p = writeSnapshot(tmpDir, {
|
|
84
|
+
schemaVersion: 1,
|
|
85
|
+
snapshottedAt: Date.now(),
|
|
86
|
+
events: [],
|
|
87
|
+
});
|
|
88
|
+
const a = new XiaohongshuAdapter();
|
|
89
|
+
const raws = [];
|
|
90
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
91
|
+
expect(raws.length).toBe(0);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("note + liked + follow round-trip normalize cleanly", async () => {
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
const p = writeSnapshot(tmpDir, {
|
|
97
|
+
schemaVersion: 1,
|
|
98
|
+
snapshottedAt: now,
|
|
99
|
+
account: { uid: "5e8c8f7e000000000abcdef0", numericUid: "12345", displayName: "alice" },
|
|
100
|
+
events: [
|
|
101
|
+
{
|
|
102
|
+
kind: "note",
|
|
103
|
+
id: "note-N1",
|
|
104
|
+
capturedAt: now - 1000,
|
|
105
|
+
title: "今日穿搭",
|
|
106
|
+
noteId: "N1",
|
|
107
|
+
desc: "夏日清凉",
|
|
108
|
+
type: "normal",
|
|
109
|
+
likedCount: 100,
|
|
110
|
+
collectedCount: 30,
|
|
111
|
+
commentCount: 15,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
kind: "liked",
|
|
115
|
+
id: "liked-N2",
|
|
116
|
+
capturedAt: now - 2000,
|
|
117
|
+
title: "好喜欢的菜谱",
|
|
118
|
+
noteId: "N2",
|
|
119
|
+
authorNickname: "美食家",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
kind: "follow",
|
|
123
|
+
id: "follow-USR99",
|
|
124
|
+
capturedAt: now - 3000,
|
|
125
|
+
userId: "USR99",
|
|
126
|
+
nickname: "carol",
|
|
127
|
+
image: "https://example.com/c.jpg",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
const a = new XiaohongshuAdapter();
|
|
132
|
+
const raws = [];
|
|
133
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
134
|
+
expect(raws.length).toBe(3);
|
|
135
|
+
|
|
136
|
+
const kinds = raws.map((r) => r.kind);
|
|
137
|
+
expect(kinds).toEqual(["note", "liked", "follow"]);
|
|
138
|
+
|
|
139
|
+
expect(raws[0].originalId).toMatch(/^xiaohongshu:note:/);
|
|
140
|
+
expect(raws[1].originalId).toMatch(/^xiaohongshu:liked:/);
|
|
141
|
+
expect(raws[2].originalId).toMatch(/^xiaohongshu:follow:/);
|
|
142
|
+
|
|
143
|
+
for (const raw of raws) {
|
|
144
|
+
const batch = a.normalize(raw);
|
|
145
|
+
expect(validateBatch(batch).valid).toBe(true);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const noteBatch = a.normalize(raws[0]);
|
|
149
|
+
expect(noteBatch.events[0].subtype).toBe("post");
|
|
150
|
+
expect(noteBatch.events[0].extra.noteId).toBe("N1");
|
|
151
|
+
expect(noteBatch.events[0].extra.likedCount).toBe(100);
|
|
152
|
+
expect(noteBatch.events[0].extra.collectedCount).toBe(30);
|
|
153
|
+
expect(noteBatch.events[0].extra.commentCount).toBe(15);
|
|
154
|
+
expect(noteBatch.events[0].extra.type).toBe("normal");
|
|
155
|
+
expect(noteBatch.events[0].source.capturedBy).toBe("api");
|
|
156
|
+
|
|
157
|
+
const likedBatch = a.normalize(raws[1]);
|
|
158
|
+
expect(likedBatch.events[0].subtype).toBe("like");
|
|
159
|
+
expect(likedBatch.events[0].extra.authorNickname).toBe("美食家");
|
|
160
|
+
|
|
161
|
+
const followBatch = a.normalize(raws[2]);
|
|
162
|
+
expect(followBatch.events.length).toBe(0);
|
|
163
|
+
expect(followBatch.persons.length).toBe(1);
|
|
164
|
+
expect(followBatch.persons[0].names).toEqual(["carol"]);
|
|
165
|
+
expect(followBatch.persons[0].identifiers["xiaohongshu-uid"]).toEqual(["USR99"]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("respects per-kind include opt-out", async () => {
|
|
169
|
+
const now = Date.now();
|
|
170
|
+
const p = writeSnapshot(tmpDir, {
|
|
171
|
+
schemaVersion: 1,
|
|
172
|
+
snapshottedAt: now,
|
|
173
|
+
events: [
|
|
174
|
+
{ kind: "note", id: "n1", capturedAt: now, title: "t", noteId: "N1" },
|
|
175
|
+
{ kind: "liked", id: "l1", capturedAt: now, title: "l", noteId: "N2" },
|
|
176
|
+
{ kind: "follow", id: "fl1", capturedAt: now, userId: "U1", nickname: "x" },
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
const a = new XiaohongshuAdapter();
|
|
180
|
+
const raws = [];
|
|
181
|
+
for await (const r of a.sync({ inputPath: p, include: { liked: false } })) {
|
|
182
|
+
raws.push(r);
|
|
183
|
+
}
|
|
184
|
+
const kinds = raws.map((r) => r.kind);
|
|
185
|
+
expect(kinds).toEqual(["note", "follow"]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("respects opts.limit", async () => {
|
|
189
|
+
const now = Date.now();
|
|
190
|
+
const events = Array.from({ length: 5 }, (_, i) => ({
|
|
191
|
+
kind: "note", id: `n${i}`, capturedAt: now - i * 100, title: `t${i}`, noteId: `N${i}`,
|
|
192
|
+
}));
|
|
193
|
+
const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
|
|
194
|
+
const a = new XiaohongshuAdapter();
|
|
195
|
+
const raws = [];
|
|
196
|
+
for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
|
|
197
|
+
expect(raws.length).toBe(2);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("filters out unknown kinds (forward compat)", async () => {
|
|
201
|
+
const now = Date.now();
|
|
202
|
+
const p = writeSnapshot(tmpDir, {
|
|
203
|
+
schemaVersion: 1,
|
|
204
|
+
snapshottedAt: now,
|
|
205
|
+
events: [
|
|
206
|
+
{ kind: "note", id: "n1", capturedAt: now, title: "ok", noteId: "N1" },
|
|
207
|
+
{ kind: "future-kind", id: "x", capturedAt: now },
|
|
208
|
+
{ kind: "history", id: "h", capturedAt: now }, // sqlite-only
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
const a = new XiaohongshuAdapter();
|
|
212
|
+
const raws = [];
|
|
213
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
214
|
+
expect(raws.length).toBe(1);
|
|
215
|
+
expect(raws[0].kind).toBe("note");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("snapshottedAt fallback when event capturedAt missing", async () => {
|
|
219
|
+
const ts = 1700000000000;
|
|
220
|
+
const p = writeSnapshot(tmpDir, {
|
|
221
|
+
schemaVersion: 1,
|
|
222
|
+
snapshottedAt: ts,
|
|
223
|
+
events: [
|
|
224
|
+
{ kind: "note", id: "n1", title: "no time", noteId: "N1" },
|
|
225
|
+
],
|
|
226
|
+
});
|
|
227
|
+
const a = new XiaohongshuAdapter();
|
|
228
|
+
const raws = [];
|
|
229
|
+
for await (const r of a.sync({ inputPath: p })) raws.push(r);
|
|
230
|
+
expect(raws[0].capturedAt).toBe(ts);
|
|
231
|
+
});
|
|
232
|
+
});
|