


























@@ -1,16 +1,27 @@
11import fs from "node:fs/promises";
22import path from "node:path";
3+import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
4+import { normalizeMainKey } from "openclaw/plugin-sdk/routing";
35import { saveSessionStore } from "openclaw/plugin-sdk/session-store-runtime";
46import { withTempDir } from "openclaw/plugin-sdk/test-env";
57import { describe, expect, it, vi } from "vitest";
68import type { WhatsAppSendResult } from "../inbound/send-result.js";
9+import {
10+evaluateSessionFreshness,
11+loadSessionStore,
12+resolveChannelResetConfig,
13+resolveSessionKey,
14+resolveSessionResetPolicy,
15+resolveSessionResetType,
16+resolveStorePath,
17+resolveThreadFlag,
18+} from "./config.runtime.js";
719import {
820debugMention,
921isBotMentionedFromTargets,
1022resolveMentionTargets,
1123resolveOwnerList,
1224} from "./mentions.js";
13-import { getSessionSnapshot } from "./session-snapshot.js";
1425import type { WebInboundMsg } from "./types.js";
1526import { elide, isLikelyWhatsAppCryptoError } from "./util.js";
1627@@ -40,6 +51,60 @@ const makeMsg = (overrides: Partial<WebInboundMsg>): WebInboundMsg =>
4051 ...overrides,
4152}) as WebInboundMsg;
425354+function getSessionSnapshotForTest(
55+cfg: OpenClawConfig,
56+from: string,
57+ctx?: {
58+sessionKey?: string | null;
59+isGroup?: boolean;
60+messageThreadId?: string | number | null;
61+threadLabel?: string | null;
62+threadStarterBody?: string | null;
63+parentSessionKey?: string | null;
64+},
65+) {
66+const sessionCfg = cfg.session;
67+const scope = sessionCfg?.scope ?? "per-sender";
68+const key =
69+ctx?.sessionKey?.trim() ??
70+resolveSessionKey(
71+scope,
72+{ From: from, To: "", Body: "" },
73+normalizeMainKey(sessionCfg?.mainKey),
74+);
75+const store = loadSessionStore(resolveStorePath(sessionCfg?.store));
76+const entry = store[key];
77+const isThread = resolveThreadFlag({
78+sessionKey: key,
79+messageThreadId: ctx?.messageThreadId ?? null,
80+threadLabel: ctx?.threadLabel ?? null,
81+threadStarterBody: ctx?.threadStarterBody ?? null,
82+parentSessionKey: ctx?.parentSessionKey ?? null,
83+});
84+const resetType = resolveSessionResetType({ sessionKey: key, isGroup: ctx?.isGroup, isThread });
85+const resetPolicy = resolveSessionResetPolicy({
86+ sessionCfg,
87+ resetType,
88+resetOverride: resolveChannelResetConfig({
89+ sessionCfg,
90+channel: entry?.lastChannel ?? entry?.channel,
91+}),
92+});
93+const freshness = entry
94+ ? evaluateSessionFreshness({ updatedAt: entry.updatedAt, now: Date.now(), policy: resetPolicy })
95+ : { fresh: false };
96+97+return {
98+ key,
99+ entry,
100+fresh: freshness.fresh,
101+ resetPolicy,
102+ resetType,
103+dailyResetAt: freshness.dailyResetAt,
104+idleExpiresAt: freshness.idleExpiresAt,
105+};
106+}
107+43108describe("isBotMentionedFromTargets", () => {
44109const mentionCfg = { mentionRegexes: [/\bopenclaw\b/i] };
45110@@ -215,9 +280,9 @@ describe("getSessionSnapshot", () => {
215280whatsapp: { mode: "idle", idleMinutes: 360 },
216281},
217282},
218-} as Parameters<typeof getSessionSnapshot>[0];
283+} as OpenClawConfig;
219284220-const snapshot = getSessionSnapshot(cfg, "whatsapp:+15550001111", true, {
285+const snapshot = getSessionSnapshotForTest(cfg, "whatsapp:+15550001111", {
221286 sessionKey,
222287});
223288此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。