@@ -36,6 +36,7 @@ import '@objectstack/runtime';
3636import { MarketplaceInstallLocalPlugin } from './marketplace-install-local-plugin.js' ;
3737import { declareInstallerPlatformOwner , installerAuthService , withInstallerGrants } from './install-local-principal.fixtures.js' ;
3838import { LocalManifestSource } from './local-manifest-source.js' ;
39+ import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol' ;
3940
4041const ROUTE = '/api/v1/marketplace/install-local' ;
4142const INSTALLER = 'usr_installer' ;
@@ -567,3 +568,61 @@ describe('install-local — `targetNamespace` renames an unmanaged copy, and onl
567568 } ) ;
568569 }
569570} ) ;
571+
572+ describe ( 'install-local — the import\'s own `targetNamespace` refusal, as the door answers it (#30794)' , ( ) => {
573+ // The REAL copy-once import, not a double: the refusal is judged by its
574+ // plan before the engine is asked anything, so an empty engine suffices.
575+ const realImporter = ( ) => {
576+ const protocol = new ObjectStackProtocolImplementation ( { registry : { } } as any , ( ) => new Map ( ) ) as any ;
577+ return ( request : any ) => protocol . importUnmanagedPackage ( request ) ;
578+ } ;
579+
580+ for ( const [ label , targetNamespace , sentence ] of [
581+ [ 'a value the namespace declaration refuses' , 'Acme' , "Invalid package namespace 'Acme' on `targetNamespace`" ] ,
582+ [ 'a platform-reserved namespace' , 'sys' , "`targetNamespace` 'sys' is a platform-reserved namespace" ] ,
583+ ] as const ) {
584+ it ( `${ label } : 400 INVALID_REQUEST, the reason in the body and \`details.targetNamespace\`; nothing written` , async ( ) => {
585+ const h = await mount ( dir , { importer : realImporter ( ) } ) ;
586+ const res = await h . install ( { manifest : crm ( { installModes : BOTH } ) , installMode : 'unmanaged' , targetNamespace } ) ;
587+ expect ( res . status , JSON . stringify ( res . payload ) ) . toBe ( 400 ) ;
588+ expect ( res . payload . error . code ) . toBe ( 'INVALID_REQUEST' ) ;
589+ expect ( res . payload . error . message ) . toContain ( sentence ) ;
590+ expect ( res . payload . error . message ) . not . toContain ( 'the reason is in the server log' ) ;
591+ expect ( res . payload . error . details ) . toEqual ( { targetNamespace } ) ;
592+ expect ( h . register ) . not . toHaveBeenCalled ( ) ;
593+ expect ( h . ledgerHas ( 'com.example.crm' ) ) . toBe ( false ) ;
594+ } ) ;
595+ }
596+ } ) ;
597+
598+ describe ( 'install-local — Q6 after a RENAMED copy: the managed install is admitted; after an unrenamed one, refused (#30794)' , ( ) => {
599+ // The ruling (record 6709037798, Q6 = B): a copy renamed into a namespace
600+ // of its own does not hold the source namespace, so a later managed
601+ // install of the same source package is not refused. A copy that kept the
602+ // source namespace still holds it, and Q6 (step 1f) refuses as written.
603+ const renamedCopyHeld : RegistryState = {
604+ owners : { acme : [ 'com.example.crm-copy' ] } ,
605+ packages : { 'com.example.crm-copy' : { manifest : { id : 'com.example.crm-copy' , namespace : 'acme' } } } ,
606+ } ;
607+ const unrenamedCopyHeld : RegistryState = {
608+ owners : { crm : [ 'com.example.crm-copy' ] } ,
609+ packages : { 'com.example.crm-copy' : { manifest : { id : 'com.example.crm-copy' , namespace : 'crm' } } } ,
610+ } ;
611+
612+ it ( 'beside a copy renamed to `acme`: the managed install of `com.example.crm` proceeds to its own steps' , async ( ) => {
613+ const h = await mount ( dir , { registry : renamedCopyHeld } ) ;
614+ const res = await h . install ( { manifest : crm ( { installModes : BOTH } ) } ) ;
615+ expect ( res . payload ?. error ?. code , JSON . stringify ( res . payload ) ) . not . toBe ( 'RESOURCE_CONFLICT' ) ;
616+ expect ( h . register ) . toHaveBeenCalledTimes ( 1 ) ;
617+ } ) ;
618+
619+ it ( 'TWIN: beside a copy that kept `crm`, the same install is refused 409 RESOURCE_CONFLICT, before any write' , async ( ) => {
620+ const h = await mount ( dir , { registry : unrenamedCopyHeld } ) ;
621+ const res = await h . install ( { manifest : crm ( { installModes : BOTH } ) } ) ;
622+ expect ( res . status ) . toBe ( 409 ) ;
623+ expect ( res . payload . error . code ) . toBe ( 'RESOURCE_CONFLICT' ) ;
624+ expect ( res . payload . error . details ) . toEqual ( { namespace : 'crm' , base : 'com.example.crm-copy' } ) ;
625+ expect ( h . register ) . not . toHaveBeenCalled ( ) ;
626+ expect ( h . ledgerHas ( 'com.example.crm' ) ) . toBe ( false ) ;
627+ } ) ;
628+ } ) ;
0 commit comments