@@ -39,6 +39,9 @@ const roots: Array<string> = [];
3939const pinnedCfVersion = JSON . parse (
4040 readFileSync ( fileURLToPath ( import . meta. resolve ( 'cf/package.json' ) ) , 'utf8' ) ,
4141) . version as string ;
42+ const voidVersion = JSON . parse ( readFileSync ( new URL ( '../../package.json' , import . meta. url ) , 'utf8' ) )
43+ . version as string ;
44+ const cfUserAgent = `cf-cli/${ pinnedCfVersion } void/${ voidVersion } ` ;
4245// Each real cf subprocess loads cf's bundle before it does any work. That takes about half a
4346// second when idle and several seconds on a busy machine, which can pass Vitest's 5s default.
4447const REAL_CF_TIMEOUT_MS = process . platform === 'win32' ? 20_000 : 15_000 ;
4952 const prepared = await output ( ) ;
5053 const draft = voidSecretDraftVersion ( ) ;
5154 const requests : Array < string > = [ ] ;
55+ const userAgents : Array < string | undefined > = [ ] ;
5256 const server = createServer ( ( request , response ) => {
5357 requests . push ( request . url ?? '' ) ;
58+ userAgents . push ( request . headers [ 'user-agent' ] ) ;
5459 request . resume ( ) ;
5560 response . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
5661 response . end ( JSON . stringify ( { success : true , errors : [ ] , messages : [ ] , result : draft } ) ) ;
6772 SYSTEMROOT : process . env . SYSTEMROOT ,
6873 WINDIR : process . env . WINDIR ,
6974 CI : 'true' ,
75+ CLI_VERSION : 'inherited-version void/stale' ,
7076 CLOUDFLARE_API_TOKEN : 'synthetic-token' ,
7177 CLOUDFLARE_ACCOUNT_ID : 'test-account' ,
7278 CLOUDFLARE_API_BASE_URL : apiBaseUrl ,
99105 `/client/v4/accounts/test-account/workers/workers/void-test/versions/${ draft . id } ?include=modules` ,
100106 ] ) ;
101107 expect ( commands ) . toHaveLength ( 1 ) ;
108+ expect ( userAgents ) . toEqual ( [ cfUserAgent ] ) ;
102109 expect ( commands [ 0 ] ! . bounds ) . toMatchObject ( { timeoutMs : 30_000 , maxOutputBytes : 1024 * 1024 } ) ;
103110 expect ( JSON . stringify ( result ) ) . not . toContain ( 'synthetic-token' ) ;
104111 } finally {
208215 async ( ) => {
209216 const prepared = await output ( ) ;
210217 const requests : Array < string > = [ ] ;
218+ const userAgents : Array < string | undefined > = [ ] ;
211219 const server = createServer ( ( request , response ) => {
212220 requests . push ( request . url ?? '' ) ;
221+ userAgents . push ( request . headers [ 'user-agent' ] ) ;
213222 request . resume ( ) ;
214223 response . writeHead ( 404 , { 'Content-Type' : 'application/json' } ) ;
215224 response . end (
252261 // cf deliberately omits the API code from this local error.
253262 expect ( result . errorCode ) . toBeUndefined ( ) ;
254263 expect ( requests ) . toEqual ( [ '/client/v4/accounts/account-id/workers/services/void-test' ] ) ;
264+ expect ( userAgents ) . toEqual ( [ cfUserAgent ] ) ;
255265 } finally {
256266 prepared . dispose ( ) ;
257267 await new Promise < void > ( ( resolve , reject ) =>
@@ -835,7 +845,12 @@ async function verifyPinnedUpload(atomic: boolean): Promise<void> {
835845 { name : 'KEY' , type : 'secret_key' } ,
836846 ] ,
837847 } ) ;
838- const requests : Array < { url : string ; body : string ; authorization : string | undefined } > = [ ] ;
848+ const requests : Array < {
849+ url : string ;
850+ body : string ;
851+ authorization : string | undefined ;
852+ userAgent : string | undefined ;
853+ } > = [ ] ;
839854 let uploadedBatches = 0 ;
840855 const server = createServer ( async ( request , response ) => {
841856 const chunks : Array < Buffer > = [ ] ;
@@ -846,6 +861,7 @@ async function verifyPinnedUpload(atomic: boolean): Promise<void> {
846861 url : request . url ?? '' ,
847862 body : Buffer . concat ( chunks ) . toString ( 'utf8' ) ,
848863 authorization : request . headers . authorization ,
864+ userAgent : request . headers [ 'user-agent' ] ,
849865 } ) ;
850866 response . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
851867 const path = request . url ?? '' ;
@@ -896,6 +912,9 @@ async function verifyPinnedUpload(atomic: boolean): Promise<void> {
896912 verifyUploader : ( ) => true ,
897913 } ) ;
898914 expect ( uploaded . id ) . toBe ( '22222222-2222-4222-8222-222222222222' ) ;
915+ expect ( requests . map ( ( { userAgent } ) => userAgent ) ) . toEqual (
916+ requests . map ( ( ) => `void/${ voidVersion } ` ) ,
917+ ) ;
899918 const upload = requests . find ( ( { url } ) =>
900919 url . endsWith ( atomic ? '/versions?deploy=true' : '/versions' ) ,
901920 ) ;
@@ -1919,16 +1938,23 @@ it(
19191938 JSON . stringify ( { name : 'cf' , version : '0.0.0' , bin : { cf : 'fake.cjs' } } ) ,
19201939 ) ;
19211940 writeFileSync ( join ( local , 'fake.cjs' ) , 'console.log("UNPINNED_PROJECT_CF_EXECUTED");' ) ;
1941+ const env = {
1942+ PATH : process . env . PATH ,
1943+ CI : 'true' ,
1944+ CLI_VERSION : 'inherited-version void/stale' ,
1945+ CLOUDFLARE_API_TOKEN : 'synthetic-token' ,
1946+ } ;
19221947 const command = createCfCommand ( {
19231948 accountId : 'test-account' ,
19241949 apiBaseUrl : 'https://api.cloudflare.com/client/v4' ,
19251950 verifyUploader : ( ) => true ,
1926- env : ( ) => ( { PATH : process . env . PATH , CI : 'true' , CLOUDFLARE_API_TOKEN : 'synthetic-token' } ) ,
1951+ env : ( ) => env ,
19271952 } ) ;
19281953 const result = await command ( [ '--version' ] , { cwd : root , capture : true } ) ;
19291954 expect ( result . status , result . stderr ) . toBe ( 0 ) ;
19301955 expect ( result . stdout ) . not . toContain ( 'UNPINNED_PROJECT_CF_EXECUTED' ) ;
1931- expect ( result . stdout ) . toContain ( pinnedCfVersion ) ;
1956+ expect ( result . stdout . trim ( ) ) . toBe ( `${ pinnedCfVersion } void/${ voidVersion } ` ) ;
1957+ expect ( env . CLI_VERSION ) . toBe ( 'inherited-version void/stale' ) ;
19321958 } ,
19331959 REAL_CF_TIMEOUT_MS ,
19341960) ;
0 commit comments