@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,362 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Phase 3a — Weibo Node API client unit cover.
|
|
5
|
-
*
|
|
6
|
-
* Same fake-fetch pattern as social-bilibili-adb-api-client.test.js.
|
|
7
|
-
* Byte-parity check against WeiboApiClient.kt (Kotlin) is in
|
|
8
|
-
* `android-app/.../WeiboApiClient*Test.kt`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, it, expect, vi } from "vitest";
|
|
12
|
-
|
|
13
|
-
const { WeiboApiClient, _internals } = require(
|
|
14
|
-
"../../lib/adapters/social-weibo-adb/api-client",
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
function makeClient(responses) {
|
|
18
|
-
const calls = [];
|
|
19
|
-
const fakeFetch = async (urlStr, opts) => {
|
|
20
|
-
calls.push({ url: urlStr, opts });
|
|
21
|
-
for (const [pattern, payload] of responses) {
|
|
22
|
-
if (urlStr.includes(pattern)) {
|
|
23
|
-
const resolved =
|
|
24
|
-
typeof payload === "function" ? await payload(urlStr, opts) : payload;
|
|
25
|
-
return {
|
|
26
|
-
ok: resolved.status == null || resolved.status === 200,
|
|
27
|
-
status: resolved.status || 200,
|
|
28
|
-
text: async () => resolved.body,
|
|
29
|
-
json: async () => JSON.parse(resolved.body),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
throw new Error("fake fetch: no scripted response for " + urlStr);
|
|
34
|
-
};
|
|
35
|
-
return { client: new WeiboApiClient({ fetch: fakeFetch }), calls };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const FAKE_COOKIE = "SUB=abc; SUBP=def; _T_WM=tw1; MLOGIN=1";
|
|
39
|
-
|
|
40
|
-
// ─── _internals.parseWeiboTime ──────────────────────────────────────────
|
|
41
|
-
|
|
42
|
-
describe("parseWeiboTime", () => {
|
|
43
|
-
it("parses 'EEE MMM dd HH:mm:ss Z yyyy' format", () => {
|
|
44
|
-
const t = _internals.parseWeiboTime("Sun Jan 12 13:45:00 +0800 2026");
|
|
45
|
-
// Sunday 2026-01-12 13:45:00 +0800 = 2026-01-12 05:45:00 UTC
|
|
46
|
-
expect(t).toBeGreaterThan(0);
|
|
47
|
-
const d = new Date(t);
|
|
48
|
-
expect(d.getUTCFullYear()).toBe(2026);
|
|
49
|
-
expect(d.getUTCMonth()).toBe(0);
|
|
50
|
-
expect(d.getUTCDate()).toBe(12);
|
|
51
|
-
expect(d.getUTCHours()).toBe(5);
|
|
52
|
-
expect(d.getUTCMinutes()).toBe(45);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("digits-only treated as unix-seconds (< 1e12)", () => {
|
|
56
|
-
expect(_internals.parseWeiboTime("1716383021")).toBe(1716383021000);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("digits-only treated as ms (> 1e12)", () => {
|
|
60
|
-
expect(_internals.parseWeiboTime("1716383021000")).toBe(1716383021000);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("returns 0 for empty / null / unparseable", () => {
|
|
64
|
-
expect(_internals.parseWeiboTime("")).toBe(0);
|
|
65
|
-
expect(_internals.parseWeiboTime(null)).toBe(0);
|
|
66
|
-
expect(_internals.parseWeiboTime(undefined)).toBe(0);
|
|
67
|
-
expect(_internals.parseWeiboTime("not a date")).toBe(0);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// ─── _internals.stripHtml ───────────────────────────────────────────────
|
|
72
|
-
|
|
73
|
-
describe("stripHtml", () => {
|
|
74
|
-
it("strips <a> / <span> tags", () => {
|
|
75
|
-
expect(
|
|
76
|
-
_internals.stripHtml(
|
|
77
|
-
'<a href="x">hello</a> <span class="y">world</span>',
|
|
78
|
-
),
|
|
79
|
-
).toBe("hello world");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("decodes / & / < / > / "", () => {
|
|
83
|
-
expect(_internals.stripHtml("a b&c<d>e"f")).toBe(
|
|
84
|
-
'a b&c<d>e"f',
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("handles Chinese + emoji", () => {
|
|
89
|
-
expect(_internals.stripHtml("<p>你好 👋</p>")).toBe("你好 👋");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("returns empty for null / empty", () => {
|
|
93
|
-
expect(_internals.stripHtml("")).toBe("");
|
|
94
|
-
expect(_internals.stripHtml(null)).toBe("");
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// ─── fetchUid ──────────────────────────────────────────────────────────
|
|
99
|
-
|
|
100
|
-
describe("WeiboApiClient.fetchUid", () => {
|
|
101
|
-
it("returns numeric UID when login=true", async () => {
|
|
102
|
-
const { client } = makeClient([
|
|
103
|
-
[
|
|
104
|
-
"api/config",
|
|
105
|
-
{ body: JSON.stringify({ ok: 1, data: { login: true, uid: "1234567890" } }) },
|
|
106
|
-
],
|
|
107
|
-
]);
|
|
108
|
-
const uid = await client.fetchUid(FAKE_COOKIE);
|
|
109
|
-
expect(uid).toBe(1234567890);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("returns null when login=false", async () => {
|
|
113
|
-
const { client } = makeClient([
|
|
114
|
-
[
|
|
115
|
-
"api/config",
|
|
116
|
-
{ body: JSON.stringify({ ok: 1, data: { login: false } }) },
|
|
117
|
-
],
|
|
118
|
-
]);
|
|
119
|
-
expect(await client.fetchUid(FAKE_COOKIE)).toBe(null);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("returns null on non-JSON (cookie expired login redirect)", async () => {
|
|
123
|
-
const { client } = makeClient([
|
|
124
|
-
["api/config", { body: "<html>login redirect</html>" }],
|
|
125
|
-
]);
|
|
126
|
-
expect(await client.fetchUid(FAKE_COOKIE)).toBe(null);
|
|
127
|
-
expect(client.lastErrorCode).toBe(-4);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("returns null on HTTP error", async () => {
|
|
131
|
-
const { client } = makeClient([
|
|
132
|
-
["api/config", { status: 503, body: "Service Unavailable" }],
|
|
133
|
-
]);
|
|
134
|
-
expect(await client.fetchUid(FAKE_COOKIE)).toBe(null);
|
|
135
|
-
expect(client.lastErrorCode).toBe(503);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("sends required browser headers", async () => {
|
|
139
|
-
const { client, calls } = makeClient([
|
|
140
|
-
[
|
|
141
|
-
"api/config",
|
|
142
|
-
{ body: JSON.stringify({ ok: 1, data: { login: true, uid: "1" } }) },
|
|
143
|
-
],
|
|
144
|
-
]);
|
|
145
|
-
await client.fetchUid(FAKE_COOKIE);
|
|
146
|
-
const h = calls[0].opts.headers;
|
|
147
|
-
expect(h["User-Agent"]).toContain("Mozilla");
|
|
148
|
-
expect(h.Referer).toBe("https://m.weibo.cn/");
|
|
149
|
-
expect(h["X-Requested-With"]).toBe("XMLHttpRequest");
|
|
150
|
-
expect(h["MWeibo-Pwa"]).toBe("1");
|
|
151
|
-
expect(h.Cookie).toBe(FAKE_COOKIE);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// ─── fetchPosts ────────────────────────────────────────────────────────
|
|
156
|
-
|
|
157
|
-
describe("WeiboApiClient.fetchPosts", () => {
|
|
158
|
-
it("parses card_type=9 mblog cards", async () => {
|
|
159
|
-
const { client } = makeClient([
|
|
160
|
-
[
|
|
161
|
-
"api/container/getIndex",
|
|
162
|
-
{
|
|
163
|
-
body: JSON.stringify({
|
|
164
|
-
ok: 1,
|
|
165
|
-
data: {
|
|
166
|
-
cards: [
|
|
167
|
-
{
|
|
168
|
-
card_type: 9,
|
|
169
|
-
mblog: {
|
|
170
|
-
mid: "MBLOG_001",
|
|
171
|
-
text: '<a href="/user/x">@friend</a> hello 你好',
|
|
172
|
-
created_at: "Sun Jan 12 13:45:00 +0800 2026",
|
|
173
|
-
source: '<a href="x">iPhone 16</a>',
|
|
174
|
-
reposts_count: 5,
|
|
175
|
-
comments_count: 10,
|
|
176
|
-
attitudes_count: 100,
|
|
177
|
-
pic_num: 2,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
{ card_type: 11 /* banner — should skip */ },
|
|
181
|
-
{
|
|
182
|
-
card_type: 9,
|
|
183
|
-
mblog: {
|
|
184
|
-
id: 12345, // alt id field
|
|
185
|
-
text: "second post",
|
|
186
|
-
created_at: "1716383021",
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
},
|
|
191
|
-
}),
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
]);
|
|
195
|
-
const posts = await client.fetchPosts(FAKE_COOKIE, 1234567890);
|
|
196
|
-
expect(posts).toHaveLength(2);
|
|
197
|
-
expect(posts[0]).toMatchObject({
|
|
198
|
-
mid: "MBLOG_001",
|
|
199
|
-
text: "@friend hello 你好",
|
|
200
|
-
// source field preserves raw HTML (Kotlin byte-parity — WeiboApiClient.kt
|
|
201
|
-
// doesn't strip it; UI can strip if it wants)
|
|
202
|
-
source: '<a href="x">iPhone 16</a>',
|
|
203
|
-
repostsCount: 5,
|
|
204
|
-
commentsCount: 10,
|
|
205
|
-
likesCount: 100,
|
|
206
|
-
picCount: 2,
|
|
207
|
-
});
|
|
208
|
-
expect(posts[1].mid).toBe("12345");
|
|
209
|
-
expect(posts[1].text).toBe("second post");
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("respects limit", async () => {
|
|
213
|
-
const items = Array.from({ length: 100 }, (_, i) => ({
|
|
214
|
-
card_type: 9,
|
|
215
|
-
mblog: { mid: `M${i}`, text: `t${i}`, created_at: "1716383021" },
|
|
216
|
-
}));
|
|
217
|
-
const { client } = makeClient([
|
|
218
|
-
[
|
|
219
|
-
"api/container/getIndex",
|
|
220
|
-
{ body: JSON.stringify({ ok: 1, data: { cards: items } }) },
|
|
221
|
-
],
|
|
222
|
-
]);
|
|
223
|
-
const posts = await client.fetchPosts(FAKE_COOKIE, 1, { limit: 5 });
|
|
224
|
-
expect(posts).toHaveLength(5);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("uses containerid=107603<uid>", async () => {
|
|
228
|
-
const { client, calls } = makeClient([
|
|
229
|
-
[
|
|
230
|
-
"api/container/getIndex",
|
|
231
|
-
{ body: JSON.stringify({ ok: 1, data: { cards: [] } }) },
|
|
232
|
-
],
|
|
233
|
-
]);
|
|
234
|
-
await client.fetchPosts(FAKE_COOKIE, 99);
|
|
235
|
-
expect(calls[0].url).toContain("containerid=10760399");
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// ─── fetchFavourites ───────────────────────────────────────────────────
|
|
240
|
-
|
|
241
|
-
describe("WeiboApiClient.fetchFavourites", () => {
|
|
242
|
-
it("parses status nested rows", async () => {
|
|
243
|
-
const { client } = makeClient([
|
|
244
|
-
[
|
|
245
|
-
"api/favorites",
|
|
246
|
-
{
|
|
247
|
-
body: JSON.stringify({
|
|
248
|
-
ok: 1,
|
|
249
|
-
data: {
|
|
250
|
-
favorites: [
|
|
251
|
-
{
|
|
252
|
-
favorited_time: "Sun Jan 12 14:00:00 +0800 2026",
|
|
253
|
-
status: {
|
|
254
|
-
mid: "FAV_001",
|
|
255
|
-
text: "interesting <em>thing</em>",
|
|
256
|
-
user: { screen_name: "@famous" },
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
},
|
|
261
|
-
}),
|
|
262
|
-
},
|
|
263
|
-
],
|
|
264
|
-
]);
|
|
265
|
-
const favs = await client.fetchFavourites(FAKE_COOKIE);
|
|
266
|
-
expect(favs).toHaveLength(1);
|
|
267
|
-
expect(favs[0]).toMatchObject({
|
|
268
|
-
mid: "FAV_001",
|
|
269
|
-
text: "interesting thing",
|
|
270
|
-
authorScreenName: "@famous",
|
|
271
|
-
});
|
|
272
|
-
expect(favs[0].favAt).toBeGreaterThan(0);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("falls back to status.created_at when favorited_time absent", async () => {
|
|
276
|
-
const { client } = makeClient([
|
|
277
|
-
[
|
|
278
|
-
"api/favorites",
|
|
279
|
-
{
|
|
280
|
-
body: JSON.stringify({
|
|
281
|
-
ok: 1,
|
|
282
|
-
data: {
|
|
283
|
-
favorites: [
|
|
284
|
-
{
|
|
285
|
-
status: {
|
|
286
|
-
mid: "X",
|
|
287
|
-
text: "y",
|
|
288
|
-
created_at: "Sun Jan 12 13:45:00 +0800 2026",
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
},
|
|
293
|
-
}),
|
|
294
|
-
},
|
|
295
|
-
],
|
|
296
|
-
]);
|
|
297
|
-
const favs = await client.fetchFavourites(FAKE_COOKIE);
|
|
298
|
-
expect(favs[0].favAt).toBeGreaterThan(0);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// ─── fetchFollows ──────────────────────────────────────────────────────
|
|
303
|
-
|
|
304
|
-
describe("WeiboApiClient.fetchFollows", () => {
|
|
305
|
-
it("parses users list", async () => {
|
|
306
|
-
const { client } = makeClient([
|
|
307
|
-
[
|
|
308
|
-
"api/friendships/friends",
|
|
309
|
-
{
|
|
310
|
-
body: JSON.stringify({
|
|
311
|
-
ok: 1,
|
|
312
|
-
data: {
|
|
313
|
-
users: [
|
|
314
|
-
{
|
|
315
|
-
id: 42,
|
|
316
|
-
screen_name: "Friend1",
|
|
317
|
-
description: "hi",
|
|
318
|
-
profile_image_url: "https://x.png",
|
|
319
|
-
},
|
|
320
|
-
{ id: 0, screen_name: "Ghost" }, // skip
|
|
321
|
-
{ id: 99, screen_name: "Friend2" },
|
|
322
|
-
],
|
|
323
|
-
},
|
|
324
|
-
}),
|
|
325
|
-
},
|
|
326
|
-
],
|
|
327
|
-
]);
|
|
328
|
-
const fols = await client.fetchFollows(FAKE_COOKIE, 1234);
|
|
329
|
-
expect(fols).toHaveLength(2);
|
|
330
|
-
expect(fols[0].uid).toBe(42);
|
|
331
|
-
expect(fols[1].uid).toBe(99);
|
|
332
|
-
expect(fols[0].screenName).toBe("Friend1");
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("uid sent as vmid query param", async () => {
|
|
336
|
-
const { client, calls } = makeClient([
|
|
337
|
-
[
|
|
338
|
-
"api/friendships/friends",
|
|
339
|
-
{ body: JSON.stringify({ ok: 1, data: { users: [] } }) },
|
|
340
|
-
],
|
|
341
|
-
]);
|
|
342
|
-
await client.fetchFollows(FAKE_COOKIE, 9999);
|
|
343
|
-
expect(calls[0].url).toContain("uid=9999");
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
// ─── error code propagation ─────────────────────────────────────────────
|
|
348
|
-
|
|
349
|
-
describe("WeiboApiClient — error propagation", () => {
|
|
350
|
-
it("ok != 1 → returns [] + sets lastError", async () => {
|
|
351
|
-
const { client } = makeClient([
|
|
352
|
-
[
|
|
353
|
-
"api/container/getIndex",
|
|
354
|
-
{ body: JSON.stringify({ ok: -100, msg: "anti-bot" }) },
|
|
355
|
-
],
|
|
356
|
-
]);
|
|
357
|
-
const r = await client.fetchPosts(FAKE_COOKIE, 1);
|
|
358
|
-
expect(r).toEqual([]);
|
|
359
|
-
expect(client.lastErrorCode).toBe(-100);
|
|
360
|
-
expect(client.lastErrorMessage).toBe("anti-bot");
|
|
361
|
-
});
|
|
362
|
-
});
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
4
|
-
import { existsSync, readFileSync, mkdtempSync, rmSync } from "node:fs";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
collect,
|
|
10
|
-
collectAndSync,
|
|
11
|
-
} = require("../../lib/adapters/social-weibo-adb/collector");
|
|
12
|
-
|
|
13
|
-
let stagingDir;
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
stagingDir = mkdtempSync(join(tmpdir(), "cc-weibo-test-"));
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
try {
|
|
21
|
-
rmSync(stagingDir, { recursive: true, force: true });
|
|
22
|
-
} catch (_e) {
|
|
23
|
-
// ignore
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
function makeFakeBridge({ cookieResult, throwOnInvoke } = {}) {
|
|
28
|
-
return {
|
|
29
|
-
invoke: vi.fn(async (_method) => {
|
|
30
|
-
if (throwOnInvoke) throw throwOnInvoke;
|
|
31
|
-
return cookieResult;
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function makeFakeApiClient({
|
|
37
|
-
uid = 1234567890,
|
|
38
|
-
posts = [],
|
|
39
|
-
favourites = [],
|
|
40
|
-
follows = [],
|
|
41
|
-
lastErrorCode = 0,
|
|
42
|
-
lastErrorMessage = null,
|
|
43
|
-
} = {}) {
|
|
44
|
-
return {
|
|
45
|
-
fetchUid: vi.fn(async () => uid),
|
|
46
|
-
fetchPosts: vi.fn(async () => posts),
|
|
47
|
-
fetchFavourites: vi.fn(async () => favourites),
|
|
48
|
-
fetchFollows: vi.fn(async () => follows),
|
|
49
|
-
lastErrorCode,
|
|
50
|
-
lastErrorMessage,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
describe("collect — happy path", () => {
|
|
55
|
-
it("invokes cookies, fetchUid, 3 endpoints, writes snapshot", async () => {
|
|
56
|
-
const bridge = makeFakeBridge({
|
|
57
|
-
cookieResult: {
|
|
58
|
-
cookie: "SUB=abc",
|
|
59
|
-
diagnostic: { cookieCount: 5, hasSub: true },
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
const apiClient = makeFakeApiClient({
|
|
63
|
-
uid: 1234567890,
|
|
64
|
-
posts: [{ mid: "P1", text: "p", createdAt: 1 }],
|
|
65
|
-
favourites: [{ mid: "F1", text: "f", favAt: 2 }],
|
|
66
|
-
follows: [{ uid: 99, screenName: "x", followedAt: 0 }],
|
|
67
|
-
});
|
|
68
|
-
const result = await collect(bridge, { apiClient, stagingDir });
|
|
69
|
-
|
|
70
|
-
expect(bridge.invoke).toHaveBeenCalledWith("weibo.cookies");
|
|
71
|
-
expect(apiClient.fetchUid).toHaveBeenCalledWith("SUB=abc");
|
|
72
|
-
expect(apiClient.fetchPosts).toHaveBeenCalledWith(
|
|
73
|
-
"SUB=abc",
|
|
74
|
-
1234567890,
|
|
75
|
-
expect.any(Object),
|
|
76
|
-
);
|
|
77
|
-
expect(result.uid).toBe(1234567890);
|
|
78
|
-
expect(result.eventCounts).toEqual({
|
|
79
|
-
post: 1,
|
|
80
|
-
favourite: 1,
|
|
81
|
-
follow: 1,
|
|
82
|
-
total: 3,
|
|
83
|
-
});
|
|
84
|
-
expect(existsSync(result.snapshotPath)).toBe(true);
|
|
85
|
-
const snap = JSON.parse(readFileSync(result.snapshotPath, "utf-8"));
|
|
86
|
-
expect(snap.schemaVersion).toBe(1);
|
|
87
|
-
expect(snap.events).toHaveLength(3);
|
|
88
|
-
expect(result.uidFetchFailed).toBe(false);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("collect — uid fetch failure (cookie expired)", () => {
|
|
93
|
-
it("returns empty-event snapshot + uidFetchFailed=true", async () => {
|
|
94
|
-
const bridge = makeFakeBridge({
|
|
95
|
-
cookieResult: { cookie: "SUB=expired", diagnostic: {} },
|
|
96
|
-
});
|
|
97
|
-
const apiClient = makeFakeApiClient({
|
|
98
|
-
uid: null,
|
|
99
|
-
lastErrorCode: -4,
|
|
100
|
-
lastErrorMessage: "non-json (cookie expired?)",
|
|
101
|
-
});
|
|
102
|
-
const result = await collect(bridge, { apiClient, stagingDir });
|
|
103
|
-
expect(result.uid).toBe(null);
|
|
104
|
-
expect(result.uidFetchFailed).toBe(true);
|
|
105
|
-
expect(result.eventCounts.total).toBe(0);
|
|
106
|
-
expect(result.lastErrorCode).toBe(-4);
|
|
107
|
-
// fetchPosts/Favourites/Follows must NOT be called when uid failed
|
|
108
|
-
expect(apiClient.fetchPosts).not.toHaveBeenCalled();
|
|
109
|
-
// Snapshot file still written so downstream caller doesn't crash on
|
|
110
|
-
// missing inputPath
|
|
111
|
-
expect(existsSync(result.snapshotPath)).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe("collect — failure modes", () => {
|
|
116
|
-
it("propagates bridge.invoke errors", async () => {
|
|
117
|
-
const bridge = makeFakeBridge({
|
|
118
|
-
throwOnInvoke: new Error("WEIBO_NO_ROOT: phone isn't rooted"),
|
|
119
|
-
});
|
|
120
|
-
await expect(collect(bridge, { stagingDir })).rejects.toThrow(/WEIBO_NO_ROOT/);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("throws TypeError when bridge missing invoke", async () => {
|
|
124
|
-
await expect(collect(null, { stagingDir })).rejects.toThrow(TypeError);
|
|
125
|
-
await expect(collect({}, { stagingDir })).rejects.toThrow(TypeError);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("throws on malformed cookieResult", async () => {
|
|
129
|
-
const bridge = makeFakeBridge({ cookieResult: { cookie: null } });
|
|
130
|
-
await expect(collect(bridge, { stagingDir })).rejects.toThrow(/malformed payload/);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("collect — partial result tolerance", () => {
|
|
135
|
-
it("0 events when uid OK but all 3 endpoints empty", async () => {
|
|
136
|
-
const bridge = makeFakeBridge({ cookieResult: { cookie: "SUB=a" } });
|
|
137
|
-
const apiClient = makeFakeApiClient();
|
|
138
|
-
const result = await collect(bridge, { apiClient, stagingDir });
|
|
139
|
-
expect(result.eventCounts.total).toBe(0);
|
|
140
|
-
expect(existsSync(result.snapshotPath)).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("partial event set when one endpoint fails", async () => {
|
|
144
|
-
const bridge = makeFakeBridge({ cookieResult: { cookie: "SUB=a" } });
|
|
145
|
-
const apiClient = makeFakeApiClient({
|
|
146
|
-
posts: [{ mid: "P", text: "x", createdAt: 1 }],
|
|
147
|
-
favourites: [], // simulated failure
|
|
148
|
-
follows: [{ uid: 1, screenName: "x" }],
|
|
149
|
-
});
|
|
150
|
-
const result = await collect(bridge, { apiClient, stagingDir });
|
|
151
|
-
expect(result.eventCounts).toEqual({ post: 1, favourite: 0, follow: 1, total: 2 });
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("collectAndSync", () => {
|
|
156
|
-
it("calls registry.syncAdapter + cleans up on success", async () => {
|
|
157
|
-
const bridge = makeFakeBridge({ cookieResult: { cookie: "SUB=a" } });
|
|
158
|
-
const apiClient = makeFakeApiClient({
|
|
159
|
-
posts: [{ mid: "P", createdAt: 1 }],
|
|
160
|
-
});
|
|
161
|
-
let syncedPath = null;
|
|
162
|
-
const registry = {
|
|
163
|
-
syncAdapter: vi.fn(async (name, opts) => {
|
|
164
|
-
if (name !== "social-weibo") throw new Error("wrong name");
|
|
165
|
-
syncedPath = opts.inputPath;
|
|
166
|
-
return { adapter: name, status: "ok", rawCount: 1 };
|
|
167
|
-
}),
|
|
168
|
-
};
|
|
169
|
-
const report = await collectAndSync(bridge, registry, {
|
|
170
|
-
apiClient,
|
|
171
|
-
stagingDir,
|
|
172
|
-
});
|
|
173
|
-
expect(report.status).toBe("ok");
|
|
174
|
-
expect(report.weibo.uid).toBe(1234567890);
|
|
175
|
-
expect(report.weibo.eventCounts.post).toBe(1);
|
|
176
|
-
expect(existsSync(syncedPath)).toBe(false);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("cleanup even on syncAdapter throw", async () => {
|
|
180
|
-
const bridge = makeFakeBridge({ cookieResult: { cookie: "SUB=a" } });
|
|
181
|
-
const apiClient = makeFakeApiClient();
|
|
182
|
-
let syncedPath = null;
|
|
183
|
-
const registry = {
|
|
184
|
-
syncAdapter: vi.fn(async (_n, opts) => {
|
|
185
|
-
syncedPath = opts.inputPath;
|
|
186
|
-
throw new Error("registry exploded");
|
|
187
|
-
}),
|
|
188
|
-
};
|
|
189
|
-
await expect(
|
|
190
|
-
collectAndSync(bridge, registry, { apiClient, stagingDir }),
|
|
191
|
-
).rejects.toThrow("registry exploded");
|
|
192
|
-
expect(existsSync(syncedPath)).toBe(false);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("rejects missing syncAdapter", async () => {
|
|
196
|
-
const bridge = makeFakeBridge({ cookieResult: { cookie: "SUB=a" } });
|
|
197
|
-
await expect(
|
|
198
|
-
collectAndSync(bridge, null, { apiClient: makeFakeApiClient() }),
|
|
199
|
-
).rejects.toThrow(TypeError);
|
|
200
|
-
});
|
|
201
|
-
});
|