@@ -860,6 +860,102 @@ t.test('user-agent', t => {
860860 t . end ( )
861861} )
862862
863+ t . test ( 'user-agent github actions ci variants' , t => {
864+ const npmVersion = '1.2.3'
865+ const base = `npm/${ npmVersion } node/${ process . version } ` +
866+ `${ process . platform } ${ process . arch } workspaces/false`
867+
868+ const cases = [
869+ {
870+ name : 'dotcom + github-hosted runner' ,
871+ env : { GITHUB_SERVER_URL : 'https://github.com' , RUNNER_ENVIRONMENT : 'github-hosted' } ,
872+ expect : `${ base } ci/github-actions/dotcom-hosted` ,
873+ } ,
874+ {
875+ name : 'dotcom + self-hosted runner' ,
876+ env : { GITHUB_SERVER_URL : 'https://github.com' , RUNNER_ENVIRONMENT : 'self-hosted' } ,
877+ expect : `${ base } ci/github-actions/dotcom-selfhosted` ,
878+ } ,
879+ {
880+ name : 'dotcom + missing runner environment' ,
881+ env : { GITHUB_SERVER_URL : 'https://github.com' , RUNNER_ENVIRONMENT : undefined } ,
882+ expect : `${ base } ci/github-actions/dotcom` ,
883+ } ,
884+ {
885+ name : 'dotcom + whitespace runner environment' ,
886+ env : { GITHUB_SERVER_URL : 'https://github.com' , RUNNER_ENVIRONMENT : ' ' } ,
887+ expect : `${ base } ci/github-actions/dotcom` ,
888+ } ,
889+ {
890+ name : 'ghe.com tenant' ,
891+ env : { GITHUB_SERVER_URL : 'https://octocorp.ghe.com' , RUNNER_ENVIRONMENT : 'github-hosted' } ,
892+ expect : `${ base } ci/github-actions/ghecom` ,
893+ } ,
894+ {
895+ name : 'bare ghe.com host' ,
896+ env : { GITHUB_SERVER_URL : 'https://ghe.com' , RUNNER_ENVIRONMENT : 'github-hosted' } ,
897+ expect : `${ base } ci/github-actions/ghecom` ,
898+ } ,
899+ {
900+ name : 'ghe.com only in path is treated as ghes' ,
901+ env : { GITHUB_SERVER_URL : 'https://evil.example/x.ghe.com' , RUNNER_ENVIRONMENT : 'self-hosted' } ,
902+ expect : `${ base } ci/github-actions/ghes` ,
903+ } ,
904+ {
905+ name : 'ghes (non-empty, non github.com, non ghe.com)' ,
906+ env : { GITHUB_SERVER_URL : 'https://github.example.com' , RUNNER_ENVIRONMENT : 'self-hosted' } ,
907+ expect : `${ base } ci/github-actions/ghes` ,
908+ } ,
909+ {
910+ name : 'missing server url stays generic' ,
911+ env : { GITHUB_SERVER_URL : undefined , RUNNER_ENVIRONMENT : undefined } ,
912+ expect : `${ base } ci/github-actions` ,
913+ } ,
914+ {
915+ name : 'whitespace server url stays generic' ,
916+ env : { GITHUB_SERVER_URL : ' ' , RUNNER_ENVIRONMENT : 'github-hosted' } ,
917+ expect : `${ base } ci/github-actions` ,
918+ } ,
919+ ]
920+
921+ for ( const { name, env, expect } of cases ) {
922+ t . test ( name , t => {
923+ mockGlobals ( t , { 'process.env' : env } )
924+ const defs = mockDefs ( {
925+ 'ci-info' : { isCi : true , name : 'GitHub Actions' , GITHUB_ACTIONS : true } ,
926+ } )
927+ const obj = {
928+ 'npm-version' : npmVersion ,
929+ 'user-agent' : defs [ 'user-agent' ] . default ,
930+ }
931+ const flat = { }
932+ defs [ 'user-agent' ] . flatten ( 'user-agent' , obj , flat )
933+ t . equal ( flat . userAgent , expect )
934+ t . equal ( process . env . npm_config_user_agent , flat . userAgent , 'npm_user_config environment is set' )
935+ t . end ( )
936+ } )
937+ }
938+
939+ t . test ( 'non github-actions ci is unchanged' , t => {
940+ mockGlobals ( t , {
941+ 'process.env' : { GITHUB_SERVER_URL : 'https://github.com' , RUNNER_ENVIRONMENT : 'github-hosted' } ,
942+ } )
943+ const defs = mockDefs ( {
944+ 'ci-info' : { isCi : true , name : 'Travis CI' , GITHUB_ACTIONS : false } ,
945+ } )
946+ const obj = {
947+ 'npm-version' : npmVersion ,
948+ 'user-agent' : defs [ 'user-agent' ] . default ,
949+ }
950+ const flat = { }
951+ defs [ 'user-agent' ] . flatten ( 'user-agent' , obj , flat )
952+ t . equal ( flat . userAgent , `${ base } ci/travis-ci` )
953+ t . end ( )
954+ } )
955+
956+ t . end ( )
957+ } )
958+
863959t . test ( 'save-prefix' , t => {
864960 const obj = {
865961 'save-exact' : true ,
0 commit comments