@@ -64,6 +64,39 @@ describe('nodePtyCompat', () => {
6464 ) ;
6565 } ) ;
6666
67+ test ( 'wrapConptyStartProcess retries with an appended boolean when native expects 7 args but JS sends 6' , ( ) => {
68+ const originalStartProcess = jest . fn ( ( ...args ) => {
69+ if ( args . length < 7 ) {
70+ throw new Error ( 'Usage: pty.startProcess(file, cols, rows, debug, pipeName, inheritCursor, useConptyDll)' ) ;
71+ }
72+ return { pty : 789 } ;
73+ } ) ;
74+ const nativeModule = { startProcess : originalStartProcess } ;
75+
76+ expect ( wrapConptyStartProcess ( nativeModule ) ) . toBe ( true ) ;
77+
78+ expect ( nativeModule . startProcess ( 'powershell.exe' , 120 , 40 , false , 'pipe-1' , true ) ) . toEqual ( { pty : 789 } ) ;
79+ expect ( originalStartProcess ) . toHaveBeenNthCalledWith (
80+ 1 ,
81+ 'powershell.exe' ,
82+ 120 ,
83+ 40 ,
84+ false ,
85+ 'pipe-1' ,
86+ true
87+ ) ;
88+ expect ( originalStartProcess ) . toHaveBeenNthCalledWith (
89+ 2 ,
90+ 'powershell.exe' ,
91+ 120 ,
92+ 40 ,
93+ false ,
94+ 'pipe-1' ,
95+ true ,
96+ false
97+ ) ;
98+ } ) ;
99+
67100 test ( 'wrapConptyConnect retries without useConptyDll on the native usage error' , ( ) => {
68101 const exitCallback = jest . fn ( ) ;
69102 const originalConnect = jest . fn ( ( ...args ) => {
@@ -96,6 +129,38 @@ describe('nodePtyCompat', () => {
96129 ) ;
97130 } ) ;
98131
132+ test ( 'wrapConptyConnect retries with inserted useConptyDll when native expects 6 args but JS sends 5' , ( ) => {
133+ const exitCallback = jest . fn ( ) ;
134+ const originalConnect = jest . fn ( ( ...args ) => {
135+ if ( args . length < 6 ) {
136+ throw new Error ( 'Usage: pty.connect(id, cmdline, cwd, env, useConptyDll, exitCallback)' ) ;
137+ }
138+ return { pid : 555 } ;
139+ } ) ;
140+ const nativeModule = { connect : originalConnect } ;
141+
142+ expect ( wrapConptyConnect ( nativeModule ) ) . toBe ( true ) ;
143+
144+ expect ( nativeModule . connect ( 7 , 'powershell.exe' , 'C:\\repo' , { PATH : 'x' } , exitCallback ) ) . toEqual ( { pid : 555 } ) ;
145+ expect ( originalConnect ) . toHaveBeenNthCalledWith (
146+ 1 ,
147+ 7 ,
148+ 'powershell.exe' ,
149+ 'C:\\repo' ,
150+ { PATH : 'x' } ,
151+ exitCallback
152+ ) ;
153+ expect ( originalConnect ) . toHaveBeenNthCalledWith (
154+ 2 ,
155+ 7 ,
156+ 'powershell.exe' ,
157+ 'C:\\repo' ,
158+ { PATH : 'x' } ,
159+ false ,
160+ exitCallback
161+ ) ;
162+ } ) ;
163+
99164 test ( 'wrapConptyCompatMethods adapts trailing boolean compatibility calls' , ( ) => {
100165 const originalResize = jest . fn ( ( ...args ) => {
101166 if ( args . length === 4 ) {
@@ -140,6 +205,53 @@ describe('nodePtyCompat', () => {
140205 expect ( originalKill ) . toHaveBeenCalledTimes ( 2 ) ;
141206 } ) ;
142207
208+ test ( 'wrapConptyCompatMethods adapts trailing boolean calls when native expects MORE args' , ( ) => {
209+ const originalResize = jest . fn ( ( ...args ) => {
210+ if ( args . length < 4 ) {
211+ throw new Error ( 'Usage: pty.resize(id, cols, rows, useConptyDll)' ) ;
212+ }
213+ return undefined ;
214+ } ) ;
215+ const originalClear = jest . fn ( ( ...args ) => {
216+ if ( args . length < 2 ) {
217+ throw new Error ( 'Usage: pty.clear(id, useConptyDll)' ) ;
218+ }
219+ return undefined ;
220+ } ) ;
221+ const originalKill = jest . fn ( ( ...args ) => {
222+ if ( args . length < 2 ) {
223+ throw new Error ( 'Usage: pty.kill(id, useConptyDll)' ) ;
224+ }
225+ return undefined ;
226+ } ) ;
227+ const nativeModule = {
228+ startProcess : jest . fn ( ( ) => ( { pty : 1 } ) ) ,
229+ connect : jest . fn ( ( ) => ( { pid : 2 } ) ) ,
230+ resize : originalResize ,
231+ clear : originalClear ,
232+ kill : originalKill
233+ } ;
234+
235+ expect ( wrapConptyCompatMethods ( nativeModule ) ) . toEqual ( [
236+ 'startProcess' ,
237+ 'connect' ,
238+ 'resize' ,
239+ 'clear' ,
240+ 'kill'
241+ ] ) ;
242+
243+ nativeModule . resize ( 1 , 120 , 40 ) ;
244+ nativeModule . clear ( 1 ) ;
245+ nativeModule . kill ( 1 ) ;
246+
247+ expect ( originalResize ) . toHaveBeenCalledTimes ( 2 ) ;
248+ expect ( originalResize ) . toHaveBeenNthCalledWith ( 2 , 1 , 120 , 40 , false ) ;
249+ expect ( originalClear ) . toHaveBeenCalledTimes ( 2 ) ;
250+ expect ( originalClear ) . toHaveBeenNthCalledWith ( 2 , 1 , false ) ;
251+ expect ( originalKill ) . toHaveBeenCalledTimes ( 2 ) ;
252+ expect ( originalKill ) . toHaveBeenNthCalledWith ( 2 , 1 , false ) ;
253+ } ) ;
254+
143255 test ( 'ensureWindowsNodePtyCompat wraps loadNativeModule for the affected Windows build' , ( ) => {
144256 const originalStartProcess = jest . fn ( ( ) => ( { pty : 789 } ) ) ;
145257 const originalConnect = jest . fn ( ( ) => ( { pid : 456 } ) ) ;
0 commit comments