@@ -371,6 +371,96 @@ export const getServers = {
371371 } ,
372372} ;
373373
374+ // Regression: dns.lookup() with all:true and family:0 must return family:6 for
375+ // IPv6 addresses (was returning family:4 due to copy-paste bug).
376+ export const lookupAllFamilyZeroIPv6Family = {
377+ async test ( ) {
378+ const results = await dnsPromises . lookup ( addresses . INET_HOST , {
379+ all : true ,
380+ family : 0 ,
381+ } ) ;
382+ ok ( Array . isArray ( results ) , 'expected array of addresses' ) ;
383+ ok ( results . length > 0 , 'expected at least one address' ) ;
384+
385+ for ( const entry of results ) {
386+ strictEqual ( typeof entry . address , 'string' ) ;
387+ ok (
388+ entry . family === 4 || entry . family === 6 ,
389+ `family must be 4 or 6, got ${ entry . family } `
390+ ) ;
391+ }
392+
393+ // If any IPv6 addresses are returned, they must have family:6
394+ const ipv6Entries = results . filter ( ( e ) => e . address . includes ( ':' ) ) ;
395+ for ( const entry of ipv6Entries ) {
396+ strictEqual (
397+ entry . family ,
398+ 6 ,
399+ `IPv6 address ${ entry . address } should have family:6 but got family:${ entry . family } `
400+ ) ;
401+ }
402+
403+ // If any IPv4 addresses are returned, they must have family:4
404+ const ipv4Entries = results . filter ( ( e ) => ! e . address . includes ( ':' ) ) ;
405+ for ( const entry of ipv4Entries ) {
406+ strictEqual (
407+ entry . family ,
408+ 4 ,
409+ `IPv4 address ${ entry . address } should have family:4 but got family:${ entry . family } `
410+ ) ;
411+ }
412+ } ,
413+ } ;
414+
415+ // Regression: dns.lookup() with default family (0) and all:false must resolve
416+ // hosts that only have A records (was only querying AAAA, failing for IPv4-only).
417+ export const lookupDefaultFamilyResolvesIPv4 = {
418+ async test ( ) {
419+ // Default options (family:0, all:false) — should return an address
420+ const result = await dnsPromises . lookup ( addresses . INET4_HOST ) ;
421+ ok ( result != null , 'expected a result' ) ;
422+ strictEqual ( typeof result . address , 'string' ) ;
423+ ok ( result . address . length > 0 , 'expected non-empty address' ) ;
424+ ok (
425+ result . family === 4 || result . family === 6 ,
426+ `family must be 4 or 6, got ${ result . family } `
427+ ) ;
428+
429+ // Also verify via callback API
430+ const { promise, resolve, reject } = Promise . withResolvers ( ) ;
431+ dns . lookup ( addresses . INET4_HOST , ( error , address , family ) => {
432+ if ( error ) {
433+ reject ( error ) ;
434+ return ;
435+ }
436+ strictEqual ( typeof address , 'string' ) ;
437+ ok ( address . length > 0 , 'expected non-empty address from callback' ) ;
438+ ok ( family === 4 || family === 6 , `family must be 4 or 6, got ${ family } ` ) ;
439+ resolve ( ) ;
440+ } ) ;
441+ await promise ;
442+ } ,
443+ } ;
444+
445+ // Regression: Resolver.resolvePtr must exist (was misspelled as 'esolvePtr').
446+ export const resolverResolvePtrExists = {
447+ async test ( ) {
448+ const resolver = new dnsPromises . Resolver ( ) ;
449+ strictEqual (
450+ typeof resolver . resolvePtr ,
451+ 'function' ,
452+ 'Resolver.resolvePtr should be a function'
453+ ) ;
454+ // Actually call it to verify it works end-to-end
455+ const result = await resolver . resolvePtr ( addresses . PTR_HOST ) ;
456+ ok ( Array . isArray ( result ) , 'expected array result' ) ;
457+ ok ( result . length > 0 , 'expected at least one PTR record' ) ;
458+ for ( const item of result ) {
459+ strictEqual ( typeof item , 'string' ) ;
460+ }
461+ } ,
462+ } ;
463+
374464// Tests are taken from
375465// https://github.com/nodejs/node/blob/3153c8333e3a8f2015b795642def4d81ec7cd7b3/test/parallel/test-dns-lookup.js
376466export const testDnsLookup = {
0 commit comments