@@ -47,9 +47,9 @@ async function writeEnvFile(entries) {
47
47
48
48
async function startAgent ( character = DEFAULT_CHARACTER ) {
49
49
log ( `Starting agent for character: ${ character } ` ) ;
50
- const proc = spawn ( "pnpm " , [ "start " , `--character=characters/${ character } .character.json` , ' --non-interactive' ] , {
51
- cwd : projectRoot ( ) ,
52
- shell : true ,
50
+ const proc = spawn ( "node " , [ "--loader " , "ts-node/esm" , "src/index.ts" , "--isRoot" , `--character=characters/${ character } .character.json` , " --non-interactive" ] , {
51
+ cwd : path . join ( projectRoot ( ) , "agent" ) ,
52
+ shell : false ,
53
53
stdio : "inherit"
54
54
} ) ;
55
55
log ( `proc=${ JSON . stringify ( proc ) } ` ) ;
@@ -62,19 +62,25 @@ async function startAgent(character = DEFAULT_CHARACTER) {
62
62
if ( Date . now ( ) - startTime > 120000 ) {
63
63
throw new Error ( "Timeout waiting for server to start" ) ;
64
64
} else {
65
- log ( "Waiting for the server to be ready..." ) ;
66
65
await sleep ( 1000 ) ;
67
66
}
68
67
}
69
- log ( "Server is ready" ) ;
70
68
await sleep ( 1000 ) ;
71
69
return proc ;
72
70
}
73
71
74
72
async function stopAgent ( proc ) {
75
- log ( "Stopping agent..." + JSON . stringify ( proc ) ) ;
76
- const q = proc . kill ( "SIGKILL" ) ;
77
- console . log ( q ) ;
73
+ log ( "Stopping agent..." + JSON . stringify ( proc . pid ) ) ;
74
+ proc . kill ( ) ;
75
+ const startTime = Date . now ( ) ;
76
+ while ( true ) {
77
+ if ( proc . killed ) break ;
78
+ if ( Date . now ( ) - startTime > 60000 ) {
79
+ throw new Error ( "Timeout waiting for the process to terminate" ) ;
80
+ }
81
+ await sleep ( 1000 ) ;
82
+ }
83
+ await sleep ( 1000 ) ;
78
84
}
79
85
80
86
async function sleep ( ms ) {
@@ -110,12 +116,11 @@ async function send(message) {
110
116
async function runIntegrationTest ( fn ) {
111
117
const proc = await startAgent ( ) ;
112
118
try {
113
- fn ( ) ;
119
+ await fn ( ) ;
114
120
log ( "✓ Test passed" ) ;
115
121
} catch ( error ) {
116
122
log ( "✗ Test failed" ) ;
117
123
logError ( error ) ;
118
- process . exit ( 1 ) ;
119
124
} finally {
120
125
await stopAgent ( proc ) ;
121
126
}
0 commit comments