99 ServeTestingWorkerMessage ,
1010 ServeTestingWorkerResponseMessage ,
1111} from '../workers/serve-testing/worker-types.js' ;
12- import { EvalID , Executor } from './executors/executor.js' ;
12+ import { EvalID } from './executors/executor.js' ;
1313import { BrowserAgentTaskInput } from '../testing/browser-agent/models.js' ;
1414import PQueue from 'p-queue' ;
1515
@@ -24,61 +24,71 @@ export async function serveAndTestApp(
2424 abortSignal : AbortSignal ,
2525 progress : ProgressLogger ,
2626 userJourneyAgentTaskInput ?: BrowserAgentTaskInput ,
27- ) : Promise < ServeTestingResult > {
27+ ) : Promise < ServeTestingResult | null > {
28+ if ( env . executor . serveWebApplication === null ) {
29+ return null ;
30+ }
31+
2832 progress . log ( rootPromptDef , 'serve-testing' , `Validating the running app` ) ;
2933
30- const result = await env . executor . serveWebApplication (
31- evalID ,
32- appDirectoryPath ,
33- rootPromptDef ,
34- progress ,
35- async serveUrl => {
36- const serveParams : ServeTestingWorkerMessage = {
37- serveUrl,
38- appName : rootPromptDef . name ,
39- enableAutoCsp : ! ! config . enableAutoCsp ,
40- includeAxeTesting : config . skipAxeTesting === false ,
41- takeScreenshots : config . skipScreenshots === false ,
42- includeLighthouseData : config . skipLighthouse !== true ,
43- userJourneyAgentTaskInput,
44- } ;
34+ try {
35+ const result = await env . executor . serveWebApplication (
36+ evalID ,
37+ appDirectoryPath ,
38+ rootPromptDef ,
39+ progress ,
40+ async serveUrl => {
41+ const serveParams : ServeTestingWorkerMessage = {
42+ serveUrl,
43+ appName : rootPromptDef . name ,
44+ enableAutoCsp : ! ! config . enableAutoCsp ,
45+ includeAxeTesting : config . skipAxeTesting === false ,
46+ takeScreenshots : config . skipScreenshots === false ,
47+ includeLighthouseData : config . skipLighthouse !== true ,
48+ userJourneyAgentTaskInput,
49+ } ;
4550
46- return await workerConcurrencyQueue . add (
47- ( ) =>
48- new Promise < ServeTestingResult > ( ( resolve , reject ) => {
49- const child : ChildProcess = fork (
50- path . resolve ( import . meta. dirname , '../workers/serve-testing/worker.js' ) ,
51- { signal : abortSignal } ,
52- ) ;
53- child . send ( serveParams ) ;
51+ return await workerConcurrencyQueue . add (
52+ ( ) =>
53+ new Promise < ServeTestingResult > ( ( resolve , reject ) => {
54+ const child : ChildProcess = fork (
55+ path . resolve ( import . meta. dirname , '../workers/serve-testing/worker.js' ) ,
56+ { signal : abortSignal } ,
57+ ) ;
58+ child . send ( serveParams ) ;
5459
55- child . on ( 'message' , async ( result : ServeTestingWorkerResponseMessage ) => {
56- if ( result . type === 'result' ) {
60+ child . on ( 'message' , async ( result : ServeTestingWorkerResponseMessage ) => {
61+ if ( result . type === 'result' ) {
62+ await killChildProcessGracefully ( child ) ;
63+ resolve ( result . payload ) ;
64+ } else {
65+ progress . log (
66+ rootPromptDef ,
67+ result . payload . state ,
68+ result . payload . message ,
69+ result . payload . details ,
70+ ) ;
71+ }
72+ } ) ;
73+ child . on ( 'error' , async err => {
5774 await killChildProcessGracefully ( child ) ;
58- resolve ( result . payload ) ;
59- } else {
60- progress . log (
61- rootPromptDef ,
62- result . payload . state ,
63- result . payload . message ,
64- result . payload . details ,
65- ) ;
66- }
67- } ) ;
68- child . on ( 'error' , async err => {
69- await killChildProcessGracefully ( child ) ;
70- reject ( err ) ;
71- } ) ;
72- } ) ,
73- ) ;
74- } ,
75- ) ;
75+ reject ( err ) ;
76+ } ) ;
77+ } ) ,
78+ ) ;
79+ } ,
80+ ) ;
81+
82+ if ( result . errorMessage === undefined ) {
83+ progress . log ( rootPromptDef , 'success' , 'Validation of running app is successful' ) ;
84+ } else {
85+ progress . log ( rootPromptDef , 'error' , 'Validation of running app failed' , result . errorMessage ) ;
86+ }
7687
77- if ( result . errorMessage === undefined ) {
78- progress . log ( rootPromptDef , 'success' , 'Testing is successful' ) ;
79- } else {
80- progress . log ( rootPromptDef , 'error' , 'Testing has failed' , result . errorMessage ) ;
88+ return result ;
89+ } catch ( e ) {
90+ progress . log ( rootPromptDef , 'error' , 'Error while trying to validate running app' , `${ e } ` ) ;
8191 }
8292
83- return result ;
93+ return null ;
8494}
0 commit comments