@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,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const os = require("node:os");
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
buildSnapshot,
|
|
10
|
-
writeSnapshotJson,
|
|
11
|
-
cleanupSnapshotJson,
|
|
12
|
-
SNAPSHOT_SCHEMA_VERSION,
|
|
13
|
-
} = require("../../lib/adapters/social-toutiao-adb/snapshot-builder");
|
|
14
|
-
|
|
15
|
-
describe("SNAPSHOT_SCHEMA_VERSION", () => {
|
|
16
|
-
it("is 1 (matches existing social-toutiao adapter)", () => {
|
|
17
|
-
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("buildSnapshot", () => {
|
|
22
|
-
it("throws on missing uid", () => {
|
|
23
|
-
expect(() => buildSnapshot({})).toThrow(/uid must be a non-empty string/);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("emits profile event when input.profile given", () => {
|
|
27
|
-
const snap = buildSnapshot({
|
|
28
|
-
uid: "12345",
|
|
29
|
-
profile: {
|
|
30
|
-
nickname: "Alice",
|
|
31
|
-
avatarUrl: "https://a/x.jpg",
|
|
32
|
-
mobile: "138****",
|
|
33
|
-
followingCount: 10,
|
|
34
|
-
followerCount: 99,
|
|
35
|
-
mediaId: "5678",
|
|
36
|
-
},
|
|
37
|
-
snapshottedAt: 1716383021000,
|
|
38
|
-
});
|
|
39
|
-
expect(snap.schemaVersion).toBe(1);
|
|
40
|
-
expect(snap.account).toEqual({ uid: "12345", displayName: "" });
|
|
41
|
-
const profileEvents = snap.events.filter((e) => e.kind === "profile");
|
|
42
|
-
expect(profileEvents).toHaveLength(1);
|
|
43
|
-
expect(profileEvents[0]).toMatchObject({
|
|
44
|
-
kind: "profile",
|
|
45
|
-
id: "profile-12345",
|
|
46
|
-
uid: "12345",
|
|
47
|
-
nickname: "Alice",
|
|
48
|
-
followingCount: 10,
|
|
49
|
-
followerCount: 99,
|
|
50
|
-
mediaId: "5678",
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("skips profile event when input.profile missing", () => {
|
|
55
|
-
const snap = buildSnapshot({ uid: "12345" });
|
|
56
|
-
expect(snap.events.filter((e) => e.kind === "profile")).toHaveLength(0);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("emits read events from feed input", () => {
|
|
60
|
-
const snap = buildSnapshot({
|
|
61
|
-
uid: "12345",
|
|
62
|
-
feed: [
|
|
63
|
-
{
|
|
64
|
-
itemId: "G1",
|
|
65
|
-
title: "Read 1",
|
|
66
|
-
category: "tech",
|
|
67
|
-
author: "AuthorA",
|
|
68
|
-
publishedAt: 1716000000000,
|
|
69
|
-
readDuration: 60,
|
|
70
|
-
source: "source-a",
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
});
|
|
74
|
-
const reads = snap.events.filter((e) => e.kind === "read");
|
|
75
|
-
expect(reads).toHaveLength(1);
|
|
76
|
-
expect(reads[0]).toMatchObject({
|
|
77
|
-
kind: "read",
|
|
78
|
-
id: "read-G1",
|
|
79
|
-
capturedAt: 1716000000000,
|
|
80
|
-
itemId: "G1",
|
|
81
|
-
title: "Read 1",
|
|
82
|
-
category: "tech",
|
|
83
|
-
author: "AuthorA",
|
|
84
|
-
readDuration: 60,
|
|
85
|
-
source: "source-a",
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("emits collection events", () => {
|
|
90
|
-
const snap = buildSnapshot({
|
|
91
|
-
uid: "12345",
|
|
92
|
-
collection: [
|
|
93
|
-
{
|
|
94
|
-
itemId: "C1",
|
|
95
|
-
title: "Saved",
|
|
96
|
-
category: "news",
|
|
97
|
-
author: "AuthorB",
|
|
98
|
-
savedAt: 1716100000000,
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
const cols = snap.events.filter((e) => e.kind === "collection");
|
|
103
|
-
expect(cols).toHaveLength(1);
|
|
104
|
-
expect(cols[0]).toMatchObject({
|
|
105
|
-
kind: "collection",
|
|
106
|
-
id: "collect-C1",
|
|
107
|
-
capturedAt: 1716100000000,
|
|
108
|
-
itemId: "C1",
|
|
109
|
-
title: "Saved",
|
|
110
|
-
category: "news",
|
|
111
|
-
author: "AuthorB",
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("emits search events with keyword as id base", () => {
|
|
116
|
-
const snap = buildSnapshot({
|
|
117
|
-
uid: "12345",
|
|
118
|
-
search: [{ keyword: "AI", searchedAt: 1716200000000 }],
|
|
119
|
-
});
|
|
120
|
-
const searches = snap.events.filter((e) => e.kind === "search");
|
|
121
|
-
expect(searches).toHaveLength(1);
|
|
122
|
-
expect(searches[0]).toMatchObject({
|
|
123
|
-
kind: "search",
|
|
124
|
-
id: "search-AI:1716200000000",
|
|
125
|
-
capturedAt: 1716200000000,
|
|
126
|
-
keyword: "AI",
|
|
127
|
-
searchAt: 1716200000000,
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("ignores search entries with empty keyword", () => {
|
|
132
|
-
const snap = buildSnapshot({
|
|
133
|
-
uid: "1",
|
|
134
|
-
search: [{ keyword: "", searchedAt: 1 }, { keyword: "ok", searchedAt: 2 }],
|
|
135
|
-
});
|
|
136
|
-
const searches = snap.events.filter((e) => e.kind === "search");
|
|
137
|
-
expect(searches).toHaveLength(1);
|
|
138
|
-
expect(searches[0].keyword).toBe("ok");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("falls back to snapshottedAt when event lacks timestamp", () => {
|
|
142
|
-
const snap = buildSnapshot({
|
|
143
|
-
uid: "1",
|
|
144
|
-
feed: [{ itemId: "G", title: "T" }],
|
|
145
|
-
snapshottedAt: 1716000000000,
|
|
146
|
-
});
|
|
147
|
-
expect(snap.events[0].capturedAt).toBe(1716000000000);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("emits multiple kinds at once with stable id formats", () => {
|
|
151
|
-
const snap = buildSnapshot({
|
|
152
|
-
uid: "12345",
|
|
153
|
-
profile: { nickname: "Alice" },
|
|
154
|
-
feed: [{ itemId: "G1", title: "T1" }],
|
|
155
|
-
collection: [{ itemId: "C1", title: "T2" }],
|
|
156
|
-
search: [{ keyword: "kw1", searchedAt: 1 }],
|
|
157
|
-
});
|
|
158
|
-
expect(snap.events).toHaveLength(4);
|
|
159
|
-
const ids = snap.events.map((e) => e.id);
|
|
160
|
-
expect(ids).toContain("profile-12345");
|
|
161
|
-
expect(ids).toContain("read-G1");
|
|
162
|
-
expect(ids).toContain("collect-C1");
|
|
163
|
-
expect(ids).toContain("search-kw1:1");
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("writeSnapshotJson + cleanupSnapshotJson", () => {
|
|
168
|
-
it("writes valid JSON to staging dir", () => {
|
|
169
|
-
const snap = buildSnapshot({ uid: "1", profile: { nickname: "A" } });
|
|
170
|
-
const fullPath = writeSnapshotJson(snap);
|
|
171
|
-
try {
|
|
172
|
-
expect(fs.existsSync(fullPath)).toBe(true);
|
|
173
|
-
const round = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
|
|
174
|
-
expect(round.account.uid).toBe("1");
|
|
175
|
-
} finally {
|
|
176
|
-
cleanupSnapshotJson(fullPath);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("rejects fileName with path separator", () => {
|
|
181
|
-
const snap = buildSnapshot({ uid: "1" });
|
|
182
|
-
expect(() =>
|
|
183
|
-
writeSnapshotJson(snap, { fileName: "../escape.json" }),
|
|
184
|
-
).toThrow(/basename, not a path/);
|
|
185
|
-
expect(() =>
|
|
186
|
-
writeSnapshotJson(snap, { fileName: "sub/dir.json" }),
|
|
187
|
-
).toThrow(/basename, not a path/);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("cleanupSnapshotJson tolerates missing file", () => {
|
|
191
|
-
expect(() => cleanupSnapshotJson(null)).not.toThrow();
|
|
192
|
-
expect(() =>
|
|
193
|
-
cleanupSnapshotJson(path.join(os.tmpdir(), "nonexistent-x-y-z.json")),
|
|
194
|
-
).not.toThrow();
|
|
195
|
-
});
|
|
196
|
-
});
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* §A8 v0.2 — Toutiao 今日头条 + Kuaishou 快手 sqlite-mode tests.
|
|
3
|
-
*
|
|
4
|
-
* Originally Phase 13.8+13.9 v0.1 scaffold tests; promoted in §A8 v0.2 to
|
|
5
|
-
* cover the dual-mode (snapshot + sqlite) adapter. Snapshot-mode coverage
|
|
6
|
-
* lives in `../social-{toutiao,kuaishou}-snapshot.test.js`; this file
|
|
7
|
-
* focuses on the legacy sqlite/device-pull path that desktop wiring still
|
|
8
|
-
* uses for PCs running AndroidExtractor.
|
|
9
|
-
*
|
|
10
|
-
* - Adapter contract conformance (assertAdapter ok)
|
|
11
|
-
* - sync() yields raw rows per `kind` from mocked SQLite driver
|
|
12
|
-
* - normalize() produces valid UnifiedSchema events with correct subtype
|
|
13
|
-
* - Account validation lazy-checked at sync() time (v0.2 changed:
|
|
14
|
-
* account.uid is now OPTIONAL at construction so snapshot-mode-only
|
|
15
|
-
* callers can omit it).
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
"use strict";
|
|
19
|
-
|
|
20
|
-
import { describe, it, expect } from "vitest";
|
|
21
|
-
|
|
22
|
-
const fs = require("node:fs");
|
|
23
|
-
const path = require("node:path");
|
|
24
|
-
const os = require("node:os");
|
|
25
|
-
|
|
26
|
-
const { ToutiaoAdapter, KuaishouAdapter } = require("../../lib");
|
|
27
|
-
const { assertAdapter } = require("../../lib/adapter-spec");
|
|
28
|
-
const { validateBatch } = require("../../lib/batch");
|
|
29
|
-
|
|
30
|
-
function makeMockDriver(scriptedRows) {
|
|
31
|
-
return function () {
|
|
32
|
-
return {
|
|
33
|
-
prepare(sql) {
|
|
34
|
-
return {
|
|
35
|
-
all() {
|
|
36
|
-
for (const [matchSubstr, rows] of scriptedRows) {
|
|
37
|
-
if (sql.includes(matchSubstr)) return rows;
|
|
38
|
-
}
|
|
39
|
-
throw new Error("no such table");
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
close() {},
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function withFakeDb(fn) {
|
|
49
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-scaffold-"));
|
|
50
|
-
const dbPath = path.join(dir, "fake.db");
|
|
51
|
-
fs.writeFileSync(dbPath, "fake");
|
|
52
|
-
return fn(dbPath);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ─── ToutiaoAdapter ─────────────────────────────────────────────────────
|
|
56
|
-
|
|
57
|
-
describe("ToutiaoAdapter — §A8 v0.2 sqlite mode", () => {
|
|
58
|
-
it("contract conformance + sensitivity high (news reading reveals political/medical interest)", () => {
|
|
59
|
-
const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
|
|
60
|
-
expect(assertAdapter(a).ok).toBe(true);
|
|
61
|
-
expect(a.name).toBe("social-toutiao");
|
|
62
|
-
expect(a.extractMode).toBe("device-pull");
|
|
63
|
-
expect(a.dataDisclosure.sensitivity).toBe("high");
|
|
64
|
-
// v0.2 dual-mode capabilities — adapter accepts both snapshot and sqlite.
|
|
65
|
-
expect(a.capabilities).toContain("sync:snapshot");
|
|
66
|
-
expect(a.capabilities).toContain("sync:sqlite");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("v0.2: account OPTIONAL at construction (snapshot mode is stateless)", () => {
|
|
70
|
-
// Used to throw in v0.1 — now legal. Sqlite-mode sync() will lazy-throw.
|
|
71
|
-
expect(() => new ToutiaoAdapter()).not.toThrow();
|
|
72
|
-
expect(() => new ToutiaoAdapter({})).not.toThrow();
|
|
73
|
-
expect(() => new ToutiaoAdapter({ account: {} })).not.toThrow();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("sqlite mode lazy-throws when account.uid missing at sync time", async () => {
|
|
77
|
-
const a = new ToutiaoAdapter({ dbPath: "/no/such/path.db" });
|
|
78
|
-
let threw = null;
|
|
79
|
-
try {
|
|
80
|
-
for await (const _r of a.sync()) {
|
|
81
|
-
/* drain */
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
threw = err;
|
|
85
|
-
}
|
|
86
|
-
expect(threw).toBeTruthy();
|
|
87
|
-
expect(String(threw.message)).toMatch(/account\.uid required/);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("sync yields read + collection + search raws via mocked driver", async () => {
|
|
91
|
-
await withFakeDb(async (dbPath) => {
|
|
92
|
-
const driver = makeMockDriver([
|
|
93
|
-
[
|
|
94
|
-
"FROM read_history",
|
|
95
|
-
[
|
|
96
|
-
{ id: 1, item_id: "i-1", title: "新闻 A", read_time: 1700000000, category: "tech" },
|
|
97
|
-
{ id: 2, item_id: "i-2", title: "新闻 B", read_time: 1700000010, category: "finance" },
|
|
98
|
-
],
|
|
99
|
-
],
|
|
100
|
-
[
|
|
101
|
-
"FROM collection_article",
|
|
102
|
-
[{ id: 1, item_id: "i-3", article_title: "深度长文", save_time: 1700001000 }],
|
|
103
|
-
],
|
|
104
|
-
[
|
|
105
|
-
"FROM search_history",
|
|
106
|
-
[{ id: 1, keyword: "Rust 语言", search_time: 1700002000 }],
|
|
107
|
-
],
|
|
108
|
-
]);
|
|
109
|
-
const a = new ToutiaoAdapter({
|
|
110
|
-
account: { uid: "u-1" },
|
|
111
|
-
dbPath,
|
|
112
|
-
dbDriverFactory: () => driver,
|
|
113
|
-
});
|
|
114
|
-
const raws = [];
|
|
115
|
-
for await (const r of a.sync()) raws.push(r);
|
|
116
|
-
expect(raws.length).toBe(4);
|
|
117
|
-
expect(raws.filter((r) => r.payload.kind === "read")).toHaveLength(2);
|
|
118
|
-
expect(raws.filter((r) => r.payload.kind === "collection")).toHaveLength(1);
|
|
119
|
-
expect(raws.filter((r) => r.payload.kind === "search")).toHaveLength(1);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("normalize maps read → browse / collection → like / search → post (all subtypes valid)", async () => {
|
|
124
|
-
const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
|
|
125
|
-
const samples = [
|
|
126
|
-
{
|
|
127
|
-
kind: "read",
|
|
128
|
-
row: { id: 1, item_id: "i-1", title: "T1", read_time: 1700000000, category: "tech" },
|
|
129
|
-
expectedSubtype: "browse",
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
kind: "collection",
|
|
133
|
-
row: { id: 1, item_id: "i-2", article_title: "T2", save_time: 1700001000 },
|
|
134
|
-
expectedSubtype: "like",
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
kind: "search",
|
|
138
|
-
row: { id: 1, keyword: "Rust", search_time: 1700002000 },
|
|
139
|
-
expectedSubtype: "post",
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
for (const s of samples) {
|
|
143
|
-
const batch = a.normalize({
|
|
144
|
-
adapter: "social-toutiao",
|
|
145
|
-
originalId: `${s.kind}-${s.row.id}`,
|
|
146
|
-
capturedAt: Date.now(),
|
|
147
|
-
payload: { row: s.row, kind: s.kind },
|
|
148
|
-
});
|
|
149
|
-
const v = validateBatch(batch);
|
|
150
|
-
expect(v.valid).toBe(true);
|
|
151
|
-
expect(batch.events[0].subtype).toBe(s.expectedSubtype);
|
|
152
|
-
expect(batch.events[0].source.adapter).toBe("social-toutiao");
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("normalize throws on missing payload row + no snapshot fields (validator-friendly)", () => {
|
|
157
|
-
const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
|
|
158
|
-
// v0.2: row-missing check moved into per-kind normalizers (snapshot
|
|
159
|
-
// payloads have no `row` but carry fields directly).
|
|
160
|
-
expect(() => a.normalize({ payload: { kind: "read" } })).toThrow(/row missing/);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("search keyword preserved verbatim in content.title + extra.keyword", () => {
|
|
164
|
-
const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
|
|
165
|
-
const batch = a.normalize({
|
|
166
|
-
adapter: "social-toutiao",
|
|
167
|
-
originalId: "search-1",
|
|
168
|
-
capturedAt: 1700002000_000,
|
|
169
|
-
payload: { row: { id: 1, keyword: "新冠 后遗症", search_time: 1700002000 }, kind: "search" },
|
|
170
|
-
});
|
|
171
|
-
expect(batch.events[0].content.title).toBe("新冠 后遗症");
|
|
172
|
-
expect(batch.events[0].extra.kind).toBe("search");
|
|
173
|
-
expect(batch.events[0].extra.keyword).toBe("新冠 后遗症");
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("sync gracefully exits when dbPath missing", async () => {
|
|
177
|
-
const a = new ToutiaoAdapter({ account: { uid: "u-1" }, dbPath: "/no/such/path.db" });
|
|
178
|
-
const raws = [];
|
|
179
|
-
for await (const r of a.sync()) raws.push(r);
|
|
180
|
-
expect(raws).toEqual([]);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// ─── KuaishouAdapter ────────────────────────────────────────────────────
|
|
185
|
-
|
|
186
|
-
describe("KuaishouAdapter — §A8 v0.2 sqlite mode", () => {
|
|
187
|
-
it("contract conformance + sensitivity medium (entertainment preference)", () => {
|
|
188
|
-
const a = new KuaishouAdapter({ account: { uid: "u-2" } });
|
|
189
|
-
expect(assertAdapter(a).ok).toBe(true);
|
|
190
|
-
expect(a.name).toBe("social-kuaishou");
|
|
191
|
-
expect(a.extractMode).toBe("device-pull");
|
|
192
|
-
expect(a.dataDisclosure.sensitivity).toBe("medium");
|
|
193
|
-
expect(a.capabilities).toContain("sync:snapshot");
|
|
194
|
-
expect(a.capabilities).toContain("sync:sqlite");
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("v0.2: account OPTIONAL at construction (snapshot mode is stateless)", () => {
|
|
198
|
-
expect(() => new KuaishouAdapter()).not.toThrow();
|
|
199
|
-
expect(() => new KuaishouAdapter({})).not.toThrow();
|
|
200
|
-
expect(() => new KuaishouAdapter({ account: {} })).not.toThrow();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("sqlite mode lazy-throws when account.uid missing at sync time", async () => {
|
|
204
|
-
const a = new KuaishouAdapter({ dbPath: "/no/such/path.db" });
|
|
205
|
-
let threw = null;
|
|
206
|
-
try {
|
|
207
|
-
for await (const _r of a.sync()) {
|
|
208
|
-
/* drain */
|
|
209
|
-
}
|
|
210
|
-
} catch (err) {
|
|
211
|
-
threw = err;
|
|
212
|
-
}
|
|
213
|
-
expect(threw).toBeTruthy();
|
|
214
|
-
expect(String(threw.message)).toMatch(/account\.uid required/);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("sync yields watch + collect + search raws via mocked driver", async () => {
|
|
218
|
-
await withFakeDb(async (dbPath) => {
|
|
219
|
-
const driver = makeMockDriver([
|
|
220
|
-
[
|
|
221
|
-
"FROM photo_history",
|
|
222
|
-
[
|
|
223
|
-
{
|
|
224
|
-
id: 1,
|
|
225
|
-
photo_id: "p-1",
|
|
226
|
-
caption: "搞笑视频",
|
|
227
|
-
view_time: 1700000000,
|
|
228
|
-
duration: 30,
|
|
229
|
-
author_name: "UpA",
|
|
230
|
-
},
|
|
231
|
-
],
|
|
232
|
-
],
|
|
233
|
-
[
|
|
234
|
-
"FROM user_collect",
|
|
235
|
-
[{ id: 1, photo_id: "p-2", caption: "美食 vlog", collect_time: 1700001000 }],
|
|
236
|
-
],
|
|
237
|
-
[
|
|
238
|
-
"FROM search_record",
|
|
239
|
-
[{ id: 1, keyword: "广场舞", search_time: 1700002000 }],
|
|
240
|
-
],
|
|
241
|
-
]);
|
|
242
|
-
const a = new KuaishouAdapter({
|
|
243
|
-
account: { uid: "u-2" },
|
|
244
|
-
dbPath,
|
|
245
|
-
dbDriverFactory: () => driver,
|
|
246
|
-
});
|
|
247
|
-
const raws = [];
|
|
248
|
-
for await (const r of a.sync()) raws.push(r);
|
|
249
|
-
expect(raws.length).toBe(3);
|
|
250
|
-
expect(raws.filter((r) => r.payload.kind === "watch")).toHaveLength(1);
|
|
251
|
-
expect(raws.filter((r) => r.payload.kind === "collect")).toHaveLength(1);
|
|
252
|
-
expect(raws.filter((r) => r.payload.kind === "search")).toHaveLength(1);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("normalize maps watch → browse / collect → like / search → post (all subtypes valid)", () => {
|
|
257
|
-
const a = new KuaishouAdapter({ account: { uid: "u-2" } });
|
|
258
|
-
const samples = [
|
|
259
|
-
{
|
|
260
|
-
kind: "watch",
|
|
261
|
-
row: { id: 1, photo_id: "p-1", caption: "C1", view_time: 1700000000, duration: 30 },
|
|
262
|
-
expectedSubtype: "browse",
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
kind: "collect",
|
|
266
|
-
row: { id: 1, photo_id: "p-2", caption: "C2", collect_time: 1700001000 },
|
|
267
|
-
expectedSubtype: "like",
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
kind: "search",
|
|
271
|
-
row: { id: 1, keyword: "广场舞", search_time: 1700002000 },
|
|
272
|
-
expectedSubtype: "post",
|
|
273
|
-
},
|
|
274
|
-
];
|
|
275
|
-
for (const s of samples) {
|
|
276
|
-
const batch = a.normalize({
|
|
277
|
-
adapter: "social-kuaishou",
|
|
278
|
-
originalId: `${s.kind}-${s.row.id}`,
|
|
279
|
-
capturedAt: Date.now(),
|
|
280
|
-
payload: { row: s.row, kind: s.kind },
|
|
281
|
-
});
|
|
282
|
-
const v = validateBatch(batch);
|
|
283
|
-
expect(v.valid).toBe(true);
|
|
284
|
-
expect(batch.events[0].subtype).toBe(s.expectedSubtype);
|
|
285
|
-
expect(batch.events[0].source.adapter).toBe("social-kuaishou");
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it("watch event extra carries photoId + duration + authorName", () => {
|
|
290
|
-
const a = new KuaishouAdapter({ account: { uid: "u-2" } });
|
|
291
|
-
const batch = a.normalize({
|
|
292
|
-
adapter: "social-kuaishou",
|
|
293
|
-
originalId: "watch-1",
|
|
294
|
-
capturedAt: 1700000000_000,
|
|
295
|
-
payload: {
|
|
296
|
-
row: {
|
|
297
|
-
id: 1,
|
|
298
|
-
photo_id: "p-1",
|
|
299
|
-
caption: "美食",
|
|
300
|
-
view_time: 1700000000,
|
|
301
|
-
duration: 60,
|
|
302
|
-
author_name: "FoodVlogger",
|
|
303
|
-
},
|
|
304
|
-
kind: "watch",
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
expect(batch.events[0].extra.photoId).toBe("p-1");
|
|
308
|
-
expect(batch.events[0].extra.duration).toBe(60);
|
|
309
|
-
expect(batch.events[0].extra.authorName).toBe("FoodVlogger");
|
|
310
|
-
});
|
|
311
|
-
});
|