@@ -40,16 +40,22 @@ describe('TtyWriter', () => {
4040 tty : '/dev/ttys030' ,
4141 } ;
4242
43- it ( 'sends message via tmux send-keys' , async ( ) => {
43+ it ( 'sends message and Enter as separate tmux send-keys calls ' , async ( ) => {
4444 mockExecFileSuccess ( ) ;
4545
4646 await TtyWriter . send ( location , 'continue' ) ;
4747
4848 expect ( mockedExecFile ) . toHaveBeenCalledWith (
4949 'tmux' ,
50- [ 'send-keys' , '-t' , 'main:0.1' , 'continue ' , 'Enter ' ] ,
50+ [ 'send-keys' , '-t' , 'main:0.1' , '-l ' , 'continue ' ] ,
5151 expect . any ( Function ) ,
5252 ) ;
53+ expect ( mockedExecFile ) . toHaveBeenCalledWith (
54+ 'tmux' ,
55+ [ 'send-keys' , '-t' , 'main:0.1' , 'Enter' ] ,
56+ expect . any ( Function ) ,
57+ ) ;
58+ expect ( mockedExecFile ) . toHaveBeenCalledTimes ( 2 ) ;
5359 } ) ;
5460
5561 it ( 'throws on tmux failure' , async ( ) => {
@@ -74,9 +80,12 @@ describe('TtyWriter', () => {
7480
7581 expect ( mockedExecFile ) . toHaveBeenCalledWith (
7682 'osascript' ,
77- [ '-e' , expect . stringContaining ( 'write text "hello"' ) ] ,
83+ [ '-e' , expect . stringContaining ( 'write text "hello" newline no ' ) ] ,
7884 expect . any ( Function ) ,
7985 ) ;
86+ const scriptArg = ( mockedExecFile . mock . calls [ 0 ] as unknown [ ] ) [ 1 ] as string [ ] ;
87+ const script = scriptArg [ 1 ] ;
88+ expect ( script ) . toContain ( 'key code 36' ) ;
8089 } ) ;
8190
8291 it ( 'escapes special characters in message' , async ( ) => {
@@ -86,7 +95,7 @@ describe('TtyWriter', () => {
8695
8796 expect ( mockedExecFile ) . toHaveBeenCalledWith (
8897 'osascript' ,
89- [ '-e' , expect . stringContaining ( 'write text "say \\"hi\\" \\\\ there"' ) ] ,
98+ [ '-e' , expect . stringContaining ( 'write text "say \\"hi\\" \\\\ there" newline no ' ) ] ,
9099 expect . any ( Function ) ,
91100 ) ;
92101 } ) ;
@@ -113,24 +122,11 @@ describe('TtyWriter', () => {
113122
114123 const scriptArg = ( mockedExecFile . mock . calls [ 0 ] as unknown [ ] ) [ 1 ] as string [ ] ;
115124 const script = scriptArg [ 1 ] ;
116- // Must use keystroke, NOT do script
117125 expect ( script ) . toContain ( 'keystroke "hello"' ) ;
118126 expect ( script ) . toContain ( 'key code 36' ) ;
119127 expect ( script ) . not . toContain ( 'do script' ) ;
120128 } ) ;
121129
122- it ( 'uses execFile to avoid shell injection' , async ( ) => {
123- mockExecFileSuccess ( 'ok' ) ;
124-
125- await TtyWriter . send ( location , "don't stop" ) ;
126-
127- expect ( mockedExecFile ) . toHaveBeenCalledWith (
128- 'osascript' ,
129- [ '-e' , expect . any ( String ) ] ,
130- expect . any ( Function ) ,
131- ) ;
132- } ) ;
133-
134130 it ( 'throws when tab not found' , async ( ) => {
135131 mockExecFileSuccess ( 'not_found' ) ;
136132
0 commit comments