88 * client id when the client declares none), the granted scopes in the
99 * consent page's own words, when authorized, and "in the hour from" the
1010 * recorded last use or "not recorded"; the organization only when it is
11- * not the active one; and no Revoke control on an assistant row;
11+ * not the active one;
12+ * - §1b Revoke on an assistant row asks first, naming the assistant; Cancel
13+ * withdraws nothing; confirming calls `withdraw(id)` and reads the list
14+ * again, and a refused withdraw (the grant already gone) names the refusal
15+ * and reads the list again too;
1216 * - §2 keys are the person's OWN `sys_api_key` rows: the read filters on the
1317 * signed-in user (a platform administrator's unfiltered read answers every
1418 * person's keys) and never selects the secret; revoked and expired keys
1519 * carry their state and no Revoke;
1620 * - §3 Revoke on an active key asks first, naming the key; Cancel writes
1721 * nothing; confirming writes `revoked: true` and the list re-reads in place;
18- * - §4 empty, failed and signed-out states.
22+ * - §4 empty, failed and signed-out states;
23+ * - §5 the administrator's widget `mcp:authorized-assistants` on a `sys_user`
24+ * record page: it reads the person from the bound record, lists through
25+ * `listForUser` and revokes through `withdrawForUser`, and renders nothing
26+ * off a `sys_user` record.
1927 *
2028 * `t` echoes the key with any interpolation values appended, so assertions
2129 * read which string was asked for and with what.
@@ -55,8 +63,10 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
5563 } ) ,
5664} ) ) ;
5765
58- import { notifyDataChanged } from '@object-ui/react' ;
66+ import { ComponentRegistry } from '@object-ui/core' ;
67+ import { notifyDataChanged , RecordContextProvider } from '@object-ui/react' ;
5968import { AuthorizedAccessList } from './AuthorizedAccessList' ;
69+ import { ManagedPersonAssistants } from './ManagedPersonAssistants' ;
6070
6171type Row = Record < string , unknown > ;
6272
@@ -93,6 +103,10 @@ const CLIENTS = [
93103const FAR_FUTURE = '2999-01-01T00:00:00.000Z' ;
94104let keyRows : Row [ ] ;
95105let listMock : ReturnType < typeof vi . fn > ;
106+ let withdrawMock : ReturnType < typeof vi . fn > ;
107+ let listForUserMock : ReturnType < typeof vi . fn > ;
108+ let withdrawForUserMock : ReturnType < typeof vi . fn > ;
109+ let granted : typeof CLIENTS ;
96110let findMock : ReturnType < typeof vi . fn > ;
97111let updateMock : ReturnType < typeof vi . fn > ;
98112
@@ -104,7 +118,18 @@ beforeEach(() => {
104118 { id : 'k_revoked' , name : 'old key' , prefix : 'osk_ghi' , created_at : '2026-10-01T10:00:00.000Z' , last_used_at : null , expires_at : FAR_FUTURE , revoked : true } ,
105119 { id : 'k_expired' , name : 'stale key' , prefix : 'osk_jkl' , created_at : '2026-01-01T10:00:00.000Z' , last_used_at : null , expires_at : '2026-02-01T00:00:00.000Z' , revoked : false } ,
106120 ] ;
107- listMock = vi . fn ( async ( ) => ( { clients : CLIENTS , truncated : false } ) ) ;
121+ granted = [ ...CLIENTS ] ;
122+ listMock = vi . fn ( async ( ) => ( { clients : [ ...granted ] , truncated : false } ) ) ;
123+ withdrawMock = vi . fn ( async ( id : string ) => {
124+ if ( ! granted . some ( ( c ) => c . id === id ) ) throw new Error ( 'No authorized assistant you may withdraw matches the supplied id.' ) ;
125+ granted = granted . filter ( ( c ) => c . id !== id ) ;
126+ return { id } ;
127+ } ) ;
128+ listForUserMock = vi . fn ( async ( ) => ( { clients : [ ...granted ] , truncated : false } ) ) ;
129+ withdrawForUserMock = vi . fn ( async ( _userId : string , id : string ) => {
130+ granted = granted . filter ( ( c ) => c . id !== id ) ;
131+ return { id } ;
132+ } ) ;
108133 findMock = vi . fn ( async ( ) => ( { data : keyRows . map ( ( r ) => ( { ...r } ) ) } ) ) ;
109134 updateMock = vi . fn ( async ( resource : string , id : string , patch : Row ) => {
110135 keyRows = keyRows . map ( ( r ) => ( r . id === id ? { ...r , ...patch } : r ) ) ;
@@ -113,7 +138,16 @@ beforeEach(() => {
113138 return keyRows . find ( ( r ) => r . id === id ) ;
114139 } ) ;
115140 adapter = {
116- getClient : ( ) => ( { oauth : { authorizedClients : { list : listMock } } } ) ,
141+ getClient : ( ) => ( {
142+ oauth : {
143+ authorizedClients : {
144+ list : listMock ,
145+ withdraw : withdrawMock ,
146+ listForUser : listForUserMock ,
147+ withdrawForUser : withdrawForUserMock ,
148+ } ,
149+ } ,
150+ } ) ,
117151 find : findMock ,
118152 update : updateMock ,
119153 } ;
@@ -173,12 +207,11 @@ describe('§1 authorized assistants', () => {
173207 expect ( within ( nameless ) . getByText ( '«connectAgent.access.unnamed»' ) ) . toBeInTheDocument ( ) ;
174208 } ) ;
175209
176- it ( 'offers no Revoke on any assistant row, and says withdrawing is not available here yet ' , async ( ) => {
210+ it ( 'offers a Revoke on every assistant row' , async ( ) => {
177211 await renderSettled ( ) ;
178212 for ( const row of screen . getAllByTestId ( 'authorized-assistant' ) ) {
179- expect ( within ( row ) . queryByRole ( 'button' ) ) . toBeNull ( ) ;
213+ expect ( within ( row ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) . toBeInTheDocument ( ) ;
180214 }
181- expect ( screen . getByText ( '«connectAgent.access.withdrawLater»' ) ) . toBeInTheDocument ( ) ;
182215 expect ( screen . queryByText ( / c o n n e c t A g e n t \. a c c e s s \. t r u n c a t e d / ) ) . toBeNull ( ) ;
183216 } ) ;
184217
@@ -189,6 +222,54 @@ describe('§1 authorized assistants', () => {
189222 } ) ;
190223} ) ;
191224
225+ describe ( '§1b revoking an assistant' , ( ) => {
226+ it ( 'asks first, naming the assistant; Cancel withdraws nothing' , async ( ) => {
227+ await renderSettled ( ) ;
228+ fireEvent . click ( within ( assistantRow ( 'Claude Desktop' ) ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
229+ const dialog = await screen . findByRole ( 'alertdialog' ) ;
230+ expect ( within ( dialog ) . getByText ( '«connectAgent.access.withdrawTitle|Claude Desktop»' ) ) . toBeInTheDocument ( ) ;
231+ expect ( within ( dialog ) . getByText ( '«connectAgent.access.withdrawBody»' ) ) . toBeInTheDocument ( ) ;
232+ fireEvent . click ( within ( dialog ) . getByRole ( 'button' , { name : '«common.cancel»' } ) ) ;
233+ await waitFor ( ( ) => expect ( screen . queryByRole ( 'alertdialog' ) ) . toBeNull ( ) ) ;
234+ expect ( withdrawMock ) . not . toHaveBeenCalled ( ) ;
235+ } ) ;
236+
237+ it ( 'names a nameless assistant by the fallback in the confirm' , async ( ) => {
238+ await renderSettled ( ) ;
239+ fireEvent . click ( within ( assistantRow ( 'client_nameless' ) ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
240+ const dialog = await screen . findByRole ( 'alertdialog' ) ;
241+ expect ( within ( dialog ) . getByText ( '«connectAgent.access.withdrawTitle|«connectAgent.access.unnamed»»' ) ) . toBeInTheDocument ( ) ;
242+ } ) ;
243+
244+ it ( 'confirming withdraws the grant by its id and reads the list again' , async ( ) => {
245+ await renderSettled ( ) ;
246+ fireEvent . click ( within ( assistantRow ( 'Claude Desktop' ) ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
247+ const dialog = await screen . findByRole ( 'alertdialog' ) ;
248+ fireEvent . click ( within ( dialog ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
249+
250+ await waitFor ( ( ) => expect ( withdrawMock ) . toHaveBeenCalledWith ( 'consent_2' ) ) ;
251+ await waitFor ( ( ) => expect ( listMock ) . toHaveBeenCalledTimes ( 2 ) ) ;
252+ await waitFor ( ( ) => expect ( screen . getAllByTestId ( 'authorized-assistant' ) ) . toHaveLength ( 2 ) ) ;
253+ expect ( screen . queryByText ( 'Claude Desktop' ) ) . toBeNull ( ) ;
254+ // An assistant withdraw is not a key write: the keys are not re-read.
255+ expect ( findMock ) . toHaveBeenCalledTimes ( 1 ) ;
256+ expect ( withdrawForUserMock ) . not . toHaveBeenCalled ( ) ;
257+ } ) ;
258+
259+ it ( 'a refused withdraw names the refusal and still reads the list again' , async ( ) => {
260+ await renderSettled ( ) ;
261+ // Withdrawn elsewhere after this page read the list: the server answers 404.
262+ granted = granted . filter ( ( c ) => c . id !== 'consent_1' ) ;
263+ fireEvent . click ( within ( assistantRow ( 'Cursor' ) ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
264+ const dialog = await screen . findByRole ( 'alertdialog' ) ;
265+ fireEvent . click ( within ( dialog ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
266+
267+ expect ( await screen . findByText ( / N o a u t h o r i z e d a s s i s t a n t y o u m a y w i t h d r a w / ) ) . toBeInTheDocument ( ) ;
268+ await waitFor ( ( ) => expect ( listMock ) . toHaveBeenCalledTimes ( 2 ) ) ;
269+ await waitFor ( ( ) => expect ( screen . queryByText ( 'Cursor' ) ) . toBeNull ( ) ) ;
270+ } ) ;
271+ } ) ;
272+
192273describe ( '§2 API keys' , ( ) => {
193274 it ( "reads only the signed-in person's own keys, and never the secret" , async ( ) => {
194275 await renderSettled ( ) ;
@@ -275,3 +356,64 @@ describe('§4 empty, failed and signed-out states', () => {
275356 expect ( findMock ) . not . toHaveBeenCalled ( ) ;
276357 } ) ;
277358} ) ;
359+
360+ describe ( '§5 the administrator widget on a person\'s record page' , ( ) => {
361+ const renderOn = ( objectName : string , recordId : string | null ) =>
362+ render (
363+ < RecordContextProvider objectName = { objectName } recordId = { recordId } >
364+ < ManagedPersonAssistants />
365+ </ RecordContextProvider > ,
366+ ) ;
367+
368+ it ( 'is registered as mcp:authorized-assistants' , ( ) => {
369+ expect ( ComponentRegistry . get ( 'mcp:authorized-assistants' ) ) . toBeDefined ( ) ;
370+ } ) ;
371+
372+ it ( "lists the person's grants through listForUser and revokes through withdrawForUser" , async ( ) => {
373+ renderOn ( 'sys_user' , 'user_mia' ) ;
374+ await screen . findAllByTestId ( 'authorized-assistant' ) ;
375+ expect ( listForUserMock ) . toHaveBeenCalledWith ( 'user_mia' ) ;
376+ expect ( listMock ) . not . toHaveBeenCalled ( ) ;
377+ expect ( screen . getByText ( '«connectAgent.access.managedBody»' ) ) . toBeInTheDocument ( ) ;
378+
379+ fireEvent . click ( within ( assistantRow ( 'Cursor' ) ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
380+ const dialog = await screen . findByRole ( 'alertdialog' ) ;
381+ expect ( within ( dialog ) . getByText ( '«connectAgent.access.withdrawTitle|Cursor»' ) ) . toBeInTheDocument ( ) ;
382+ fireEvent . click ( within ( dialog ) . getByRole ( 'button' , { name : '«connectAgent.access.revoke»' } ) ) ;
383+
384+ await waitFor ( ( ) => expect ( withdrawForUserMock ) . toHaveBeenCalledWith ( 'user_mia' , 'consent_1' ) ) ;
385+ await waitFor ( ( ) => expect ( listForUserMock ) . toHaveBeenCalledTimes ( 2 ) ) ;
386+ await waitFor ( ( ) => expect ( screen . queryByText ( 'Cursor' ) ) . toBeNull ( ) ) ;
387+ expect ( withdrawMock ) . not . toHaveBeenCalled ( ) ;
388+ } ) ;
389+
390+ it ( 'speaks of this person when the list is empty or truncated' , async ( ) => {
391+ listForUserMock . mockResolvedValueOnce ( { clients : [ ] , truncated : false } ) ;
392+ const first = renderOn ( 'sys_user' , 'user_mia' ) ;
393+ expect ( await screen . findByText ( '«connectAgent.access.managedEmpty»' ) ) . toBeInTheDocument ( ) ;
394+ expect ( screen . queryByText ( '«connectAgent.access.assistantsEmpty»' ) ) . toBeNull ( ) ;
395+ first . unmount ( ) ;
396+ listForUserMock . mockResolvedValueOnce ( { clients : CLIENTS , truncated : true } ) ;
397+ renderOn ( 'sys_user' , 'user_mia' ) ;
398+ expect ( await screen . findByText ( '«connectAgent.access.managedTruncated»' ) ) . toBeInTheDocument ( ) ;
399+ } ) ;
400+
401+ it ( 'names a refused read (not a platform administrator) instead of an empty list' , async ( ) => {
402+ listForUserMock . mockRejectedValueOnce ( new Error ( 'Admin role required' ) ) ;
403+ renderOn ( 'sys_user' , 'user_mia' ) ;
404+ expect ( await screen . findByText ( '«connectAgent.access.loadFailed|Admin role required»' ) ) . toBeInTheDocument ( ) ;
405+ expect ( screen . queryByText ( '«connectAgent.access.managedEmpty»' ) ) . toBeNull ( ) ;
406+ } ) ;
407+
408+ it ( "renders nothing and reads nothing off a sys_user record" , ( ) => {
409+ const other = renderOn ( 'crm_account' , 'acc_1' ) ;
410+ expect ( other . container ) . toBeEmptyDOMElement ( ) ;
411+ other . unmount ( ) ;
412+ const unbound = render ( < ManagedPersonAssistants /> ) ;
413+ expect ( unbound . container ) . toBeEmptyDOMElement ( ) ;
414+ unbound . unmount ( ) ;
415+ const noId = renderOn ( 'sys_user' , null ) ;
416+ expect ( noId . container ) . toBeEmptyDOMElement ( ) ;
417+ expect ( listForUserMock ) . not . toHaveBeenCalled ( ) ;
418+ } ) ;
419+ } ) ;
0 commit comments