@@ -21,6 +21,8 @@ import {
2121 MAX_UDS_INBOX_BYTES ,
2222 MAX_UDS_FRAME_BYTES ,
2323 MAX_UDS_CLIENTS ,
24+ MAX_UNIX_SOCKET_PATH_LENGTH ,
25+ assertValidUnixSocketPath ,
2426 formatUdsAddress ,
2527 parseUdsTarget ,
2628 sendUdsMessage ,
@@ -34,11 +36,23 @@ let previousConfigDir: string | undefined
3436let tempConfigDir = ''
3537
3638function socketPath ( label : string ) : string {
37- const suffix = `${ process . pid } -${ Date . now ( ) } - ${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } -${ label } `
39+ const suffix = `${ process . pid } -${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } -${ label } `
3840 if ( process . platform === 'win32' ) {
3941 return `\\\\.\\pipe\\claude-code-test-${ suffix } `
4042 }
41- return join ( tmpdir ( ) , 'claude-code-test' , `${ suffix } .sock` )
43+ const base =
44+ process . platform === 'darwin'
45+ ? '/tmp/claude-uds-test'
46+ : join ( tmpdir ( ) , 'cc-uds-test' )
47+ return join ( base , `${ suffix } .sock` )
48+ }
49+
50+ function shortTestDir ( prefix : string ) : string {
51+ const id = `${ process . pid } -${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } `
52+ if ( process . platform === 'darwin' ) {
53+ return join ( '/tmp' , `${ prefix } -${ id } ` )
54+ }
55+ return join ( tmpdir ( ) , `${ prefix } -${ id } ` )
4256}
4357
4458function sleep ( ms : number ) : Promise < void > {
@@ -499,6 +513,27 @@ describe('UDS inbox retention', () => {
499513 expect ( getDefaultUdsSocketPath ( ) ) . not . toBe ( firstPath )
500514 } )
501515
516+ test ( 'default socket path stays within AF_UNIX length limit' , ( ) => {
517+ const path = getDefaultUdsSocketPath ( )
518+ if ( process . platform === 'win32' ) return
519+ expect ( Buffer . byteLength ( path , 'utf8' ) ) . toBeLessThanOrEqual (
520+ MAX_UNIX_SOCKET_PATH_LENGTH ,
521+ )
522+ expect ( ( ) => assertValidUnixSocketPath ( path ) ) . not . toThrow ( )
523+ } )
524+
525+ test ( 'rejects socket paths longer than AF_UNIX limit' , ( ) => {
526+ if ( process . platform === 'win32' ) return
527+ const longPath = `/tmp/${ 'x' . repeat ( MAX_UNIX_SOCKET_PATH_LENGTH ) } .sock`
528+ expect ( ( ) => assertValidUnixSocketPath ( longPath ) ) . toThrow ( / m a x 1 0 4 / )
529+ } )
530+
531+ test ( 'default socket path can bind on Node.js' , async ( ) => {
532+ const path = getDefaultUdsSocketPath ( )
533+ await startUdsMessaging ( path , { isExplicit : true } )
534+ await stopUdsMessaging ( )
535+ } )
536+
502537 test ( 'rejects oversized receiver responses before retaining them' , async ( ) => {
503538 const path = socketPath ( 'oversized-response' )
504539 if ( process . platform !== 'win32' ) {
@@ -688,10 +723,7 @@ describe('UDS inbox retention', () => {
688723 } )
689724
690725 test ( 'fails closed when an explicit socket parent is not private' , async ( ) => {
691- const parent = join (
692- tmpdir ( ) ,
693- `uds-socket-parent-${ process . pid } -${ Date . now ( ) } -${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } ` ,
694- )
726+ const parent = shortTestDir ( 'uds-sp' )
695727 await mkdir ( parent , { recursive : true , mode : 0o755 } )
696728 await chmod ( parent , 0o755 )
697729
@@ -707,10 +739,7 @@ describe('UDS inbox retention', () => {
707739 } )
708740
709741 test ( 'fails closed when an explicit socket parent is a file' , async ( ) => {
710- const parentFile = join (
711- tmpdir ( ) ,
712- `uds-socket-parent-file-${ process . pid } -${ Date . now ( ) } -${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } ` ,
713- )
742+ const parentFile = shortTestDir ( 'uds-spf' )
714743 await writeFile ( parentFile , 'not a directory' , 'utf-8' )
715744
716745 try {
0 commit comments