@@ -198,31 +198,16 @@ const recordInboundSession = vi.hoisted(() =>
198198 vi . fn < ( params ?: unknown ) => Promise < void > > ( async ( ) => { } ) ,
199199) ;
200200const configSessionsMocks = vi . hoisted ( ( ) => ( {
201- loadSessionStore : vi . fn < ( storePath : string , opts ?: unknown ) => Record < string , unknown > > (
202- ( ) => ( { } ) ,
203- ) ,
201+ getSessionEntry : vi . fn < ( params ?: unknown ) => unknown > ( ( ) => undefined ) ,
202+ readSessionTranscriptEvents : vi . fn < ( params ?: unknown ) => Promise < unknown [ ] > > ( async ( ) => [ ] ) ,
204203 readSessionUpdatedAt : vi . fn < ( params ?: unknown ) => number | undefined > ( ( ) => undefined ) ,
205- readLatestAssistantTextFromSessionTranscript : vi . fn <
206- ( sessionFile : string ) => Promise < { text : string ; timestamp ?: number } | undefined >
207- > ( async ( ) => undefined ) ,
208- resolveAndPersistSessionFile : vi . fn < ( params ?: unknown ) => Promise < { sessionFile : string } > > (
209- async ( ) => ( { sessionFile : "/tmp/openclaw-discord-process-test-session.jsonl" } ) ,
210- ) ,
211- resolveSessionStoreEntry : vi . fn <
212- ( params : { store : Record < string , unknown > ; sessionKey ?: string } ) => { existing ?: unknown }
213- > ( ( params ) => ( {
214- existing : params . sessionKey ? params . store [ params . sessionKey ] : undefined ,
215- } ) ) ,
216204 resolveStorePath : vi . fn < ( path ?: unknown , opts ?: unknown ) => string > (
217205 ( ) => "/tmp/openclaw-discord-process-test-sessions.json" ,
218206 ) ,
219207} ) ) ;
220- const loadSessionStore = configSessionsMocks . loadSessionStore ;
208+ const getSessionEntry = configSessionsMocks . getSessionEntry ;
209+ const readSessionTranscriptEvents = configSessionsMocks . readSessionTranscriptEvents ;
221210const readSessionUpdatedAt = configSessionsMocks . readSessionUpdatedAt ;
222- const readLatestAssistantTextFromSessionTranscript =
223- configSessionsMocks . readLatestAssistantTextFromSessionTranscript ;
224- const resolveAndPersistSessionFile = configSessionsMocks . resolveAndPersistSessionFile ;
225- const resolveSessionStoreEntry = configSessionsMocks . resolveSessionStoreEntry ;
226211const resolveStorePath = configSessionsMocks . resolveStorePath ;
227212const createDiscordRestClientSpy = vi . hoisted ( ( ) =>
228213 vi . fn <
@@ -394,19 +379,17 @@ vi.mock("openclaw/plugin-sdk/conversation-runtime", () => ({
394379} ) ) ;
395380
396381vi . mock ( "openclaw/plugin-sdk/session-store-runtime" , ( ) => ( {
397- loadSessionStore : ( storePath : string , opts ?: unknown ) =>
398- configSessionsMocks . loadSessionStore ( storePath , opts ) ,
382+ getSessionEntry : ( params ?: unknown ) => configSessionsMocks . getSessionEntry ( params ) ,
399383 readSessionUpdatedAt : ( params ?: unknown ) => configSessionsMocks . readSessionUpdatedAt ( params ) ,
400- readLatestAssistantTextFromSessionTranscript : ( sessionFile : string ) =>
401- configSessionsMocks . readLatestAssistantTextFromSessionTranscript ( sessionFile ) ,
402- resolveAndPersistSessionFile : ( params ?: unknown ) =>
403- configSessionsMocks . resolveAndPersistSessionFile ( params ) ,
404- resolveSessionStoreEntry : ( params : { store : Record < string , unknown > ; sessionKey ?: string } ) =>
405- configSessionsMocks . resolveSessionStoreEntry ( params ) ,
406384 resolveStorePath : ( path ?: unknown , opts ?: unknown ) =>
407385 configSessionsMocks . resolveStorePath ( path , opts ) ,
408386} ) ) ;
409387
388+ vi . mock ( "openclaw/plugin-sdk/session-transcript-runtime" , ( ) => ( {
389+ readSessionTranscriptEvents : ( params ?: unknown ) =>
390+ configSessionsMocks . readSessionTranscriptEvents ( params ) ,
391+ } ) ) ;
392+
410393vi . mock ( "../client.js" , ( ) => ( {
411394 createDiscordRuntimeAccountContext : ( params : { cfg : unknown ; accountId : string } ) => ( {
412395 cfg : params . cfg ,
@@ -499,24 +482,16 @@ beforeEach(() => {
499482 createDiscordDraftStream . mockClear ( ) ;
500483 dispatchInboundMessage . mockClear ( ) ;
501484 recordInboundSession . mockClear ( ) ;
502- loadSessionStore . mockClear ( ) ;
503485 readSessionUpdatedAt . mockClear ( ) ;
504- readLatestAssistantTextFromSessionTranscript . mockClear ( ) ;
505- resolveAndPersistSessionFile . mockClear ( ) ;
506- resolveSessionStoreEntry . mockClear ( ) ;
486+ getSessionEntry . mockClear ( ) ;
487+ readSessionTranscriptEvents . mockClear ( ) ;
507488 resolveStorePath . mockClear ( ) ;
508489 createDiscordRestClientSpy . mockClear ( ) ;
509490 dispatchInboundMessage . mockResolvedValue ( createNoQueuedDispatchResult ( ) ) ;
510491 recordInboundSession . mockResolvedValue ( undefined ) ;
511- loadSessionStore . mockReturnValue ( { } ) ;
512492 readSessionUpdatedAt . mockReturnValue ( undefined ) ;
513- readLatestAssistantTextFromSessionTranscript . mockResolvedValue ( undefined ) ;
514- resolveAndPersistSessionFile . mockResolvedValue ( {
515- sessionFile : "/tmp/openclaw-discord-process-test-session.jsonl" ,
516- } ) ;
517- resolveSessionStoreEntry . mockImplementation ( ( params ) => ( {
518- existing : params . sessionKey ? params . store [ params . sessionKey ] : undefined ,
519- } ) ) ;
493+ getSessionEntry . mockReturnValue ( undefined ) ;
494+ readSessionTranscriptEvents . mockResolvedValue ( [ ] ) ;
520495 resolveStorePath . mockReturnValue ( "/tmp/openclaw-discord-process-test-sessions.json" ) ;
521496 threadBindingTesting . resetThreadBindingsForTests ( ) ;
522497} ) ;
@@ -2202,13 +2177,16 @@ describe("processDiscordMessage draft streaming", () => {
22022177 ( _value , index ) => `continuation${ index } ` ,
22032178 ) . join ( " " ) } `;
22042179
2205- loadSessionStore . mockReturnValue ( {
2206- "agent:main:discord:channel:c1" : { sessionId : "session-1" } ,
2207- } ) ;
2208- readLatestAssistantTextFromSessionTranscript . mockResolvedValue ( {
2209- text : fullAnswer ,
2210- timestamp : Date . now ( ) + 60_000 ,
2211- } ) ;
2180+ getSessionEntry . mockReturnValue ( { sessionId : "session-1" } ) ;
2181+ readSessionTranscriptEvents . mockResolvedValue ( [
2182+ {
2183+ message : {
2184+ role : "assistant" ,
2185+ content : [ { type : "text" , text : fullAnswer } ] ,
2186+ timestamp : Date . now ( ) + 60_000 ,
2187+ } ,
2188+ } ,
2189+ ] ) ;
22122190 dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
22132191 await params ?. replyOptions ?. onToolStart ?.( { name : "exec" , phase : "start" } ) ;
22142192 await params ?. replyOptions ?. onItemEvent ?.( { progressText : "exec done" } ) ;
0 commit comments