@@ -16,29 +16,75 @@ function envFile(contents) {
1616 return file
1717}
1818
19+ function doctorArgs ( file , ...extraArgs ) {
20+ return [ script , `--env-file=${ file } ` , '--skip-tools' , ...extraArgs ]
21+ }
22+
1923test ( 'accepts the default core profile with an empty Chrome suffix' , ( ) => {
20- const output = execFileSync ( process . execPath , [ script , `--env-file= ${ envFile ( validCore ) } ` ] , {
24+ const output = execFileSync ( process . execPath , doctorArgs ( envFile ( validCore ) ) , {
2125 cwd : root ,
2226 encoding : 'utf8' ,
2327 } )
2428 assert . match ( output , / E n v i r o n m e n t r e a d y : c o r e / )
2529} )
2630
2731test ( 'rejects embedded Chrome without the image suffix' , ( ) => {
28- const result = spawnSync ( process . execPath , [ script , `--env-file=${ envFile ( validCore ) } ` , '--profiles=embedded-chrome' ] , {
32+ const result = spawnSync (
33+ process . execPath ,
34+ doctorArgs ( envFile ( validCore ) , '--profiles=embedded-chrome' ) ,
35+ {
36+ cwd : root ,
37+ encoding : 'utf8' ,
38+ } ,
39+ )
40+ assert . notEqual ( result . status , 0 )
41+ assert . match ( result . stderr , / C H R O M E _ S U F F I X (?: i s r e q u i r e d | m u s t b e - c h r o m e ) / )
42+ } )
43+
44+ test ( 'accepts AGENT_REGISTER=off without a central URL' , ( ) => {
45+ const file = envFile ( `${ validCore } AGENT_REGISTER=off\n` )
46+ const output = execFileSync ( process . execPath , doctorArgs ( file , '--profiles=agent' ) , {
2947 cwd : root ,
3048 encoding : 'utf8' ,
3149 } )
32- assert . notEqual ( result . status , 0 )
33- assert . match ( result . stderr , / C H R O M E _ S U F F I X (?: i s r e q u i r e d | m u s t b e - c h r o m e ) / )
50+ assert . match ( output , / E n v i r o n m e n t r e a d y : c o r e , a g e n t / )
51+ } )
52+
53+ test ( 'allows active registration modes to skip auto-registration without a central URL' , ( ) => {
54+ for ( const registration of [ 'http' , 'ws' ] ) {
55+ const file = envFile ( `${ validCore } AGENT_REGISTER=${ registration } \n` )
56+ const output = execFileSync ( process . execPath , doctorArgs ( file , '--profiles=agent' ) , {
57+ cwd : root ,
58+ encoding : 'utf8' ,
59+ } )
60+ assert . match ( output , / C E N T R A L _ A P I _ U R L i s e m p t y ; a u t o - r e g i s t r a t i o n i s d i s a b l e d / )
61+ }
3462} )
3563
36- test ( 'rejects HTTP agent registration without an advertised URL' , ( ) => {
64+ test ( 'accepts HTTP registration with an auto-detected advertised URL' , ( ) => {
3765 const file = envFile ( `${ validCore } CENTRAL_API_URL=http://center:8031\nAGENT_REGISTER=http\n` )
38- const result = spawnSync ( process . execPath , [ script , `--env-file=${ file } ` , '--profiles=agent' ] , {
66+ const output = execFileSync ( process . execPath , doctorArgs ( file , '--profiles=agent' ) , {
67+ cwd : root ,
68+ encoding : 'utf8' ,
69+ } )
70+ assert . match ( output , / A G E N T _ A D V E R T I S E _ U R L i s e m p t y ; t h e a g e n t U R L w i l l b e a u t o - d e t e c t e d / )
71+ } )
72+
73+ test ( 'accepts WS registration with an auto-detected advertised URL' , ( ) => {
74+ const file = envFile ( `${ validCore } CENTRAL_API_URL=http://center:8031\nAGENT_REGISTER=ws\n` )
75+ const output = execFileSync ( process . execPath , doctorArgs ( file , '--profiles=agent' ) , {
76+ cwd : root ,
77+ encoding : 'utf8' ,
78+ } )
79+ assert . match ( output , / E n v i r o n m e n t r e a d y : c o r e , a g e n t / )
80+ } )
81+
82+ test ( 'rejects an unsupported agent registration mode' , ( ) => {
83+ const file = envFile ( `${ validCore } AGENT_REGISTER=udp\n` )
84+ const result = spawnSync ( process . execPath , doctorArgs ( file , '--profiles=agent' ) , {
3985 cwd : root ,
4086 encoding : 'utf8' ,
4187 } )
4288 assert . notEqual ( result . status , 0 )
43- assert . match ( result . stderr , / A G E N T _ A D V E R T I S E _ U R L i s r e q u i r e d / )
89+ assert . match ( result . stderr , / A G E N T _ R E G I S T E R m u s t b e h t t p , w s , o r o f f / )
4490} )
0 commit comments