1
- import { $ , fs , path , chalk } from 'zx' ;
2
- import { DEFAULT_AGENT_ID , DEFAULT_CHARACTER } from './test1.mjs' ;
3
1
import { spawn } from 'node:child_process' ;
4
- $ . verbose = false ; // Suppress command output unless there's an error
2
+ import { stringToUuid } from '../packages/core/dist/index.js' ;
3
+
4
+ export const DEFAULT_CHARACTER = "trump"
5
+ export const DEFAULT_AGENT_ID = stringToUuid ( DEFAULT_CHARACTER ?? uuidv4 ( ) ) ;
5
6
6
7
function projectRoot ( ) {
7
8
return path . join ( import . meta. dirname , ".." ) ;
8
9
}
9
10
10
11
async function runProcess ( command , args = [ ] , directory = projectRoot ( ) ) {
11
12
try {
12
- const result = await $ `cd ${ directory } && ${ command } ${ args } ` ;
13
+ throw new Exception ( "Not implemented yet" ) ; // TODO
14
+ // const result = await $`cd ${directory} && ${command} ${args}`;
13
15
return result . stdout . trim ( ) ;
14
16
} catch ( error ) {
15
17
throw new Error ( `Command failed: ${ error . message } ` ) ;
16
18
}
17
19
}
18
20
19
21
async function installProjectDependencies ( ) {
20
- console . log ( chalk . blue ( 'Installing dependencies...' ) ) ;
22
+ console . log ( 'Installing dependencies...' ) ;
21
23
return await runProcess ( 'pnpm' , [ 'install' , '-r' ] ) ;
22
24
}
23
25
24
26
async function buildProject ( ) {
25
- console . log ( chalk . blue ( 'Building project...' ) ) ;
27
+ console . log ( 'Building project...' ) ;
26
28
return await runProcess ( 'pnpm' , [ 'build' ] ) ;
27
29
}
28
30
@@ -34,18 +36,21 @@ async function writeEnvFile(entries) {
34
36
}
35
37
36
38
async function startAgent ( character = DEFAULT_CHARACTER ) {
37
- console . log ( chalk . blue ( `Starting agent for character: ${ character } ` ) ) ;
39
+ console . log ( `Starting agent for character: ${ character } ` ) ;
38
40
const proc = spawn ( 'pnpm' , [ 'start' , `--character=characters/${ character } .character.json` , '--non-interactive' ] , { shell : true , "stdio" : "inherit" } ) ;
39
41
log ( `proc=${ JSON . stringify ( proc ) } ` ) ;
40
42
41
- // Wait for server to be ready
42
- await new Promise ( resolve => setTimeout ( resolve , 60000 ) ) ;
43
+ sleep ( 60000 ) ; // Wait for server to be ready
43
44
return proc ;
44
45
}
45
46
46
47
async function stopAgent ( proc ) {
47
- console . log ( chalk . blue ( 'Stopping agent...' ) ) ;
48
- proc . kill ( 'SIGTERM' )
48
+ console . log ( 'Stopping agent...' ) ;
49
+ proc . kill ( 'SIGTERM' ) ;
50
+ }
51
+
52
+ async function sleep ( ms ) {
53
+ await new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
49
54
}
50
55
51
56
async function send ( message ) {
@@ -76,8 +81,18 @@ async function send(message) {
76
81
}
77
82
}
78
83
79
- function log ( message ) {
80
- console . log ( message ) ;
84
+ async function runIntegrationTest ( fn ) {
85
+ const proc = await startAgent ( ) ;
86
+ try {
87
+ fn ( ) ;
88
+ console . log ( '✓ Test passed' ) ;
89
+ } catch ( error ) {
90
+ console . error ( `✗ Test failed: ${ error . message } ` ) ;
91
+ console . log ( error ) ;
92
+ process . exit ( 1 ) ;
93
+ } finally {
94
+ await stopAgent ( proc ) ;
95
+ }
81
96
}
82
97
83
98
export {
@@ -89,5 +104,6 @@ export {
89
104
startAgent ,
90
105
stopAgent ,
91
106
send ,
107
+ runIntegrationTest ,
92
108
log
93
- }
109
+ }
0 commit comments