11import assert from "node:assert/strict" ;
22import { chmod , copyFile , mkdir , mkdtemp , readFile , rm , writeFile } from "node:fs/promises" ;
3- import { spawnSync } from "node:child_process" ;
3+ import { spawn , spawnSync } from "node:child_process" ;
44import { tmpdir } from "node:os" ;
55import { dirname , join , resolve } from "node:path" ;
66import { test } from "node:test" ;
@@ -21,6 +21,45 @@ function shellQuote(value) {
2121 return `'${ value . replaceAll ( "'" , `'\\''` ) } '` ;
2222}
2323
24+ function runScriptPTY ( command , input , env ) {
25+ return new Promise ( ( resolve , reject ) => {
26+ const child = spawn (
27+ "script" ,
28+ [ "-qefc" , `${ shellQuote ( command ) } setup` , "/dev/null" ] ,
29+ { env, stdio : [ "pipe" , "pipe" , "pipe" ] }
30+ ) ;
31+ let stdout = "" ;
32+ let stderr = "" ;
33+ let interruptScheduled = false ;
34+ let interrupt ;
35+ const scheduleInterrupt = ( ) => {
36+ if ( interruptScheduled || ! `${ stdout } \n${ stderr } ` . includes ( "future GitHub syncs authenticate?" ) ) return ;
37+ interruptScheduled = true ;
38+ interrupt = setTimeout ( ( ) => {
39+ if ( child . exitCode === null ) child . stdin . write ( "\x03" ) ;
40+ } , 100 ) ;
41+ } ;
42+ child . stdout . setEncoding ( "utf8" ) ;
43+ child . stderr . setEncoding ( "utf8" ) ;
44+ child . stdout . on ( "data" , ( chunk ) => {
45+ stdout += chunk ;
46+ scheduleInterrupt ( ) ;
47+ } ) ;
48+ child . stderr . on ( "data" , ( chunk ) => {
49+ stderr += chunk ;
50+ scheduleInterrupt ( ) ;
51+ } ) ;
52+ child . on ( "error" , reject ) ;
53+ const timeout = setTimeout ( ( ) => child . kill ( "SIGKILL" ) , 20_000 ) ;
54+ child . on ( "close" , ( status ) => {
55+ clearTimeout ( timeout ) ;
56+ clearTimeout ( interrupt ) ;
57+ resolve ( { status, stdout, stderr } ) ;
58+ } ) ;
59+ child . stdin . write ( input ) ;
60+ } ) ;
61+ }
62+
2463async function packCurrentPlatform ( workspace ) {
2564 const platform = platforms [ `${ process . platform } -${ process . arch } ` ] ;
2665 assert . ok ( platform , `unsupported test platform ${ process . platform } -${ process . arch } ` ) ;
@@ -183,7 +222,7 @@ test(
183222 const home = join ( workspace , "home" ) ;
184223 await mkdir ( join ( home , ".codex" ) , { recursive : true } ) ;
185224 const command = join ( runner , "node_modules" , ".bin" , "gitcontribute" ) ;
186- const input = "\x1b]11;rgb:0000/0000/0000\x07\x1b[1;1R\r\x1b[Z\x1b[B\r\x03 " ;
225+ const input = "\x1b]11;rgb:0000/0000/0000\x07\x1b[1;1R\r\x1b[Z\x1b[B\r" ;
187226 const env = {
188227 ...process . env ,
189228 HOME : home ,
@@ -236,11 +275,7 @@ exit [lindex $result 3]`,
236275 ] ,
237276 { encoding : "utf8" , env }
238277 )
239- : spawnSync ( "script" , [ "-qefc" , `${ shellQuote ( command ) } setup` , "/dev/null" ] , {
240- encoding : "utf8" ,
241- env,
242- input,
243- } ) ;
278+ : await runScriptPTY ( command , input , env ) ;
244279
245280 assert . ok (
246281 result . status === 0 || ( process . platform !== "darwin" && result . status === 130 ) ,
0 commit comments