@chainlesschain/personal-data-hub 0.2.0 → 0.2.2
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/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +211 -0
- package/__tests__/adapters/ai-chat-health-checker.test.js +262 -0
- package/__tests__/adapters/ai-chat-history.test.js +8 -7
- package/__tests__/adapters/ai-chat-vendors.test.js +149 -8
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +269 -0
- package/__tests__/adapters/system-data-android-ingest.test.js +144 -0
- package/__tests__/adapters/system-data-android.test.js +387 -0
- package/__tests__/adapters/wechat-bootstrap.test.js +240 -0
- package/__tests__/adapters/wechat-env-probe.test.js +162 -0
- package/__tests__/adapters/wechat-frida-agent.test.js +322 -0
- package/__tests__/adapters/wechat-frida-integration.test.js +149 -0
- package/__tests__/adapters/wechat-frida-key-provider.test.js +188 -0
- package/__tests__/adapters/wechat-md5-key-provider.test.js +101 -0
- package/__tests__/analysis-skills.test.js +147 -0
- package/__tests__/analysis.test.js +329 -1
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +213 -0
- package/__tests__/e2e/full-user-journey.test.js +188 -0
- package/__tests__/integration/ai-chat-history-registry.test.js +228 -0
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +282 -0
- package/__tests__/integration/cross-adapter-pipelines.test.js +396 -0
- package/__tests__/integration/social-bilibili-pipeline.test.js +261 -0
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +390 -0
- package/__tests__/registry.test.js +4 -2
- package/__tests__/social-adapters.test.js +63 -14
- package/__tests__/social-bilibili-snapshot.test.js +278 -0
- package/__tests__/wechat-adapter.test.js +118 -0
- package/lib/adapters/ai-chat-history/ai-chat-adapter.js +55 -16
- package/lib/adapters/ai-chat-history/cookie-capture-spec.js +331 -0
- package/lib/adapters/ai-chat-history/health-checker.js +210 -0
- package/lib/adapters/ai-chat-history/schema-map.js +42 -5
- package/lib/adapters/ai-chat-history/vendor-spec.js +1 -0
- package/lib/adapters/ai-chat-history/vendors/doubao.js +255 -0
- package/lib/adapters/ai-chat-history/wizard-controller.js +473 -0
- package/lib/adapters/alipay-bill/alipay-bill-adapter.js +4 -0
- package/lib/adapters/social-bilibili/adapter.js +500 -0
- package/lib/adapters/social-bilibili/index.js +21 -169
- package/lib/adapters/social-kuaishou/index.js +237 -0
- package/lib/adapters/social-toutiao/index.js +236 -0
- package/lib/adapters/system-data-android/adapter.js +348 -0
- package/lib/adapters/system-data-android/index.js +76 -0
- package/lib/adapters/wechat/bootstrap.js +146 -0
- package/lib/adapters/wechat/content-parser.js +11 -2
- package/lib/adapters/wechat/db-reader.js +88 -10
- package/lib/adapters/wechat/env-probe.js +218 -0
- package/lib/adapters/wechat/frida-agent/loader.js +74 -0
- package/lib/adapters/wechat/frida-agent/wechat-key-hook.js +248 -0
- package/lib/adapters/wechat/index.js +9 -0
- package/lib/adapters/wechat/key-providers/frida-key-provider.js +252 -0
- package/lib/adapters/wechat/key-providers/index.js +22 -0
- package/lib/adapters/wechat/key-providers/key-provider-base.js +44 -0
- package/lib/adapters/wechat/key-providers/md5-key-provider.js +81 -0
- package/lib/adapters/wechat/normalize.js +12 -3
- package/lib/analysis-skills/spending.js +4 -1
- package/lib/analysis.js +191 -2
- package/lib/index.js +16 -0
- package/lib/prompt-builder.js +11 -1
- package/lib/query-parser.js +7 -1
- package/lib/vault.js +77 -0
- package/package.json +8 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const { FridaKeyProvider } = require("../../lib/adapters/wechat/key-providers/frida-key-provider");
|
|
6
|
+
|
|
7
|
+
/** Helper that builds a mock frida binding with a scripted message timeline. */
|
|
8
|
+
function makeMockFrida({ onAttachThrow, onCreateScriptThrow, onLoadThrow, messages = [], deviceId = "device" }) {
|
|
9
|
+
const ops = {
|
|
10
|
+
unloadCalled: 0,
|
|
11
|
+
detachCalled: 0,
|
|
12
|
+
loadCalled: 0,
|
|
13
|
+
messageHandler: null,
|
|
14
|
+
};
|
|
15
|
+
const script = {
|
|
16
|
+
message: {
|
|
17
|
+
connect: (handler) => { ops.messageHandler = handler; },
|
|
18
|
+
},
|
|
19
|
+
load: vi.fn(async () => {
|
|
20
|
+
ops.loadCalled++;
|
|
21
|
+
if (onLoadThrow) throw onLoadThrow;
|
|
22
|
+
// Replay the scripted messages on next tick so .connect handler is
|
|
23
|
+
// wired before the first send fires.
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
for (const m of messages) {
|
|
26
|
+
if (ops.messageHandler) ops.messageHandler({ type: "send", payload: m });
|
|
27
|
+
}
|
|
28
|
+
}, 0);
|
|
29
|
+
}),
|
|
30
|
+
unload: vi.fn(async () => { ops.unloadCalled++; }),
|
|
31
|
+
};
|
|
32
|
+
const session = {
|
|
33
|
+
createScript: vi.fn(async () => {
|
|
34
|
+
if (onCreateScriptThrow) throw onCreateScriptThrow;
|
|
35
|
+
return script;
|
|
36
|
+
}),
|
|
37
|
+
detach: vi.fn(async () => { ops.detachCalled++; }),
|
|
38
|
+
};
|
|
39
|
+
const device = {
|
|
40
|
+
attach: vi.fn(async (pkg) => {
|
|
41
|
+
if (onAttachThrow) throw onAttachThrow;
|
|
42
|
+
device._attachedTo = pkg;
|
|
43
|
+
return session;
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
const frida = {
|
|
47
|
+
getDevice: vi.fn(async (id) => {
|
|
48
|
+
device._id = id;
|
|
49
|
+
return device;
|
|
50
|
+
}),
|
|
51
|
+
getUsbDevice: vi.fn(async () => device),
|
|
52
|
+
};
|
|
53
|
+
return { frida, device, session, script, ops };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("FridaKeyProvider — construction", () => {
|
|
57
|
+
it("defaults packageName to com.tencent.mm", () => {
|
|
58
|
+
const p = new FridaKeyProvider({});
|
|
59
|
+
expect(p._packageName).toBe("com.tencent.mm");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("name is frida", () => {
|
|
63
|
+
const p = new FridaKeyProvider({});
|
|
64
|
+
expect(p.name).toBe("frida");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("getKey throws FRIDA_BINDING_MISSING when frida not available", async () => {
|
|
68
|
+
const p = new FridaKeyProvider({});
|
|
69
|
+
try {
|
|
70
|
+
await p.getKey();
|
|
71
|
+
throw new Error("should have thrown");
|
|
72
|
+
} catch (err) {
|
|
73
|
+
expect(err.code).toBe("FRIDA_BINDING_MISSING");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("FridaKeyProvider — happy path", () => {
|
|
79
|
+
it("captures key hex and detaches", async () => {
|
|
80
|
+
const keyHex = "00112233445566778899aabbccddeeff" +
|
|
81
|
+
"ffeeddccbbaa99887766554433221100";
|
|
82
|
+
const { frida, ops } = makeMockFrida({
|
|
83
|
+
messages: [
|
|
84
|
+
{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" },
|
|
85
|
+
{ kind: "key", hex: keyHex.toUpperCase(), source: "sqlite3_key" },
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "/* mock agent */" });
|
|
89
|
+
const k = await p.getKey();
|
|
90
|
+
expect(k).toBe(keyHex); // lowercased
|
|
91
|
+
expect(ops.unloadCalled).toBe(1);
|
|
92
|
+
expect(ops.detachCalled).toBe(1);
|
|
93
|
+
const tel = p.getLastTelemetry();
|
|
94
|
+
expect(tel.keySource).toBe("sqlite3_key");
|
|
95
|
+
expect(tel.hooked).toHaveLength(1);
|
|
96
|
+
expect(tel.durationMs).toBeGreaterThanOrEqual(0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("uses USB device when no deviceId provided", async () => {
|
|
100
|
+
const { frida } = makeMockFrida({
|
|
101
|
+
messages: [{ kind: "key", hex: "aa" + "00".repeat(31), source: "sqlite3_key" }],
|
|
102
|
+
});
|
|
103
|
+
const p = new FridaKeyProvider({ frida, agentLoader: () => "/* mock */" });
|
|
104
|
+
await p.getKey();
|
|
105
|
+
expect(frida.getUsbDevice).toHaveBeenCalled();
|
|
106
|
+
expect(frida.getDevice).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("FridaKeyProvider — error paths", () => {
|
|
111
|
+
it("WECHAT_NOT_RUNNING when attach reports process not found", async () => {
|
|
112
|
+
const { frida } = makeMockFrida({
|
|
113
|
+
onAttachThrow: new Error("unable to find process with name 'com.tencent.mm'"),
|
|
114
|
+
});
|
|
115
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "" });
|
|
116
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "WECHAT_NOT_RUNNING" });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("FRIDA_ATTACH_FAILED on generic attach error", async () => {
|
|
120
|
+
const { frida } = makeMockFrida({
|
|
121
|
+
onAttachThrow: new Error("permission denied"),
|
|
122
|
+
});
|
|
123
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "" });
|
|
124
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "FRIDA_ATTACH_FAILED" });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("FRIDA_ATTACH_FAILED + session cleanup when createScript throws", async () => {
|
|
128
|
+
const { frida, ops } = makeMockFrida({
|
|
129
|
+
onCreateScriptThrow: new Error("syntax error in agent"),
|
|
130
|
+
});
|
|
131
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "BAD" });
|
|
132
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "FRIDA_ATTACH_FAILED" });
|
|
133
|
+
// Even though createScript threw, the session was already attached;
|
|
134
|
+
// implementation cleans it up in the catch path.
|
|
135
|
+
expect(ops.detachCalled).toBe(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("WCDB_KEY_TIMEOUT when no key event in time", async () => {
|
|
139
|
+
const { frida, ops } = makeMockFrida({
|
|
140
|
+
messages: [{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" }],
|
|
141
|
+
});
|
|
142
|
+
const p = new FridaKeyProvider({
|
|
143
|
+
frida,
|
|
144
|
+
deviceId: "Z1",
|
|
145
|
+
timeoutMs: 50,
|
|
146
|
+
agentLoader: () => "",
|
|
147
|
+
});
|
|
148
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "WCDB_KEY_TIMEOUT" });
|
|
149
|
+
expect(ops.unloadCalled).toBe(1);
|
|
150
|
+
expect(ops.detachCalled).toBe(1);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("non-fatal hook errors are recorded but don't reject", async () => {
|
|
154
|
+
const keyHex = "ee" + "00".repeat(31);
|
|
155
|
+
const { frida } = makeMockFrida({
|
|
156
|
+
messages: [
|
|
157
|
+
{ kind: "error", message: "Interceptor.attach failed for WCDBKeyDerive: not found" },
|
|
158
|
+
{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" },
|
|
159
|
+
{ kind: "key", hex: keyHex, source: "sqlite3_key" },
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "" });
|
|
163
|
+
const k = await p.getKey();
|
|
164
|
+
expect(k).toBe(keyHex);
|
|
165
|
+
expect(p.getLastTelemetry().errors).toContain("Interceptor.attach failed for WCDBKeyDerive: not found");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("FridaKeyProvider — logger DI", () => {
|
|
170
|
+
it("logger receives frida-message events", async () => {
|
|
171
|
+
const events = [];
|
|
172
|
+
const { frida } = makeMockFrida({
|
|
173
|
+
messages: [
|
|
174
|
+
{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" },
|
|
175
|
+
{ kind: "key", hex: "ff" + "00".repeat(31), source: "sqlite3_key" },
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
const p = new FridaKeyProvider({
|
|
179
|
+
frida,
|
|
180
|
+
deviceId: "Z1",
|
|
181
|
+
agentLoader: () => "",
|
|
182
|
+
logger: (e) => events.push(e),
|
|
183
|
+
});
|
|
184
|
+
await p.getKey();
|
|
185
|
+
expect(events.some((e) => e.kind === "frida-message" && e.evt.kind === "hooked")).toBe(true);
|
|
186
|
+
expect(events.some((e) => e.kind === "frida-message" && e.evt.kind === "key")).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
WeChatKeyProvider,
|
|
7
|
+
WeChatMD5KeyProvider,
|
|
8
|
+
} = require("../../lib/adapters/wechat");
|
|
9
|
+
|
|
10
|
+
describe("WeChatKeyProvider — base contract", () => {
|
|
11
|
+
it("getKey throws on bare base instance (subclass must override)", async () => {
|
|
12
|
+
const base = new WeChatKeyProvider();
|
|
13
|
+
await expect(base.getKey()).rejects.toThrow(/must be overridden/);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("name defaults to key-provider-base", () => {
|
|
17
|
+
const base = new WeChatKeyProvider();
|
|
18
|
+
expect(base.name).toBe("key-provider-base");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("WeChatMD5KeyProvider — construction validation", () => {
|
|
23
|
+
it("throws if opts missing", () => {
|
|
24
|
+
expect(() => new WeChatMD5KeyProvider()).toThrow(/wechatDataPath/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("throws if wechatDataPath missing", () => {
|
|
28
|
+
expect(() => new WeChatMD5KeyProvider({ uin: "1" })).toThrow(/wechatDataPath/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("name returns md5", () => {
|
|
32
|
+
const p = new WeChatMD5KeyProvider({ wechatDataPath: "/tmp/wx" });
|
|
33
|
+
expect(p.name).toBe("md5");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("WeChatMD5KeyProvider — extractor DI happy path", () => {
|
|
38
|
+
it("getKey returns hex when extractor yields key", async () => {
|
|
39
|
+
const extractor = (opts) => {
|
|
40
|
+
expect(opts.wechatDataPath).toBe("/tmp/wx");
|
|
41
|
+
return {
|
|
42
|
+
uin: "100200300",
|
|
43
|
+
imei: "350123456789012",
|
|
44
|
+
key: "abcdef1",
|
|
45
|
+
source: "test",
|
|
46
|
+
warnings: [],
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const p = new WeChatMD5KeyProvider({
|
|
50
|
+
wechatDataPath: "/tmp/wx",
|
|
51
|
+
extractor,
|
|
52
|
+
});
|
|
53
|
+
const key = await p.getKey();
|
|
54
|
+
expect(key).toBe("abcdef1");
|
|
55
|
+
expect(p.getLastResult().uin).toBe("100200300");
|
|
56
|
+
expect(p.getLastResult().imei).toBe("350123456789012");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("getKey passes uin/imei overrides through to extractor", async () => {
|
|
60
|
+
let passedOpts = null;
|
|
61
|
+
const extractor = (opts) => {
|
|
62
|
+
passedOpts = opts;
|
|
63
|
+
return { key: "0000000", uin: opts.uin, imei: opts.imei, warnings: [] };
|
|
64
|
+
};
|
|
65
|
+
const p = new WeChatMD5KeyProvider({
|
|
66
|
+
wechatDataPath: "/tmp/wx",
|
|
67
|
+
uin: "999",
|
|
68
|
+
imei: "deadbeef",
|
|
69
|
+
extractor,
|
|
70
|
+
});
|
|
71
|
+
await p.getKey();
|
|
72
|
+
expect(passedOpts.uin).toBe("999");
|
|
73
|
+
expect(passedOpts.imei).toBe("deadbeef");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("WeChatMD5KeyProvider — extractor failure surfaces as throw", () => {
|
|
78
|
+
it("throws with warnings when extractor returns no key", async () => {
|
|
79
|
+
const extractor = () => ({
|
|
80
|
+
uin: null,
|
|
81
|
+
imei: null,
|
|
82
|
+
key: null,
|
|
83
|
+
source: "missing",
|
|
84
|
+
warnings: ["UIN not found in shared_prefs", "IMEI not found in CompatibleInfo.cfg"],
|
|
85
|
+
});
|
|
86
|
+
const p = new WeChatMD5KeyProvider({
|
|
87
|
+
wechatDataPath: "/tmp/empty",
|
|
88
|
+
extractor,
|
|
89
|
+
});
|
|
90
|
+
await expect(p.getKey()).rejects.toThrow(/UIN not found/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("throws with generic reason when warnings empty", async () => {
|
|
94
|
+
const extractor = () => ({ key: null, warnings: [] });
|
|
95
|
+
const p = new WeChatMD5KeyProvider({
|
|
96
|
+
wechatDataPath: "/tmp/empty",
|
|
97
|
+
extractor,
|
|
98
|
+
});
|
|
99
|
+
await expect(p.getKey()).rejects.toThrow(/extraction returned empty/);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -250,6 +250,64 @@ describe("RelationsSkill", () => {
|
|
|
250
250
|
expect(r.ranked[0].personId).toBe("p-mom");
|
|
251
251
|
expect(r.ranked[0].totalInteractions).toBe(2);
|
|
252
252
|
});
|
|
253
|
+
|
|
254
|
+
it("empty vault → ranked mode returns empty list, no crash", async () => {
|
|
255
|
+
const skill = new RelationsSkill({ vault: rig.vault });
|
|
256
|
+
const r = await skill.run({});
|
|
257
|
+
expect(r.mode).toBe("ranked");
|
|
258
|
+
expect(r.ranked).toEqual([]);
|
|
259
|
+
expect(r.citations).toEqual([]);
|
|
260
|
+
expect(r.llm_commentary).toBeNull();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("non-local LLM gate: isLocal=false without acceptNonLocal → commentary stays null", async () => {
|
|
264
|
+
makePerson(rig.vault, "p-mom", ["妈"]);
|
|
265
|
+
makePayment(rig.vault, { id: "e1", occurredAt: ts(2026, 5, 1), counterpartyId: "p-mom", counterpartyName: "妈", amount: 100 });
|
|
266
|
+
const nonLocalLlm = {
|
|
267
|
+
isLocal: false,
|
|
268
|
+
chat: async () => ({ text: "this should never reach the caller" }),
|
|
269
|
+
};
|
|
270
|
+
const skill = new RelationsSkill({ vault: rig.vault, llm: nonLocalLlm });
|
|
271
|
+
const r = await skill.run({ personId: "p-mom" });
|
|
272
|
+
expect(r.mode).toBe("single");
|
|
273
|
+
expect(r.profile.totalInteractions).toBe(1);
|
|
274
|
+
// gate enforced by base.callLlmCommentary
|
|
275
|
+
expect(r.llm_commentary).toBeNull();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("LLM exception swallowed → commentary null but profile data intact", async () => {
|
|
279
|
+
makePerson(rig.vault, "p-mom", ["妈"]);
|
|
280
|
+
makePayment(rig.vault, { id: "e1", occurredAt: ts(2026, 5, 1), counterpartyId: "p-mom", counterpartyName: "妈", amount: 100 });
|
|
281
|
+
const throwingLlm = {
|
|
282
|
+
isLocal: true,
|
|
283
|
+
chat: async () => { throw new Error("model timeout"); },
|
|
284
|
+
};
|
|
285
|
+
const skill = new RelationsSkill({ vault: rig.vault, llm: throwingLlm });
|
|
286
|
+
const r = await skill.run({ personId: "p-mom" });
|
|
287
|
+
expect(r.profile.totalInteractions).toBe(1); // data path unaffected
|
|
288
|
+
expect(r.llm_commentary).toBeNull();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("merge-group expansion: vault.getMergeGroupMembers fans the personId out", async () => {
|
|
292
|
+
// Two PersonIds representing the same real-world person across sources;
|
|
293
|
+
// EntityResolver (Phase 8) would normally merge them into a group.
|
|
294
|
+
makePerson(rig.vault, "p-mom-email", ["妈"], { email: ["mom@163.com"] });
|
|
295
|
+
makePerson(rig.vault, "p-mom-alipay", ["陈XX"], { alipay: ["mom@163.com"] });
|
|
296
|
+
makePayment(rig.vault, { id: "e1", occurredAt: ts(2026, 4, 1), counterpartyId: "p-mom-email", counterpartyName: "妈", amount: 200, adapter: "email-imap" });
|
|
297
|
+
makePayment(rig.vault, { id: "e2", occurredAt: ts(2026, 5, 1), counterpartyId: "p-mom-alipay", counterpartyName: "陈XX", amount: 300, adapter: "alipay-bill" });
|
|
298
|
+
|
|
299
|
+
// Stub the resolver hook
|
|
300
|
+
rig.vault.getMergeGroupMembers = (pid) =>
|
|
301
|
+
(pid === "p-mom-email" || pid === "p-mom-alipay")
|
|
302
|
+
? ["p-mom-email", "p-mom-alipay"]
|
|
303
|
+
: [pid];
|
|
304
|
+
|
|
305
|
+
const skill = new RelationsSkill({ vault: rig.vault });
|
|
306
|
+
const r = await skill.run({ personId: "p-mom-email" });
|
|
307
|
+
expect(r.profile.totalInteractions).toBe(2); // both events counted
|
|
308
|
+
expect(r.profile.totalSpend).toBe(500);
|
|
309
|
+
expect(Object.keys(r.profile.byAdapter).sort()).toEqual(["alipay-bill", "email-imap"]);
|
|
310
|
+
});
|
|
253
311
|
});
|
|
254
312
|
|
|
255
313
|
// ─── FootprintSkill ──────────────────────────────────────────────────────
|
|
@@ -301,6 +359,55 @@ describe("FootprintSkill", () => {
|
|
|
301
359
|
expect(r.summary.totalTrips).toBe(0);
|
|
302
360
|
expect(r.topPlaces).toEqual([]);
|
|
303
361
|
});
|
|
362
|
+
|
|
363
|
+
it("local LLM commentary fires when trips present", async () => {
|
|
364
|
+
rig.vault.putEvent({
|
|
365
|
+
id: "trip-1", type: "event", subtype: "trip",
|
|
366
|
+
occurredAt: ts(2026, 4, 1),
|
|
367
|
+
actor: "person-self",
|
|
368
|
+
content: { title: "Hangzhou trip" },
|
|
369
|
+
ingestedAt: Date.now(),
|
|
370
|
+
source: defaultSource("travel"),
|
|
371
|
+
extra: { to: "Hangzhou" },
|
|
372
|
+
});
|
|
373
|
+
const llm = { isLocal: true, chat: async () => ({ text: "你这个月去过 1 个地方。" }) };
|
|
374
|
+
const skill = new FootprintSkill({ vault: rig.vault, llm });
|
|
375
|
+
const r = await skill.run({});
|
|
376
|
+
expect(r.llm_commentary).toBe("你这个月去过 1 个地方。");
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("non-local LLM gate → llm_commentary null", async () => {
|
|
380
|
+
rig.vault.putEvent({
|
|
381
|
+
id: "trip-1", type: "event", subtype: "trip",
|
|
382
|
+
occurredAt: ts(2026, 4, 1),
|
|
383
|
+
actor: "person-self",
|
|
384
|
+
content: { title: "Beijing" },
|
|
385
|
+
ingestedAt: Date.now(),
|
|
386
|
+
source: defaultSource("travel"),
|
|
387
|
+
extra: { to: "Beijing" },
|
|
388
|
+
});
|
|
389
|
+
const llm = { isLocal: false, chat: async () => ({ text: "should not appear" }) };
|
|
390
|
+
const skill = new FootprintSkill({ vault: rig.vault, llm });
|
|
391
|
+
const r = await skill.run({});
|
|
392
|
+
expect(r.llm_commentary).toBeNull();
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("LLM exception swallowed → commentary null but data intact", async () => {
|
|
396
|
+
rig.vault.putEvent({
|
|
397
|
+
id: "trip-1", type: "event", subtype: "trip",
|
|
398
|
+
occurredAt: ts(2026, 4, 1),
|
|
399
|
+
actor: "person-self",
|
|
400
|
+
content: { title: "Tokyo" },
|
|
401
|
+
ingestedAt: Date.now(),
|
|
402
|
+
source: defaultSource("travel"),
|
|
403
|
+
extra: { to: "Tokyo" },
|
|
404
|
+
});
|
|
405
|
+
const llm = { isLocal: true, chat: async () => { throw new Error("net down"); } };
|
|
406
|
+
const skill = new FootprintSkill({ vault: rig.vault, llm });
|
|
407
|
+
const r = await skill.run({});
|
|
408
|
+
expect(r.summary.totalTrips).toBe(1);
|
|
409
|
+
expect(r.llm_commentary).toBeNull();
|
|
410
|
+
});
|
|
304
411
|
});
|
|
305
412
|
|
|
306
413
|
// ─── InterestsSkill ──────────────────────────────────────────────────────
|
|
@@ -349,6 +456,46 @@ describe("InterestsSkill", () => {
|
|
|
349
456
|
expect(r.llmInterests).toHaveLength(1);
|
|
350
457
|
expect(r.llmInterests[0].category).toBe("摄影");
|
|
351
458
|
});
|
|
459
|
+
|
|
460
|
+
it("empty vault → topTopics + topItems empty, no crash", async () => {
|
|
461
|
+
const skill = new InterestsSkill({ vault: rig.vault });
|
|
462
|
+
const r = await skill.run({});
|
|
463
|
+
expect(r.topTopics).toEqual([]);
|
|
464
|
+
expect(r.topItems).toEqual([]);
|
|
465
|
+
expect(r.llmInterests).toBeNull();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("non-local LLM gate → llmInterests null even with topics present", async () => {
|
|
469
|
+
rig.vault.putTopic({
|
|
470
|
+
id: "topic-b", type: "topic", name: "Cooking",
|
|
471
|
+
derivedFromEvents: ["e-1"],
|
|
472
|
+
ingestedAt: Date.now(), source: defaultSource("test"),
|
|
473
|
+
});
|
|
474
|
+
const llm = {
|
|
475
|
+
isLocal: false,
|
|
476
|
+
chat: async () => ({ text: '[{"category":"烹饪","evidenceCount":1,"examples":["Cooking"]}]' }),
|
|
477
|
+
};
|
|
478
|
+
const skill = new InterestsSkill({ vault: rig.vault, llm });
|
|
479
|
+
const r = await skill.run({});
|
|
480
|
+
expect(r.topTopics[0].name).toBe("Cooking");
|
|
481
|
+
expect(r.llmInterests).toBeNull();
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it("LLM clustering exception swallowed → llmInterests null but data intact", async () => {
|
|
485
|
+
rig.vault.putTopic({
|
|
486
|
+
id: "topic-c", type: "topic", name: "Travel",
|
|
487
|
+
derivedFromEvents: ["e-1", "e-2"],
|
|
488
|
+
ingestedAt: Date.now(), source: defaultSource("test"),
|
|
489
|
+
});
|
|
490
|
+
const llm = {
|
|
491
|
+
isLocal: true,
|
|
492
|
+
chat: async () => { throw new Error("vllm 500"); },
|
|
493
|
+
};
|
|
494
|
+
const skill = new InterestsSkill({ vault: rig.vault, llm });
|
|
495
|
+
const r = await skill.run({});
|
|
496
|
+
expect(r.topTopics[0].name).toBe("Travel");
|
|
497
|
+
expect(r.llmInterests).toBeNull();
|
|
498
|
+
});
|
|
352
499
|
});
|
|
353
500
|
|
|
354
501
|
// ─── TimelineSkill ──────────────────────────────────────────────────────
|