11// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22
33import { describe , it , expect , vi , beforeEach } from 'vitest' ;
4- import { MetadataManager , type MetadataManagerOptions } from './metadata-manager' ;
4+ import { MetadataManager } from './metadata-manager' ;
55import { MemoryLoader } from './loaders/memory-loader' ;
66import type { MetadataLoader } from './loaders/loader-interface' ;
77
@@ -109,7 +109,7 @@ describe('MetadataManager', () => {
109109
110110 it ( 'should throw when no writable loader is available' , async ( ) => {
111111 const readOnlyLoader : MetadataLoader = {
112- contract : { name : 'readonly' , protocol : 'test' , capabilities : { read : true , write : false , watch : false , list : true } } ,
112+ contract : { name : 'readonly' , protocol : 'memory:' as const , capabilities : { read : true , write : false , watch : false , list : true } } ,
113113 load : vi . fn ( ) . mockResolvedValue ( { data : null } ) ,
114114 loadMany : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
115115 exists : vi . fn ( ) . mockResolvedValue ( false ) ,
@@ -163,15 +163,15 @@ describe('MetadataManager', () => {
163163
164164 it ( 'should deduplicate across loaders' , async ( ) => {
165165 const loader1 : MetadataLoader = {
166- contract : { name : 'l1' , protocol : 'test' , capabilities : { read : true , write : false , watch : false , list : true } } ,
166+ contract : { name : 'l1' , protocol : 'memory:' as const , capabilities : { read : true , write : false , watch : false , list : true } } ,
167167 load : vi . fn ( ) . mockResolvedValue ( { data : null } ) ,
168168 loadMany : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
169169 exists : vi . fn ( ) . mockResolvedValue ( false ) ,
170170 stat : vi . fn ( ) . mockResolvedValue ( null ) ,
171171 list : vi . fn ( ) . mockResolvedValue ( [ 'account' , 'contact' ] ) ,
172172 } ;
173173 const loader2 : MetadataLoader = {
174- contract : { name : 'l2' , protocol : 'test' , capabilities : { read : true , write : false , watch : false , list : true } } ,
174+ contract : { name : 'l2' , protocol : 'memory:' as const , capabilities : { read : true , write : false , watch : false , list : true } } ,
175175 load : vi . fn ( ) . mockResolvedValue ( { data : null } ) ,
176176 loadMany : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
177177 exists : vi . fn ( ) . mockResolvedValue ( false ) ,
@@ -269,7 +269,7 @@ describe('MemoryLoader', () => {
269269
270270 it ( 'should have correct contract' , ( ) => {
271271 expect ( loader . contract . name ) . toBe ( 'memory' ) ;
272- expect ( loader . contract . protocol ) . toBe ( 'memory' ) ;
272+ expect ( loader . contract . protocol ) . toBe ( 'memory: ' ) ;
273273 expect ( loader . contract . capabilities . read ) . toBe ( true ) ;
274274 expect ( loader . contract . capabilities . write ) . toBe ( true ) ;
275275 } ) ;
@@ -356,15 +356,15 @@ describe('MetadataPlugin', () => {
356356 } ) ) ;
357357
358358 it ( 'should have correct plugin metadata' , async ( ) => {
359- const { MetadataPlugin } = await import ( './plugin' ) ;
359+ const { MetadataPlugin } = await import ( './plugin.js ' ) ;
360360 const plugin = new MetadataPlugin ( { rootDir : '/tmp/test' , watch : false } ) ;
361361 expect ( plugin . name ) . toBe ( 'com.objectstack.metadata' ) ;
362362 expect ( plugin . version ) . toBe ( '1.0.0' ) ;
363363 expect ( plugin . type ) . toBe ( 'standard' ) ;
364364 } ) ;
365365
366366 it ( 'should call init and register metadata service' , async ( ) => {
367- const { MetadataPlugin } = await import ( './plugin' ) ;
367+ const { MetadataPlugin } = await import ( './plugin.js ' ) ;
368368 const plugin = new MetadataPlugin ( { rootDir : '/tmp/test' , watch : false } ) ;
369369
370370 const ctx = createMockPluginContext ( ) ;
@@ -374,7 +374,7 @@ describe('MetadataPlugin', () => {
374374 } ) ;
375375
376376 it ( 'should call start and attempt to load metadata types' , async ( ) => {
377- const { MetadataPlugin } = await import ( './plugin' ) ;
377+ const { MetadataPlugin } = await import ( './plugin.js ' ) ;
378378 const plugin = new MetadataPlugin ( { rootDir : '/tmp/test' , watch : false } ) ;
379379
380380 const ctx = createMockPluginContext ( ) ;
@@ -390,7 +390,7 @@ describe('MetadataPlugin', () => {
390390
391391function createMockLoader ( name : string , data : any , shouldFail = false ) : MetadataLoader {
392392 return {
393- contract : { name, protocol : 'test' , capabilities : { read : true , write : false , watch : false , list : true } } ,
393+ contract : { name, protocol : 'memory:' as const , capabilities : { read : true , write : false , watch : false , list : true } } ,
394394 load : shouldFail
395395 ? vi . fn ( ) . mockRejectedValue ( new Error ( 'loader failed' ) )
396396 : vi . fn ( ) . mockResolvedValue ( { data } ) ,
@@ -403,7 +403,7 @@ function createMockLoader(name: string, data: any, shouldFail = false): Metadata
403403
404404function createMockLoaderMany ( name : string , items : any [ ] , shouldFail = false ) : MetadataLoader {
405405 return {
406- contract : { name, protocol : 'test' , capabilities : { read : true , write : false , watch : false , list : true } } ,
406+ contract : { name, protocol : 'memory:' as const , capabilities : { read : true , write : false , watch : false , list : true } } ,
407407 load : vi . fn ( ) . mockResolvedValue ( { data : null } ) ,
408408 loadMany : shouldFail
409409 ? vi . fn ( ) . mockRejectedValue ( new Error ( 'loader failed' ) )
@@ -417,6 +417,7 @@ function createMockLoaderMany(name: string, items: any[], shouldFail = false): M
417417function createMockPluginContext ( ) {
418418 return {
419419 registerService : vi . fn ( ) ,
420+ replaceService : vi . fn ( ) ,
420421 getService : vi . fn ( ) . mockReturnValue ( null ) ,
421422 getServices : vi . fn ( ) . mockReturnValue ( new Map ( ) ) ,
422423 hook : vi . fn ( ) ,
0 commit comments