


























@@ -204,31 +204,18 @@ const recordInboundSession = vi.hoisted(() =>
204204vi.fn<(params?: unknown) => Promise<void>>(async () => {}),
205205);
206206const configSessionsMocks = vi.hoisted(() => ({
207-loadSessionStore: vi.fn<(storePath: string, opts?: unknown) => Record<string, unknown>>(
208-() => ({}),
209-),
210-readSessionUpdatedAt: vi.fn<(params?: unknown) => number | undefined>(() => undefined),
211-readLatestAssistantTextFromSessionTranscript: vi.fn<
212-(sessionFile: string) => Promise<{ text: string; timestamp?: number } | undefined>
207+getSessionEntry: vi.fn<(params?: unknown) => unknown>(() => undefined),
208+readLatestAssistantTextByIdentity: vi.fn<
209+(params?: unknown) => Promise<{ text: string; timestamp?: number } | undefined>
213210>(async () => undefined),
214-resolveAndPersistSessionFile: vi.fn<(params?: unknown) => Promise<{ sessionFile: string }>>(
215-async () => ({ sessionFile: "/tmp/openclaw-discord-process-test-session.jsonl" }),
216-),
217-resolveSessionStoreEntry: vi.fn<
218-(params: { store: Record<string, unknown>; sessionKey?: string }) => { existing?: unknown }
219->((params) => ({
220-existing: params.sessionKey ? params.store[params.sessionKey] : undefined,
221-})),
211+readSessionUpdatedAt: vi.fn<(params?: unknown) => number | undefined>(() => undefined),
222212resolveStorePath: vi.fn<(path?: unknown, opts?: unknown) => string>(
223213() => "/tmp/openclaw-discord-process-test-sessions.json",
224214),
225215}));
226-const loadSessionStore = configSessionsMocks.loadSessionStore;
216+const getSessionEntry = configSessionsMocks.getSessionEntry;
217+const readLatestAssistantTextByIdentity = configSessionsMocks.readLatestAssistantTextByIdentity;
227218const readSessionUpdatedAt = configSessionsMocks.readSessionUpdatedAt;
228-const readLatestAssistantTextFromSessionTranscript =
229-configSessionsMocks.readLatestAssistantTextFromSessionTranscript;
230-const resolveAndPersistSessionFile = configSessionsMocks.resolveAndPersistSessionFile;
231-const resolveSessionStoreEntry = configSessionsMocks.resolveSessionStoreEntry;
232219const resolveStorePath = configSessionsMocks.resolveStorePath;
233220const createDiscordRestClientSpy = vi.hoisted(() =>
234221vi.fn<
@@ -400,19 +387,17 @@ vi.mock("openclaw/plugin-sdk/conversation-runtime", () => ({
400387}));
401388402389vi.mock("openclaw/plugin-sdk/session-store-runtime", () => ({
403-loadSessionStore: (storePath: string, opts?: unknown) =>
404-configSessionsMocks.loadSessionStore(storePath, opts),
390+getSessionEntry: (params?: unknown) => configSessionsMocks.getSessionEntry(params),
405391readSessionUpdatedAt: (params?: unknown) => configSessionsMocks.readSessionUpdatedAt(params),
406-readLatestAssistantTextFromSessionTranscript: (sessionFile: string) =>
407-configSessionsMocks.readLatestAssistantTextFromSessionTranscript(sessionFile),
408-resolveAndPersistSessionFile: (params?: unknown) =>
409-configSessionsMocks.resolveAndPersistSessionFile(params),
410-resolveSessionStoreEntry: (params: { store: Record<string, unknown>; sessionKey?: string }) =>
411-configSessionsMocks.resolveSessionStoreEntry(params),
412392resolveStorePath: (path?: unknown, opts?: unknown) =>
413393configSessionsMocks.resolveStorePath(path, opts),
414394}));
415395396+vi.mock("openclaw/plugin-sdk/session-transcript-runtime", () => ({
397+readLatestAssistantTextByIdentity: (params?: unknown) =>
398+configSessionsMocks.readLatestAssistantTextByIdentity(params),
399+}));
400+416401vi.mock("../client.js", () => ({
417402createDiscordRuntimeAccountContext: (params: { cfg: unknown; accountId: string }) => ({
418403cfg: params.cfg,
@@ -505,24 +490,16 @@ beforeEach(() => {
505490createDiscordDraftStream.mockClear();
506491dispatchInboundMessage.mockClear();
507492recordInboundSession.mockClear();
508-loadSessionStore.mockClear();
509493readSessionUpdatedAt.mockClear();
510-readLatestAssistantTextFromSessionTranscript.mockClear();
511-resolveAndPersistSessionFile.mockClear();
512-resolveSessionStoreEntry.mockClear();
494+getSessionEntry.mockClear();
495+readLatestAssistantTextByIdentity.mockClear();
513496resolveStorePath.mockClear();
514497createDiscordRestClientSpy.mockClear();
515498dispatchInboundMessage.mockResolvedValue(createNoQueuedDispatchResult());
516499recordInboundSession.mockResolvedValue(undefined);
517-loadSessionStore.mockReturnValue({});
518500readSessionUpdatedAt.mockReturnValue(undefined);
519-readLatestAssistantTextFromSessionTranscript.mockResolvedValue(undefined);
520-resolveAndPersistSessionFile.mockResolvedValue({
521-sessionFile: "/tmp/openclaw-discord-process-test-session.jsonl",
522-});
523-resolveSessionStoreEntry.mockImplementation((params) => ({
524-existing: params.sessionKey ? params.store[params.sessionKey] : undefined,
525-}));
501+getSessionEntry.mockReturnValue(undefined);
502+readLatestAssistantTextByIdentity.mockResolvedValue(undefined);
526503resolveStorePath.mockReturnValue("/tmp/openclaw-discord-process-test-sessions.json");
527504threadBindingTesting.resetThreadBindingsForTests();
528505});
@@ -2272,10 +2249,8 @@ describe("processDiscordMessage draft streaming", () => {
22722249 (_value, index) => `continuation${index}`,
22732250 ).join(" ")}`;
227422512275-loadSessionStore.mockReturnValue({
2276-"agent:main:discord:channel:c1": { sessionId: "session-1" },
2277-});
2278-readLatestAssistantTextFromSessionTranscript.mockResolvedValue({
2252+getSessionEntry.mockReturnValue({ sessionId: "session-1" });
2253+readLatestAssistantTextByIdentity.mockResolvedValue({
22792254text: fullAnswer,
22802255timestamp: Date.now() + 60_000,
22812256});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。