@chainlesschain/personal-data-hub 0.4.28 → 0.4.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/lib/adapters/social-douyin-adb/usage-profile-reader.js +253 -0
- package/lib/adapters/social-douyin-adb/watch-history-reader.js +104 -31
- package/lib/adapters/social-toutiao-adb/article-reader.js +202 -0
- package/lib/analysis-skills/overview.js +24 -4
- package/lib/analysis-skills/spending.js +63 -2
- package/lib/analysis-skills/timeline.js +11 -6
- package/lib/prompt-builder.js +15 -1
- package/lib/query-parser.js +38 -8
- package/package.json +4 -1
- package/__tests__/adapter-guide.test.js +0 -47
- package/__tests__/adapter-spec.test.js +0 -78
- package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
- package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
- package/__tests__/adapters/ai-chat-history.test.js +0 -396
- package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
- package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
- package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
- package/__tests__/adapters/apple-health.test.js +0 -95
- package/__tests__/adapters/bank-family.test.js +0 -125
- package/__tests__/adapters/biz-tianyancha.test.js +0 -159
- package/__tests__/adapters/browser-history-chrome.test.js +0 -377
- package/__tests__/adapters/browser-history-edge.test.js +0 -159
- package/__tests__/adapters/car-mercedesme.test.js +0 -74
- package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
- package/__tests__/adapters/doc-camscanner.test.js +0 -147
- package/__tests__/adapters/doc-platforms.test.js +0 -177
- package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
- package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
- package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
- package/__tests__/adapters/email-adapter.test.js +0 -742
- package/__tests__/adapters/email-classifier.test.js +0 -347
- package/__tests__/adapters/email-imap-session.test.js +0 -334
- package/__tests__/adapters/email-parser.test.js +0 -244
- package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
- package/__tests__/adapters/email-providers.test.js +0 -84
- package/__tests__/adapters/email-retry-progress.test.js +0 -294
- package/__tests__/adapters/email-templates.test.js +0 -822
- package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
- package/__tests__/adapters/finance-alipay-live.test.js +0 -258
- package/__tests__/adapters/finance-dcep.test.js +0 -74
- package/__tests__/adapters/fitness-joyrun.test.js +0 -82
- package/__tests__/adapters/game-genshin-live.test.js +0 -238
- package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
- package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
- package/__tests__/adapters/git-activity.test.js +0 -222
- package/__tests__/adapters/gov-12123.test.js +0 -103
- package/__tests__/adapters/gov-ixiamen.test.js +0 -150
- package/__tests__/adapters/gov-tax.test.js +0 -135
- package/__tests__/adapters/health-meiyou.test.js +0 -125
- package/__tests__/adapters/local-files.test.js +0 -264
- package/__tests__/adapters/local-im-pc.test.js +0 -154
- package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
- package/__tests__/adapters/music-kugou.test.js +0 -187
- package/__tests__/adapters/music-qq.test.js +0 -112
- package/__tests__/adapters/netease-music-live.test.js +0 -244
- package/__tests__/adapters/netease-music.test.js +0 -74
- package/__tests__/adapters/pc-local-discovery.test.js +0 -141
- package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
- package/__tests__/adapters/reading-family.test.js +0 -108
- package/__tests__/adapters/recruit-boss.test.js +0 -180
- package/__tests__/adapters/shell-history.test.js +0 -180
- package/__tests__/adapters/shopping-base.test.js +0 -179
- package/__tests__/adapters/shopping-dianping.test.js +0 -239
- package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
- package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
- package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
- package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
- package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
- package/__tests__/adapters/social-csdn.test.js +0 -175
- package/__tests__/adapters/social-dongchedi.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
- package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
- package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
- package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
- package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -192
- package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
- package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
- package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
- package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
- package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
- package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
- package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
- package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
- package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
- package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
- package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
- package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
- package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
- package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
- package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
- package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
- package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
- package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
- package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
- package/__tests__/adapters/social-zhihu.test.js +0 -246
- package/__tests__/adapters/system-data-adapter.test.js +0 -443
- package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
- package/__tests__/adapters/system-data-android.test.js +0 -519
- package/__tests__/adapters/system-data-disclosure.test.js +0 -153
- package/__tests__/adapters/travel-12306.test.js +0 -512
- package/__tests__/adapters/travel-amap.test.js +0 -219
- package/__tests__/adapters/travel-baidu-map.test.js +0 -305
- package/__tests__/adapters/travel-base.test.js +0 -205
- package/__tests__/adapters/travel-ctrip.test.js +0 -377
- package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
- package/__tests__/adapters/travel-didi.test.js +0 -204
- package/__tests__/adapters/travel-tencent-map.test.js +0 -207
- package/__tests__/adapters/travel-tongcheng.test.js +0 -289
- package/__tests__/adapters/video-platforms.test.js +0 -152
- package/__tests__/adapters/video-xigua.test.js +0 -106
- package/__tests__/adapters/vscode.test.js +0 -299
- package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
- package/__tests__/adapters/wechat-env-probe.test.js +0 -162
- package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
- package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
- package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
- package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
- package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
- package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
- package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
- package/__tests__/adapters/weread.test.js +0 -123
- package/__tests__/adapters/wework-pc.test.js +0 -124
- package/__tests__/adapters/win-recent.test.js +0 -192
- package/__tests__/analysis-skills.test.js +0 -679
- package/__tests__/analysis.test.js +0 -1845
- package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
- package/__tests__/batch.test.js +0 -133
- package/__tests__/bridges-cc-kg.test.js +0 -231
- package/__tests__/bridges-cc-llm.test.js +0 -191
- package/__tests__/bridges-cc-rag.test.js +0 -162
- package/__tests__/categories.test.js +0 -92
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
- package/__tests__/e2e/full-user-journey.test.js +0 -188
- package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
- package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
- package/__tests__/entity-resolver-stages.test.js +0 -411
- package/__tests__/entity-resolver-vault.test.js +0 -249
- package/__tests__/entity-resolver.test.js +0 -526
- package/__tests__/fitness-keep-snapshot.test.js +0 -224
- package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
- package/__tests__/ids.test.js +0 -45
- package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
- package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
- package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
- package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
- package/__tests__/key-providers.test.js +0 -126
- package/__tests__/kg-derive.test.js +0 -219
- package/__tests__/llm-client.test.js +0 -122
- package/__tests__/longtail-adapters.test.js +0 -281
- package/__tests__/messaging-qq-snapshot.test.js +0 -294
- package/__tests__/mobile-extractor-encrypted.test.js +0 -460
- package/__tests__/mobile-extractor.test.js +0 -288
- package/__tests__/mock-adapter.test.js +0 -93
- package/__tests__/prompt-builder.test.js +0 -249
- package/__tests__/query-parser.test.js +0 -302
- package/__tests__/rag-derive.test.js +0 -169
- package/__tests__/registry-readiness.test.js +0 -292
- package/__tests__/registry.test.js +0 -420
- package/__tests__/salvage-ingest.test.js +0 -97
- package/__tests__/schemas.test.js +0 -331
- package/__tests__/shopping-adapters.test.js +0 -392
- package/__tests__/shopping-eleme-snapshot.test.js +0 -454
- package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
- package/__tests__/shopping-snapshot.test.js +0 -438
- package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
- package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
- package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
- package/__tests__/sidecar-supervisor.test.js +0 -128
- package/__tests__/sign-providers.test.js +0 -62
- package/__tests__/social-adapters.test.js +0 -280
- package/__tests__/social-bilibili-snapshot.test.js +0 -278
- package/__tests__/social-douban-snapshot.test.js +0 -351
- package/__tests__/social-douyin-im-direct-read.test.js +0 -377
- package/__tests__/social-douyin-salvage-collector.test.js +0 -98
- package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
- package/__tests__/social-douyin-snapshot.test.js +0 -256
- package/__tests__/social-kuaishou-snapshot.test.js +0 -362
- package/__tests__/social-toutiao-snapshot.test.js +0 -366
- package/__tests__/social-weibo-snapshot.test.js +0 -234
- package/__tests__/social-weibo-sqlite-device.test.js +0 -174
- package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
- package/__tests__/sqlite-leaf-salvage.test.js +0 -97
- package/__tests__/travel-adapters.test.js +0 -483
- package/__tests__/travel-maps-snapshot.test.js +0 -426
- package/__tests__/vault-driver-error.test.js +0 -74
- package/__tests__/vault-search-helpers.test.js +0 -104
- package/__tests__/vault-search.test.js +0 -423
- package/__tests__/vault.test.js +0 -767
- package/__tests__/wechat-adapter.test.js +0 -594
- package/__tests__/whatsapp-adapter.test.js +0 -138
- package/scripts/_make-fixture-all.js +0 -126
- package/scripts/_make-fixture-contacts.js +0 -84
- package/scripts/evaluate-entity-resolver.js +0 -213
- package/scripts/run-native-tests-sandbox.sh +0 -55
- package/scripts/smoke-phase-5-5.js +0 -196
- package/scripts/smoke-phase-5-7.js +0 -181
- package/scripts/smoke-system-data-contacts.js +0 -309
- package/scripts/smoke-system-data.js +0 -312
- package/vitest.config.js +0 -88
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
4
|
-
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
const os = require("node:os");
|
|
8
|
-
|
|
9
|
-
const { WeiboAdapter } = require("../lib/adapters/social-weibo");
|
|
10
|
-
|
|
11
|
-
// §A8 sqlite mode — device-verified schema regression tests.
|
|
12
|
-
//
|
|
13
|
-
// The legacy sqlite path queried `post`/`status`/`search_history`, but a real
|
|
14
|
-
// Weibo install (Redmi M2104K10AC, 微博 16.5.3, verified 2026-06-16) has NO
|
|
15
|
-
// such tables — its data lives in `home_table` (timeline), `like_table`
|
|
16
|
-
// (likes), `follower_table` (following). So the legacy path silently
|
|
17
|
-
// collected ZERO on a real device. These tests pin the device-verified
|
|
18
|
-
// table/column mapping + the legacy fallback.
|
|
19
|
-
//
|
|
20
|
-
// A fake driver returns synthetic rows keyed off the table name in the SQL,
|
|
21
|
-
// and throws "no such table" for absent tables (mirroring better-sqlite3) so
|
|
22
|
-
// `trySelect` falls through exactly as on a real DB.
|
|
23
|
-
|
|
24
|
-
function makeFakeDriver(tables) {
|
|
25
|
-
return function dbDriverFactory() {
|
|
26
|
-
return class FakeDb {
|
|
27
|
-
constructor() {}
|
|
28
|
-
prepare(sql) {
|
|
29
|
-
return {
|
|
30
|
-
all: () => {
|
|
31
|
-
for (const [name, rows] of Object.entries(tables)) {
|
|
32
|
-
if (new RegExp(`FROM ${name}\\b`).test(sql)) return rows;
|
|
33
|
-
}
|
|
34
|
-
throw new Error("no such table");
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
close() {}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const SELF_UID = "2075014533";
|
|
44
|
-
|
|
45
|
-
// Device-verified column shapes.
|
|
46
|
-
const HOME_ROW = {
|
|
47
|
-
mblogid: "MID_001",
|
|
48
|
-
uid: SELF_UID,
|
|
49
|
-
own_uid: SELF_UID,
|
|
50
|
-
nick: "me",
|
|
51
|
-
content: "今天去爬山了 ⛰️",
|
|
52
|
-
time: "1718500000",
|
|
53
|
-
src: "微博 weibo.com",
|
|
54
|
-
rtnum: 3,
|
|
55
|
-
commentnum: 7,
|
|
56
|
-
attitudenum: 42,
|
|
57
|
-
};
|
|
58
|
-
const LIKE_ROW = {
|
|
59
|
-
mblogid: "MID_LIKED",
|
|
60
|
-
uid: "999",
|
|
61
|
-
nick: "好友A",
|
|
62
|
-
content: "一条被点赞的微博",
|
|
63
|
-
time: "1718400000",
|
|
64
|
-
attitudenum: 100,
|
|
65
|
-
};
|
|
66
|
-
const FOLLOW_ROW = {
|
|
67
|
-
user_id: "555",
|
|
68
|
-
id: "555",
|
|
69
|
-
screen_name: "关注的人",
|
|
70
|
-
remark: "",
|
|
71
|
-
gender: "f",
|
|
72
|
-
following: 1,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
function newAdapter(tables) {
|
|
76
|
-
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "weibo-sqlite-"));
|
|
77
|
-
const dbPath = path.join(tmp, "sina_weibo");
|
|
78
|
-
fs.writeFileSync(dbPath, "x"); // existsSync gate
|
|
79
|
-
const a = new WeiboAdapter({
|
|
80
|
-
account: { uid: SELF_UID },
|
|
81
|
-
dbPath,
|
|
82
|
-
dbDriverFactory: makeFakeDriver(tables),
|
|
83
|
-
});
|
|
84
|
-
return { a, dbPath, tmp };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function collect(a, dbPath) {
|
|
88
|
-
const out = [];
|
|
89
|
-
for await (const raw of a.sync({ dbPath })) out.push(raw);
|
|
90
|
-
return out;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
describe("WeiboAdapter sqlite mode — device-verified schema", () => {
|
|
94
|
-
let dirs = [];
|
|
95
|
-
afterEach(() => {
|
|
96
|
-
for (const d of dirs) {
|
|
97
|
-
try { fs.rmSync(d, { recursive: true, force: true }); } catch (_e) { /* ignore */ }
|
|
98
|
-
}
|
|
99
|
-
dirs = [];
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("modern device (home/like/follower only) collects posts+favs+follows", async () => {
|
|
103
|
-
const { a, dbPath, tmp } = newAdapter({
|
|
104
|
-
home_table: [HOME_ROW],
|
|
105
|
-
like_table: [LIKE_ROW],
|
|
106
|
-
follower_table: [FOLLOW_ROW],
|
|
107
|
-
});
|
|
108
|
-
dirs.push(tmp);
|
|
109
|
-
const raws = await collect(a, dbPath);
|
|
110
|
-
const kinds = raws.map((r) => r.payload.kind).sort();
|
|
111
|
-
expect(kinds).toEqual(["favourite", "follow", "post"]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("home_table post normalizes content/time/counts correctly", async () => {
|
|
115
|
-
const { a, dbPath, tmp } = newAdapter({ home_table: [HOME_ROW] });
|
|
116
|
-
dirs.push(tmp);
|
|
117
|
-
const raws = await collect(a, dbPath);
|
|
118
|
-
expect(raws).toHaveLength(1);
|
|
119
|
-
const norm = a.normalize(raws[0]);
|
|
120
|
-
const ev = norm.events[0];
|
|
121
|
-
expect(ev.subtype).toBe("post");
|
|
122
|
-
expect(ev.content.text).toBe("今天去爬山了 ⛰️");
|
|
123
|
-
expect(ev.extra.weiboMid).toBe("MID_001");
|
|
124
|
-
expect(ev.extra.likesCount).toBe(42);
|
|
125
|
-
expect(ev.extra.repostsCount).toBe(3);
|
|
126
|
-
expect(ev.extra.commentsCount).toBe(7);
|
|
127
|
-
// time '1718500000' (epoch seconds) → ms
|
|
128
|
-
expect(ev.occurredAt).toBe(1718500000 * 1000);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("like_table normalizes to a LIKE event with author nick", async () => {
|
|
132
|
-
const { a, dbPath, tmp } = newAdapter({ like_table: [LIKE_ROW] });
|
|
133
|
-
dirs.push(tmp);
|
|
134
|
-
const raws = await collect(a, dbPath);
|
|
135
|
-
const norm = a.normalize(raws[0]);
|
|
136
|
-
const ev = norm.events[0];
|
|
137
|
-
expect(ev.subtype).toBe("like");
|
|
138
|
-
expect(ev.content.text).toBe("一条被点赞的微博");
|
|
139
|
-
expect(ev.extra.weiboMid).toBe("MID_LIKED");
|
|
140
|
-
expect(ev.extra.authorScreenName).toBe("好友A");
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("follower_table normalizes to a CONTACT person with weibo-uid", async () => {
|
|
144
|
-
const { a, dbPath, tmp } = newAdapter({ follower_table: [FOLLOW_ROW] });
|
|
145
|
-
dirs.push(tmp);
|
|
146
|
-
const raws = await collect(a, dbPath);
|
|
147
|
-
const norm = a.normalize(raws[0]);
|
|
148
|
-
expect(norm.events).toHaveLength(0);
|
|
149
|
-
expect(norm.persons).toHaveLength(1);
|
|
150
|
-
const person = norm.persons[0];
|
|
151
|
-
expect(person.names).toEqual(["关注的人"]);
|
|
152
|
-
expect(person.identifiers["weibo-uid"]).toEqual(["555"]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("legacy device (post table, no home_table) still works via fallback", async () => {
|
|
156
|
-
const { a, dbPath, tmp } = newAdapter({
|
|
157
|
-
post: [{ id: "L1", text: "legacy post", created_at: "1700000000", attitudes_count: 5 }],
|
|
158
|
-
});
|
|
159
|
-
dirs.push(tmp);
|
|
160
|
-
const raws = await collect(a, dbPath);
|
|
161
|
-
expect(raws).toHaveLength(1);
|
|
162
|
-
const ev = a.normalize(raws[0]).events[0];
|
|
163
|
-
expect(ev.subtype).toBe("post");
|
|
164
|
-
expect(ev.content.text).toBe("legacy post");
|
|
165
|
-
expect(ev.extra.likesCount).toBe(5);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("empty DB (none of the tables exist) collects nothing, no throw", async () => {
|
|
169
|
-
const { a, dbPath, tmp } = newAdapter({});
|
|
170
|
-
dirs.push(tmp);
|
|
171
|
-
const raws = await collect(a, dbPath);
|
|
172
|
-
expect(raws).toEqual([]);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
@@ -1,232 +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
|
-
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
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
4
|
-
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
const os = require("node:os");
|
|
8
|
-
|
|
9
|
-
// The salvager lives in scripts/ (a standalone forensic tool) but exports its
|
|
10
|
-
// pure parsers for testing.
|
|
11
|
-
const {
|
|
12
|
-
parseLeafPage,
|
|
13
|
-
readVarint,
|
|
14
|
-
serialTypeSize,
|
|
15
|
-
} = require("../../../scripts/android/pdh-sqlite-leaf-salvage.js");
|
|
16
|
-
|
|
17
|
-
// Build a real (UTF-8) SQLite DB via the SQLCipher-capable driver, then salvage
|
|
18
|
-
// records straight from its raw page bytes — proving the leaf-page parser reads
|
|
19
|
-
// rowids + columns + UTF-8 text correctly (the Method-B reconstruction step for
|
|
20
|
-
// scattered/malformed memory dumps). See docs/internal/pdh-db-decryption-runbook.md.
|
|
21
|
-
describe("pdh-sqlite-leaf-salvage — leaf-page record salvager", () => {
|
|
22
|
-
let dir, dbPath, buf;
|
|
23
|
-
beforeAll(() => {
|
|
24
|
-
const Database = require("better-sqlite3-multiple-ciphers");
|
|
25
|
-
dir = fs.mkdtempSync(path.join(os.tmpdir(), "salvage-"));
|
|
26
|
-
dbPath = path.join(dir, "u.db");
|
|
27
|
-
const db = new Database(dbPath);
|
|
28
|
-
db.exec(
|
|
29
|
-
"CREATE TABLE msg(msg_uuid TEXT, conversation_id TEXT, sender INTEGER, content TEXT, created_time INTEGER)",
|
|
30
|
-
);
|
|
31
|
-
const ins = db.prepare("INSERT INTO msg VALUES(?,?,?,?,?)");
|
|
32
|
-
ins.run("uuid-1", "conv-1", 111, "你好呀 hello", 1700000000000);
|
|
33
|
-
ins.run("uuid-2", "conv-1", 222, "在吗?晚上一起吃饭", 1700000001000);
|
|
34
|
-
ins.run("uuid-3", "conv-2", 333, "ok 👍", 1700000002000);
|
|
35
|
-
db.close();
|
|
36
|
-
buf = fs.readFileSync(dbPath);
|
|
37
|
-
});
|
|
38
|
-
afterAll(() => {
|
|
39
|
-
try { fs.rmSync(dir, { recursive: true, force: true }); } catch (_e) { /* ignore */ }
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("varint + serialTypeSize basics", () => {
|
|
43
|
-
expect(readVarint(Buffer.from([0x01]), 0)[0]).toBe(1n);
|
|
44
|
-
expect(readVarint(Buffer.from([0x81, 0x00]), 0)[0]).toBe(128n);
|
|
45
|
-
expect(serialTypeSize(1n)).toBe(1); // 1-byte int
|
|
46
|
-
expect(serialTypeSize(6n)).toBe(8); // 8-byte int
|
|
47
|
-
expect(serialTypeSize(13n)).toBe(0); // text len 0
|
|
48
|
-
expect(serialTypeSize(0x29n)).toBe(14); // text serial 41 → 14 bytes
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("salvages all 3 msg rows with correct columns + UTF-8 text", () => {
|
|
52
|
-
const PAGE = 4096;
|
|
53
|
-
const records = [];
|
|
54
|
-
for (let base = 0; base + PAGE <= buf.length; base += PAGE) {
|
|
55
|
-
const recs = parseLeafPage(buf, base, PAGE, 3);
|
|
56
|
-
if (recs) records.push(...recs);
|
|
57
|
-
}
|
|
58
|
-
// find the msg rows (5 cols, content is the 4th)
|
|
59
|
-
const msgRows = records.filter((r) => r.cols.length === 5);
|
|
60
|
-
expect(msgRows.length).toBe(3);
|
|
61
|
-
const byUuid = Object.fromEntries(msgRows.map((r) => [r.cols[0], r]));
|
|
62
|
-
expect(byUuid["uuid-1"].cols[2]).toBe(111); // sender int
|
|
63
|
-
expect(byUuid["uuid-1"].cols[3]).toBe("你好呀 hello"); // UTF-8 intact
|
|
64
|
-
expect(byUuid["uuid-2"].cols[3]).toBe("在吗?晚上一起吃饭");
|
|
65
|
-
expect(byUuid["uuid-2"].cols[4]).toBe(1700000001000); // created_time
|
|
66
|
-
expect(byUuid["uuid-3"].cols[3]).toBe("ok 👍"); // emoji (4-byte UTF-8)
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("finds a leaf page at a NON-4096-aligned offset (unaligned scan)", () => {
|
|
70
|
-
const PAGE = 4096;
|
|
71
|
-
// locate a real data leaf page on the aligned grid
|
|
72
|
-
let leaf = null;
|
|
73
|
-
for (let base = 0; base + PAGE <= buf.length; base += PAGE) {
|
|
74
|
-
const recs = parseLeafPage(buf, base, PAGE, 3);
|
|
75
|
-
if (recs && recs.some((r) => r.cols.length === 5)) { leaf = buf.slice(base, base + PAGE); break; }
|
|
76
|
-
}
|
|
77
|
-
expect(leaf).not.toBeNull();
|
|
78
|
-
// embed it at a 512-aligned-but-not-4096-aligned offset inside a zero buffer
|
|
79
|
-
const big = Buffer.alloc(PAGE * 4, 0);
|
|
80
|
-
const off = 512 * 3; // 1536: hit by stride-512, missed by stride-4096
|
|
81
|
-
leaf.copy(big, off);
|
|
82
|
-
// aligned 4096-grid misses it
|
|
83
|
-
expect(parseLeafPage(big, 0, PAGE, 3)).toBeNull();
|
|
84
|
-
expect(parseLeafPage(big, PAGE, PAGE, 3)).toBeNull();
|
|
85
|
-
// unaligned stride finds it at its true offset
|
|
86
|
-
const recs = parseLeafPage(big, off, PAGE, 3);
|
|
87
|
-
expect(recs).not.toBeNull();
|
|
88
|
-
expect(recs.some((r) => r.cols[0] === "uuid-1")).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("returns null for non-leaf / garbage pages", () => {
|
|
92
|
-
const garbage = Buffer.alloc(4096, 0xff);
|
|
93
|
-
expect(parseLeafPage(garbage, 0, 4096, 3)).toBeNull();
|
|
94
|
-
const zeros = Buffer.alloc(4096, 0);
|
|
95
|
-
expect(parseLeafPage(zeros, 0, 4096, 3)).toBeNull();
|
|
96
|
-
});
|
|
97
|
-
});
|