@@ -56,12 +56,15 @@ import { type VerifyStack } from '@objectstack/verify';
5656import { MCPServerPlugin , MCPServerRuntime } from '@objectstack/mcp' ;
5757import { bootShowcase } from './showcase-boot.js' ;
5858import { showcaseAppDefaultSecurity } from './showcase-security.js' ;
59+ import { catalogPermissionSet } from './catalog-permission-set.js' ;
5960
6061const OBJECT = 'mcpif_vault' ;
6162const FLAGGED = 'pin' ;
6263const ORDINARY = 'tier' ;
6364const SYS = { context : { isSystem : true } } as const ;
6465const MEMBER_EMAIL = 'mcp-internal-field@verify.test' ;
66+ /** Object-level read on the runtime object, the member's only grant on it. */
67+ const READER_SET = 'mcpif_vault_reader' ;
6568
6669/** The runtime object: one ordinary column to control with, one flagged `internal: true`. */
6770const DEFINITION = {
@@ -251,9 +254,14 @@ describe('MCP data tools refuse an internal field in every evaluate position, as
251254 return String ( key ) ;
252255 }
253256
257+ /**
258+ * `POST /data/:object/query` as `persona`. The data door's refusal envelope is
259+ * flat: the code beside the sentence, which rides under `error`.
260+ */
254261 async function rest ( persona : string , body : Record < string , unknown > ) {
255262 const res = await stack . apiAs ( sessionTokens [ persona ] ! , 'POST' , `/data/${ OBJECT } /query` , body ) ;
256- return { status : res . status , body : ( await res . json ( ) ) as any } ;
263+ const json : any = await res . json ( ) ;
264+ return { status : res . status , code : json ?. code , message : json ?. error , json } ;
257265 }
258266
259267 beforeAll ( async ( ) => {
@@ -269,6 +277,20 @@ describe('MCP data tools refuse an internal field in every evaluate position, as
269277 const ql : any = await stack . kernel . getServiceAsync ( 'objectql' ) ;
270278 for ( const row of ROWS ) await ql . insert ( OBJECT , row , SYS ) ;
271279
280+ // The member reads the object through one authored set and nothing else.
281+ const authored = await stack . apiAs ( sessionTokens . admin , 'PUT' , `/meta/permission/${ READER_SET } ` , {
282+ name : READER_SET ,
283+ label : 'Scratch: object read on the MCP internal-field fixture' ,
284+ objects : { [ OBJECT ] : { allowRead : true } } ,
285+ fields : { } ,
286+ } ) ;
287+ expect ( authored . status , `reader set authored: ${ await authored . clone ( ) . text ( ) } ` ) . toBeLessThan ( 300 ) ;
288+ const set = await catalogPermissionSet ( ql , READER_SET ) ;
289+ expect ( set , 'reader set served by the catalog' ) . toBeTruthy ( ) ;
290+ const memberId = ( await ql . findOne ( 'sys_user' , { where : { email : MEMBER_EMAIL } , ...SYS } ) ) ?. id ;
291+ expect ( memberId , 'member provisioned' ) . toBeTruthy ( ) ;
292+ await ql . insert ( 'sys_user_permission_set' , { user_id : memberId , permission_set : set . name } , SYS ) ;
293+
272294 for ( const persona of [ 'admin' , 'member' ] as const ) {
273295 stdio [ persona ] = await stdioSession ( await mintKey ( sessionTokens [ persona ] ! , `mcp-internal-field-${ persona } ` ) ) ;
274296 }
@@ -292,16 +314,16 @@ describe('MCP data tools refuse an internal field in every evaluate position, as
292314 for ( const [ transport , callFor ] of Object . entries ( transports ) ) {
293315 it ( `${ position . tool } ${ position . label } — ${ transport } , ${ persona } : the door's 400 INVALID_FIELD, word for word` , async ( ) => {
294316 const door = await rest ( persona , position . rest ) ;
295- expect ( door . status , `REST: ${ JSON . stringify ( door . body ) } ` ) . toBe ( 400 ) ;
296- expect ( door . body ?. error ?. code ) . toBe ( 'INVALID_FIELD ' ) ;
317+ expect ( { status : door . status , code : door . code } , `REST: ${ JSON . stringify ( door . json ) } ` ) . toEqual ( { status : 400 , code : 'INVALID_FIELD' } ) ;
318+ expect ( typeof door . message , `REST: ${ JSON . stringify ( door . json ) } ` ) . toBe ( 'string ' ) ;
297319
298320 const answer = await callFor ( persona ) ( position . tool , position . args ) ;
299321 expect ( answer . isError , `${ transport } served the position: ${ answer . text } ` ) . toBe ( true ) ;
300322 expect ( {
301323 code : answer . payload ?. error ?. code ,
302324 status : answer . payload ?. error ?. status ,
303325 message : answer . payload ?. error ?. message ,
304- } ) . toEqual ( { code : 'INVALID_FIELD' , status : 400 , message : door . body . error . message } ) ;
326+ } ) . toEqual ( { code : 'INVALID_FIELD' , status : 400 , message : door . message } ) ;
305327 } ) ;
306328 }
307329 }
0 commit comments