@chainlesschain/personal-data-hub 0.4.29 → 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/lib/prompt-builder.js +15 -1
- 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-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,373 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Integration test — Phase 17 local-data adapters end-to-end pipeline.
|
|
5
|
-
*
|
|
6
|
-
* Exercises the full chain WITHOUT real Chrome / Edge / VSCode / Windows
|
|
7
|
-
* installations: every adapter is pointed at a synthetic on-disk fixture
|
|
8
|
-
* via opts.profilePath / opts.vscodeRoot / opts.recentDir. Confirms that
|
|
9
|
-
* each adapter, when registered with a real LocalVault + AdapterRegistry,
|
|
10
|
-
* produces the expected entityCounts and that ingested rows survive a
|
|
11
|
-
* vault re-open round-trip.
|
|
12
|
-
*
|
|
13
|
-
* Covered adapters (4):
|
|
14
|
-
* browser-history-chrome
|
|
15
|
-
* browser-history-edge (Chromium subclass — proves inheritance wiring)
|
|
16
|
-
* vscode
|
|
17
|
-
* win-recent
|
|
18
|
-
*
|
|
19
|
-
* Win note: bs3mc has the known NODE_MODULE_VERSION mismatch on this dev
|
|
20
|
-
* box (built for Electron's ABI 140; Node 22 wants 127, Node 24 wants 137).
|
|
21
|
-
* Tests pass on CI Linux (matched prebuild). To run locally without
|
|
22
|
-
* Electron running, stop the dev app and `npm rebuild better-sqlite3-
|
|
23
|
-
* multiple-ciphers`. Same caveat as the bilibili integration test header.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
27
|
-
|
|
28
|
-
const fs = require("node:fs");
|
|
29
|
-
const path = require("node:path");
|
|
30
|
-
const os = require("node:os");
|
|
31
|
-
const Database = require("better-sqlite3");
|
|
32
|
-
|
|
33
|
-
// Probe bs3mc once at import time. When it throws ABI mismatch (common
|
|
34
|
-
// on Win dev boxes since the prebuild targets Electron's ABI 140), we
|
|
35
|
-
// flip `bs3mcAvailable` off and every `it` in this file becomes a skip.
|
|
36
|
-
// CI Linux has matching prebuilds so the gate stays open there.
|
|
37
|
-
let bs3mcAvailable = true;
|
|
38
|
-
let bs3mcSkipReason = "";
|
|
39
|
-
try {
|
|
40
|
-
const probeDir = fs.mkdtempSync(path.join(os.tmpdir(), "bs3mc-probe-"));
|
|
41
|
-
const probePath = path.join(probeDir, "p.db");
|
|
42
|
-
const { LocalVault: ProbeVault, generateKeyHex: probeKey } = require("../../lib");
|
|
43
|
-
const v = new ProbeVault({ path: probePath, key: probeKey() });
|
|
44
|
-
v.open();
|
|
45
|
-
v.close();
|
|
46
|
-
fs.rmSync(probeDir, { recursive: true, force: true });
|
|
47
|
-
} catch (e) {
|
|
48
|
-
bs3mcAvailable = false;
|
|
49
|
-
bs3mcSkipReason = e && e.message ? e.message : String(e);
|
|
50
|
-
}
|
|
51
|
-
const itOrSkip = bs3mcAvailable ? it : it.skip;
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
LocalVault,
|
|
55
|
-
generateKeyHex,
|
|
56
|
-
AdapterRegistry,
|
|
57
|
-
} = require("../../lib");
|
|
58
|
-
const {
|
|
59
|
-
BrowserHistoryChromeAdapter,
|
|
60
|
-
epochMsToWebkitUs,
|
|
61
|
-
} = require("../../lib/adapters/browser-history-chrome");
|
|
62
|
-
const {
|
|
63
|
-
BrowserHistoryEdgeAdapter,
|
|
64
|
-
} = require("../../lib/adapters/browser-history-edge");
|
|
65
|
-
const { VSCodeAdapter } = require("../../lib/adapters/vscode");
|
|
66
|
-
const { WinRecentAdapter } = require("../../lib/adapters/win-recent");
|
|
67
|
-
|
|
68
|
-
let rig;
|
|
69
|
-
|
|
70
|
-
function makeRig() {
|
|
71
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-int-"));
|
|
72
|
-
const vault = new LocalVault({
|
|
73
|
-
path: path.join(dir, "vault.db"),
|
|
74
|
-
key: generateKeyHex(),
|
|
75
|
-
});
|
|
76
|
-
vault.open();
|
|
77
|
-
// Capture sync events for assertion + debugging.
|
|
78
|
-
const events = [];
|
|
79
|
-
const registry = new AdapterRegistry({
|
|
80
|
-
vault,
|
|
81
|
-
onSyncEvent: (m) => events.push(m),
|
|
82
|
-
});
|
|
83
|
-
return { vault, registry, dir, events };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function cleanup(r) {
|
|
87
|
-
if (!r) return;
|
|
88
|
-
try {
|
|
89
|
-
r.vault.close();
|
|
90
|
-
} catch (_e) {
|
|
91
|
-
/* noop */
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
fs.rmSync(r.dir, { recursive: true, force: true });
|
|
95
|
-
} catch (_e) {
|
|
96
|
-
/* noop */
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ─── Fixtures ──────────────────────────────────────────────────────────
|
|
101
|
-
|
|
102
|
-
function buildChromeFixture(profileDir, { visits = [], bookmarks = null } = {}) {
|
|
103
|
-
fs.mkdirSync(profileDir, { recursive: true });
|
|
104
|
-
const db = new Database(path.join(profileDir, "History"));
|
|
105
|
-
db.exec(`
|
|
106
|
-
CREATE TABLE urls(
|
|
107
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
108
|
-
url LONGVARCHAR, title LONGVARCHAR,
|
|
109
|
-
visit_count INTEGER DEFAULT 0 NOT NULL,
|
|
110
|
-
typed_count INTEGER DEFAULT 0 NOT NULL,
|
|
111
|
-
last_visit_time INTEGER NOT NULL,
|
|
112
|
-
hidden INTEGER DEFAULT 0 NOT NULL
|
|
113
|
-
);
|
|
114
|
-
CREATE TABLE visits(
|
|
115
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
116
|
-
url INTEGER NOT NULL,
|
|
117
|
-
visit_time INTEGER NOT NULL,
|
|
118
|
-
from_visit INTEGER,
|
|
119
|
-
transition INTEGER DEFAULT 0 NOT NULL,
|
|
120
|
-
visit_duration INTEGER DEFAULT 0 NOT NULL
|
|
121
|
-
);
|
|
122
|
-
`);
|
|
123
|
-
const ins = db.prepare(
|
|
124
|
-
"INSERT INTO urls(url, title, last_visit_time) VALUES(?, ?, ?)",
|
|
125
|
-
);
|
|
126
|
-
const insv = db.prepare(
|
|
127
|
-
"INSERT INTO visits(url, visit_time, transition) VALUES(?, ?, 1)",
|
|
128
|
-
);
|
|
129
|
-
for (const v of visits) {
|
|
130
|
-
const wk = epochMsToWebkitUs(v.visitTimeMs).toString();
|
|
131
|
-
const r = ins.run(v.url, v.title || "", wk);
|
|
132
|
-
insv.run(r.lastInsertRowid, wk);
|
|
133
|
-
}
|
|
134
|
-
db.close();
|
|
135
|
-
if (bookmarks) {
|
|
136
|
-
fs.writeFileSync(path.join(profileDir, "Bookmarks"), JSON.stringify(bookmarks), "utf-8");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function buildVscodeFixture(vscodeRoot, { workspaces = [], commands = [], dirs = [] } = {}) {
|
|
141
|
-
const wsRoot = path.join(vscodeRoot, "User", "workspaceStorage");
|
|
142
|
-
fs.mkdirSync(wsRoot, { recursive: true });
|
|
143
|
-
for (const w of workspaces) {
|
|
144
|
-
const d = path.join(wsRoot, w.hash);
|
|
145
|
-
fs.mkdirSync(d, { recursive: true });
|
|
146
|
-
const wsFile = path.join(d, "workspace.json");
|
|
147
|
-
fs.writeFileSync(wsFile, JSON.stringify({ folder: w.folderUri }), "utf-8");
|
|
148
|
-
if (w.mtimeMs) fs.utimesSync(wsFile, w.mtimeMs / 1000, w.mtimeMs / 1000);
|
|
149
|
-
}
|
|
150
|
-
const stateDir = path.join(vscodeRoot, "User", "globalStorage");
|
|
151
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
152
|
-
const db = new Database(path.join(stateDir, "state.vscdb"));
|
|
153
|
-
db.exec("CREATE TABLE ItemTable(key TEXT PRIMARY KEY, value BLOB)");
|
|
154
|
-
const put = db.prepare("INSERT INTO ItemTable(key, value) VALUES(?, ?)");
|
|
155
|
-
put.run(
|
|
156
|
-
"terminal.history.entries.commands",
|
|
157
|
-
JSON.stringify({ entries: commands.map((c) => ({ key: c, value: { shellType: "pwsh" } })) }),
|
|
158
|
-
);
|
|
159
|
-
put.run(
|
|
160
|
-
"terminal.history.entries.dirs",
|
|
161
|
-
JSON.stringify({ entries: dirs.map((d) => ({ key: d, value: { shellType: "pwsh" } })) }),
|
|
162
|
-
);
|
|
163
|
-
put.run("terminal.history.timestamp.commands", String(1_700_000_010_000));
|
|
164
|
-
put.run("terminal.history.timestamp.dirs", String(1_700_000_020_000));
|
|
165
|
-
db.close();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function buildRecentFixture(recentDir, lnks = []) {
|
|
169
|
-
fs.mkdirSync(recentDir, { recursive: true });
|
|
170
|
-
for (const l of lnks) {
|
|
171
|
-
const p = path.join(recentDir, l.name);
|
|
172
|
-
fs.writeFileSync(p, "lnk-blob", "utf-8");
|
|
173
|
-
if (l.mtimeMs) fs.utimesSync(p, l.mtimeMs / 1000, l.mtimeMs / 1000);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
// Skip rig creation when bs3mc isn't loadable — the it.skip won't reach
|
|
179
|
-
// these tests, but beforeEach still runs and would throw.
|
|
180
|
-
if (!bs3mcAvailable) return;
|
|
181
|
-
rig = makeRig();
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
afterEach(() => {
|
|
185
|
-
cleanup(rig);
|
|
186
|
-
rig = null;
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// ─── Per-adapter pipeline tests ────────────────────────────────────────
|
|
190
|
-
|
|
191
|
-
describe("browser-history-chrome pipeline", () => {
|
|
192
|
-
itOrSkip("syncs visits + bookmarks into vault, status=ok, entityCounts match", async () => {
|
|
193
|
-
const profileDir = path.join(rig.dir, "ChromeProfile");
|
|
194
|
-
buildChromeFixture(profileDir, {
|
|
195
|
-
visits: [
|
|
196
|
-
{ url: "https://anthropic.com", title: "Anthropic", visitTimeMs: 1_700_000_001_000 },
|
|
197
|
-
{ url: "https://example.com", title: "Example", visitTimeMs: 1_700_000_002_000 },
|
|
198
|
-
],
|
|
199
|
-
bookmarks: {
|
|
200
|
-
version: 1,
|
|
201
|
-
roots: {
|
|
202
|
-
bookmark_bar: {
|
|
203
|
-
type: "folder",
|
|
204
|
-
name: "bar",
|
|
205
|
-
children: [
|
|
206
|
-
{
|
|
207
|
-
type: "url",
|
|
208
|
-
id: "1",
|
|
209
|
-
guid: "g1",
|
|
210
|
-
url: "https://saved.test",
|
|
211
|
-
name: "Saved",
|
|
212
|
-
date_added: "13300000000000000",
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
const adapter = new BrowserHistoryChromeAdapter({ profilePath: profileDir });
|
|
220
|
-
rig.registry.register(adapter);
|
|
221
|
-
const report = await rig.registry.syncAdapter("browser-history-chrome");
|
|
222
|
-
expect(report.status).toBe("ok");
|
|
223
|
-
expect(report.rawCount).toBe(3); // 2 visits + 1 bookmark
|
|
224
|
-
expect(report.entityCounts.events).toBe(2);
|
|
225
|
-
expect(report.entityCounts.items).toBe(1);
|
|
226
|
-
expect(report.invalidCount).toBe(0);
|
|
227
|
-
|
|
228
|
-
// Vault row count crosscheck (proves entities really persisted)
|
|
229
|
-
const eventsN = rig.vault.db.prepare("SELECT COUNT(*) AS n FROM events").get().n;
|
|
230
|
-
const itemsN = rig.vault.db.prepare("SELECT COUNT(*) AS n FROM items").get().n;
|
|
231
|
-
expect(eventsN).toBe(2);
|
|
232
|
-
expect(itemsN).toBe(1);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
itOrSkip("re-sync is idempotent — same originalId, no duplicate rows", async () => {
|
|
236
|
-
const profileDir = path.join(rig.dir, "ChromeProfile");
|
|
237
|
-
buildChromeFixture(profileDir, {
|
|
238
|
-
visits: [{ url: "https://idem.test", title: "Idem", visitTimeMs: 1_700_000_000_000 }],
|
|
239
|
-
});
|
|
240
|
-
const adapter = new BrowserHistoryChromeAdapter({ profilePath: profileDir });
|
|
241
|
-
rig.registry.register(adapter);
|
|
242
|
-
await rig.registry.syncAdapter("browser-history-chrome");
|
|
243
|
-
await rig.registry.syncAdapter("browser-history-chrome");
|
|
244
|
-
const n = rig.vault.db.prepare("SELECT COUNT(*) AS n FROM events").get().n;
|
|
245
|
-
expect(n).toBe(1); // dedup by source.originalId UNIQUE constraint
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe("browser-history-edge pipeline (Chromium subclass)", () => {
|
|
250
|
-
itOrSkip("syncs visits with edge-tagged source.adapter, not chrome", async () => {
|
|
251
|
-
const profileDir = path.join(rig.dir, "EdgeProfile");
|
|
252
|
-
buildChromeFixture(profileDir, {
|
|
253
|
-
visits: [{ url: "https://bing.com", title: "Bing", visitTimeMs: 1_700_000_001_000 }],
|
|
254
|
-
});
|
|
255
|
-
const adapter = new BrowserHistoryEdgeAdapter({ profilePath: profileDir });
|
|
256
|
-
rig.registry.register(adapter);
|
|
257
|
-
const report = await rig.registry.syncAdapter("browser-history-edge");
|
|
258
|
-
expect(report.status).toBe("ok");
|
|
259
|
-
expect(report.entityCounts.events).toBe(1);
|
|
260
|
-
|
|
261
|
-
// Drill into the row to confirm the subclass set source.adapter correctly
|
|
262
|
-
const row = rig.vault.db.prepare("SELECT source FROM events LIMIT 1").get();
|
|
263
|
-
const source = JSON.parse(row.source);
|
|
264
|
-
expect(source.adapter).toBe("browser-history-edge");
|
|
265
|
-
expect(source.originalId).toMatch(/^edge-visit:/);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
describe("vscode pipeline", () => {
|
|
270
|
-
itOrSkip("syncs workspaces (items) + terminal commands+dirs (events)", async () => {
|
|
271
|
-
const vscodeRoot = path.join(rig.dir, "VSCode");
|
|
272
|
-
buildVscodeFixture(vscodeRoot, {
|
|
273
|
-
workspaces: [
|
|
274
|
-
{ hash: "h1", folderUri: "file:///c%3A/code/foo", mtimeMs: 1_700_000_001_000 },
|
|
275
|
-
{ hash: "h2", folderUri: "file:///c%3A/code/bar", mtimeMs: 1_700_000_002_000 },
|
|
276
|
-
],
|
|
277
|
-
commands: ["ls", "git status"],
|
|
278
|
-
dirs: ["/c/code/foo"],
|
|
279
|
-
});
|
|
280
|
-
const adapter = new VSCodeAdapter({ vscodeRoot });
|
|
281
|
-
rig.registry.register(adapter);
|
|
282
|
-
const report = await rig.registry.syncAdapter("vscode");
|
|
283
|
-
expect(report.status).toBe("ok");
|
|
284
|
-
expect(report.entityCounts.items).toBe(2); // 2 workspaces
|
|
285
|
-
expect(report.entityCounts.events).toBe(3); // 2 commands + 1 dir
|
|
286
|
-
expect(report.invalidCount).toBe(0);
|
|
287
|
-
|
|
288
|
-
const items = rig.vault.db
|
|
289
|
-
.prepare("SELECT name, category FROM items ORDER BY name")
|
|
290
|
-
.all();
|
|
291
|
-
expect(items.map((i) => i.category)).toEqual(["code-project", "code-project"]);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
describe("win-recent pipeline", () => {
|
|
296
|
-
itOrSkip("syncs recent shortcuts to Event(OTHER) with '打开了 X' title", async () => {
|
|
297
|
-
const recentDir = path.join(rig.dir, "Recent");
|
|
298
|
-
buildRecentFixture(recentDir, [
|
|
299
|
-
{ name: "report.docx.lnk", mtimeMs: 1_700_000_001_000 },
|
|
300
|
-
{ name: "todo.txt.lnk", mtimeMs: 1_700_000_002_000 },
|
|
301
|
-
]);
|
|
302
|
-
const adapter = new WinRecentAdapter({ recentDir });
|
|
303
|
-
rig.registry.register(adapter);
|
|
304
|
-
const report = await rig.registry.syncAdapter("win-recent");
|
|
305
|
-
expect(report.status).toBe("ok");
|
|
306
|
-
expect(report.entityCounts.events).toBe(2);
|
|
307
|
-
|
|
308
|
-
const titles = rig.vault.db
|
|
309
|
-
.prepare("SELECT content FROM events ORDER BY occurred_at")
|
|
310
|
-
.all()
|
|
311
|
-
.map((r) => JSON.parse(r.content).title);
|
|
312
|
-
expect(titles).toEqual(["打开了 report.docx", "打开了 todo.txt"]);
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
// ─── Cross-adapter / mixed registry ────────────────────────────────────
|
|
317
|
-
|
|
318
|
-
describe("all 4 adapters registered together", () => {
|
|
319
|
-
itOrSkip("each adapter writes its own source-tagged rows; counts add up", async () => {
|
|
320
|
-
const chromeDir = path.join(rig.dir, "ChromeProfile");
|
|
321
|
-
const edgeDir = path.join(rig.dir, "EdgeProfile");
|
|
322
|
-
const vscodeRoot = path.join(rig.dir, "VSCode");
|
|
323
|
-
const recentDir = path.join(rig.dir, "Recent");
|
|
324
|
-
|
|
325
|
-
buildChromeFixture(chromeDir, {
|
|
326
|
-
visits: [{ url: "https://a.test", title: "A", visitTimeMs: 1_700_000_001_000 }],
|
|
327
|
-
});
|
|
328
|
-
buildChromeFixture(edgeDir, {
|
|
329
|
-
visits: [{ url: "https://b.test", title: "B", visitTimeMs: 1_700_000_002_000 }],
|
|
330
|
-
});
|
|
331
|
-
buildVscodeFixture(vscodeRoot, {
|
|
332
|
-
workspaces: [{ hash: "hX", folderUri: "file:///c%3A/x", mtimeMs: 1_700_000_001_000 }],
|
|
333
|
-
commands: ["ls"],
|
|
334
|
-
});
|
|
335
|
-
buildRecentFixture(recentDir, [{ name: "x.txt.lnk", mtimeMs: 1_700_000_001_000 }]);
|
|
336
|
-
|
|
337
|
-
rig.registry.register(new BrowserHistoryChromeAdapter({ profilePath: chromeDir }));
|
|
338
|
-
rig.registry.register(new BrowserHistoryEdgeAdapter({ profilePath: edgeDir }));
|
|
339
|
-
rig.registry.register(new VSCodeAdapter({ vscodeRoot }));
|
|
340
|
-
rig.registry.register(new WinRecentAdapter({ recentDir }));
|
|
341
|
-
|
|
342
|
-
const r1 = await rig.registry.syncAdapter("browser-history-chrome");
|
|
343
|
-
const r2 = await rig.registry.syncAdapter("browser-history-edge");
|
|
344
|
-
const r3 = await rig.registry.syncAdapter("vscode");
|
|
345
|
-
const r4 = await rig.registry.syncAdapter("win-recent");
|
|
346
|
-
|
|
347
|
-
expect([r1, r2, r3, r4].every((r) => r.status === "ok")).toBe(true);
|
|
348
|
-
|
|
349
|
-
// Totals across vault
|
|
350
|
-
const eventsTotal = rig.vault.db.prepare("SELECT COUNT(*) AS n FROM events").get().n;
|
|
351
|
-
const itemsTotal = rig.vault.db.prepare("SELECT COUNT(*) AS n FROM items").get().n;
|
|
352
|
-
// Chrome 1 visit + Edge 1 visit + VSCode 1 command + Win 1 recent = 4 events
|
|
353
|
-
// VSCode 1 workspace = 1 item
|
|
354
|
-
expect(eventsTotal).toBe(4);
|
|
355
|
-
expect(itemsTotal).toBe(1);
|
|
356
|
-
|
|
357
|
-
// Source-tagged distribution
|
|
358
|
-
const sourceCounts = rig.vault.db
|
|
359
|
-
.prepare("SELECT source FROM events")
|
|
360
|
-
.all()
|
|
361
|
-
.map((r) => JSON.parse(r.source).adapter)
|
|
362
|
-
.reduce((acc, a) => {
|
|
363
|
-
acc[a] = (acc[a] || 0) + 1;
|
|
364
|
-
return acc;
|
|
365
|
-
}, {});
|
|
366
|
-
expect(sourceCounts).toEqual({
|
|
367
|
-
"browser-history-chrome": 1,
|
|
368
|
-
"browser-history-edge": 1,
|
|
369
|
-
vscode: 1,
|
|
370
|
-
"win-recent": 1,
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
});
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Integration test — A8 v0.1 Bilibili snapshot → vault pipeline.
|
|
5
|
-
*
|
|
6
|
-
* Exercises the full chain WITHOUT any real WebView / OkHttp / Android JNI:
|
|
7
|
-
*
|
|
8
|
-
* Synthetic snapshot JSON (4 kinds)
|
|
9
|
-
* ↓
|
|
10
|
-
* AdapterRegistry (real) + LocalVault (real, SQLCipher)
|
|
11
|
-
* ↓
|
|
12
|
-
* adapter.sync({ inputPath }) → _syncViaSnapshot yields raw events
|
|
13
|
-
* ↓
|
|
14
|
-
* registry.putRawEvent → vault.raw_events
|
|
15
|
-
* ↓
|
|
16
|
-
* adapter.normalize(raw) → batch
|
|
17
|
-
* ↓
|
|
18
|
-
* vault.putBatch → events / persons / places / items / topics tables
|
|
19
|
-
*
|
|
20
|
-
* Two scenarios:
|
|
21
|
-
* A. happy path — 4-kind snapshot ingests; vault yields exact counts;
|
|
22
|
-
* KG triples derive; originalId stable across re-sync (idempotency)
|
|
23
|
-
* B. partial snapshot — only history + follow; vault gets correct subset
|
|
24
|
-
*
|
|
25
|
-
* Win note: bs3mc has a known NODE_MODULE_VERSION mismatch on this dev box
|
|
26
|
-
* (Node 22.22.2 ABI v127 vs prebuild ABI v140); test passes on CI Linux
|
|
27
|
-
* which uses the matched prebuild. See memory pdh-plan-a-android-standalone-
|
|
28
|
-
* design §"bs3mc NODE_MODULE_VERSION mismatch".
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
32
|
-
|
|
33
|
-
const fs = require("node:fs");
|
|
34
|
-
const path = require("node:path");
|
|
35
|
-
const os = require("node:os");
|
|
36
|
-
|
|
37
|
-
const {
|
|
38
|
-
LocalVault,
|
|
39
|
-
generateKeyHex,
|
|
40
|
-
AdapterRegistry,
|
|
41
|
-
} = require("../../lib");
|
|
42
|
-
const {
|
|
43
|
-
BilibiliAdapter,
|
|
44
|
-
SNAPSHOT_SCHEMA_VERSION,
|
|
45
|
-
} = require("../../lib/adapters/social-bilibili");
|
|
46
|
-
|
|
47
|
-
function makeRig() {
|
|
48
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bili-int-"));
|
|
49
|
-
const vault = new LocalVault({ path: path.join(dir, "v.db"), key: generateKeyHex() });
|
|
50
|
-
vault.open();
|
|
51
|
-
const registry = new AdapterRegistry({ vault });
|
|
52
|
-
return { vault, registry, dir };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function cleanup(rig) {
|
|
56
|
-
if (!rig) return;
|
|
57
|
-
try { rig.vault.close(); } catch (_e) { /* noop */ }
|
|
58
|
-
try { fs.rmSync(rig.dir, { recursive: true, force: true }); } catch (_e) { /* noop */ }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function writeSnapshot(dir, snapshot) {
|
|
62
|
-
const p = path.join(dir, "social-bilibili.json");
|
|
63
|
-
fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
|
|
64
|
-
return p;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function sampleSnapshot(opts = {}) {
|
|
68
|
-
const include = {
|
|
69
|
-
history: true,
|
|
70
|
-
favourite: true,
|
|
71
|
-
dynamic: true,
|
|
72
|
-
follow: true,
|
|
73
|
-
...opts.include,
|
|
74
|
-
};
|
|
75
|
-
const events = [];
|
|
76
|
-
if (include.history) {
|
|
77
|
-
events.push({
|
|
78
|
-
kind: "history",
|
|
79
|
-
id: "BV1abc",
|
|
80
|
-
capturedAt: 1715000000000,
|
|
81
|
-
title: "Rust 异步学习",
|
|
82
|
-
bvid: "BV1abc",
|
|
83
|
-
avid: 42,
|
|
84
|
-
duration: 600,
|
|
85
|
-
uploader: "技术UP主",
|
|
86
|
-
uploaderMid: 100,
|
|
87
|
-
part: "01 介绍",
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (include.favourite) {
|
|
91
|
-
events.push({
|
|
92
|
-
kind: "favourite",
|
|
93
|
-
id: "fav-BV2def",
|
|
94
|
-
capturedAt: 1714000000000,
|
|
95
|
-
title: "前端架构",
|
|
96
|
-
bvid: "BV2def",
|
|
97
|
-
folderName: "学习",
|
|
98
|
-
uploader: "码农UP",
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (include.dynamic) {
|
|
102
|
-
events.push({
|
|
103
|
-
kind: "dynamic",
|
|
104
|
-
id: "dyn-99",
|
|
105
|
-
capturedAt: 1713000000000,
|
|
106
|
-
summary: "今天发了一个新视频",
|
|
107
|
-
dynamicType: "av",
|
|
108
|
-
rid: "99",
|
|
109
|
-
authorMid: 200,
|
|
110
|
-
authorName: "我关注的UP",
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
if (include.follow) {
|
|
114
|
-
events.push({
|
|
115
|
-
kind: "follow",
|
|
116
|
-
id: "follow-300",
|
|
117
|
-
capturedAt: 1712000000000,
|
|
118
|
-
mid: 300,
|
|
119
|
-
uname: "美食UP",
|
|
120
|
-
face: "https://i0.hdslb.com/300.jpg",
|
|
121
|
-
sign: "好吃的视频",
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
schemaVersion: SNAPSHOT_SCHEMA_VERSION,
|
|
126
|
-
snapshottedAt: 1716000000000,
|
|
127
|
-
account: { uid: "12345", displayName: "alice" },
|
|
128
|
-
events,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
describe("Integration — A8 Bilibili snapshot → vault end-to-end", () => {
|
|
133
|
-
let rig;
|
|
134
|
-
afterEach(() => { cleanup(rig); rig = null; });
|
|
135
|
-
|
|
136
|
-
it("4 kinds ingest into vault with exact entity counts", async () => {
|
|
137
|
-
rig = makeRig();
|
|
138
|
-
const adapter = new BilibiliAdapter();
|
|
139
|
-
rig.registry.register(adapter);
|
|
140
|
-
|
|
141
|
-
const snapshotPath = writeSnapshot(rig.dir, sampleSnapshot());
|
|
142
|
-
const report = await rig.registry.syncAdapter("social-bilibili", {
|
|
143
|
-
inputPath: snapshotPath,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// 3 events (history + favourite + dynamic) + 1 person (follow) +
|
|
147
|
-
// 2 items (history-video + favourite-video)
|
|
148
|
-
expect(report.status).toBe("ok");
|
|
149
|
-
expect(report.entityCounts.events).toBe(3);
|
|
150
|
-
expect(report.entityCounts.persons).toBe(1);
|
|
151
|
-
expect(report.entityCounts.items).toBe(2);
|
|
152
|
-
|
|
153
|
-
// Vault round-trip
|
|
154
|
-
const events = rig.vault.queryEvents({ limit: 100 });
|
|
155
|
-
expect(events).toHaveLength(3);
|
|
156
|
-
const subtypes = events.map((e) => e.subtype).sort();
|
|
157
|
-
expect(subtypes).toEqual(["browse", "browse", "like"]); // history+dynamic+favourite
|
|
158
|
-
|
|
159
|
-
const persons = rig.vault.queryPersons({ limit: 100 });
|
|
160
|
-
expect(persons).toHaveLength(1);
|
|
161
|
-
expect(persons[0].names[0]).toBe("美食UP");
|
|
162
|
-
|
|
163
|
-
const items = rig.vault.queryItems({ limit: 100 });
|
|
164
|
-
expect(items).toHaveLength(2);
|
|
165
|
-
expect(items.map((i) => i.name).sort()).toEqual(["Rust 异步学习", "前端架构"]);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("re-sync is idempotent — same snapshot twice does NOT double entities", async () => {
|
|
169
|
-
rig = makeRig();
|
|
170
|
-
const adapter = new BilibiliAdapter();
|
|
171
|
-
rig.registry.register(adapter);
|
|
172
|
-
const snapshotPath = writeSnapshot(rig.dir, sampleSnapshot());
|
|
173
|
-
|
|
174
|
-
// First sync
|
|
175
|
-
const report1 = await rig.registry.syncAdapter("social-bilibili", {
|
|
176
|
-
inputPath: snapshotPath,
|
|
177
|
-
});
|
|
178
|
-
expect(report1.status).toBe("ok");
|
|
179
|
-
|
|
180
|
-
// Second sync — same snapshot
|
|
181
|
-
const report2 = await rig.registry.syncAdapter("social-bilibili", {
|
|
182
|
-
inputPath: snapshotPath,
|
|
183
|
-
});
|
|
184
|
-
expect(report2.status).toBe("ok");
|
|
185
|
-
|
|
186
|
-
// Stable originalId means re-sync de-dups at raw_events layer.
|
|
187
|
-
// The person/item entities should remain at 1 / 2 respectively
|
|
188
|
-
// because their IDs derive from bvid / mid (stable). Events can
|
|
189
|
-
// legitimately double-write because each "browse" is a separate
|
|
190
|
-
// occurrence — registry doesn't dedup events.
|
|
191
|
-
const persons = rig.vault.queryPersons({ limit: 100 });
|
|
192
|
-
expect(persons).toHaveLength(1);
|
|
193
|
-
|
|
194
|
-
const items = rig.vault.queryItems({ limit: 100 });
|
|
195
|
-
// Items with same bvid produce same ID, so item table stays at 2
|
|
196
|
-
// (UPSERT semantics via primary-key id).
|
|
197
|
-
expect(items).toHaveLength(2);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("partial snapshot (history + follow only) yields exact subset", async () => {
|
|
201
|
-
rig = makeRig();
|
|
202
|
-
const adapter = new BilibiliAdapter();
|
|
203
|
-
rig.registry.register(adapter);
|
|
204
|
-
|
|
205
|
-
const snapshotPath = writeSnapshot(
|
|
206
|
-
rig.dir,
|
|
207
|
-
sampleSnapshot({ include: { favourite: false, dynamic: false } })
|
|
208
|
-
);
|
|
209
|
-
const report = await rig.registry.syncAdapter("social-bilibili", {
|
|
210
|
-
inputPath: snapshotPath,
|
|
211
|
-
});
|
|
212
|
-
expect(report.status).toBe("ok");
|
|
213
|
-
expect(report.entityCounts.events).toBe(1); // history only
|
|
214
|
-
expect(report.entityCounts.persons).toBe(1); // follow
|
|
215
|
-
expect(report.entityCounts.items).toBe(1); // history video
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("empty events array → ok status with 0 entity counts", async () => {
|
|
219
|
-
rig = makeRig();
|
|
220
|
-
const adapter = new BilibiliAdapter();
|
|
221
|
-
rig.registry.register(adapter);
|
|
222
|
-
|
|
223
|
-
const snapshotPath = writeSnapshot(rig.dir, {
|
|
224
|
-
schemaVersion: SNAPSHOT_SCHEMA_VERSION,
|
|
225
|
-
snapshottedAt: Date.now(),
|
|
226
|
-
events: [],
|
|
227
|
-
});
|
|
228
|
-
const report = await rig.registry.syncAdapter("social-bilibili", {
|
|
229
|
-
inputPath: snapshotPath,
|
|
230
|
-
});
|
|
231
|
-
expect(report.status).toBe("ok");
|
|
232
|
-
expect(report.entityCounts.events).toBe(0);
|
|
233
|
-
expect(report.entityCounts.persons).toBe(0);
|
|
234
|
-
expect(report.entityCounts.items).toBe(0);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("schemaVersion mismatch surfaces in SyncReport.error (not silent)", async () => {
|
|
238
|
-
rig = makeRig();
|
|
239
|
-
const adapter = new BilibiliAdapter();
|
|
240
|
-
rig.registry.register(adapter);
|
|
241
|
-
|
|
242
|
-
const snapshotPath = writeSnapshot(rig.dir, {
|
|
243
|
-
schemaVersion: 99, // wrong
|
|
244
|
-
snapshottedAt: Date.now(),
|
|
245
|
-
events: [],
|
|
246
|
-
});
|
|
247
|
-
const report = await rig.registry.syncAdapter("social-bilibili", {
|
|
248
|
-
inputPath: snapshotPath,
|
|
249
|
-
});
|
|
250
|
-
expect(report.status).toBe("error");
|
|
251
|
-
expect(String(report.error)).toMatch(/schemaVersion mismatch/);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("registry queryable by adapter.name after register()", () => {
|
|
255
|
-
rig = makeRig();
|
|
256
|
-
const adapter = new BilibiliAdapter();
|
|
257
|
-
rig.registry.register(adapter);
|
|
258
|
-
expect(rig.registry.has("social-bilibili")).toBe(true);
|
|
259
|
-
expect(rig.registry.list().some((m) => m.name === "social-bilibili")).toBe(true);
|
|
260
|
-
});
|
|
261
|
-
});
|