@@ -10,7 +10,7 @@ type TestPluginRegistry = Omit<PluginRegistry, "sessionCatalogs"> & {
1010type TestClient = {
1111 connect : { scopes : string [ ] } ;
1212 connId ?: string ;
13- authenticatedUserProfile : { profileId : string } ;
13+ authenticatedUserProfile ? : { profileId : string } ;
1414} ;
1515
1616const hoisted = vi . hoisted ( ( ) => ( {
@@ -42,6 +42,10 @@ function client(profileId: string, scopes = ["operator.read", "operator.write"])
4242 return { connect : { scopes } , authenticatedUserProfile : { profileId } } ;
4343}
4444
45+ function unprofiledClient ( scopes = [ "operator.read" , "operator.write" ] ) : TestClient {
46+ return { connect : { scopes } } ;
47+ }
48+
4549function session ( threadId : string , sessionKey ?: string ) {
4650 return {
4751 threadId,
@@ -197,6 +201,57 @@ describe("session catalog caller visibility", () => {
197201 expect ( archive ) . not . toHaveBeenCalled ( ) ;
198202 } ) ;
199203
204+ it ( "hides every row from an unprofiled multi-identity caller" , async ( ) => {
205+ hoisted . hasMultipleSessionSharingIdentities . mockReturnValue ( true ) ;
206+ const listedHost = host ( [ session ( "unadopted-thread" ) ] ) ;
207+ hoisted . activeRegistry . sessionCatalogs = [
208+ { provider : provider ( { list : vi . fn ( async ( ) => [ listedHost ] ) } ) } ,
209+ ] ;
210+
211+ const listed = await call ( "sessions.catalog.list" , { } , unprofiledClient ( ) ) ;
212+
213+ expect ( listed ) . toHaveBeenCalledWith ( true , {
214+ catalogs : [
215+ expect . objectContaining ( {
216+ hosts : [ expect . objectContaining ( { sessions : [ ] } ) ] ,
217+ } ) ,
218+ ] ,
219+ } ) ;
220+ } ) ;
221+
222+ it ( "rejects reads for an unprofiled multi-identity caller" , async ( ) => {
223+ hoisted . hasMultipleSessionSharingIdentities . mockReturnValue ( true ) ;
224+ const read = vi . fn ( async ( ) => ( {
225+ hostId : "gateway:local" ,
226+ threadId : "unadopted-thread" ,
227+ items : [ { type : "userMessage" as const , text : "private host history" } ] ,
228+ } ) ) ;
229+ hoisted . activeRegistry . sessionCatalogs = [
230+ {
231+ provider : provider ( {
232+ list : vi . fn ( async ( ) => [ host ( [ session ( "unadopted-thread" ) ] ) ] ) ,
233+ read,
234+ } ) ,
235+ } ,
236+ ] ;
237+
238+ const transcript = await call (
239+ "sessions.catalog.read" ,
240+ { catalogId : "codex" , hostId : "gateway:local" , threadId : "unadopted-thread" } ,
241+ unprofiledClient ( ) ,
242+ ) ;
243+
244+ expect ( transcript ) . toHaveBeenCalledWith (
245+ false ,
246+ undefined ,
247+ expect . objectContaining ( {
248+ code : ErrorCodes . FORBIDDEN ,
249+ message : "session catalog thread is not visible to this caller" ,
250+ } ) ,
251+ ) ;
252+ expect ( read ) . not . toHaveBeenCalled ( ) ;
253+ } ) ;
254+
200255 it . each ( [
201256 { label : "admin" , multiple : true , scopes : [ "operator.admin" ] } ,
202257 { label : "solo Gateway" , multiple : false , scopes : [ "operator.read" ] } ,
@@ -314,20 +369,23 @@ describe("session catalog caller visibility", () => {
314369 host ( [
315370 session ( "alpha-thread" , "agent:main:alpha" ) ,
316371 session ( "beta-thread" , "agent:main:beta" ) ,
372+ session ( "unadopted-thread" ) ,
317373 ] ) ,
318374 ] ) ;
319375 hoisted . activeRegistry . sessionCatalogs = [ { provider : provider ( { list } ) } ] ;
320376 const config = { } ;
321377
322378 const alpha = await call ( "sessions.catalog.list" , { } , client ( "profile-alpha" ) , config ) ;
379+ const unprofiled = await call ( "sessions.catalog.list" , { } , unprofiledClient ( ) , config ) ;
323380 const beta = await call ( "sessions.catalog.list" , { } , client ( "profile-beta" ) , config ) ;
324381 const rows = ( respond : ReturnType < typeof vi . fn > ) =>
325382 respond . mock . calls [ 0 ] ?. [ 1 ] ?. catalogs [ 0 ] ?. hosts [ 0 ] ?. sessions . map (
326383 ( item : { threadId : string } ) => item . threadId ,
327384 ) ;
328385
329386 expect ( rows ( alpha ) ) . toEqual ( [ "alpha-thread" ] ) ;
387+ expect ( rows ( unprofiled ) ) . toEqual ( [ ] ) ;
330388 expect ( rows ( beta ) ) . toEqual ( [ "beta-thread" ] ) ;
331- expect ( list ) . toHaveBeenCalledTimes ( 2 ) ;
389+ expect ( list ) . toHaveBeenCalledTimes ( 3 ) ;
332390 } ) ;
333391} ) ;
0 commit comments