@@ -568,10 +568,10 @@ describe('docker-manager', () => {
568568 expect ( volumes ) . toContain ( '/etc/ca-certificates:/host/etc/ca-certificates:ro' ) ;
569569 expect ( volumes ) . toContain ( '/etc/alternatives:/host/etc/alternatives:ro' ) ;
570570 expect ( volumes ) . toContain ( '/etc/ld.so.cache:/host/etc/ld.so.cache:ro' ) ;
571- // /etc/hosts is now always a custom chroot- hosts file in chroot mode (for pre-resolved domains)
571+ // /etc/hosts is always a custom hosts file in a secure chroot temp dir (for pre-resolved domains)
572572 const hostsVolume = volumes . find ( ( v : string ) => v . includes ( '/host/etc/hosts' ) ) ;
573573 expect ( hostsVolume ) . toBeDefined ( ) ;
574- expect ( hostsVolume ) . toContain ( ' chroot-hosts:/host/etc/hosts:ro' ) ;
574+ expect ( hostsVolume ) . toMatch ( / c h r o o t - . * \/ h o s t s : \ /h o s t \ /e t c \ /h o s t s : r o / ) ;
575575
576576 // Should still include essential mounts
577577 expect ( volumes ) . toContain ( '/tmp:/tmp:rw' ) ;
@@ -799,7 +799,7 @@ describe('docker-manager', () => {
799799 // Should mount a read-only copy of /etc/hosts with host.docker.internal pre-injected
800800 const hostsVolume = volumes . find ( ( v : string ) => v . includes ( '/host/etc/hosts' ) ) ;
801801 expect ( hostsVolume ) . toBeDefined ( ) ;
802- expect ( hostsVolume ) . toContain ( ' chroot-hosts:/host/etc/hosts:ro' ) ;
802+ expect ( hostsVolume ) . toMatch ( / c h r o o t - . * \/ h o s t s : \ /h o s t \ /e t c \ /h o s t s : r o / ) ;
803803 } ) ;
804804
805805 it ( 'should inject host.docker.internal into chroot-hosts file' , ( ) => {
@@ -810,8 +810,10 @@ describe('docker-manager', () => {
810810 } ;
811811 generateDockerCompose ( config , mockNetworkConfig ) ;
812812
813- // The chroot-hosts file should exist and contain host.docker.internal
814- const chrootHostsPath = `${ mockConfig . workDir } /chroot-hosts` ;
813+ // Find the chroot hosts file (mkdtempSync creates chroot-XXXXXX directory)
814+ const chrootDir = fs . readdirSync ( mockConfig . workDir ) . find ( d => d . startsWith ( 'chroot-' ) ) ;
815+ expect ( chrootDir ) . toBeDefined ( ) ;
816+ const chrootHostsPath = `${ mockConfig . workDir } /${ chrootDir } /hosts` ;
815817 expect ( fs . existsSync ( chrootHostsPath ) ) . toBe ( true ) ;
816818 const content = fs . readFileSync ( chrootHostsPath , 'utf8' ) ;
817819 // Docker bridge gateway resolution may succeed or fail in test env,
@@ -829,10 +831,10 @@ describe('docker-manager', () => {
829831 const agent = result . services . agent ;
830832 const volumes = agent . volumes as string [ ] ;
831833
832- // Should mount a custom chroot- hosts file (for pre-resolved domains)
834+ // Should mount a custom hosts file in a secure chroot temp dir (for pre-resolved domains)
833835 const hostsVolume = volumes . find ( ( v : string ) => v . includes ( '/host/etc/hosts' ) ) ;
834836 expect ( hostsVolume ) . toBeDefined ( ) ;
835- expect ( hostsVolume ) . toContain ( ' chroot-hosts:/host/etc/hosts:ro' ) ;
837+ expect ( hostsVolume ) . toMatch ( / c h r o o t - . * \/ h o s t s : \ /h o s t \ /e t c \ /h o s t s : r o / ) ;
836838 } ) ;
837839
838840 it ( 'should pre-resolve allowed domains into chroot-hosts file' , ( ) => {
@@ -859,7 +861,10 @@ describe('docker-manager', () => {
859861 } ;
860862 generateDockerCompose ( config , mockNetworkConfig ) ;
861863
862- const chrootHostsPath = `${ mockConfig . workDir } /chroot-hosts` ;
864+ // Find the chroot hosts file (mkdtempSync creates chroot-XXXXXX directory)
865+ const chrootDir = fs . readdirSync ( mockConfig . workDir ) . find ( d => d . startsWith ( 'chroot-' ) ) ;
866+ expect ( chrootDir ) . toBeDefined ( ) ;
867+ const chrootHostsPath = `${ mockConfig . workDir } /${ chrootDir } /hosts` ;
863868 expect ( fs . existsSync ( chrootHostsPath ) ) . toBe ( true ) ;
864869 const content = fs . readFileSync ( chrootHostsPath , 'utf8' ) ;
865870
@@ -887,7 +892,10 @@ describe('docker-manager', () => {
887892 // Should not throw even if resolution fails
888893 generateDockerCompose ( config , mockNetworkConfig ) ;
889894
890- const chrootHostsPath = `${ mockConfig . workDir } /chroot-hosts` ;
895+ // Find the chroot hosts file (mkdtempSync creates chroot-XXXXXX directory)
896+ const chrootDir = fs . readdirSync ( mockConfig . workDir ) . find ( d => d . startsWith ( 'chroot-' ) ) ;
897+ expect ( chrootDir ) . toBeDefined ( ) ;
898+ const chrootHostsPath = `${ mockConfig . workDir } /${ chrootDir } /hosts` ;
891899 expect ( fs . existsSync ( chrootHostsPath ) ) . toBe ( true ) ;
892900 const content = fs . readFileSync ( chrootHostsPath , 'utf8' ) ;
893901
@@ -916,7 +924,10 @@ describe('docker-manager', () => {
916924 } ;
917925 generateDockerCompose ( config , mockNetworkConfig ) ;
918926
919- const chrootHostsPath = `${ mockConfig . workDir } /chroot-hosts` ;
927+ // Find the chroot hosts file (mkdtempSync creates chroot-XXXXXX directory)
928+ const chrootDir = fs . readdirSync ( mockConfig . workDir ) . find ( d => d . startsWith ( 'chroot-' ) ) ;
929+ expect ( chrootDir ) . toBeDefined ( ) ;
930+ const chrootHostsPath = `${ mockConfig . workDir } /${ chrootDir } /hosts` ;
920931 const content = fs . readFileSync ( chrootHostsPath , 'utf8' ) ;
921932
922933 // Count occurrences of 'localhost' - should only be the original entries, not duplicated
0 commit comments