@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.
Files changed (39) hide show
  1. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +58 -16
  2. package/__tests__/adapters/wechat-frida-agent.test.js +132 -1
  3. package/__tests__/integration/social-bilibili-pipeline.test.js +261 -0
  4. package/__tests__/longtail-adapters.test.js +60 -14
  5. package/__tests__/messaging-qq-snapshot.test.js +294 -0
  6. package/__tests__/shopping-pinduoduo-snapshot.test.js +302 -0
  7. package/__tests__/shopping-snapshot.test.js +438 -0
  8. package/__tests__/social-adapters.test.js +91 -17
  9. package/__tests__/social-bilibili-snapshot.test.js +278 -0
  10. package/__tests__/social-douyin-snapshot.test.js +253 -0
  11. package/__tests__/social-kuaishou-snapshot.test.js +309 -0
  12. package/__tests__/social-toutiao-snapshot.test.js +314 -0
  13. package/__tests__/social-weibo-snapshot.test.js +234 -0
  14. package/__tests__/social-xiaohongshu-snapshot.test.js +232 -0
  15. package/__tests__/travel-maps-snapshot.test.js +426 -0
  16. package/__tests__/vault-driver-error.test.js +74 -0
  17. package/__tests__/wechat-adapter.test.js +118 -0
  18. package/lib/adapters/messaging-qq/index.js +498 -92
  19. package/lib/adapters/shopping-jd/index.js +228 -25
  20. package/lib/adapters/shopping-meituan/index.js +222 -26
  21. package/lib/adapters/shopping-pinduoduo/index.js +275 -0
  22. package/lib/adapters/social-bilibili/adapter.js +500 -0
  23. package/lib/adapters/social-bilibili/index.js +21 -169
  24. package/lib/adapters/social-douyin/index.js +454 -63
  25. package/lib/adapters/social-kuaishou/index.js +379 -127
  26. package/lib/adapters/social-toutiao/index.js +400 -130
  27. package/lib/adapters/social-weibo/index.js +393 -95
  28. package/lib/adapters/social-xiaohongshu/index.js +389 -49
  29. package/lib/adapters/travel-baidu-map/index.js +286 -26
  30. package/lib/adapters/travel-tencent-map/index.js +414 -0
  31. package/lib/adapters/wechat/content-parser.js +11 -2
  32. package/lib/adapters/wechat/db-reader.js +88 -10
  33. package/lib/adapters/wechat/frida-agent/loader.js +7 -0
  34. package/lib/adapters/wechat/frida-agent/wechat-key-hook.js +140 -18
  35. package/lib/adapters/wechat/key-providers/frida-key-provider.js +8 -0
  36. package/lib/adapters/wechat/normalize.js +12 -3
  37. package/lib/index.js +5 -1
  38. package/lib/vault.js +60 -8
  39. package/package.json +2 -1
@@ -0,0 +1,278 @@
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
+ BilibiliAdapter,
11
+ SNAPSHOT_SCHEMA_VERSION,
12
+ VALID_KINDS,
13
+ } = require("../lib/adapters/social-bilibili");
14
+ const { validateBatch } = require("../lib/batch");
15
+
16
+ // A8 v0.1 (2026-05-22) — snapshot-mode tests, mirroring system-data-android.
17
+ //
18
+ // Why a separate file? `social-adapters.test.js` covers the legacy sqlite
19
+ // path (Phase 7.5 device-pull). Snapshot mode is a brand-new ingestion path
20
+ // driven by in-APK Android cc reading JSON from the phone's own WebView+OkHttp
21
+ // pipeline. Keeping tests separated makes it obvious which mode a regression
22
+ // belongs to.
23
+
24
+ function writeSnapshot(dir, snapshot) {
25
+ const p = path.join(dir, "social-bilibili.json");
26
+ fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
27
+ return p;
28
+ }
29
+
30
+ describe("BilibiliAdapter snapshot mode", () => {
31
+ let tmpDir;
32
+ beforeEach(() => {
33
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "bili-snap-"));
34
+ });
35
+
36
+ it("exports SNAPSHOT_SCHEMA_VERSION = 1 + 4 VALID_KINDS", () => {
37
+ expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
38
+ expect(VALID_KINDS).toEqual(["history", "favourite", "dynamic", "follow"]);
39
+ });
40
+
41
+ it("authenticate(inputPath) ok when readable", async () => {
42
+ const p = writeSnapshot(tmpDir, {
43
+ schemaVersion: 1,
44
+ snapshottedAt: Date.now(),
45
+ events: [],
46
+ });
47
+ const a = new BilibiliAdapter();
48
+ const res = await a.authenticate({ inputPath: p });
49
+ expect(res.ok).toBe(true);
50
+ expect(res.mode).toBe("snapshot-file");
51
+ });
52
+
53
+ it("authenticate(inputPath) fails when path unreadable", async () => {
54
+ const a = new BilibiliAdapter();
55
+ const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
56
+ expect(res.ok).toBe(false);
57
+ expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
58
+ });
59
+
60
+ it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
61
+ const a = new BilibiliAdapter();
62
+ const res = await a.authenticate({});
63
+ expect(res.ok).toBe(false);
64
+ expect(res.reason).toBe("NO_INPUT");
65
+ });
66
+
67
+ it("rejects schemaVersion mismatch", async () => {
68
+ const p = writeSnapshot(tmpDir, {
69
+ schemaVersion: 99,
70
+ snapshottedAt: Date.now(),
71
+ events: [],
72
+ });
73
+ const a = new BilibiliAdapter();
74
+ let threw = null;
75
+ try {
76
+ for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
77
+ } catch (err) {
78
+ threw = err;
79
+ }
80
+ expect(threw).toBeTruthy();
81
+ expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
82
+ });
83
+
84
+ it("empty events array yields nothing (no crash)", async () => {
85
+ const p = writeSnapshot(tmpDir, {
86
+ schemaVersion: 1,
87
+ snapshottedAt: Date.now(),
88
+ events: [],
89
+ });
90
+ const a = new BilibiliAdapter();
91
+ const raws = [];
92
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
93
+ expect(raws).toHaveLength(0);
94
+ });
95
+
96
+ it("yields all 4 kinds + normalize produces valid batches", async () => {
97
+ const p = writeSnapshot(tmpDir, {
98
+ schemaVersion: 1,
99
+ snapshottedAt: 1716000000000,
100
+ account: { uid: "12345", displayName: "alice" },
101
+ events: [
102
+ {
103
+ kind: "history",
104
+ id: "BV1abc",
105
+ capturedAt: 1715000000000,
106
+ title: "Rust 异步学习",
107
+ bvid: "BV1abc",
108
+ avid: 42,
109
+ duration: 600,
110
+ uploader: "技术UP主",
111
+ uploaderMid: 100,
112
+ part: "01 介绍",
113
+ },
114
+ {
115
+ kind: "favourite",
116
+ id: "fav-BV2def",
117
+ capturedAt: 1714000000000,
118
+ title: "前端架构",
119
+ bvid: "BV2def",
120
+ folderName: "学习",
121
+ uploader: "码农UP",
122
+ },
123
+ {
124
+ kind: "dynamic",
125
+ id: "dyn-99",
126
+ capturedAt: 1713000000000,
127
+ summary: "今天发了一个新视频",
128
+ dynamicType: "video",
129
+ rid: 99,
130
+ authorMid: 200,
131
+ authorName: "我关注的UP",
132
+ },
133
+ {
134
+ kind: "follow",
135
+ id: "follow-300",
136
+ capturedAt: 1712000000000,
137
+ mid: 300,
138
+ uname: "美食UP",
139
+ face: "https://i0.hdslb.com/...",
140
+ sign: "好吃的视频",
141
+ },
142
+ ],
143
+ });
144
+ const a = new BilibiliAdapter();
145
+ const raws = [];
146
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
147
+
148
+ expect(raws).toHaveLength(4);
149
+ expect(raws.map((r) => r.kind).sort()).toEqual([
150
+ "dynamic",
151
+ "favourite",
152
+ "follow",
153
+ "history",
154
+ ]);
155
+ // Stable originalId format
156
+ expect(raws.find((r) => r.kind === "history").originalId).toBe("bilibili:history:BV1abc");
157
+ expect(raws.find((r) => r.kind === "favourite").originalId).toBe("bilibili:favourite:fav-BV2def");
158
+ expect(raws.find((r) => r.kind === "dynamic").originalId).toBe("bilibili:dynamic:dyn-99");
159
+ expect(raws.find((r) => r.kind === "follow").originalId).toBe("bilibili:follow:follow-300");
160
+
161
+ // Normalize each + validate
162
+ for (const raw of raws) {
163
+ const batch = a.normalize(raw);
164
+ const v = validateBatch(batch);
165
+ expect(v.valid).toBe(true);
166
+
167
+ if (raw.kind === "history") {
168
+ expect(batch.events[0].subtype).toBe("browse");
169
+ expect(batch.events[0].extra.bvid).toBe("BV1abc");
170
+ expect(batch.events[0].extra.duration).toBe(600);
171
+ expect(batch.items).toHaveLength(1);
172
+ expect(batch.items[0].name).toBe("Rust 异步学习");
173
+ } else if (raw.kind === "favourite") {
174
+ expect(batch.events[0].subtype).toBe("like");
175
+ expect(batch.events[0].extra.folderName).toBe("学习");
176
+ expect(batch.items).toHaveLength(1);
177
+ } else if (raw.kind === "dynamic") {
178
+ expect(batch.events[0].subtype).toBe("browse");
179
+ expect(batch.events[0].extra.dynamicType).toBe("video");
180
+ expect(batch.events[0].extra.authorName).toBe("我关注的UP");
181
+ } else if (raw.kind === "follow") {
182
+ // Follow yields a person, not an event
183
+ expect(batch.events).toHaveLength(0);
184
+ expect(batch.persons).toHaveLength(1);
185
+ expect(batch.persons[0].names[0]).toBe("美食UP");
186
+ expect(batch.persons[0].identifiers["bilibili-mid"]).toEqual(["300"]);
187
+ }
188
+ }
189
+ });
190
+
191
+ it("per-kind include filter (e.g. include.follow=false drops follows)", async () => {
192
+ const p = writeSnapshot(tmpDir, {
193
+ schemaVersion: 1,
194
+ snapshottedAt: Date.now(),
195
+ events: [
196
+ { kind: "history", id: "h1", title: "x" },
197
+ { kind: "follow", id: "f1", mid: 1, uname: "u" },
198
+ ],
199
+ });
200
+ const a = new BilibiliAdapter();
201
+ const raws = [];
202
+ for await (const r of a.sync({ inputPath: p, include: { follow: false } })) {
203
+ raws.push(r);
204
+ }
205
+ expect(raws).toHaveLength(1);
206
+ expect(raws[0].kind).toBe("history");
207
+ });
208
+
209
+ it("limit caps emission", async () => {
210
+ const p = writeSnapshot(tmpDir, {
211
+ schemaVersion: 1,
212
+ snapshottedAt: Date.now(),
213
+ events: [
214
+ { kind: "history", id: "1", title: "a" },
215
+ { kind: "history", id: "2", title: "b" },
216
+ { kind: "history", id: "3", title: "c" },
217
+ ],
218
+ });
219
+ const a = new BilibiliAdapter();
220
+ const raws = [];
221
+ for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
222
+ expect(raws).toHaveLength(2);
223
+ });
224
+
225
+ it("skips unknown kinds (forward-compat with future event types)", async () => {
226
+ const p = writeSnapshot(tmpDir, {
227
+ schemaVersion: 1,
228
+ snapshottedAt: Date.now(),
229
+ events: [
230
+ { kind: "history", id: "1", title: "ok" },
231
+ { kind: "fancy-new-kind-from-future", id: "x", data: "?" },
232
+ { kind: "favourite", id: "f", title: "also ok" },
233
+ ],
234
+ });
235
+ const a = new BilibiliAdapter();
236
+ const raws = [];
237
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
238
+ expect(raws).toHaveLength(2);
239
+ expect(raws.map((r) => r.kind).sort()).toEqual(["favourite", "history"]);
240
+ });
241
+
242
+ it("uses fallback originalId when event.id absent (no crash, still ingestable)", async () => {
243
+ const p = writeSnapshot(tmpDir, {
244
+ schemaVersion: 1,
245
+ snapshottedAt: Date.now(),
246
+ events: [
247
+ // Missing id — adapter should derive from bvid/mid/rid or generate fallback
248
+ { kind: "history", bvid: "BV1xyz", title: "no-id" },
249
+ { kind: "follow", mid: 999, uname: "with-mid-no-id" },
250
+ { kind: "dynamic", summary: "no id no rid" },
251
+ ],
252
+ });
253
+ const a = new BilibiliAdapter();
254
+ const raws = [];
255
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
256
+ expect(raws).toHaveLength(3);
257
+ // history derives from bvid
258
+ expect(raws[0].originalId).toBe("bilibili:history:BV1xyz");
259
+ // follow derives from mid
260
+ expect(raws[1].originalId).toBe("bilibili:follow:999");
261
+ // dynamic with no id/bvid/mid/rid → fallback unknown- prefix
262
+ expect(raws[2].originalId).toMatch(/^bilibili:dynamic:unknown-/);
263
+ });
264
+
265
+ it("snapshot account propagates to payload (Path Y can re-attribute later)", async () => {
266
+ const p = writeSnapshot(tmpDir, {
267
+ schemaVersion: 1,
268
+ snapshottedAt: Date.now(),
269
+ account: { uid: "55555", displayName: "tester" },
270
+ events: [{ kind: "history", id: "1", title: "x" }],
271
+ });
272
+ const a = new BilibiliAdapter();
273
+ const raws = [];
274
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
275
+ expect(raws).toHaveLength(1);
276
+ expect(raws[0].payload.account.uid).toBe("55555");
277
+ });
278
+ });
@@ -0,0 +1,253 @@
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 + 4 VALID_SNAPSHOT_KINDS", () => {
37
+ expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
38
+ // v0.2 emits only profile; v0.3 will add history/favourite/like.
39
+ expect(VALID_SNAPSHOT_KINDS).toEqual([
40
+ "profile",
41
+ "history",
42
+ "favourite",
43
+ "like",
44
+ ]);
45
+ });
46
+
47
+ it("authenticate(inputPath) ok when readable", async () => {
48
+ const p = writeSnapshot(tmpDir, {
49
+ schemaVersion: 1,
50
+ snapshottedAt: Date.now(),
51
+ events: [],
52
+ });
53
+ const a = new DouyinAdapter();
54
+ const res = await a.authenticate({ inputPath: p });
55
+ expect(res.ok).toBe(true);
56
+ expect(res.mode).toBe("snapshot-file");
57
+ });
58
+
59
+ it("authenticate(inputPath) fails when path unreadable", async () => {
60
+ const a = new DouyinAdapter();
61
+ const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
62
+ expect(res.ok).toBe(false);
63
+ expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
64
+ });
65
+
66
+ it("authenticate() with neither inputPath nor dbPath returns NO_INPUT", async () => {
67
+ const a = new DouyinAdapter();
68
+ const res = await a.authenticate({});
69
+ expect(res.ok).toBe(false);
70
+ expect(res.reason).toBe("NO_INPUT");
71
+ });
72
+
73
+ it("rejects schemaVersion mismatch", async () => {
74
+ const p = writeSnapshot(tmpDir, {
75
+ schemaVersion: 99,
76
+ snapshottedAt: Date.now(),
77
+ events: [],
78
+ });
79
+ const a = new DouyinAdapter();
80
+ let threw = null;
81
+ try {
82
+ for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
83
+ } catch (err) {
84
+ threw = err;
85
+ }
86
+ expect(threw).toBeTruthy();
87
+ expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
88
+ });
89
+
90
+ it("empty events array yields nothing (no crash)", async () => {
91
+ const p = writeSnapshot(tmpDir, {
92
+ schemaVersion: 1,
93
+ snapshottedAt: Date.now(),
94
+ events: [],
95
+ });
96
+ const a = new DouyinAdapter();
97
+ const raws = [];
98
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
99
+ expect(raws.length).toBe(0);
100
+ });
101
+
102
+ it("profile event round-trips normalize cleanly", async () => {
103
+ const now = Date.now();
104
+ const p = writeSnapshot(tmpDir, {
105
+ schemaVersion: 1,
106
+ snapshottedAt: now,
107
+ account: {
108
+ secUid: "MS4wLjABAAAA_alice",
109
+ shortId: "12345678",
110
+ displayName: "alice",
111
+ },
112
+ events: [
113
+ {
114
+ kind: "profile",
115
+ id: "profile-MS4wLjABAAAA_alice",
116
+ capturedAt: now - 1000,
117
+ secUid: "MS4wLjABAAAA_alice",
118
+ shortId: "12345678",
119
+ nickname: "alice",
120
+ signature: "hello world",
121
+ followingCount: 100,
122
+ followerCount: 200,
123
+ awemeCount: 5,
124
+ favoritingCount: 30,
125
+ totalFavorited: 1500,
126
+ },
127
+ ],
128
+ });
129
+ const a = new DouyinAdapter();
130
+ const raws = [];
131
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
132
+ expect(raws.length).toBe(1);
133
+ expect(raws[0].kind).toBe("profile");
134
+ expect(raws[0].originalId).toMatch(/^douyin:profile:/);
135
+
136
+ const batch = a.normalize(raws[0]);
137
+ expect(validateBatch(batch).valid).toBe(true);
138
+ // v0.2 emits a person record (self) not an event — repeated syncs
139
+ // dedupe on the same id.
140
+ expect(batch.events.length).toBe(0);
141
+ expect(batch.persons.length).toBe(1);
142
+ const person = batch.persons[0];
143
+ expect(person.id).toBe("person-douyin-MS4wLjABAAAA_alice");
144
+ expect(person.subtype).toBe("self");
145
+ expect(person.names).toEqual(["alice"]);
146
+ expect(person.identifiers["douyin-sec-uid"]).toEqual(["MS4wLjABAAAA_alice"]);
147
+ expect(person.identifiers["douyin-short-id"]).toEqual(["12345678"]);
148
+ expect(person.extra.platform).toBe("douyin");
149
+ expect(person.extra.signature).toBe("hello world");
150
+ expect(person.extra.followerCount).toBe(200);
151
+ expect(person.extra.awemeCount).toBe(5);
152
+ expect(person.extra.totalFavorited).toBe(1500);
153
+ expect(person.source.capturedBy).toBe("api");
154
+ });
155
+
156
+ it("respects per-kind include opt-out", async () => {
157
+ const now = Date.now();
158
+ const p = writeSnapshot(tmpDir, {
159
+ schemaVersion: 1,
160
+ snapshottedAt: now,
161
+ events: [
162
+ { kind: "profile", id: "profile-X", capturedAt: now, secUid: "X", nickname: "x" },
163
+ ],
164
+ });
165
+ const a = new DouyinAdapter();
166
+ const raws = [];
167
+ for await (const r of a.sync({ inputPath: p, include: { profile: false } })) {
168
+ raws.push(r);
169
+ }
170
+ expect(raws.length).toBe(0);
171
+ });
172
+
173
+ it("respects opts.limit", async () => {
174
+ // v0.2 unlikely to emit more than 1 profile, but verify the gate is wired.
175
+ const now = Date.now();
176
+ const events = [
177
+ { kind: "profile", id: "p1", capturedAt: now, secUid: "X1", nickname: "x1" },
178
+ // simulate forward-compat: a v0.3 snapshot with history events
179
+ { kind: "history", id: "h1", capturedAt: now - 1000, awemeId: "A1", title: "t1" },
180
+ { kind: "history", id: "h2", capturedAt: now - 2000, awemeId: "A2", title: "t2" },
181
+ ];
182
+ const p = writeSnapshot(tmpDir, { schemaVersion: 1, snapshottedAt: now, events });
183
+ const a = new DouyinAdapter();
184
+ const raws = [];
185
+ for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
186
+ expect(raws.length).toBe(2);
187
+ });
188
+
189
+ it("filters out unknown kinds (forward compat)", async () => {
190
+ const now = Date.now();
191
+ const p = writeSnapshot(tmpDir, {
192
+ schemaVersion: 1,
193
+ snapshottedAt: now,
194
+ events: [
195
+ { kind: "profile", id: "p1", capturedAt: now, secUid: "X", nickname: "x" },
196
+ { kind: "future-kind", id: "x", capturedAt: now },
197
+ { kind: "search", id: "s", capturedAt: now }, // search is sqlite-only
198
+ ],
199
+ });
200
+ const a = new DouyinAdapter();
201
+ const raws = [];
202
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
203
+ expect(raws.length).toBe(1);
204
+ expect(raws[0].kind).toBe("profile");
205
+ });
206
+
207
+ it("snapshottedAt fallback when event capturedAt missing", async () => {
208
+ const ts = 1700000000000;
209
+ const p = writeSnapshot(tmpDir, {
210
+ schemaVersion: 1,
211
+ snapshottedAt: ts,
212
+ events: [
213
+ { kind: "profile", id: "p1", secUid: "X", nickname: "x" },
214
+ ],
215
+ });
216
+ const a = new DouyinAdapter();
217
+ const raws = [];
218
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
219
+ expect(raws[0].capturedAt).toBe(ts);
220
+ });
221
+
222
+ it("v0.3 forward-compat: history events round-trip if a future snapshot ships them", async () => {
223
+ // The Kotlin LocalCollector won't emit these in v0.2, but the JS adapter
224
+ // already knows how to ingest them — so when v0.3 lands we won't have to
225
+ // bump SNAPSHOT_SCHEMA_VERSION.
226
+ const now = Date.now();
227
+ const p = writeSnapshot(tmpDir, {
228
+ schemaVersion: 1,
229
+ snapshottedAt: now,
230
+ events: [
231
+ {
232
+ kind: "history",
233
+ id: "history-A1",
234
+ capturedAt: now - 1000,
235
+ awemeId: "A1",
236
+ title: "future video",
237
+ author: "creator",
238
+ duration: 30,
239
+ },
240
+ ],
241
+ });
242
+ const a = new DouyinAdapter();
243
+ const raws = [];
244
+ for await (const r of a.sync({ inputPath: p })) raws.push(r);
245
+ expect(raws.length).toBe(1);
246
+ expect(raws[0].kind).toBe("history");
247
+ const batch = a.normalize(raws[0]);
248
+ expect(validateBatch(batch).valid).toBe(true);
249
+ expect(batch.events[0].subtype).toBe("browse");
250
+ expect(batch.events[0].extra.awemeId).toBe("A1");
251
+ expect(batch.events[0].extra.duration).toBe(30);
252
+ });
253
+ });