@@ -116,6 +116,67 @@ suite('DeepnoteServerStarter - Port Allocation Integration Tests', () => {
116116 warnStub . restore ( ) ;
117117 }
118118 } ) ;
119+
120+ test ( 'should return true when IPv6 is disabled (EAFNOSUPPORT error)' , async ( ) => {
121+ const port = 54324 ;
122+ const ipv6Error = new Error ( 'connect EAFNOSUPPORT ::1:54324' ) ;
123+ ( ipv6Error as any ) . code = 'EAFNOSUPPORT' ;
124+
125+ // IPv4 check succeeds (port is available)
126+ checkStub . onFirstCall ( ) . resolves ( false ) ;
127+
128+ // IPv6 check throws EAFNOSUPPORT (IPv6 not supported)
129+ checkStub . onSecondCall ( ) . rejects ( ipv6Error ) ;
130+
131+ const debugStub = sinon . stub ( logger , 'debug' ) ;
132+
133+ try {
134+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
135+ const isPortAvailable = getPrivateMethod ( serverStarter as any , 'isPortAvailable' ) ;
136+ const result = await isPortAvailable ( port ) ;
137+
138+ assert . isTrue ( result , 'Expected port to be available when IPv4 is free and IPv6 is not supported' ) ;
139+ assert . strictEqual ( checkStub . callCount , 2 , 'Should check both IPv4 and IPv6' ) ;
140+ assert . deepEqual ( checkStub . getCall ( 0 ) . args , [ port , '127.0.0.1' ] ) ;
141+ assert . deepEqual ( checkStub . getCall ( 1 ) . args , [ port , '::1' ] ) ;
142+ assert . isTrue (
143+ debugStub . calledWith ( 'IPv6 is not supported on this system' ) ,
144+ 'Should log debug message about IPv6 not being supported'
145+ ) ;
146+ } finally {
147+ debugStub . restore ( ) ;
148+ }
149+ } ) ;
150+
151+ test ( 'should return false when IPv6 check throws non-EAFNOSUPPORT error' , async ( ) => {
152+ const port = 54325 ;
153+ const ipv6Error = new Error ( 'Some other IPv6 error' ) ;
154+
155+ // IPv4 check succeeds (port is available)
156+ checkStub . onFirstCall ( ) . resolves ( false ) ;
157+
158+ // IPv6 check throws a different error
159+ checkStub . onSecondCall ( ) . rejects ( ipv6Error ) ;
160+
161+ const warnStub = sinon . stub ( logger , 'warn' ) ;
162+
163+ try {
164+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
165+ const isPortAvailable = getPrivateMethod ( serverStarter as any , 'isPortAvailable' ) ;
166+ const result = await isPortAvailable ( port ) ;
167+
168+ assert . isFalse (
169+ result ,
170+ 'Expected port check to fail closed when IPv6 check fails with non-EAFNOSUPPORT error'
171+ ) ;
172+ assert . strictEqual ( checkStub . callCount , 2 , 'Should check both IPv4 and IPv6' ) ;
173+ assert . isTrue ( warnStub . called , 'Should log warning when IPv6 check fails' ) ;
174+ const warnCall = warnStub . getCall ( 0 ) ;
175+ assert . include ( warnCall . args [ 0 ] , 'Failed to check IPv6 port availability' ) ;
176+ } finally {
177+ warnStub . restore ( ) ;
178+ }
179+ } ) ;
119180 } ) ;
120181
121182 suite ( 'findAvailablePort' , ( ) => {
0 commit comments