@chainlesschain/personal-data-hub 0.4.29 → 0.4.31
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/lib/forensics/qq-nt-collect.js +190 -0
- package/lib/prompt-builder.js +15 -1
- package/package.json +8 -3
- 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-usage-profile.test.js +0 -229
- package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
- 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-article.test.js +0 -155
- 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 -754
- 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 -365
- 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,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 网易云音乐 LIVE cookie web-API (weapi) fetcher tests.
|
|
3
|
-
* weapi crypto determinism (fixed secKey) + account/play/playlist parsing +
|
|
4
|
-
* adapter cookie-mode sync + error mapping. All network via injected fetch.
|
|
5
|
-
*/
|
|
6
|
-
"use strict";
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect } from "vitest";
|
|
9
|
-
|
|
10
|
-
const { NeteaseMusicAdapter } = require("../../lib/adapters/netease-music");
|
|
11
|
-
const {
|
|
12
|
-
NeteaseMusicApiClient,
|
|
13
|
-
weapiEncrypt,
|
|
14
|
-
aesEncrypt,
|
|
15
|
-
rsaEncrypt,
|
|
16
|
-
modpow,
|
|
17
|
-
} = require("../../lib/adapters/netease-music/api-client");
|
|
18
|
-
const { partitionBatch } = require("../../lib/batch");
|
|
19
|
-
|
|
20
|
-
const FIXED_SECKEY = "0123456789abcdef"; // 16 chars → deterministic weapi
|
|
21
|
-
const COOKIE = "MUSIC_U=abcdef0123456789; __csrf=zzz";
|
|
22
|
-
|
|
23
|
-
/** Map endpoint path substrings → JSON bodies; record posted form bodies. */
|
|
24
|
-
function makeFetch(routes, calls) {
|
|
25
|
-
return async (url, init) => {
|
|
26
|
-
calls.push({ url, body: init && init.body, headers: (init && init.headers) || {} });
|
|
27
|
-
const route = routes.find((r) => url.includes(r.match));
|
|
28
|
-
if (!route) return { ok: false, status: 404, text: async () => "not mapped" };
|
|
29
|
-
return {
|
|
30
|
-
ok: route.status ? route.status >= 200 && route.status < 300 : true,
|
|
31
|
-
status: route.status || 200,
|
|
32
|
-
text: async () =>
|
|
33
|
-
typeof route.body === "string" ? route.body : JSON.stringify(route.body),
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function collect(iter) {
|
|
39
|
-
const out = [];
|
|
40
|
-
for await (const r of iter) out.push(r);
|
|
41
|
-
return out;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
describe("weapi crypto primitives", () => {
|
|
45
|
-
it("modpow matches BigInt ** % for small values", () => {
|
|
46
|
-
expect(modpow(4n, 13n, 497n)).toBe(445n); // textbook RSA example
|
|
47
|
-
expect(modpow(7n, 0n, 13n)).toBe(1n);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("aesEncrypt is deterministic (fixed key + IV) and base64", () => {
|
|
51
|
-
const a = aesEncrypt("hello", "0CoJUm6Qyw8W8jud");
|
|
52
|
-
const b = aesEncrypt("hello", "0CoJUm6Qyw8W8jud");
|
|
53
|
-
expect(a).toBe(b);
|
|
54
|
-
expect(a).toMatch(/^[A-Za-z0-9+/=]+$/);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("rsaEncrypt yields zero-padded 256-hex", () => {
|
|
58
|
-
const enc = rsaEncrypt("test", "010001", "e0b5");
|
|
59
|
-
expect(enc).toHaveLength(256);
|
|
60
|
-
expect(enc).toMatch(/^[0-9a-f]{256}$/);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("weapiEncrypt produces stable { params, encSecKey } for a fixed secKey", () => {
|
|
64
|
-
const a = weapiEncrypt({ uid: 1 }, FIXED_SECKEY);
|
|
65
|
-
const b = weapiEncrypt({ uid: 1 }, FIXED_SECKEY);
|
|
66
|
-
expect(a).toEqual(b);
|
|
67
|
-
expect(a.encSecKey).toHaveLength(256);
|
|
68
|
-
expect(a.params).toMatch(/^[A-Za-z0-9+/=]+$/);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("NeteaseMusicApiClient.fetchSnapshot — live (mocked fetch)", () => {
|
|
73
|
-
it("resolves account, play record, playlists into snapshot-shaped events", async () => {
|
|
74
|
-
const calls = [];
|
|
75
|
-
const fetch = makeFetch(
|
|
76
|
-
[
|
|
77
|
-
{
|
|
78
|
-
match: "/weapi/w/nuser/account/get",
|
|
79
|
-
body: { code: 200, profile: { userId: 42, nickname: "听歌的人" }, account: { id: 42 } },
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
match: "/weapi/v1/play/record",
|
|
83
|
-
body: {
|
|
84
|
-
code: 200,
|
|
85
|
-
weekData: [
|
|
86
|
-
{ playCount: 50, song: { id: 186016, name: "晴天", ar: [{ name: "周杰伦" }], al: { name: "叶惠美" } } },
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
match: "/weapi/user/playlist",
|
|
92
|
-
body: {
|
|
93
|
-
code: 200,
|
|
94
|
-
playlist: [{ id: 999, name: "我喜欢的音乐", trackCount: 200, creator: { nickname: "听歌的人" } }],
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
calls,
|
|
99
|
-
);
|
|
100
|
-
const client = new NeteaseMusicApiClient({ fetch, secKey: FIXED_SECKEY });
|
|
101
|
-
const result = await client.fetchSnapshot(COOKIE);
|
|
102
|
-
expect(result.account).toEqual({ uid: "42", nickname: "听歌的人" });
|
|
103
|
-
expect(result.events).toHaveLength(2);
|
|
104
|
-
const play = result.events.find((e) => e.kind === "play");
|
|
105
|
-
expect(play).toMatchObject({ songId: "186016", song: "晴天", artist: "周杰伦", album: "叶惠美", playCount: 50 });
|
|
106
|
-
const pl = result.events.find((e) => e.kind === "playlist");
|
|
107
|
-
expect(pl).toMatchObject({ playlistId: "999", name: "我喜欢的音乐", trackCount: 200, creator: "听歌的人" });
|
|
108
|
-
// every POST is form-encoded weapi (params + encSecKey) with the cookie.
|
|
109
|
-
for (const c of calls) {
|
|
110
|
-
expect(c.body).toMatch(/^params=.+&encSecKey=.+$/);
|
|
111
|
-
expect(c.headers.Cookie).toBe(COOKIE);
|
|
112
|
-
expect(c.headers["Content-Type"]).toContain("x-www-form-urlencoded");
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("multi-artist joined with ' / '; falls back to allData when weekData empty", async () => {
|
|
117
|
-
const calls = [];
|
|
118
|
-
const fetch = makeFetch(
|
|
119
|
-
[
|
|
120
|
-
{ match: "account/get", body: { code: 200, profile: { userId: 7 } } },
|
|
121
|
-
{
|
|
122
|
-
match: "play/record",
|
|
123
|
-
body: {
|
|
124
|
-
code: 200,
|
|
125
|
-
weekData: [],
|
|
126
|
-
allData: [{ playCount: 3, song: { id: 1, name: "S", ar: [{ name: "A" }, { name: "B" }], al: { name: "Al" } } }],
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
{ match: "user/playlist", body: { code: 200, playlist: [] } },
|
|
130
|
-
],
|
|
131
|
-
calls,
|
|
132
|
-
);
|
|
133
|
-
const client = new NeteaseMusicApiClient({ fetch, secKey: FIXED_SECKEY });
|
|
134
|
-
const result = await client.fetchSnapshot(COOKIE);
|
|
135
|
-
const play = result.events.find((e) => e.kind === "play");
|
|
136
|
-
expect(play.artist).toBe("A / B");
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("include flags skip endpoints", async () => {
|
|
140
|
-
const calls = [];
|
|
141
|
-
const fetch = makeFetch(
|
|
142
|
-
[
|
|
143
|
-
{ match: "account/get", body: { code: 200, profile: { userId: 7 } } },
|
|
144
|
-
{ match: "user/playlist", body: { code: 200, playlist: [] } },
|
|
145
|
-
],
|
|
146
|
-
calls,
|
|
147
|
-
);
|
|
148
|
-
const client = new NeteaseMusicApiClient({ fetch, secKey: FIXED_SECKEY });
|
|
149
|
-
const result = await client.fetchSnapshot(COOKIE, { include: { play: false } });
|
|
150
|
-
expect(calls.some((c) => c.url.includes("play/record"))).toBe(false);
|
|
151
|
-
expect(result.events.every((e) => e.kind !== "play")).toBe(true);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("maps API code != 200 to null + lastError (e.g. -460 risk-control)", async () => {
|
|
155
|
-
const calls = [];
|
|
156
|
-
const fetch = makeFetch(
|
|
157
|
-
[{ match: "account/get", body: { code: -460, message: "Cheating" } }],
|
|
158
|
-
calls,
|
|
159
|
-
);
|
|
160
|
-
const client = new NeteaseMusicApiClient({ fetch, secKey: FIXED_SECKEY });
|
|
161
|
-
expect(await client.fetchSnapshot(COOKIE)).toBeNull();
|
|
162
|
-
expect(client.lastError.code).toBe(-460);
|
|
163
|
-
expect(client.lastError.message).toContain("Cheating");
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("account with no userId → null + lastError -7", async () => {
|
|
167
|
-
const calls = [];
|
|
168
|
-
const fetch = makeFetch([{ match: "account/get", body: { code: 200, profile: null, account: null } }], calls);
|
|
169
|
-
const client = new NeteaseMusicApiClient({ fetch, secKey: FIXED_SECKEY });
|
|
170
|
-
expect(await client.fetchSnapshot(COOKIE)).toBeNull();
|
|
171
|
-
expect(client.lastError.code).toBe(-7);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("empty cookie → null + lastError -1 (no network)", async () => {
|
|
175
|
-
const calls = [];
|
|
176
|
-
const client = new NeteaseMusicApiClient({ fetch: makeFetch([], calls), secKey: FIXED_SECKEY });
|
|
177
|
-
expect(await client.fetchSnapshot("")).toBeNull();
|
|
178
|
-
expect(client.lastError.code).toBe(-1);
|
|
179
|
-
expect(calls).toHaveLength(0);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("HTTP non-2xx → null + lastError with status", async () => {
|
|
183
|
-
const calls = [];
|
|
184
|
-
const fetch = makeFetch([{ match: "account/get", status: 502, body: "bad gw" }], calls);
|
|
185
|
-
const client = new NeteaseMusicApiClient({ fetch, secKey: FIXED_SECKEY });
|
|
186
|
-
expect(await client.fetchSnapshot(COOKIE)).toBeNull();
|
|
187
|
-
expect(client.lastError.code).toBe(502);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe("NeteaseMusicAdapter — cookie (live) sync mode", () => {
|
|
192
|
-
it("authenticate accepts a cookie with MUSIC_U; rejects without it", async () => {
|
|
193
|
-
const a = new NeteaseMusicAdapter();
|
|
194
|
-
expect((await a.authenticate({ cookie: COOKIE })).mode).toBe("cookie");
|
|
195
|
-
const bad = await a.authenticate({ cookie: "foo=bar" });
|
|
196
|
-
expect(bad.ok).toBe(false);
|
|
197
|
-
expect(bad.reason).toBe("INVALID_COOKIE");
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("capabilities/version reflect v0.2 live mode", () => {
|
|
201
|
-
const a = new NeteaseMusicAdapter();
|
|
202
|
-
expect(a.version).toBe("0.2.0");
|
|
203
|
-
expect(a.capabilities).toContain("sync:cookie");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("sync via cookie yields play+playlist raws → valid normalized batch", async () => {
|
|
207
|
-
const calls = [];
|
|
208
|
-
const fetch = makeFetch(
|
|
209
|
-
[
|
|
210
|
-
{ match: "account/get", body: { code: 200, profile: { userId: 42, nickname: "me" } } },
|
|
211
|
-
{
|
|
212
|
-
match: "play/record",
|
|
213
|
-
body: { code: 200, weekData: [{ playCount: 9, song: { id: 5, name: "夜曲", ar: [{ name: "周杰伦" }], al: { name: "11月的萧邦" } } }] },
|
|
214
|
-
},
|
|
215
|
-
{ match: "user/playlist", body: { code: 200, playlist: [{ id: 8, name: "练歌", trackCount: 12, creator: { nickname: "me" } }] } },
|
|
216
|
-
],
|
|
217
|
-
calls,
|
|
218
|
-
);
|
|
219
|
-
const a = new NeteaseMusicAdapter();
|
|
220
|
-
const raws = await collect(a.sync({ cookie: COOKIE, fetch, secKey: FIXED_SECKEY }));
|
|
221
|
-
expect(raws.map((r) => r.kind).sort()).toEqual(["play", "playlist"]);
|
|
222
|
-
const playRaw = raws.find((r) => r.kind === "play");
|
|
223
|
-
expect(playRaw.originalId).toBe("netease-music:play:play-5");
|
|
224
|
-
|
|
225
|
-
// normalize → vault-valid batch for both kinds.
|
|
226
|
-
for (const raw of raws) {
|
|
227
|
-
const batch = a.normalize(raw);
|
|
228
|
-
const { invalidReasons } = partitionBatch(batch);
|
|
229
|
-
expect(invalidReasons).toHaveLength(0);
|
|
230
|
-
}
|
|
231
|
-
const playBatch = a.normalize(playRaw);
|
|
232
|
-
expect(playBatch.items[0].extra.songId).toBe("5");
|
|
233
|
-
expect(playBatch.events[0].content.title).toContain("夜曲");
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it("sync via cookie throws (mapped lastError) on risk-control", async () => {
|
|
237
|
-
const calls = [];
|
|
238
|
-
const fetch = makeFetch([{ match: "account/get", body: { code: -460, message: "Cheating" } }], calls);
|
|
239
|
-
const a = new NeteaseMusicAdapter();
|
|
240
|
-
await expect(collect(a.sync({ cookie: COOKIE, fetch, secKey: FIXED_SECKEY }))).rejects.toThrow(
|
|
241
|
-
/Cheating|code -460/,
|
|
242
|
-
);
|
|
243
|
-
});
|
|
244
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
const { NeteaseMusicAdapter } = require("../../lib/adapters/netease-music");
|
|
6
|
-
const { partitionBatch } = require("../../lib/batch");
|
|
7
|
-
|
|
8
|
-
const SNAPSHOT = {
|
|
9
|
-
schemaVersion: 1,
|
|
10
|
-
snapshottedAt: 1700000000000,
|
|
11
|
-
account: { uid: "42", nickname: "me" },
|
|
12
|
-
events: [
|
|
13
|
-
{ kind: "play", id: "p1", capturedAt: 1700000001000, song: "晴天", artist: "周杰伦", album: "叶惠美", songId: "186016", playCount: 50 },
|
|
14
|
-
{ kind: "favorite", id: "f1", capturedAt: 1700000002000, song: "稻香", artist: "周杰伦", songId: "186001" },
|
|
15
|
-
{ kind: "playlist", id: "pl1", capturedAt: 1700000003000, name: "我喜欢的音乐", playlistId: "999", trackCount: 200, creator: "me" },
|
|
16
|
-
{ kind: "bogus", id: "x" },
|
|
17
|
-
],
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function adapter(snap = SNAPSHOT, { exists = true } = {}) {
|
|
21
|
-
const a = new NeteaseMusicAdapter();
|
|
22
|
-
a._deps.fs = {
|
|
23
|
-
existsSync: () => exists,
|
|
24
|
-
readFileSync: () => JSON.stringify(snap),
|
|
25
|
-
accessSync: () => {},
|
|
26
|
-
constants: { R_OK: 4 },
|
|
27
|
-
};
|
|
28
|
-
return a;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function collect(iter) {
|
|
32
|
-
const out = [];
|
|
33
|
-
for await (const r of iter) out.push(r);
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe("NeteaseMusicAdapter", () => {
|
|
38
|
-
it("readinessOnly → NO_INPUT (snapshot)", async () => {
|
|
39
|
-
const r = await new NeteaseMusicAdapter().authenticate({ readinessOnly: true });
|
|
40
|
-
expect(r.reason).toBe("NO_INPUT");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("ingests play/favorite/playlist, skips unknown kinds", async () => {
|
|
44
|
-
const raws = await collect(adapter().sync({ inputPath: "/x" }));
|
|
45
|
-
expect(raws.map((r) => r.kind)).toEqual(["play", "favorite", "playlist"]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("normalizes to valid batch (events + items + topic)", async () => {
|
|
49
|
-
const a = adapter();
|
|
50
|
-
const raws = await collect(a.sync({ inputPath: "/x" }));
|
|
51
|
-
const merged = { events: [], persons: [], places: [], items: [], topics: [] };
|
|
52
|
-
for (const r of raws) {
|
|
53
|
-
const n = a.normalize(r);
|
|
54
|
-
for (const k of Object.keys(merged)) merged[k].push(...n[k]);
|
|
55
|
-
}
|
|
56
|
-
const { valid, invalidReasons } = partitionBatch(merged);
|
|
57
|
-
expect(invalidReasons).toHaveLength(0);
|
|
58
|
-
expect(valid.events).toHaveLength(2); // play + favorite
|
|
59
|
-
expect(valid.items).toHaveLength(2); // two songs
|
|
60
|
-
expect(valid.topics).toHaveLength(1); // playlist
|
|
61
|
-
const play = valid.events.find((e) => e.subtype === "media");
|
|
62
|
-
expect(play.content.title).toContain("晴天");
|
|
63
|
-
expect(valid.topics[0].name).toBe("我喜欢的音乐");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("schemaVersion mismatch throws", async () => {
|
|
67
|
-
const a = adapter({ schemaVersion: 99, events: [] });
|
|
68
|
-
await expect(collect(a.sync({ inputPath: "/x" }))).rejects.toThrow(/schemaVersion/);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("missing file yields nothing", async () => {
|
|
72
|
-
expect(await collect(adapter(SNAPSHOT, { exists: false }).sync({ inputPath: "/x" }))).toHaveLength(0);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Unit tests for _pc-local-discovery against a synthetic filesystem — no real
|
|
5
|
-
* App needs to be installed. Uses posix path so assertions are host-agnostic.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect } from "vitest";
|
|
9
|
-
const path = require("node:path");
|
|
10
|
-
const { discover, SUPPORTED_APPS } = require("../../lib/adapters/_pc-local-discovery");
|
|
11
|
-
|
|
12
|
-
// Build a fake fs from a map of { dirPath: [entryName...] } + a set of file paths.
|
|
13
|
-
function makeFakeFs({ tree = {}, files = {}, sizes = {} } = {}) {
|
|
14
|
-
const norm = (p) => p.replace(/\\/g, "/");
|
|
15
|
-
const fileSet = new Set(Object.keys(files).map(norm));
|
|
16
|
-
const dirSet = new Set(Object.keys(tree).map(norm));
|
|
17
|
-
return {
|
|
18
|
-
existsSync: (p) => fileSet.has(norm(p)) || dirSet.has(norm(p)),
|
|
19
|
-
readdirSync: (p) => {
|
|
20
|
-
const entries = tree[norm(p)] || [];
|
|
21
|
-
return entries.map((e) => ({
|
|
22
|
-
name: e.name,
|
|
23
|
-
isDirectory: () => e.type === "dir",
|
|
24
|
-
isFile: () => e.type === "file",
|
|
25
|
-
}));
|
|
26
|
-
},
|
|
27
|
-
statSync: (p) => ({ size: sizes[norm(p)] || 1 }),
|
|
28
|
-
constants: { R_OK: 4 },
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const D = (name) => ({ name, type: "dir" });
|
|
33
|
-
const F = (name) => ({ name, type: "file" });
|
|
34
|
-
|
|
35
|
-
describe("_pc-local-discovery", () => {
|
|
36
|
-
it("supports the expected app keys", () => {
|
|
37
|
-
expect(SUPPORTED_APPS).toEqual(["wechat-pc", "qq-pc", "dingtalk-pc", "feishu-pc"]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("returns installed:false for an unknown app key (never throws)", () => {
|
|
41
|
-
const r = discover("totally-unknown", { fs: makeFakeFs(), home: "/h", env: {}, path: path.posix });
|
|
42
|
-
expect(r.installed).toBe(false);
|
|
43
|
-
expect(r.note).toMatch(/不支持/);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("returns installed:false when nothing is on disk", () => {
|
|
47
|
-
const r = discover("wechat-pc", { fs: makeFakeFs(), home: "/h", env: {}, path: path.posix });
|
|
48
|
-
expect(r.installed).toBe(false);
|
|
49
|
-
expect(r.primaryDb).toBe(null);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("discovers a WeChat 4.x account and picks message_0.db as primary", () => {
|
|
53
|
-
const base = "/h/Documents/xwechat_files";
|
|
54
|
-
const acc = `${base}/wxid_demo_42`;
|
|
55
|
-
const fs = makeFakeFs({
|
|
56
|
-
tree: {
|
|
57
|
-
[base]: [D("wxid_demo_42"), D("all_users")],
|
|
58
|
-
[`${acc}/db_storage/message`]: [F("message_0.db"), F("biz_message_0.db"), F("message_fts.db")],
|
|
59
|
-
},
|
|
60
|
-
files: {
|
|
61
|
-
[`${acc}/db_storage`]: 1,
|
|
62
|
-
[`${acc}/db_storage/message/message_0.db`]: 1,
|
|
63
|
-
[`${acc}/db_storage/contact/contact.db`]: 1,
|
|
64
|
-
[`${acc}/db_storage/sns/sns.db`]: 1,
|
|
65
|
-
},
|
|
66
|
-
sizes: {
|
|
67
|
-
[`${acc}/db_storage/message/message_0.db`]: 99,
|
|
68
|
-
[`${acc}/db_storage/message/biz_message_0.db`]: 50,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const r = discover("wechat-pc", { fs, home: "/h", env: {}, path: path.posix });
|
|
72
|
-
expect(r.installed).toBe(true);
|
|
73
|
-
expect(r.layout).toBe("4.x");
|
|
74
|
-
expect(r.encrypted).toBe(true);
|
|
75
|
-
expect(r.accounts).toHaveLength(1);
|
|
76
|
-
expect(r.accounts[0].id).toBe("wxid_demo");
|
|
77
|
-
expect(r.primaryDb).toContain("message_0.db");
|
|
78
|
-
// message_fts.db must NOT be picked up as a message db
|
|
79
|
-
const purposes = r.accounts[0].dbs.map((d) => d.purpose).sort();
|
|
80
|
-
expect(purposes).toContain("message");
|
|
81
|
-
expect(purposes).toContain("contact");
|
|
82
|
-
expect(r.accounts[0].dbs.some((d) => /message_fts/.test(d.path))).toBe(false);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("discovers a WeChat 3.x account (MSG*.db + MicroMsg.db)", () => {
|
|
86
|
-
const base = "/h/Documents/WeChat Files";
|
|
87
|
-
const acc = `${base}/wxid_old`;
|
|
88
|
-
const fs = makeFakeFs({
|
|
89
|
-
tree: {
|
|
90
|
-
[base]: [D("wxid_old"), D("All Users")],
|
|
91
|
-
[`${acc}/Msg/Multi`]: [F("MSG0.db"), F("MSG1.db")],
|
|
92
|
-
},
|
|
93
|
-
files: {
|
|
94
|
-
[`${acc}/Msg/Multi/MSG0.db`]: 1,
|
|
95
|
-
[`${acc}/Msg/Multi/MSG1.db`]: 1,
|
|
96
|
-
[`${acc}/Msg/MicroMsg.db`]: 1,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
const r = discover("wechat-pc", { fs, home: "/h", env: {}, path: path.posix });
|
|
100
|
-
expect(r.installed).toBe(true);
|
|
101
|
-
expect(r.layout).toBe("3.x");
|
|
102
|
-
expect(r.accounts[0].dbs.filter((d) => d.purpose === "message")).toHaveLength(2);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("discovers a QQ NT account by numeric uin dir", () => {
|
|
106
|
-
const base = "/h/Documents/Tencent Files";
|
|
107
|
-
const acc = `${base}/896075341`;
|
|
108
|
-
const fs = makeFakeFs({
|
|
109
|
-
tree: { [base]: [D("896075341"), D("nt_qq")] },
|
|
110
|
-
files: {
|
|
111
|
-
[`${acc}/nt_qq/nt_db/nt_msg.db`]: 1,
|
|
112
|
-
[`${acc}/nt_qq/nt_db/group_info.db`]: 1,
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
const r = discover("qq-pc", { fs, home: "/h", env: {}, path: path.posix });
|
|
116
|
-
expect(r.installed).toBe(true);
|
|
117
|
-
expect(r.accounts[0].id).toBe("896075341");
|
|
118
|
-
expect(r.primaryDb).toContain("nt_msg.db");
|
|
119
|
-
expect(r.encrypted).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("dingtalk best-effort scan finds plaintext db (encrypted:false)", () => {
|
|
123
|
-
const root = "/appdata/DingTalk";
|
|
124
|
-
const fs = makeFakeFs({
|
|
125
|
-
tree: {
|
|
126
|
-
[root]: [D("user1")],
|
|
127
|
-
[`${root}/user1`]: [F("im_message.db"), F("cache.db")],
|
|
128
|
-
},
|
|
129
|
-
files: {
|
|
130
|
-
[`${root}/user1/im_message.db`]: 1,
|
|
131
|
-
[`${root}/user1/cache.db`]: 1,
|
|
132
|
-
},
|
|
133
|
-
sizes: { [`${root}/user1/im_message.db`]: 100 },
|
|
134
|
-
});
|
|
135
|
-
const r = discover("dingtalk-pc", { fs, home: "/h", env: { APPDATA: "/appdata" }, path: path.posix });
|
|
136
|
-
expect(r.installed).toBe(true);
|
|
137
|
-
expect(r.encrypted).toBe(false);
|
|
138
|
-
expect(r.bestEffort).toBe(true);
|
|
139
|
-
expect(r.primaryDb).toContain("im_message.db");
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
const { QQPcAdapter } = require("../../lib/adapters/qq-pc");
|
|
6
|
-
const { partitionBatch } = require("../../lib/batch");
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* QQ NT (PC desktop) local-direct-read — 本地直读样板 (ported from wechat-pc).
|
|
10
|
-
*
|
|
11
|
-
* No native SQLite: fake driver via `_deps.dbDriverFactory`. The point of
|
|
12
|
-
* these tests is the PLUMBING + honest defensiveness (resolve columns,
|
|
13
|
-
* preserve raw row, loud diagnostic, best-effort text) — not protobuf
|
|
14
|
-
* decoding, which is real-device tuning.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
function makeFakeDb(spec) {
|
|
18
|
-
class FakeStmt {
|
|
19
|
-
constructor(sql) {
|
|
20
|
-
this.sql = sql;
|
|
21
|
-
}
|
|
22
|
-
all() {
|
|
23
|
-
const s = this.sql;
|
|
24
|
-
const m = s.match(/PRAGMA table_info\((\w+)\)/);
|
|
25
|
-
if (m) return spec.cols[m[1]] || [];
|
|
26
|
-
const f = s.match(/FROM (\w+)/);
|
|
27
|
-
if (f) return spec.rows[f[1]] || [];
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
get() {
|
|
31
|
-
return { n: 1 };
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return class FakeDb {
|
|
35
|
-
// eslint-disable-next-line no-unused-vars
|
|
36
|
-
constructor(_path, _opts) {}
|
|
37
|
-
prepare(sql) {
|
|
38
|
-
return new FakeStmt(sql);
|
|
39
|
-
}
|
|
40
|
-
pragma() {}
|
|
41
|
-
exec() {}
|
|
42
|
-
close() {}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// readable-name schema (decrypted/re-exported db) — text resolves cleanly
|
|
47
|
-
const READABLE_SPEC = {
|
|
48
|
-
cols: {
|
|
49
|
-
c2c_msg_table: [
|
|
50
|
-
{ name: "msgId" },
|
|
51
|
-
{ name: "msgTime" },
|
|
52
|
-
{ name: "msgType" },
|
|
53
|
-
{ name: "senderUin" },
|
|
54
|
-
{ name: "peerUin" },
|
|
55
|
-
{ name: "content" },
|
|
56
|
-
],
|
|
57
|
-
group_msg_table: [
|
|
58
|
-
{ name: "msgId" },
|
|
59
|
-
{ name: "msgTime" },
|
|
60
|
-
{ name: "senderUin" },
|
|
61
|
-
{ name: "peerUin" },
|
|
62
|
-
{ name: "content" },
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
rows: {
|
|
66
|
-
c2c_msg_table: [
|
|
67
|
-
{ msgId: "c1", msgTime: 1700000000, msgType: 1, senderUin: "111", peerUin: "222", content: "hi there" },
|
|
68
|
-
],
|
|
69
|
-
group_msg_table: [
|
|
70
|
-
{ msgId: "g1", msgTime: 1700000100, senderUin: "333", peerUin: "9001", content: "群里大家好" },
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// obfuscated numeric schema + BLOB content — text is null but raw preserved
|
|
76
|
-
const NUMERIC_SPEC = {
|
|
77
|
-
cols: {
|
|
78
|
-
c2c_msg_table: [
|
|
79
|
-
{ name: "40001" }, // msgId
|
|
80
|
-
{ name: "40050" }, // time
|
|
81
|
-
{ name: "40011" }, // type
|
|
82
|
-
{ name: "40033" }, // sender
|
|
83
|
-
{ name: "40021" }, // peer
|
|
84
|
-
{ name: "40800" }, // content (blob)
|
|
85
|
-
],
|
|
86
|
-
},
|
|
87
|
-
rows: {
|
|
88
|
-
c2c_msg_table: [
|
|
89
|
-
{ "40001": 9001, "40050": 1700000000, "40011": 1, "40033": 111, "40021": 222, "40800": Buffer.from([1, 2, 3]) },
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
function freshAdapter(spec, { fsOverride } = {}) {
|
|
95
|
-
const a = new QQPcAdapter({ dbPath: "/fake/nt_msg.db" });
|
|
96
|
-
a._deps.fs = fsOverride || { existsSync: () => true, accessSync: () => {}, constants: { R_OK: 4 } };
|
|
97
|
-
a._deps.dbDriverFactory = () => makeFakeDb(spec);
|
|
98
|
-
return a;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function collect(iter) {
|
|
102
|
-
const out = [];
|
|
103
|
-
for await (const r of iter) out.push(r);
|
|
104
|
-
return out;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
describe("QQPcAdapter — readiness + construction", () => {
|
|
108
|
-
it("no-arg construct + APP_NOT_INSTALLED when nothing discoverable", async () => {
|
|
109
|
-
const a = new QQPcAdapter();
|
|
110
|
-
a._deps.discoveryDeps = {
|
|
111
|
-
fs: { existsSync: () => false, readdirSync: () => [], statSync: () => ({ size: 0 }), constants: { R_OK: 4 } },
|
|
112
|
-
home: "/no-home",
|
|
113
|
-
env: {},
|
|
114
|
-
};
|
|
115
|
-
expect(a.name).toBe("qq-pc");
|
|
116
|
-
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
117
|
-
const r = await a.authenticate({ readinessOnly: true });
|
|
118
|
-
expect(r.reason).toBe("APP_NOT_INSTALLED");
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe("QQPcAdapter — nt_msg.db (readable schema)", () => {
|
|
123
|
-
it("reads c2c + group messages → valid events, 0 invalid", async () => {
|
|
124
|
-
const a = freshAdapter(READABLE_SPEC);
|
|
125
|
-
const raws = await collect(a.sync({ dbPath: "/fake/nt_msg.db" }));
|
|
126
|
-
expect(raws).toHaveLength(2);
|
|
127
|
-
expect(raws.every((r) => r.kind === "message")).toBe(true);
|
|
128
|
-
const merged = { events: [], persons: [], places: [], items: [], topics: [] };
|
|
129
|
-
for (const r of raws) {
|
|
130
|
-
const n = a.normalize(r);
|
|
131
|
-
for (const k of Object.keys(merged)) merged[k].push(...n[k]);
|
|
132
|
-
}
|
|
133
|
-
const { valid, invalidReasons } = partitionBatch(merged);
|
|
134
|
-
expect(invalidReasons).toHaveLength(0);
|
|
135
|
-
expect(valid.events).toHaveLength(2);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("resolves text + flags group + preserves timestamp", async () => {
|
|
139
|
-
const a = freshAdapter(READABLE_SPEC);
|
|
140
|
-
const raws = await collect(a.sync({ dbPath: "/fake/nt_msg.db" }));
|
|
141
|
-
const group = raws.find((r) => r.payload.isGroup);
|
|
142
|
-
expect(group.payload.text).toBe("群里大家好");
|
|
143
|
-
expect(group.payload.createdTimeMs).toBe(1700000100000);
|
|
144
|
-
const ev = a.normalize(group).events[0];
|
|
145
|
-
expect(ev.extra.isGroup).toBe(true);
|
|
146
|
-
expect(ev.extra.textResolved).toBe(true);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe("QQPcAdapter — nt_msg.db (numeric/obfuscated + BLOB body)", () => {
|
|
151
|
-
it("still ingests, text null, raw row preserved, loud diagnostic", async () => {
|
|
152
|
-
const a = freshAdapter(NUMERIC_SPEC);
|
|
153
|
-
const events = [];
|
|
154
|
-
const raws = await collect(
|
|
155
|
-
a.sync({ dbPath: "/fake/nt_msg.db", onProgress: (e) => events.push(e) }),
|
|
156
|
-
);
|
|
157
|
-
expect(raws).toHaveLength(1);
|
|
158
|
-
const ev = a.normalize(raws[0]).events[0];
|
|
159
|
-
// No silent drop: it's a valid event even with unresolved protobuf text.
|
|
160
|
-
const { valid, invalidReasons } = partitionBatch({
|
|
161
|
-
events: [ev], persons: [], places: [], items: [], topics: [],
|
|
162
|
-
});
|
|
163
|
-
expect(invalidReasons).toHaveLength(0);
|
|
164
|
-
expect(valid.events).toHaveLength(1);
|
|
165
|
-
expect(ev.extra.textResolved).toBe(false);
|
|
166
|
-
expect(ev.extra.rawRow).toBeTruthy(); // nothing lost
|
|
167
|
-
// diagnostic tells the user what resolved
|
|
168
|
-
const diag = events.find((e) => e.phase === "qq-nt-read");
|
|
169
|
-
expect(diag.hadC2cTable).toBe(true);
|
|
170
|
-
expect(diag.messageCount).toBe(1);
|
|
171
|
-
expect(diag.resolvedColumns.c2c_msg_table.time).toBe("40050");
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe("QQPcAdapter — edge cases", () => {
|
|
176
|
-
it("respects limit", async () => {
|
|
177
|
-
const a = freshAdapter(READABLE_SPEC);
|
|
178
|
-
const capped = await collect(a.sync({ dbPath: "/fake/nt_msg.db", limit: 1 }));
|
|
179
|
-
expect(capped).toHaveLength(1);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("missing db yields nothing", async () => {
|
|
183
|
-
const a = freshAdapter(READABLE_SPEC, { fsOverride: { existsSync: () => false } });
|
|
184
|
-
expect(await collect(a.sync({ dbPath: "/nope.db" }))).toHaveLength(0);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("unknown normalize kind throws", () => {
|
|
188
|
-
const a = new QQPcAdapter();
|
|
189
|
-
expect(() => a.normalize({ kind: "x", payload: { kind: "x" } })).toThrow(/unknown kind/);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe("QQPcAdapter — QQ NT sidecar path (passphrase)", () => {
|
|
194
|
-
const fakeCollector = (result) => async (_opts) => result;
|
|
195
|
-
|
|
196
|
-
it("opts.passphrase routes through the sidecar collector and yields messages", async () => {
|
|
197
|
-
const a = new QQPcAdapter({
|
|
198
|
-
qqCollector: fakeCollector({
|
|
199
|
-
account: "896075341",
|
|
200
|
-
messageCount: 2,
|
|
201
|
-
c2c: 1,
|
|
202
|
-
group: 1,
|
|
203
|
-
messages: [
|
|
204
|
-
{ kind: "group", peer: 88966001, peerUid: "u_x", senderUin: 38181604, senderName: "疯子", type: 0, createTime: 1780941580, text: "保持高贵的沉默。", originalId: "qq-pc:group:88966001:1" },
|
|
205
|
-
{ kind: "c2c", peer: 2747277822, peerUid: "u_y", senderUin: 12345, senderName: "张三", type: 0, createTime: 1780900000, text: "在吗", originalId: "qq-pc:c2c:2747277822:2" },
|
|
206
|
-
],
|
|
207
|
-
}),
|
|
208
|
-
});
|
|
209
|
-
const raws = await collect(a.sync({ passphrase: "5{sww#,6aq=)8=A@" }));
|
|
210
|
-
expect(raws).toHaveLength(2);
|
|
211
|
-
expect(raws[0].payload.text).toBe("保持高贵的沉默。");
|
|
212
|
-
expect(raws[0].payload.isGroup).toBe(true);
|
|
213
|
-
expect(raws[0].payload.senderName).toBe("疯子");
|
|
214
|
-
expect(raws[1].payload.isGroup).toBe(false);
|
|
215
|
-
|
|
216
|
-
const merged = { events: [], persons: [], places: [], items: [], topics: [] };
|
|
217
|
-
for (const r of raws) {
|
|
218
|
-
const n = a.normalize(r);
|
|
219
|
-
for (const k of Object.keys(merged)) if (Array.isArray(n[k])) merged[k].push(...n[k]);
|
|
220
|
-
}
|
|
221
|
-
const { valid } = partitionBatch(merged);
|
|
222
|
-
expect(valid.events.length).toBe(2);
|
|
223
|
-
const texts = valid.events.map((e) => e.content && e.content.text);
|
|
224
|
-
expect(texts).toContain("保持高贵的沉默。");
|
|
225
|
-
expect(valid.events.find((e) => e.content.text === "保持高贵的沉默。").extra.senderName).toBe("疯子");
|
|
226
|
-
});
|
|
227
|
-
});
|