@@ -836,6 +836,66 @@ describe('Package Version Create', () => {
836836 expect ( pkgTypeMembers [ 1 ] . members ) . to . deep . equal ( [ 'Test Profile' ] ) ;
837837 } ) ;
838838
839+ it ( 'should include profiles from all package directories when scopeProfiles is false' , async ( ) => {
840+ project . getSfProjectJson ( ) . set ( 'packageDirectories' , [
841+ { path : './src-access-management' , package : 'ACCESS' , versionName : 'ver 0.1' , versionNumber : '0.1.0.NEXT' } ,
842+ { path : 'force-app' , package : 'TEST' , versionName : 'ver 0.1' , versionNumber : '0.1.0.NEXT' , default : true } ,
843+ ] ) ;
844+ await project . getSfProjectJson ( ) . write ( ) ;
845+
846+ const siblingDir = path . join ( project . getPath ( ) , 'src-access-management' ) ;
847+ await fs . promises . mkdir ( siblingDir , { recursive : true } ) ;
848+ const fileContents = '<?xml version="1.0" encoding="UTF-8"?>' ;
849+ await fs . promises . writeFile ( path . join ( siblingDir , 'Sibling Profile.profile-meta.xml' ) , fileContents ) ;
850+ await fs . promises . writeFile (
851+ path . join ( project . getPath ( ) , 'force-app' , 'Target Profile.profile-meta.xml' ) ,
852+ fileContents
853+ ) ;
854+
855+ const pkgProfileApi = await PackageProfileApi . create ( { project, includeUserLicenses : false } ) ;
856+ const types = [
857+ { name : 'Layout' , members : [ 'Test Layout' ] } ,
858+ { name : 'Profile' , members : [ 'Sibling Profile' , 'Target Profile' ] } ,
859+ ] ;
860+
861+ // With no excludedDirectories (scopeProfiles=false), all profiles from all dirs are included
862+ const pkgTypeMembers = pkgProfileApi . filterAndGenerateProfilesForManifest ( types ) ;
863+ expect ( pkgTypeMembers . find ( ( t ) => t . name === 'Profile' ) ?. members ) . to . deep . equal ( [
864+ 'Sibling Profile' ,
865+ 'Target Profile' ,
866+ ] ) ;
867+ } ) ;
868+
869+ it ( 'should exclude profiles from ./-prefixed sibling package directories when scopeProfiles is true' , async ( ) => {
870+ // Configure a multi-directory project where sibling uses ./ prefix in path
871+ project . getSfProjectJson ( ) . set ( 'packageDirectories' , [
872+ { path : './src-access-management' , package : 'ACCESS' , versionName : 'ver 0.1' , versionNumber : '0.1.0.NEXT' } ,
873+ { path : 'force-app' , package : 'TEST' , versionName : 'ver 0.1' , versionNumber : '0.1.0.NEXT' , default : true } ,
874+ ] ) ;
875+ await project . getSfProjectJson ( ) . write ( ) ;
876+
877+ const siblingDir = path . join ( project . getPath ( ) , 'src-access-management' ) ;
878+ await fs . promises . mkdir ( siblingDir , { recursive : true } ) ;
879+ const fileContents = '<?xml version="1.0" encoding="UTF-8"?>' ;
880+ await fs . promises . writeFile ( path . join ( siblingDir , 'Sibling Profile.profile-meta.xml' ) , fileContents ) ;
881+ await fs . promises . writeFile (
882+ path . join ( project . getPath ( ) , 'force-app' , 'Target Profile.profile-meta.xml' ) ,
883+ fileContents
884+ ) ;
885+
886+ const pkgProfileApi = await PackageProfileApi . create ( { project, includeUserLicenses : false } ) ;
887+ const types = [
888+ { name : 'Layout' , members : [ 'Test Layout' ] } ,
889+ { name : 'Profile' , members : [ 'Sibling Profile' , 'Target Profile' ] } ,
890+ ] ;
891+
892+ // When scopeProfiles is true, packageVersionCreate passes sibling package dir paths
893+ // as excludedDirectories. These retain the ./ prefix from sfdx-project.json.
894+ const excludedDirectories = [ './src-access-management' ] ;
895+ const pkgTypeMembers = pkgProfileApi . filterAndGenerateProfilesForManifest ( types , excludedDirectories ) ;
896+ expect ( pkgTypeMembers . find ( ( t ) => t . name === 'Profile' ) ?. members ) . to . deep . equal ( [ 'Target Profile' ] ) ;
897+ } ) ;
898+
839899 describe ( 'validateAncestorId' , ( ) => {
840900 it ( 'should throw if the explicitUseNoAncestor is true and highestReleasedVersion is not undefined' , ( ) => {
841901 const ancestorId = 'ancestorId' ;
0 commit comments