@@ -161,7 +161,12 @@ function makeRealtime() {
161161 * Registers the SQL driver, the test object and, when asked, a realtime
162162 * service, in init(); the knowledge adapter in start(), as a store plugin does.
163163 */
164- function hostPlugin ( file : string , realtime : IRealtimeService | undefined , adapter : IKnowledgeAdapter ) : Plugin {
164+ function hostPlugin (
165+ file : string ,
166+ realtime : IRealtimeService | undefined ,
167+ adapter : IKnowledgeAdapter ,
168+ others : Record < string , IKnowledgeAdapter > = { } ,
169+ ) : Plugin {
165170 return {
166171 name : 'test.knowledge-queue-host' ,
167172 version : '1.0.0' ,
@@ -175,7 +180,9 @@ function hostPlugin(file: string, realtime: IRealtimeService | undefined, adapte
175180 if ( realtime ) ctx . registerService ( 'realtime' , realtime ) ;
176181 } ,
177182 async start ( ctx : PluginContext ) {
178- ctx . getService < KnowledgeService > ( 'knowledge' ) . registerAdapter ( 'memory' , adapter ) ;
183+ const service = ctx . getService < KnowledgeService > ( 'knowledge' ) ;
184+ service . registerAdapter ( 'memory' , adapter ) ;
185+ for ( const [ id , other ] of Object . entries ( others ) ) service . registerAdapter ( id , other ) ;
179186 } ,
180187 } as unknown as Plugin ;
181188}
@@ -221,6 +228,8 @@ interface BootOptions {
221228 realtime ?: boolean ;
222229 queue ?: boolean ;
223230 knowledge ?: KnowledgeServicePluginOptions ;
231+ /** Further stores, registered beside `memory`. */
232+ adapters ?: Record < string , IKnowledgeAdapter > ;
224233}
225234
226235async function boot ( opts : BootOptions = { } ) {
@@ -231,7 +240,7 @@ async function boot(opts: BootOptions = {}) {
231240 const kernel = new ObjectKernel ( { logger : { level : 'fatal' } , gracefulShutdown : false } as never ) ;
232241 kernels . push ( kernel ) ;
233242 await kernel . use ( new ObjectQLPlugin ( ) ) ;
234- await kernel . use ( hostPlugin ( file , realtime , memory . adapter ) ) ;
243+ await kernel . use ( hostPlugin ( file , realtime , memory . adapter , opts . adapters ) ) ;
235244 if ( opts . queue !== false ) {
236245 await kernel . use ( new QueueServicePlugin ( { adapter : 'db' , db : { pollIntervalMs : 10 , maxIdleIntervalMs : 20 } } ) ) ;
237246 }
@@ -439,6 +448,24 @@ describe.each(TRIGGERS)('record sync through the queue — %s', (_label, realtim
439448 expect ( t . docs . size ) . toBe ( 0 ) ;
440449 } ) ;
441450
451+ it ( "a source that names no adapter syncs through the queue to the deployment's store" , async ( ) => {
452+ const { adapter : _named , ...unplaced } = source ( ) ;
453+ const decoy = makeAdapter ( ) ;
454+ const t = await boot ( {
455+ realtime,
456+ adapters : { decoy : decoy . adapter } ,
457+ knowledge : { sources : [ unplaced as KnowledgeSource ] , deploymentAdapter : 'memory' } ,
458+ } ) ;
459+ expect ( t . service . recordSyncQueued ) . toBe ( true ) ;
460+ const row = await t . insert ( { title : 'Leave policy' , body : 'Twenty days of paid leave' , status : 'published' } ) ;
461+ await t . drained ( ) ;
462+ const rows = await t . queueRows ( ) ;
463+ expect ( rows . map ( ( r ) => r . status ) ) . toEqual ( [ 'completed' ] ) ;
464+ expect ( t . docs . size ) . toBe ( 1 ) ;
465+ expect ( decoy . docs . size ) . toBe ( 0 ) ;
466+ expect ( await t . found ( 'paid leave' ) ) . toEqual ( [ String ( row . id ) ] ) ;
467+ } ) ;
468+
442469 it ( 'a source unregistered before its message is processed: completed, no write, no retry' , async ( ) => {
443470 const t = await boot ( { realtime } ) ;
444471 await t . queue . stop ( ) ;
0 commit comments