@@ -19,7 +19,8 @@ import { eq, inArray } from 'drizzle-orm'
1919import { afterAll , beforeAll , beforeEach , expect , it , vi } from 'vitest'
2020import type { LiveContributionItem } from '@/lib/sim-search/live/application'
2121
22- const { liveItems, peopleOpen } = vi . hoisted ( ( ) => ( {
22+ const { liveItems, peopleOpen, directoryWithheld } = vi . hoisted ( ( ) => ( {
23+ directoryWithheld : { value : false } ,
2324 liveItems : { value : [ ] as unknown [ ] } ,
2425 peopleOpen : { value : true } ,
2526} ) )
@@ -55,6 +56,18 @@ vi.mock('@/lib/sim-search/live/application', () => ({
5556 } ,
5657 } ,
5758} ) )
59+ vi . mock ( '@/lib/permission-groups/capability-assertions' , async ( importOriginal ) => {
60+ const actual =
61+ await importOriginal < typeof import ( '@/lib/permission-groups/capability-assertions' ) > ( )
62+ return {
63+ ...actual ,
64+ isOrganizationCapabilityWithheld : async (
65+ ...args : Parameters < typeof actual . isOrganizationCapabilityWithheld >
66+ ) =>
67+ ( directoryWithheld . value && args [ 1 ] === 'organization.member_directory' ) ||
68+ actual . isOrganizationCapabilityWithheld ( ...args ) ,
69+ }
70+ } )
5871vi . mock ( '@/lib/people/feature-flag' , async ( importOriginal ) => ( {
5972 ...( await importOriginal < typeof import ( '@/lib/people/feature-flag' ) > ( ) ) ,
6073 requirePeopleEnabled : async ( ) => {
@@ -66,7 +79,10 @@ import { searchExperts } from '@/lib/knowledge/application/experts'
6679
6780const organizationId = generateId ( )
6881const adminId = generateId ( )
82+ const readerId = generateId ( )
6983const principal = createSessionPrincipal ( { userId : adminId } )
84+ /** A plain member, whom a withheld member directory keeps out of People. */
85+ const reader = createSessionPrincipal ( { userId : readerId } )
7086const email = ( name : string ) => `${ name } -${ organizationId } @example.test`
7187const [ billingLead , billingDev , namesake ] = [ generateId ( ) , generateId ( ) , generateId ( ) ]
7288const now = new Date ( ) . toISOString ( )
@@ -98,28 +114,34 @@ function item(
98114 }
99115}
100116
101- function search ( extra : { department ?: string } = { } ) {
117+ function search ( extra : { department ?: string } = { } , as = principal ) {
102118 return searchExperts . execute ( {
103- principal,
119+ principal : as ,
104120 input : { query : 'billing' , topK : 10 , organizationId, surface : 'mcp' , ...extra } ,
105121 } )
106122}
107123
108124beforeAll ( async ( ) => {
109- await db . insert ( user ) . values ( {
110- id : adminId ,
111- name : 'Administrator' ,
112- email : email ( 'admin' ) ,
113- emailVerified : true ,
114- createdAt : new Date ( ) ,
115- updatedAt : new Date ( ) ,
116- } )
125+ await db . insert ( user ) . values (
126+ [
127+ [ adminId , 'Administrator' ] ,
128+ [ readerId , 'Reader' ] ,
129+ ] . map ( ( [ id , name ] ) => ( {
130+ id,
131+ name,
132+ email : email ( id ) ,
133+ emailVerified : true ,
134+ createdAt : new Date ( ) ,
135+ updatedAt : new Date ( ) ,
136+ } ) )
137+ )
117138 await db
118139 . insert ( organization )
119140 . values ( { id : organizationId , slug : organizationId , name : 'Experts' , createdAt : new Date ( ) } )
120- await db
121- . insert ( member )
122- . values ( { id : generateId ( ) , organizationId, userId : adminId , role : 'owner' } )
141+ await db . insert ( member ) . values ( [
142+ { id : generateId ( ) , organizationId, userId : adminId , role : 'owner' } ,
143+ { id : generateId ( ) , organizationId, userId : readerId , role : 'member' } ,
144+ ] )
123145 await db
124146 . insert ( peopleDirectorySync )
125147 . values ( { organizationId, source : 'okta' , sourceTarget : 'example.okta.com' } )
@@ -151,6 +173,7 @@ beforeAll(async () => {
151173
152174beforeEach ( ( ) => {
153175 peopleOpen . value = true
176+ directoryWithheld . value = false
154177 liveItems . value = [
155178 item ( 'jira' , 'ENG-1' , [
156179 { role : 'assignee' , email : email ( billingLead ) , name : 'Billing Lead' } ,
@@ -164,7 +187,7 @@ beforeEach(() => {
164187
165188afterAll ( async ( ) => {
166189 await db . delete ( organization ) . where ( eq ( organization . id , organizationId ) )
167- await db . delete ( user ) . where ( eq ( user . id , adminId ) )
190+ await db . delete ( user ) . where ( inArray ( user . id , [ adminId , readerId ] ) )
168191 vi . unstubAllEnvs ( )
169192} )
170193
@@ -215,9 +238,24 @@ it('narrows to a department', async () => {
215238 expect ( result . otherContributors ) . toBeUndefined ( )
216239} )
217240
218- it ( 'names experts without profiles when the directory is closed to the caller' , async ( ) => {
219- peopleOpen . value = false
220- const result = await search ( )
241+ it . each ( [
242+ [
243+ 'People is off for the organization' ,
244+ ( ) : void => {
245+ peopleOpen . value = false
246+ } ,
247+ principal ,
248+ ] ,
249+ [
250+ 'the member directory is withheld from members' ,
251+ ( ) : void => {
252+ directoryWithheld . value = true
253+ } ,
254+ reader ,
255+ ] ,
256+ ] as const ) ( 'names experts without profiles when %s' , async ( _closed , close , as ) => {
257+ close ( )
258+ const result = await search ( { } , as )
221259 expect ( result . experts ) . toEqual ( [ ] )
222260 expect ( result . otherContributors ?. [ 0 ] ) . toMatchObject ( { email : email ( billingLead ) } )
223261 expect ( result . otherContributors ?. [ 0 ] ) . not . toHaveProperty ( 'personId' )
@@ -269,8 +307,8 @@ it('counts an item two connected accounts both return once', async () => {
269307} )
270308
271309it ( 'still names contributors when the directory is closed and a department is asked for' , async ( ) => {
272- peopleOpen . value = false
273- const result = await search ( { department : 'platform' } )
310+ directoryWithheld . value = true
311+ const result = await search ( { department : 'platform' } , reader )
274312 expect ( result . experts ) . toEqual ( [ ] )
275313 expect ( result . otherContributors ?. length ) . toBeGreaterThan ( 0 )
276314 expect ( result . note ) . toMatch ( / d e p a r t m e n t a n d l o c a t i o n f i l t e r s w e r e n o t a p p l i e d / )
@@ -311,3 +349,9 @@ it('matches no one by an email two directory people share, or a Slack ID two wor
311349 await db . delete ( peopleSlackIdentity ) . where ( eq ( peopleSlackIdentity . slackUserId , 'U-DUP' ) )
312350 }
313351} )
352+
353+ it ( 'says the filter, not the topic, left no one when a department matches no contributor' , async ( ) => {
354+ const result = await search ( { department : 'no such department' } )
355+ expect ( result . experts ) . toEqual ( [ ] )
356+ expect ( result . note ) . toMatch ( / n o o n e i n t h e d i r e c t o r y m a t c h e s t h e d e p a r t m e n t o r l o c a t i o n f i l t e r / )
357+ } )
0 commit comments