@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,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
4
|
-
import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { execFileSync } from "node:child_process";
|
|
8
|
-
|
|
9
|
-
// Every test here spawns real `git` (init/config/commit) across throwaway
|
|
10
|
-
// repos. On Windows, under the full-suite parallel worker pool, that subprocess
|
|
11
|
-
// fan-out routinely blows past the 10s default and flakes. Give the whole file
|
|
12
|
-
// generous headroom — the work is real, the default timeout is just too tight.
|
|
13
|
-
vi.setConfig({ testTimeout: 30000, hookTimeout: 30000 });
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
GitActivityAdapter,
|
|
17
|
-
GIT_ACTIVITY_NAME,
|
|
18
|
-
GIT_ACTIVITY_VERSION,
|
|
19
|
-
} = require("../../lib/adapters/git-activity");
|
|
20
|
-
const { assertAdapter } = require("../../lib/adapter-spec");
|
|
21
|
-
const { EVENT_SUBTYPES } = require("../../lib/constants");
|
|
22
|
-
const { validateEvent } = require("../../lib/schemas");
|
|
23
|
-
|
|
24
|
-
let tmpDir;
|
|
25
|
-
let codeRoot;
|
|
26
|
-
|
|
27
|
-
// Anchor fixtures to "now - 1h" so the default --since=180.days filter
|
|
28
|
-
// never drops them. Bumping the literal in one place avoids drift if the
|
|
29
|
-
// adapter's default window changes.
|
|
30
|
-
const FIXTURE_NOW = Date.now();
|
|
31
|
-
function ts(offsetSec = 0) {
|
|
32
|
-
return FIXTURE_NOW - 3_600_000 + offsetSec * 1000;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Build a single throwaway repo with N commits — each committed with
|
|
36
|
-
// GIT_AUTHOR_DATE so the timestamps are deterministic.
|
|
37
|
-
function makeRepo(name, commits) {
|
|
38
|
-
const dir = join(codeRoot, name);
|
|
39
|
-
mkdirSync(dir, { recursive: true });
|
|
40
|
-
const G = (args, env = {}) =>
|
|
41
|
-
execFileSync("git", ["-C", dir, ...args], {
|
|
42
|
-
encoding: "utf-8",
|
|
43
|
-
env: {
|
|
44
|
-
...process.env,
|
|
45
|
-
GIT_CONFIG_NOSYSTEM: "1",
|
|
46
|
-
...env,
|
|
47
|
-
},
|
|
48
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
49
|
-
});
|
|
50
|
-
G(["init", "-q", "-b", "main"]);
|
|
51
|
-
G(["config", "user.email", "test@example.com"]);
|
|
52
|
-
G(["config", "user.name", "Test"]);
|
|
53
|
-
G(["config", "commit.gpgsign", "false"]);
|
|
54
|
-
let i = 0;
|
|
55
|
-
for (const c of commits) {
|
|
56
|
-
const file = join(dir, `f${i}.txt`);
|
|
57
|
-
writeFileSync(file, `content ${i}\n`, "utf-8");
|
|
58
|
-
G(["add", "."]);
|
|
59
|
-
const dt = new Date(c.tsMs).toISOString();
|
|
60
|
-
G(["commit", "-m", c.subject, "--author", `${c.author || "Test User"} <test@example.com>`], {
|
|
61
|
-
GIT_AUTHOR_DATE: dt,
|
|
62
|
-
GIT_COMMITTER_DATE: dt,
|
|
63
|
-
});
|
|
64
|
-
i++;
|
|
65
|
-
}
|
|
66
|
-
return dir;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
tmpDir = mkdtempSync(join(tmpdir(), "git-act-test-"));
|
|
71
|
-
codeRoot = join(tmpDir, "code");
|
|
72
|
-
mkdirSync(codeRoot, { recursive: true });
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
afterEach(() => {
|
|
76
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("GitActivityAdapter — contract + identity", () => {
|
|
80
|
-
it("conforms to PersonalDataAdapter contract", () => {
|
|
81
|
-
expect(assertAdapter(new GitActivityAdapter())).toEqual({ ok: true });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("identifies as git-activity with sync:git-log-local capability", () => {
|
|
85
|
-
const a = new GitActivityAdapter();
|
|
86
|
-
expect(a.name).toBe(GIT_ACTIVITY_NAME);
|
|
87
|
-
expect(a.name).toBe("git-activity");
|
|
88
|
-
expect(a.version).toBe(GIT_ACTIVITY_VERSION);
|
|
89
|
-
expect(a.capabilities).toContain("sync:git-log-local");
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe("GitActivityAdapter.authenticate", () => {
|
|
94
|
-
it("NO_GIT_REPOS when codeRoot empty", async () => {
|
|
95
|
-
const a = new GitActivityAdapter({ codeRoots: [codeRoot] });
|
|
96
|
-
const r = await a.authenticate({});
|
|
97
|
-
expect(r.ok).toBe(false);
|
|
98
|
-
expect(r.reason).toBe("NO_GIT_REPOS");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("ok when at least one repo exists", async () => {
|
|
102
|
-
makeRepo("a", [{ subject: "init", tsMs: ts(0) }]);
|
|
103
|
-
const a = new GitActivityAdapter({ codeRoots: [codeRoot] });
|
|
104
|
-
const r = await a.authenticate({});
|
|
105
|
-
expect(r.ok).toBe(true);
|
|
106
|
-
expect(r.repoCount).toBe(1);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("GitActivityAdapter.sync", () => {
|
|
111
|
-
it("yields commits with author+subject+ts, originalId stable across syncs", async () => {
|
|
112
|
-
makeRepo("a", [
|
|
113
|
-
{ subject: "first commit", tsMs: ts(1), author: "Alice" },
|
|
114
|
-
{ subject: "second commit", tsMs: ts(2), author: "Alice" },
|
|
115
|
-
]);
|
|
116
|
-
const a = new GitActivityAdapter({ codeRoots: [codeRoot] });
|
|
117
|
-
const raws1 = [];
|
|
118
|
-
for await (const r of a.sync()) raws1.push(r);
|
|
119
|
-
expect(raws1).toHaveLength(2);
|
|
120
|
-
expect(raws1[0].payload.subject).toBeTruthy();
|
|
121
|
-
expect(raws1[0].payload.authorName).toBe("Alice");
|
|
122
|
-
expect(raws1[0].payload.repoName).toBe("a");
|
|
123
|
-
expect(raws1[0].originalId).toMatch(/^git-commit:/);
|
|
124
|
-
// Re-sync — originalIds should match (idempotent)
|
|
125
|
-
const raws2 = [];
|
|
126
|
-
for await (const r of a.sync()) raws2.push(r);
|
|
127
|
-
const ids1 = raws1.map((r) => r.originalId).sort();
|
|
128
|
-
const ids2 = raws2.map((r) => r.originalId).sort();
|
|
129
|
-
expect(ids2).toEqual(ids1);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("multi-repo: enumerates every .git dir under the root", async () => {
|
|
133
|
-
makeRepo("repo-a", [{ subject: "a1", tsMs: ts(1) }]);
|
|
134
|
-
makeRepo("repo-b", [{ subject: "b1", tsMs: ts(2) }]);
|
|
135
|
-
makeRepo("repo-c", [{ subject: "c1", tsMs: ts(3) }]);
|
|
136
|
-
const a = new GitActivityAdapter({ codeRoots: [codeRoot] });
|
|
137
|
-
const raws = [];
|
|
138
|
-
for await (const r of a.sync()) raws.push(r);
|
|
139
|
-
const repoNames = new Set(raws.map((r) => r.payload.repoName));
|
|
140
|
-
expect(repoNames).toEqual(new Set(["repo-a", "repo-b", "repo-c"]));
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("respects limit", async () => {
|
|
144
|
-
makeRepo("a", [
|
|
145
|
-
{ subject: "1", tsMs: ts(1) },
|
|
146
|
-
{ subject: "2", tsMs: ts(2) },
|
|
147
|
-
{ subject: "3", tsMs: ts(3) },
|
|
148
|
-
]);
|
|
149
|
-
const a = new GitActivityAdapter({ codeRoots: [codeRoot] });
|
|
150
|
-
const raws = [];
|
|
151
|
-
for await (const r of a.sync({ limit: 2 })) raws.push(r);
|
|
152
|
-
expect(raws).toHaveLength(2);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("skips non-.git directories silently", async () => {
|
|
156
|
-
makeRepo("real-repo", [{ subject: "x", tsMs: ts(1) }]);
|
|
157
|
-
mkdirSync(join(codeRoot, "not-a-repo"), { recursive: true });
|
|
158
|
-
writeFileSync(join(codeRoot, "not-a-repo", "README.md"), "no .git here", "utf-8");
|
|
159
|
-
const a = new GitActivityAdapter({ codeRoots: [codeRoot] });
|
|
160
|
-
const raws = [];
|
|
161
|
-
for await (const r of a.sync()) raws.push(r);
|
|
162
|
-
expect(raws).toHaveLength(1);
|
|
163
|
-
expect(raws[0].payload.repoName).toBe("real-repo");
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("GitActivityAdapter.normalize", () => {
|
|
168
|
-
it("maps commit → schema-valid Event(OTHER) with author as actor", () => {
|
|
169
|
-
const a = new GitActivityAdapter();
|
|
170
|
-
const { events } = a.normalize({
|
|
171
|
-
kind: "commit",
|
|
172
|
-
originalId: "git-commit:/code/foo:abc",
|
|
173
|
-
capturedAt: 1_700_000_005_000,
|
|
174
|
-
payload: {
|
|
175
|
-
sha: "abcdef0123456789",
|
|
176
|
-
shortSha: "abcdef01",
|
|
177
|
-
authoredAtMs: 1_700_000_001_000,
|
|
178
|
-
authorName: "Alice",
|
|
179
|
-
authorEmail: "alice@example.com",
|
|
180
|
-
subject: "Fix the bug",
|
|
181
|
-
repoDir: "/code/foo",
|
|
182
|
-
repoName: "foo",
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
expect(events).toHaveLength(1);
|
|
186
|
-
const e = events[0];
|
|
187
|
-
expect(e.subtype).toBe(EVENT_SUBTYPES.OTHER);
|
|
188
|
-
expect(e.actor).toBe("Alice");
|
|
189
|
-
expect(e.content.title).toBe("Fix the bug");
|
|
190
|
-
expect(e.occurredAt).toBe(1_700_000_001_000);
|
|
191
|
-
expect(e.extra.repoName).toBe("foo");
|
|
192
|
-
expect(e.extra.sha).toBe("abcdef0123456789");
|
|
193
|
-
expect(validateEvent(e).valid).toBe(true);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("truncates long commit subjects to 100 chars in title", () => {
|
|
197
|
-
const a = new GitActivityAdapter();
|
|
198
|
-
const longSubj = "x".repeat(200);
|
|
199
|
-
const { events } = a.normalize({
|
|
200
|
-
kind: "commit",
|
|
201
|
-
capturedAt: 1_700_000_000_000,
|
|
202
|
-
originalId: "git-commit:foo:long",
|
|
203
|
-
payload: {
|
|
204
|
-
sha: "deadbeef",
|
|
205
|
-
shortSha: "deadbeef",
|
|
206
|
-
authoredAtMs: 1_700_000_000_000,
|
|
207
|
-
subject: longSubj,
|
|
208
|
-
authorName: "X",
|
|
209
|
-
repoName: "r",
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
expect(events[0].content.title.length).toBeLessThanOrEqual(101);
|
|
213
|
-
expect(events[0].content.title.endsWith("…")).toBe(true);
|
|
214
|
-
expect(events[0].content.text).toBe(longSubj);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("throws on unknown raw.kind", () => {
|
|
218
|
-
expect(() => new GitActivityAdapter().normalize({ kind: "bogus" })).toThrow(
|
|
219
|
-
/unknown raw\.kind=bogus/,
|
|
220
|
-
);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
@@ -1,103 +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
|
-
const crypto = require("node:crypto");
|
|
8
|
-
|
|
9
|
-
const g = require("../../lib/adapters/gov-12123");
|
|
10
|
-
|
|
11
|
-
function writeTmp(content) {
|
|
12
|
-
const p = path.join(os.tmpdir(), `cc-12123-${crypto.randomUUID()}.json`);
|
|
13
|
-
fs.writeFileSync(p, content, "utf-8");
|
|
14
|
-
return p;
|
|
15
|
-
}
|
|
16
|
-
async function collect(gen) {
|
|
17
|
-
const out = [];
|
|
18
|
-
for await (const x of gen) out.push(x);
|
|
19
|
-
return out;
|
|
20
|
-
}
|
|
21
|
-
const COOKIES = "GAB_SSO=abc";
|
|
22
|
-
|
|
23
|
-
describe("gov-12123", () => {
|
|
24
|
-
it("name + mappers (chinese-field aliases)", () => {
|
|
25
|
-
expect(g.NAME).toBe("gov-12123");
|
|
26
|
-
const v = g.mapViolation({ wzbh: "V1", wfsj: 1716383000, wfdz: "环岛路", wfxw: "超速50%以下", fkje: "200", wfjfs: "3" });
|
|
27
|
-
expect(v).toMatchObject({ violationId: "V1", location: "环岛路", reason: "超速50%以下" });
|
|
28
|
-
expect(v.fine).toBe(200);
|
|
29
|
-
expect(v.points).toBe(3);
|
|
30
|
-
expect(g.mapViolation({ wfxw: "x" })).toBe(null);
|
|
31
|
-
const l = g.mapLicense({ dabh: "L1", zt: "正常", ljjf: 3, yxqz: 1900000000 });
|
|
32
|
-
expect(l).toMatchObject({ licenseId: "L1", status: "正常", cumulativePoints: 3 });
|
|
33
|
-
expect(g.mapLicense({ zt: "x" })).toBe(null);
|
|
34
|
-
});
|
|
35
|
-
it("extractLicense wraps single object", () => {
|
|
36
|
-
expect(g.extractLicense({ data: { dabh: "L1" } })).toHaveLength(1);
|
|
37
|
-
expect(g.extractLicense({ licenseId: "L2" })).toHaveLength(1);
|
|
38
|
-
expect(g.extractLicense({ list: [{ dabh: "L3" }] })).toHaveLength(1);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("snapshot → violation + license OTHER events", async () => {
|
|
42
|
-
const SNAP = JSON.stringify({
|
|
43
|
-
schemaVersion: 1,
|
|
44
|
-
snapshottedAt: 1716383000000,
|
|
45
|
-
account: { userId: "u1" },
|
|
46
|
-
events: [
|
|
47
|
-
{ kind: "violation", id: "v-V1", violationId: "V1", time: 1716383000, location: "环岛路", reason: "超速", fine: 200, points: 3 },
|
|
48
|
-
{ kind: "license", id: "l-L1", licenseId: "L1", status: "正常", cumulativePoints: 3, validUntil: 1900000000 },
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
const p = writeTmp(SNAP);
|
|
52
|
-
try {
|
|
53
|
-
const a = new g.Tmri12123Adapter();
|
|
54
|
-
const items = await collect(a.sync({ inputPath: p }));
|
|
55
|
-
expect(items).toHaveLength(2);
|
|
56
|
-
const v = a.normalize(items[0]);
|
|
57
|
-
expect(v.events[0].subtype).toBe("other");
|
|
58
|
-
expect(v.events[0].content.title).toContain("交通违章");
|
|
59
|
-
expect(v.events[0].extra.fine).toBe(200);
|
|
60
|
-
expect(v.events[0].extra.points).toBe(3);
|
|
61
|
-
expect(items[0].originalId).toBe("12123:violation:V1");
|
|
62
|
-
const l = a.normalize(items[1]);
|
|
63
|
-
expect(l.events[0].content.title).toContain("驾驶证状态");
|
|
64
|
-
expect(l.events[0].extra.cumulativePoints).toBe(3);
|
|
65
|
-
expect(items[1].originalId).toBe("12123:license:L1");
|
|
66
|
-
} finally {
|
|
67
|
-
fs.unlinkSync(p);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("cookie-api: paginated violations + single license + unverified", async () => {
|
|
72
|
-
const a = new g.Tmri12123Adapter({
|
|
73
|
-
account: { cookies: COOKIES, userId: "u1" },
|
|
74
|
-
fetchFn: async ({ url, query }) => {
|
|
75
|
-
if (url.includes("/violation")) return query.page > 1 ? { list: [] } : { list: [{ wzbh: "V9", wfsj: 1716383000, wfxw: "闯红灯", fkje: 200, wfjfs: 6 }] };
|
|
76
|
-
return { data: { dabh: "L9", zt: "正常", ljjf: 6 } };
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
expect(await a.authenticate()).toMatchObject({ ok: true, mode: "cookie", unverified: true });
|
|
80
|
-
const items = await collect(a.sync({}));
|
|
81
|
-
expect(items).toHaveLength(2);
|
|
82
|
-
expect(items.map((i) => i.originalId).sort()).toEqual(["12123:license:L9", "12123:violation:V9"]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("province base host (verified .122.gov.cn/app); override + default", () => {
|
|
86
|
-
// default province bj
|
|
87
|
-
const a = new g.Tmri12123Adapter({ province: "fj" });
|
|
88
|
-
expect(a.province).toBe("fj");
|
|
89
|
-
expect(a._urls.violation).toBe("https://fj.122.gov.cn/app/violation/list");
|
|
90
|
-
expect(a._urls.license).toBe("https://fj.122.gov.cn/app/license/info");
|
|
91
|
-
// bad province → default bj
|
|
92
|
-
expect(new g.Tmri12123Adapter({ province: "XX" })._urls.violation).toBe("https://bj.122.gov.cn/app/violation/list");
|
|
93
|
-
// explicit url override still wins
|
|
94
|
-
expect(new g.Tmri12123Adapter({ violationUrl: "https://x/y" })._urls.violation).toBe("https://x/y");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("high sensitivity + legalGate; default fetch / no input throw", async () => {
|
|
98
|
-
expect(new g.Tmri12123Adapter().dataDisclosure.sensitivity).toBe("high");
|
|
99
|
-
expect(new g.Tmri12123Adapter().dataDisclosure.legalGate).toBe(true);
|
|
100
|
-
await expect(collect(new g.Tmri12123Adapter({ account: { cookies: COOKIES } }).sync({}))).rejects.toThrow(/no fetchFn/);
|
|
101
|
-
await expect(collect(new g.Tmri12123Adapter().sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,150 +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
|
-
const crypto = require("node:crypto");
|
|
8
|
-
|
|
9
|
-
const ix = require("../../lib/adapters/gov-ixiamen");
|
|
10
|
-
|
|
11
|
-
function writeTmp(content) {
|
|
12
|
-
const p = path.join(os.tmpdir(), `cc-ix-${crypto.randomUUID()}.json`);
|
|
13
|
-
fs.writeFileSync(p, content, "utf-8");
|
|
14
|
-
return p;
|
|
15
|
-
}
|
|
16
|
-
async function collect(gen) {
|
|
17
|
-
const out = [];
|
|
18
|
-
for await (const x of gen) out.push(x);
|
|
19
|
-
return out;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const COOKIES = "XMGOV_SSO=abc; tgc=xyz";
|
|
23
|
-
|
|
24
|
-
describe("gov-ixiamen mappers", () => {
|
|
25
|
-
it("name/version/capabilities", () => {
|
|
26
|
-
expect(ix.NAME).toBe("gov-ixiamen");
|
|
27
|
-
expect(ix.VERSION).toBe("0.2.0");
|
|
28
|
-
});
|
|
29
|
-
it("inferCategory: explicit wins, else keyword, else fallback", () => {
|
|
30
|
-
expect(ix.inferCategory("随便", "医保")).toBe("医保");
|
|
31
|
-
expect(ix.inferCategory("城乡居民医保缴费")).toBe("医保");
|
|
32
|
-
expect(ix.inferCategory("住房公积金提取")).toBe("公积金");
|
|
33
|
-
expect(ix.inferCategory("机动车违章处理")).toBe("车驾管");
|
|
34
|
-
expect(ix.inferCategory("某个没见过的事项")).toBe("其他政务");
|
|
35
|
-
});
|
|
36
|
-
it("mapService maps gov-service fields; no id → null", () => {
|
|
37
|
-
const rec = ix.mapService({
|
|
38
|
-
service_id: "S1",
|
|
39
|
-
service_name: "养老保险待遇资格认证",
|
|
40
|
-
handle_time: 1716383000,
|
|
41
|
-
status: "已办结",
|
|
42
|
-
deptName: "厦门市社保中心",
|
|
43
|
-
});
|
|
44
|
-
expect(rec).toMatchObject({ serviceId: "S1", category: "社保", status: "已办结", dept: "厦门市社保中心" });
|
|
45
|
-
expect(rec.handledMs).toBe(1716383000000);
|
|
46
|
-
expect(ix.mapService({ service_name: "noid" })).toBe(null);
|
|
47
|
-
});
|
|
48
|
-
it("extractList tolerant", () => {
|
|
49
|
-
expect(ix.extractList({ list: [{ id: 1 }] })).toHaveLength(1);
|
|
50
|
-
expect(ix.extractList({ data: { records: [{ id: 1 }] } })).toHaveLength(1);
|
|
51
|
-
expect(ix.extractList({})).toEqual([]);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("IXiamenAdapter (snapshot + cookie-api)", () => {
|
|
56
|
-
const SNAP = JSON.stringify({
|
|
57
|
-
schemaVersion: 1,
|
|
58
|
-
snapshottedAt: 1716383000000,
|
|
59
|
-
account: { userId: "u1", name: "张三" },
|
|
60
|
-
events: [
|
|
61
|
-
{
|
|
62
|
-
kind: "service",
|
|
63
|
-
id: "svc-S1",
|
|
64
|
-
serviceId: "S1",
|
|
65
|
-
serviceName: "住房公积金缴存明细查询",
|
|
66
|
-
handledTime: 1716383000,
|
|
67
|
-
status: "已办结",
|
|
68
|
-
dept: "厦门住房公积金中心",
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("snapshot sync + normalize → INTERACTION event + category topic", async () => {
|
|
74
|
-
const p = writeTmp(SNAP);
|
|
75
|
-
try {
|
|
76
|
-
const a = new ix.IXiamenAdapter();
|
|
77
|
-
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
78
|
-
const items = await collect(a.sync({ inputPath: p }));
|
|
79
|
-
expect(items).toHaveLength(1);
|
|
80
|
-
expect(items[0].originalId).toBe("ixiamen:service:S1");
|
|
81
|
-
const batch = a.normalize(items[0]);
|
|
82
|
-
expect(batch.events[0].subtype).toBe("interaction");
|
|
83
|
-
expect(batch.events[0].content.title).toBe("办理: 住房公积金缴存明细查询");
|
|
84
|
-
expect(batch.events[0].extra.category).toBe("公积金");
|
|
85
|
-
expect(batch.topics[0].name).toBe("公积金");
|
|
86
|
-
expect(batch.topics[0].id).toBe("topic-ixiamen-cat-公积金");
|
|
87
|
-
expect(batch.events[0].extra.topicRef).toBe("topic-ixiamen-cat-公积金");
|
|
88
|
-
} finally {
|
|
89
|
-
fs.unlinkSync(p);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("dataDisclosure: high sensitivity + legalGate (gov real-name)", () => {
|
|
94
|
-
const a = new ix.IXiamenAdapter();
|
|
95
|
-
expect(a.dataDisclosure.sensitivity).toBe("high");
|
|
96
|
-
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("cookie-api: best-effort fetch + paginate + unverified flag", async () => {
|
|
100
|
-
const pages = [
|
|
101
|
-
{ list: [{ id: 7, name: "门诊报销", category: "医保", handledTime: 1716383000 }] },
|
|
102
|
-
{ list: [] },
|
|
103
|
-
];
|
|
104
|
-
const calls = [];
|
|
105
|
-
const a = new ix.IXiamenAdapter({
|
|
106
|
-
account: { cookies: COOKIES, userId: "u1" },
|
|
107
|
-
fetchFn: async ({ url, cookies, query, sign }) => {
|
|
108
|
-
calls.push({ url, cookies, page: query.page, sign });
|
|
109
|
-
return query.page === 1 ? pages[0] : pages[1];
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
const auth = await a.authenticate();
|
|
113
|
-
expect(auth).toMatchObject({ ok: true, mode: "cookie", unverified: true });
|
|
114
|
-
const items = await collect(a.sync({}));
|
|
115
|
-
expect(items).toHaveLength(1);
|
|
116
|
-
expect(items[0].originalId).toBe("ixiamen:service:7");
|
|
117
|
-
expect(calls[0].cookies).toBe(COOKIES);
|
|
118
|
-
expect(calls[0].sign).toBe(null);
|
|
119
|
-
const batch = a.normalize(items[0]);
|
|
120
|
-
expect(batch.events[0].extra.category).toBe("医保");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("cookie-api: signProvider seam invoked + sinceWatermark stops early", async () => {
|
|
124
|
-
let seen = null;
|
|
125
|
-
const a = new ix.IXiamenAdapter({
|
|
126
|
-
account: { cookies: COOKIES },
|
|
127
|
-
signProvider: async ({ url, query }) => {
|
|
128
|
-
seen = { url, page: query.page };
|
|
129
|
-
return "gov-sig";
|
|
130
|
-
},
|
|
131
|
-
fetchFn: async () => ({
|
|
132
|
-
list: [
|
|
133
|
-
{ id: "new", name: "新事项", handledTime: 1716390000 },
|
|
134
|
-
{ id: "old", name: "旧事项", handledTime: 1700000000 },
|
|
135
|
-
],
|
|
136
|
-
}),
|
|
137
|
-
});
|
|
138
|
-
const items = await collect(a.sync({ sinceWatermark: 1716000000000 }));
|
|
139
|
-
expect(items).toHaveLength(1); // old one below watermark stops iteration
|
|
140
|
-
expect(items[0].originalId).toBe("ixiamen:service:new");
|
|
141
|
-
expect(seen.url).toContain("buss.ixiamen.org.cn");
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("default fetch throws; no input throws", async () => {
|
|
145
|
-
const a = new ix.IXiamenAdapter({ account: { cookies: COOKIES } });
|
|
146
|
-
await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
147
|
-
const b = new ix.IXiamenAdapter();
|
|
148
|
-
await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,135 +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
|
-
const crypto = require("node:crypto");
|
|
8
|
-
|
|
9
|
-
const tx = require("../../lib/adapters/gov-tax");
|
|
10
|
-
|
|
11
|
-
function writeTmp(content) {
|
|
12
|
-
const p = path.join(os.tmpdir(), `cc-tax-${crypto.randomUUID()}.json`);
|
|
13
|
-
fs.writeFileSync(p, content, "utf-8");
|
|
14
|
-
return p;
|
|
15
|
-
}
|
|
16
|
-
async function collect(gen) {
|
|
17
|
-
const out = [];
|
|
18
|
-
for await (const x of gen) out.push(x);
|
|
19
|
-
return out;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const COOKIES = "ETAX_SSO=abc; sid=xyz";
|
|
23
|
-
|
|
24
|
-
describe("gov-tax mappers", () => {
|
|
25
|
-
it("name/version", () => {
|
|
26
|
-
expect(tx.NAME).toBe("gov-tax");
|
|
27
|
-
expect(tx.VERSION).toBe("0.1.0");
|
|
28
|
-
});
|
|
29
|
-
it("periodToMs / toAmount", () => {
|
|
30
|
-
expect(tx.periodToMs("2025-03")).toBe(Date.parse("2025-03-01T00:00:00Z"));
|
|
31
|
-
expect(tx.periodToMs("202503")).toBe(Date.parse("2025-03-01T00:00:00Z"));
|
|
32
|
-
expect(tx.toAmount("¥1,234.56")).toBeCloseTo(1234.56, 2);
|
|
33
|
-
expect(tx.toAmount(2000)).toBe(2000);
|
|
34
|
-
expect(tx.toAmount("abc")).toBe(null);
|
|
35
|
-
});
|
|
36
|
-
it("mapIncome / mapDeclaration field aliases; no id → null", () => {
|
|
37
|
-
const inc = tx.mapIncome({ record_id: "I1", tax_period: "2025-03", income_type: "工资薪金", amount: "20,000", withheldTax: 1234.56, company: "某某公司", companyId: "9144" });
|
|
38
|
-
expect(inc).toMatchObject({ recordId: "I1", incomeType: "工资薪金", payerName: "某某公司", payerId: "9144" });
|
|
39
|
-
expect(inc.amount).toBe(20000);
|
|
40
|
-
expect(inc.withheld).toBeCloseTo(1234.56, 2);
|
|
41
|
-
expect(tx.mapIncome({ amount: 1 })).toBe(null);
|
|
42
|
-
const dec = tx.mapDeclaration({ id: "D1", tax_year: 2024, type: "综合所得年度汇算", status: "已退税", amount: -800 });
|
|
43
|
-
expect(dec).toMatchObject({ recordId: "D1", year: 2024, declType: "综合所得年度汇算", status: "已退税", settleAmount: -800 });
|
|
44
|
-
expect(tx.mapDeclaration({ year: 2024 })).toBe(null);
|
|
45
|
-
});
|
|
46
|
-
it("extractList tolerant", () => {
|
|
47
|
-
expect(tx.extractList({ list: [{ id: 1 }] })).toHaveLength(1);
|
|
48
|
-
expect(tx.extractList({ data: { records: [{ id: 1 }] } })).toHaveLength(1);
|
|
49
|
-
expect(tx.extractList({})).toEqual([]);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("TaxAdapter (snapshot + cookie-api)", () => {
|
|
54
|
-
const SNAP = JSON.stringify({
|
|
55
|
-
schemaVersion: 1,
|
|
56
|
-
snapshottedAt: 1716383000000,
|
|
57
|
-
account: { userId: "u1" },
|
|
58
|
-
events: [
|
|
59
|
-
{ kind: "income", id: "inc-I1", recordId: "I1", period: "2025-03", incomeType: "工资薪金", amount: 20000, withheld: 1234.56, payerName: "某某科技有限公司", payerId: "9144ABC" },
|
|
60
|
-
{ kind: "declaration", id: "dec-D1", recordId: "D1", year: 2024, declType: "综合所得年度汇算", status: "已退税", settleAmount: -800, declaredAt: 1716383000 },
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("income → INCOME event + employer Person(MERCHANT)", async () => {
|
|
65
|
-
const p = writeTmp(SNAP);
|
|
66
|
-
try {
|
|
67
|
-
const a = new tx.TaxAdapter();
|
|
68
|
-
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
69
|
-
const items = await collect(a.sync({ inputPath: p }));
|
|
70
|
-
expect(items).toHaveLength(2);
|
|
71
|
-
const inc = a.normalize(items[0]);
|
|
72
|
-
expect(inc.events[0].subtype).toBe("income");
|
|
73
|
-
expect(inc.events[0].extra.incomeType).toBe("工资薪金");
|
|
74
|
-
expect(inc.events[0].extra.amount).toBe(20000);
|
|
75
|
-
expect(inc.persons).toHaveLength(1);
|
|
76
|
-
expect(inc.persons[0].subtype).toBe("merchant");
|
|
77
|
-
expect(inc.persons[0].names[0]).toBe("某某科技有限公司");
|
|
78
|
-
expect(inc.events[0].extra.payerRef).toBe(inc.persons[0].id);
|
|
79
|
-
expect(items[0].originalId).toBe("tax:income:I1");
|
|
80
|
-
} finally {
|
|
81
|
-
fs.unlinkSync(p);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("declaration → OTHER event with settleAmount", async () => {
|
|
86
|
-
const p = writeTmp(SNAP);
|
|
87
|
-
try {
|
|
88
|
-
const a = new tx.TaxAdapter();
|
|
89
|
-
const items = await collect(a.sync({ inputPath: p }));
|
|
90
|
-
const dec = a.normalize(items[1]);
|
|
91
|
-
expect(dec.events[0].subtype).toBe("other");
|
|
92
|
-
expect(dec.events[0].content.title).toContain("个税申报");
|
|
93
|
-
expect(dec.events[0].extra.settleAmount).toBe(-800);
|
|
94
|
-
expect(dec.events[0].extra.year).toBe(2024);
|
|
95
|
-
expect(items[1].originalId).toBe("tax:declaration:D1");
|
|
96
|
-
} finally {
|
|
97
|
-
fs.unlinkSync(p);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("dataDisclosure: high sensitivity + legalGate (financial/tax)", () => {
|
|
102
|
-
const a = new tx.TaxAdapter();
|
|
103
|
-
expect(a.dataDisclosure.sensitivity).toBe("high");
|
|
104
|
-
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("cookie-api: best-effort both kinds + unverified flag + sign seam", async () => {
|
|
108
|
-
let signed = 0;
|
|
109
|
-
const a = new tx.TaxAdapter({
|
|
110
|
-
account: { cookies: COOKIES, userId: "u1" },
|
|
111
|
-
signProvider: async () => {
|
|
112
|
-
signed += 1;
|
|
113
|
-
return "sig";
|
|
114
|
-
},
|
|
115
|
-
fetchFn: async ({ url, query }) => {
|
|
116
|
-
if (query.page > 1) return { list: [] };
|
|
117
|
-
if (url.includes("/income")) return { list: [{ recordId: "I9", period: "2025-01", incomeType: "劳务报酬", amount: 5000 }] };
|
|
118
|
-
return { list: [{ recordId: "D9", year: 2024, declType: "年度汇算", settleAmount: 300 }] };
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
const auth = await a.authenticate();
|
|
122
|
-
expect(auth).toMatchObject({ ok: true, mode: "cookie", unverified: true });
|
|
123
|
-
const items = await collect(a.sync({}));
|
|
124
|
-
expect(items).toHaveLength(2);
|
|
125
|
-
expect(items.map((i) => i.originalId).sort()).toEqual(["tax:declaration:D9", "tax:income:I9"]);
|
|
126
|
-
expect(signed).toBeGreaterThan(0);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("default fetch throws; no input throws", async () => {
|
|
130
|
-
const a = new tx.TaxAdapter({ account: { cookies: COOKIES } });
|
|
131
|
-
await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
132
|
-
const b = new tx.TaxAdapter();
|
|
133
|
-
await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
134
|
-
});
|
|
135
|
-
});
|