@@ -530,6 +530,7 @@ describe('admitAuthoredSource — source admission at save, as the authoring pri
530530 . toMatchObject ( { admitted : false , code : 'SERVICE_UNAVAILABLE' , status : 503 } ) ;
531531
532532 const noEngine = new KnowledgeService ( { } ) ;
533+ noEngine . registerAdapter ( 'memory' , makeAdapter ( ) ) ;
533534 expect ( await noEngine . admitAuthoredSource ( item ( 'ticket' , [ 'body' ] ) , MANAGER ) )
534535 . toMatchObject ( { admitted : false , code : 'SERVICE_UNAVAILABLE' , status : 503 } ) ;
535536 } ) ;
@@ -543,6 +544,51 @@ describe('admitAuthoredSource — source admission at save, as the authoring pri
543544 }
544545 } ) ;
545546
547+ // [ADR-0161 K4] The store a source names must be one this deployment mounts:
548+ // a retired adapter ('ragflow') or a typo is refused at the save, not left to
549+ // the boot's error line and a search's 503.
550+ it ( 'a source naming an adapter the deployment does not mount is refused VALIDATION_ERROR / 400, naming the source, the adapter and the mounted ones' , async ( ) => {
551+ const { svc } = setup ( { sources : [ ] , security : salaryHiddenFromMembers } ) ;
552+ for ( const adapter of [ 'ragflow' , 'memroy' , '' ] ) {
553+ const verdict = await svc . admitAuthoredSource ( { ...item ( 'ticket' , [ 'body' ] ) , adapter } , MANAGER ) ;
554+ expect ( verdict , adapter ) . toMatchObject ( { admitted : false , code : 'VALIDATION_ERROR' , status : 400 , object : 'ticket' } ) ;
555+ const message = ( verdict as { message : string } ) . message ;
556+ expect ( message ) . toContain ( 'knowledge source "authored" was not saved' ) ;
557+ expect ( message ) . toContain ( `names adapter '${ adapter } ', which this deployment does not mount (mounted: memory)` ) ;
558+ }
559+ // Refused before the gates are asked: an author the field gate would refuse hears the adapter first.
560+ expect ( await svc . admitAuthoredSource ( { ...item ( 'ticket' , [ 'body' , 'salary_note' ] ) , adapter : 'ragflow' } , MEMBER ) )
561+ . toMatchObject ( { admitted : false , code : 'VALIDATION_ERROR' , status : 400 } ) ;
562+ // The engine's own write (a package install) is not judged at this door.
563+ expect ( await svc . admitAuthoredSource ( { ...item ( 'ticket' , [ 'body' ] ) , adapter : 'ragflow' } , SYSTEM ) ) . toEqual ( { admitted : true } ) ;
564+ } ) ;
565+
566+ it ( 'with no adapter mounted, a named one is refused naming none mounted; with two, both are named' , async ( ) => {
567+ const bare = new KnowledgeService ( { dataEngine : makeEngine ( [ TICKET ] ) } ) ;
568+ expect ( await bare . admitAuthoredSource ( item ( 'ticket' , [ 'body' ] ) , MANAGER ) ) . toMatchObject ( {
569+ admitted : false , code : 'VALIDATION_ERROR' , status : 400 ,
570+ message : expect . stringContaining ( "names adapter 'memory', which this deployment does not mount (mounted: none)" ) ,
571+ } ) ;
572+ const { svc } = setup ( { sources : [ ] } ) ;
573+ svc . registerAdapter ( 'turso' , makeAdapter ( ) ) ;
574+ expect ( await svc . admitAuthoredSource ( { ...item ( 'ticket' , [ 'body' ] ) , adapter : 'pgvector' } , MANAGER ) ) . toMatchObject ( {
575+ admitted : false , code : 'VALIDATION_ERROR' , status : 400 ,
576+ message : expect . stringContaining ( "(mounted: memory, turso)" ) ,
577+ } ) ;
578+ } ) ;
579+
580+ it ( 'CONTROL: a source naming a mounted adapter, and one that leaves `adapter` out, are admitted' , async ( ) => {
581+ const { svc } = setup ( { sources : [ ] } ) ;
582+ svc . registerAdapter ( 'turso' , makeAdapter ( ) ) ;
583+ expect ( await svc . admitAuthoredSource ( item ( 'ticket' , [ 'body' ] ) , MANAGER ) ) . toEqual ( { admitted : true } ) ;
584+ expect ( await svc . admitAuthoredSource ( { ...item ( 'ticket' , [ 'body' ] ) , adapter : 'turso' } , MANAGER ) ) . toEqual ( { admitted : true } ) ;
585+ const placed = new KnowledgeService ( { dataEngine : makeEngine ( [ TICKET ] ) , deploymentAdapter : 'turso' } ) ;
586+ placed . registerAdapter ( 'turso' , makeAdapter ( ) ) ;
587+ placed . registerAdapter ( 'memory' , makeAdapter ( ) ) ;
588+ const { adapter : _omitted , ...omitted } = item ( 'ticket' , [ 'body' ] ) ;
589+ expect ( await placed . admitAuthoredSource ( omitted , MANAGER ) ) . toEqual ( { admitted : true } ) ;
590+ } ) ;
591+
546592 it ( 'registers nothing and searches nothing: the verdict is a read' , async ( ) => {
547593 const { svc, adapter } = setup ( { sources : [ ] , security : salaryHiddenFromMembers } ) ;
548594 await svc . admitAuthoredSource ( item ( 'ticket' , [ 'body' ] ) , MANAGER ) ;
0 commit comments