@@ -33,9 +33,14 @@ import { withOpenClawTestState } from "../../test-utils/openclaw-test-state.js";
3333import { invalidateOperatorRolePolicy } from "../operator-role-policy.js" ;
3434import { bumpSessionAutomationVersion } from "../session-automation-index.js" ;
3535import { persistGatewaySessionLifecycleEvent } from "../session-lifecycle-state.js" ;
36- import type { GatewaySessionRow } from "../session-utils.types.js" ;
3736import type { WorkerSessionPlacementRecord } from "../worker-environments/placement-store.js" ;
38- import type { GatewayClient , GatewayRequestContext , RespondFn } from "./types.js" ;
37+ import {
38+ identifiedClient ,
39+ listSessions ,
40+ requestContext ,
41+ sessionReadHandlers ,
42+ } from "./sessions-read-cache.test-support.js" ;
43+ import type { GatewayRequestContext } from "./types.js" ;
3944
4045const loader = vi . hoisted ( ( ) => ( {
4146 calls : vi . fn ( ) ,
@@ -68,60 +73,9 @@ vi.mock("../session-utils.js", async (importOriginal) => {
6873 } ;
6974} ) ;
7075
71- const { sessionReadHandlers } = await import ( "./sessions-read.js" ) ;
7276const { emitSessionsChanged } = await import ( "./session-change-event.js" ) ;
7377const { emitSessionTranscriptUpdate } = await import ( "../../sessions/transcript-events.js" ) ;
7478
75- function identifiedClient ( profileId : string ) : GatewayClient {
76- return {
77- connect : {
78- minProtocol : 1 ,
79- maxProtocol : 1 ,
80- client : { id : "openclaw-control-ui" , version : "test" , platform : "test" , mode : "webchat" } ,
81- role : "operator" ,
82- scopes : [ "operator.read" , "operator.write" ] ,
83- } ,
84- authenticatedUserProfile : {
85- profileId,
86- displayName : profileId ,
87- hasAvatar : false ,
88- updatedAt : 1 ,
89- } ,
90- } ;
91- }
92-
93- function requestContext ( config : OpenClawConfig ) : GatewayRequestContext {
94- return {
95- chatAbortControllers : new Map ( ) ,
96- getRuntimeConfig : ( ) => config ,
97- getSessionEventSubscriberConnIds : ( ) => new Set ( ) ,
98- loadGatewayModelCatalog : async ( ) => [ ] ,
99- logGateway : { debug : vi . fn ( ) } ,
100- } as unknown as GatewayRequestContext ;
101- }
102-
103- async function listSessions ( params : {
104- client : GatewayClient ;
105- context : GatewayRequestContext ;
106- request : SessionsListParams ;
107- } ) {
108- const responses : Parameters < RespondFn > [ ] = [ ] ;
109- await sessionReadHandlers [ "sessions.list" ] ?.( {
110- params : params . request ,
111- client : params . client ,
112- context : params . context ,
113- respond : ( ...response : Parameters < RespondFn > ) => responses . push ( response ) ,
114- } as never ) ;
115- expect ( responses ) . toHaveLength ( 1 ) ;
116- expect ( responses [ 0 ] ?. [ 0 ] ) . toBe ( true ) ;
117- return responses [ 0 ] ?. [ 1 ] as {
118- count : number ;
119- nextOffset : number | null ;
120- sessions : GatewaySessionRow [ ] ;
121- totalCount : number ;
122- } ;
123- }
124-
12579async function seedSessions ( ) : Promise < OpenClawConfig > {
12680 const config : OpenClawConfig = {
12781 agents : { list : [ { id : "main" , default : true } , { id : "work" } ] } ,
0 commit comments