@@ -30,7 +30,7 @@ import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts'
3030import { createRecordContextTools } from '@objectstack/service-record-context' ;
3131import { ObjectQL } from '@objectstack/objectql/core' ;
3232import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol' ;
33- import { InMemoryDriver } from '@objectstack/driver-memory ' ;
33+ import { SqlDriver } from '@objectstack/driver-sql ' ;
3434import { SysMetadataObject } from '@objectstack/metadata-core' ;
3535import { MCPServerRuntime } from './mcp-server-runtime.js' ;
3636import type { McpDataBridge } from './mcp-http-tools.js' ;
@@ -306,7 +306,9 @@ describe('[ADR-0160 D4] get_record_context — the gates the record tools put be
306306describe ( '[ADR-0160 D4] get_record_context — a package pack the real protocol serves' , ( ) => {
307307 it ( 'the served listing carries the read decoration, and both doors answer through the pack' , async ( ) => {
308308 const engineOfRecord = new ObjectQL ( ) ;
309- engineOfRecord . registerDriver ( new InMemoryDriver ( ) as never , true ) ;
309+ const store = new SqlDriver ( { client : 'better-sqlite3' , connection : { filename : ':memory:' } , useNullAsDefault : true } as never ) ;
310+ await store . initObjects ( [ SysMetadataObject ] as never ) ;
311+ engineOfRecord . registerDriver ( store as never , true ) ;
310312 await engineOfRecord . init ( ) ;
311313 engineOfRecord . registry . registerObject ( SysMetadataObject as never , '@objectstack/platform-objects' ) ;
312314 engineOfRecord . registerApp ( {
@@ -319,24 +321,27 @@ describe('[ADR-0160 D4] get_record_context — a package pack the real protocol
319321 aiContexts : [ PACK ] ,
320322 } as never ) ;
321323 const protocol = new ObjectStackProtocolImplementation ( engineOfRecord as never ) ;
324+ try {
325+ // Precondition: the protocol serves the pack decorated, as `/meta/ai_context` does.
326+ // Were it served bare, this case could not tell a door that strips from one that does not.
327+ const listed = ( await protocol . getMetaItems ( { type : 'ai_context' } ) ) as { items : Array < Record < string , unknown > > } ;
328+ const served = listed . items . find ( ( p ) => p . name === PACK . name ) ;
329+ expect ( served ?. _packageId ) . toBe ( 'com.objectstack.qa.record-context-stdio' ) ;
330+ expect ( served ) . toHaveProperty ( '_diagnostics' ) ;
322331
323- // Precondition: the protocol serves the pack decorated, as `/meta/ai_context` does.
324- // Were it served bare, this case could not tell a door that strips from one that does not.
325- const listed = ( await protocol . getMetaItems ( { type : 'ai_context' } ) ) as { items : Array < Record < string , unknown > > } ;
326- const served = listed . items . find ( ( p ) => p . name === PACK . name ) ;
327- expect ( served ?. _packageId ) . toBe ( 'com.objectstack.qa.record-context-stdio' ) ;
328- expect ( served ) . toHaveProperty ( '_diagnostics' ) ;
329-
330- // No pack on the metadata service: the only listing is the protocol's.
331- const bridge = stdioBridge ( [ ] , true , protocol as unknown as Record < string , unknown > ) ;
332- const { http, stdio } = await callBoth ( bridge , GET_RECORD_CONTEXT_TOOL_NAME , {
333- objectName : 'policy' ,
334- recordId : 'p1' ,
335- context : PACK . name ,
336- } ) ;
337- expect ( http . isError , JSON . stringify ( http . payload ) ) . toBe ( false ) ;
338- expect ( stdio ) . toEqual ( http ) ;
339- expect ( http . payload . data . pack . name ) . toBe ( PACK . name ) ;
340- expect ( http . payload . data . related [ 0 ] . rows . map ( ( r : { id : string } ) => r . id ) ) . toEqual ( [ 'r1' , 'r2' ] ) ;
332+ // No pack on the metadata service: the only listing is the protocol's.
333+ const bridge = stdioBridge ( [ ] , true , protocol as unknown as Record < string , unknown > ) ;
334+ const { http, stdio } = await callBoth ( bridge , GET_RECORD_CONTEXT_TOOL_NAME , {
335+ objectName : 'policy' ,
336+ recordId : 'p1' ,
337+ context : PACK . name ,
338+ } ) ;
339+ expect ( http . isError , JSON . stringify ( http . payload ) ) . toBe ( false ) ;
340+ expect ( stdio ) . toEqual ( http ) ;
341+ expect ( http . payload . data . pack . name ) . toBe ( PACK . name ) ;
342+ expect ( http . payload . data . related [ 0 ] . rows . map ( ( r : { id : string } ) => r . id ) ) . toEqual ( [ 'r1' , 'r2' ] ) ;
343+ } finally {
344+ await engineOfRecord . destroy ( ) ;
345+ }
341346 } ) ;
342347} ) ;
0 commit comments