@@ -24,6 +24,7 @@ vi.mock('@/lib/mothership/resources/persistence', () => ({
2424
2525import { MothershipStreamV1EventType } from '@/lib/mothership/generated/mothership-stream-v1'
2626import { handleResourceSideEffects } from '@/lib/mothership/request/tools/resources'
27+ import type { StreamEvent } from '@/lib/mothership/request/types'
2728import type { MothershipResource } from '@/lib/mothership/resources/types'
2829
2930describe ( 'handleResourceSideEffects' , ( ) => {
@@ -97,31 +98,35 @@ describe('handleResourceSideEffects', () => {
9798 } )
9899 }
99100 )
100- it . each ( [ 'workspace-a' ] ) ( 'addresses extracted exports to admitted %s' , async ( workspaceId ) => {
101- const resource = { type : 'file' as const , id : 'export' , title : 'decisions.csv' }
102- mocks . extractResourcesFromToolResult . mockReturnValue ( [ resource ] )
103- const onEvent = vi . fn ( )
104- await handleResourceSideEffects (
105- 'run_function' ,
106- undefined ,
107- { success : true , output : { } } ,
108- { success : true , output : { } } ,
109- 'org-chat' ,
110- onEvent ,
111- ( ) => false ,
112- workspaceId
113- )
114- expect ( mocks . persistChatResources ) . toHaveBeenCalledWith ( 'org-chat' , [
115- { ...resource , workspaceId } ,
116- ] )
117- expect ( onEvent ) . toHaveBeenCalledWith ( {
118- type : 'resource' ,
119- payload : {
120- op : 'upsert' ,
121- resource : { ...resource , workspaceId } ,
122- } ,
123- } )
124- } )
101+ it . each ( [
102+ { chat : 'organization' , organizationId : 'org' , expected : { workspaceId : 'workspace-a' } } ,
103+ { chat : 'workspace' , organizationId : undefined , expected : { } } ,
104+ ] ) (
105+ 'addresses extracted exports in a $chat chat like its open tabs' ,
106+ async ( { organizationId, expected } ) => {
107+ const resource = { type : 'file' as const , id : 'export' , title : 'decisions.csv' }
108+ mocks . extractResourcesFromToolResult . mockReturnValue ( [ resource ] )
109+ const events : StreamEvent [ ] = [ ]
110+ await handleResourceSideEffects (
111+ 'run_function' ,
112+ undefined ,
113+ { success : true , output : { } } ,
114+ { success : true , output : { } } ,
115+ 'chat' ,
116+ ( event ) => {
117+ events . push ( event )
118+ } ,
119+ ( ) => false ,
120+ { organizationId, workspaceId : 'workspace-a' }
121+ )
122+ expect ( events ) . toEqual ( [
123+ {
124+ type : 'resource' ,
125+ payload : { op : 'upsert' , resource : { ...resource , ...expected } } ,
126+ } ,
127+ ] )
128+ }
129+ )
125130} )
126131
127132it ( 'emits authorized Search results beside the persisted address, never inside it' , async ( ) => {
0 commit comments