@@ -66,7 +66,7 @@ describe('terminal utils', () => {
6666 it ( 'returns width from the immediate parent tty when available' , ( ) => {
6767 pinPosixPlatform ( ) ;
6868 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
69- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
69+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
7070 return '1234 ttys001\n' ;
7171 }
7272
@@ -79,23 +79,23 @@ describe('terminal utils', () => {
7979
8080 expect ( getTerminalWidth ( ) ) . toBe ( 120 ) ;
8181 expect ( mockExecFileSync . mock . calls . map ( ( [ file , args ] ) => `${ file as string } ${ ( args as string [ ] ) . join ( ' ' ) } ` ) ) . toEqual ( [
82- `ps -o ppid=, tty= -p ${ process . pid } ` ,
82+ `ps -o ppid= -o tty= -p ${ process . ppid } ` ,
8383 'stty -F /dev/ttys001 size'
8484 ] ) ;
8585 } ) ;
8686
8787 it ( 'walks ancestor processes until it finds a valid tty' , ( ) => {
8888 pinPosixPlatform ( ) ;
8989 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
90- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
90+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
9191 return '1234 ?\n' ;
9292 }
9393
94- if ( file === 'ps' && args . join ( ' ' ) === '-o ppid=, tty= -p 1234' ) {
94+ if ( file === 'ps' && args . join ( ' ' ) === '-o ppid= -o tty= -p 1234' ) {
9595 return '5678 ??\n' ;
9696 }
9797
98- if ( file === 'ps' && args . join ( ' ' ) === '-o ppid=, tty= -p 5678' ) {
98+ if ( file === 'ps' && args . join ( ' ' ) === '-o ppid= -o tty= -p 5678' ) {
9999 return '1 ttys009\n' ;
100100 }
101101
@@ -109,11 +109,30 @@ describe('terminal utils', () => {
109109 expect ( getTerminalWidth ( ) ) . toBe ( 104 ) ;
110110 } ) ;
111111
112+ it ( 'reads the current generation TTY even when its PPID ends the walk' , ( ) => {
113+ pinPosixPlatform ( ) ;
114+ // A PPID of 0 terminates the walk after this row, not before it:
115+ // the parent's own width must still win over the tput fallback.
116+ mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
117+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
118+ return '0 ttys001\n' ;
119+ }
120+
121+ if ( file === 'stty' && args . join ( ' ' ) === '-F /dev/ttys001 size' ) {
122+ return '24 120\n' ;
123+ }
124+
125+ throw new Error ( `Unexpected command: ${ file } ${ args . join ( ' ' ) } ` ) ;
126+ } ) ;
127+
128+ expect ( getTerminalWidth ( ) ) . toBe ( 120 ) ;
129+ } ) ;
130+
112131 it ( 'falls back through stty variants when the first form returns no value' , ( ) => {
113132 pinPosixPlatform ( ) ;
114133 // Simulates BSD/macOS, where `stty -F` exits with an error; `stty -f` succeeds.
115134 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
116- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
135+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
117136 return '1234 ttys003\n' ;
118137 }
119138
@@ -144,11 +163,11 @@ describe('terminal utils', () => {
144163 it ( 'returns null when ancestor and fallback probes all fail' , ( ) => {
145164 pinPosixPlatform ( ) ;
146165 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
147- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
166+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
148167 return '1234 ttys001\n' ;
149168 }
150169
151- if ( file === 'ps' && args . join ( ' ' ) === '-o ppid=, tty= -p 1234' ) {
170+ if ( file === 'ps' && args . join ( ' ' ) === '-o ppid= -o tty= -p 1234' ) {
152171 return '0 ttys001\n' ;
153172 }
154173
@@ -169,15 +188,15 @@ describe('terminal utils', () => {
169188 it ( 'detects availability when an ancestor tty probe succeeds' , ( ) => {
170189 pinPosixPlatform ( ) ;
171190 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
172- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
191+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
173192 return '1234 ?\n' ;
174193 }
175194
176- if ( file === 'ps' && args . join ( ' ' ) === '-o ppid=, tty= -p 1234' ) {
195+ if ( file === 'ps' && args . join ( ' ' ) === '-o ppid= -o tty= -p 1234' ) {
177196 return '5678 ??\n' ;
178197 }
179198
180- if ( file === 'ps' && args . join ( ' ' ) === '-o ppid=, tty= -p 5678' ) {
199+ if ( file === 'ps' && args . join ( ' ' ) === '-o ppid= -o tty= -p 5678' ) {
181200 return '1 ttys010\n' ;
182201 }
183202
@@ -211,7 +230,7 @@ describe('terminal utils', () => {
211230 process . env . CCSTATUSLINE_WIDTH = '0' ;
212231
213232 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
214- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
233+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
215234 return '1234 ttys001\n' ;
216235 }
217236
@@ -230,7 +249,7 @@ describe('terminal utils', () => {
230249 process . env . CCSTATUSLINE_WIDTH = 'wide' ;
231250
232251 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
233- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
252+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
234253 return '1234 ttys001\n' ;
235254 }
236255
@@ -264,7 +283,7 @@ describe('terminal utils', () => {
264283 it ( 'probes only once across repeated calls when a width is found' , ( ) => {
265284 pinPosixPlatform ( ) ;
266285 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
267- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
286+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
268287 return '1234 ttys001\n' ;
269288 }
270289
@@ -280,7 +299,7 @@ describe('terminal utils', () => {
280299 expect ( canDetectTerminalWidth ( ) ) . toBe ( true ) ;
281300
282301 const ppidProbes = mockExecFileSync . mock . calls . filter (
283- call => call [ 0 ] === 'ps' && Array . isArray ( call [ 1 ] ) && ( call [ 1 ] ) [ 1 ] === 'ppid=,tty= '
302+ call => call [ 0 ] === 'ps' && Array . isArray ( call [ 1 ] ) && ( call [ 1 ] ) [ 1 ] === 'ppid='
284303 ) ;
285304 expect ( ppidProbes ) . toHaveLength ( 1 ) ;
286305 } ) ;
@@ -300,7 +319,7 @@ describe('terminal utils', () => {
300319 expect ( canDetectTerminalWidth ( ) ) . toBe ( false ) ;
301320
302321 const ppidProbes = mockExecFileSync . mock . calls . filter (
303- call => call [ 0 ] === 'ps' && Array . isArray ( call [ 1 ] ) && ( call [ 1 ] ) [ 1 ] === 'ppid=,tty= '
322+ call => call [ 0 ] === 'ps' && Array . isArray ( call [ 1 ] ) && ( call [ 1 ] ) [ 1 ] === 'ppid='
304323 ) ;
305324 expect ( ppidProbes ) . toHaveLength ( 1 ) ;
306325 } ) ;
@@ -401,7 +420,7 @@ describe('terminal utils', () => {
401420 it ( 'never persists a discovered numeric width to the L2 cache' , ( ) => {
402421 pinPosixPlatform ( ) ;
403422 mockExecFileSync . mockImplementation ( ( file : string , args : string [ ] ) => {
404- if ( file === 'ps' && args . join ( ' ' ) === `-o ppid=, tty= -p ${ process . pid } ` ) {
423+ if ( file === 'ps' && args . join ( ' ' ) === `-o ppid= -o tty= -p ${ process . ppid } ` ) {
405424 return '1234 ttys001\n' ;
406425 }
407426
0 commit comments