@@ -3,8 +3,9 @@ import os from "node:os";
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
55import { resetTopicNameCacheForTest } from "./topic-name-cache.js" ;
6- const { recordInboundSessionMock } = vi . hoisted ( ( ) => ( {
6+ const { recordInboundSessionMock, resolveStorePathMock } = vi . hoisted ( ( ) => ( {
77 recordInboundSessionMock : vi . fn ( ) . mockResolvedValue ( undefined ) ,
8+ resolveStorePathMock : vi . fn ( ( ) => "/tmp/openclaw-session-store.json" ) ,
89} ) ) ;
910
1011vi . mock ( "./bot-message-context.session.runtime.js" , async ( ) => {
@@ -14,6 +15,7 @@ vi.mock("./bot-message-context.session.runtime.js", async () => {
1415 return {
1516 ...actual ,
1617 recordInboundSession : ( ...args : unknown [ ] ) => recordInboundSessionMock ( ...args ) ,
18+ resolveStorePath : ( ...args : unknown [ ] ) => resolveStorePathMock ( ...args ) ,
1719 } ;
1820} ) ;
1921
@@ -45,6 +47,8 @@ afterEach(() => {
4547 clearRuntimeConfigSnapshot ( ) ;
4648 resetTopicNameCacheForTest ( ) ;
4749 recordInboundSessionMock . mockClear ( ) ;
50+ resolveStorePathMock . mockReset ( ) ;
51+ resolveStorePathMock . mockReturnValue ( "/tmp/openclaw-session-store.json" ) ;
4852} ) ;
4953
5054describe ( "buildTelegramMessageContext dm thread sessions" , ( ) => {
@@ -236,6 +240,54 @@ describe("buildTelegramMessageContext group sessions without forum", () => {
236240 resetTopicNameCacheForTest ( ) ;
237241 }
238242 } ) ;
243+
244+ it ( "persists topic names through the default session runtime path" , async ( ) => {
245+ const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-telegram-topic-name-" ) ) ;
246+ const sessionStorePath = path . join ( tempDir , "sessions.json" ) ;
247+ resolveStorePathMock . mockReturnValue ( sessionStorePath ) ;
248+
249+ try {
250+ await buildTelegramMessageContextForTest ( {
251+ message : {
252+ message_id : 6 ,
253+ chat : { id : - 1001234567890 , type : "supergroup" , title : "Test Forum" , is_forum : true } ,
254+ date : 1700000005 ,
255+ text : "@bot hello" ,
256+ message_thread_id : 99 ,
257+ from : { id : 42 , first_name : "Alice" } ,
258+ reply_to_message : {
259+ message_id : 5 ,
260+ forum_topic_created : { name : "Deployments" , icon_color : 0x6fb9f0 } ,
261+ } ,
262+ } ,
263+ options : { forceWasMentioned : true } ,
264+ resolveGroupActivation : ( ) => true ,
265+ sessionRuntime : null ,
266+ } ) ;
267+
268+ resetTopicNameCacheForTest ( ) ;
269+
270+ const ctx = await buildTelegramMessageContextForTest ( {
271+ message : {
272+ message_id : 7 ,
273+ chat : { id : - 1001234567890 , type : "supergroup" , title : "Test Forum" , is_forum : true } ,
274+ date : 1700000006 ,
275+ text : "@bot again" ,
276+ message_thread_id : 99 ,
277+ from : { id : 42 , first_name : "Alice" } ,
278+ } ,
279+ options : { forceWasMentioned : true } ,
280+ resolveGroupActivation : ( ) => true ,
281+ sessionRuntime : null ,
282+ } ) ;
283+
284+ expect ( ctx ) . not . toBeNull ( ) ;
285+ expect ( ctx ?. ctxPayload ?. TopicName ) . toBe ( "Deployments" ) ;
286+ } finally {
287+ await fs . rm ( tempDir , { recursive : true , force : true } ) ;
288+ resetTopicNameCacheForTest ( ) ;
289+ }
290+ } ) ;
239291} ) ;
240292
241293describe ( "buildTelegramMessageContext direct peer routing" , ( ) => {
0 commit comments