@@ -2806,6 +2806,110 @@ describe('runCloudflareDeploy — static, SPA, and SSG apps', () => {
28062806 } ) ;
28072807 } ) ;
28082808
2809+ it . each ( [ 'first deployment' , 'update' ] as const ) (
2810+ 'validates static candidate history through real activation on %s' ,
2811+ async ( scenario ) => {
2812+ const root = makeProject ( {
2813+ 'package.json' : JSON . stringify ( { name : 'static-app' } ) ,
2814+ 'void.json' : JSON . stringify ( { output : 'static' } ) ,
2815+ 'wrangler.jsonc' : JSON . stringify ( {
2816+ account_id : 'acc123' ,
2817+ workers_dev : true ,
2818+ preview_urls : true ,
2819+ routes : [ ] ,
2820+ } ) ,
2821+ 'pages/index.vue' : '<template><div>Static</div></template>' ,
2822+ } ) ;
2823+ const current = '11111111-1111-4111-8111-111111111111' ;
2824+ const next = '22222222-2222-4222-8222-222222222222' ;
2825+ let active : string | null = scenario === 'update' ? current : null ;
2826+ const history = scenario === 'update' ? [ { id : current , number : 1 } ] : [ ] ;
2827+ const operations : Array < CloudflareOperation > = [ ] ;
2828+ const runWrangler : DeployWranglerRun = ( operation ) => {
2829+ operations . push ( operation ) ;
2830+ if ( operation . type === 'auth.whoami' ) {
2831+ return { ...cleanExit , data : { loggedIn : true , accounts : [ ] } } ;
2832+ }
2833+ if ( operation . type === 'deployments.status' ) {
2834+ return {
2835+ ...cleanExit ,
2836+ data : { versions : active ? [ { version_id : active , percentage : 100 } ] : [ ] } ,
2837+ } ;
2838+ }
2839+ if ( operation . type === 'versions.list' ) {
2840+ return { ...cleanExit , data : history . map ( ( version ) => ( { ...version } ) ) } ;
2841+ }
2842+ if ( operation . type === 'versions.view' ) {
2843+ return { ...cleanExit , data : { id : operation . versionId , resources : { bindings : [ ] } } } ;
2844+ }
2845+ if ( operation . type === 'versions.upload' ) {
2846+ if ( scenario === 'first deployment' ) {
2847+ return { ...cleanExit , status : 1 , failure : 'not-found' , errorCode : 10007 } ;
2848+ }
2849+ history . push ( { id : next , number : 2 } ) ;
2850+ return {
2851+ ...cleanExit ,
2852+ data : {
2853+ versionId : next ,
2854+ previewUrl : `https://${ next . slice ( 0 , 8 ) } -static-app.example.workers.dev` ,
2855+ } ,
2856+ } ;
2857+ }
2858+ if ( operation . type === 'worker.deploy' ) {
2859+ active = next ;
2860+ history . push ( { id : next , number : 1 } ) ;
2861+ return {
2862+ ...cleanExit ,
2863+ data : { versionId : next , workersDevUrl : 'https://static-app.example.workers.dev' } ,
2864+ } ;
2865+ }
2866+ if ( operation . type === 'versions.deploy' ) {
2867+ active = operation . versions [ 0 ] ! . versionId ;
2868+ return cleanExit ;
2869+ }
2870+ if ( operation . type === 'triggers.deploy' || operation . type === 'triggers.clear-crons' ) {
2871+ expect ( active ) . toBe ( next ) ;
2872+ return cleanExit ;
2873+ }
2874+ throw new Error ( `Unexpected Cloudflare operation: ${ operation . type } ` ) ;
2875+ } ;
2876+ const { deps, exitCalls } = harness ( {
2877+ runWrangler,
2878+ runStaticBuild : ( ) => {
2879+ mkdirSync ( join ( root , 'dist/client' ) , { recursive : true } ) ;
2880+ writeFileSync ( join ( root , 'dist/client/index.html' ) , '<h1>Static</h1>' ) ;
2881+ } ,
2882+ activateVersion : ( options ) =>
2883+ activateCloudflareVersionPrimitive ( {
2884+ ...options ,
2885+ fetch : async ( ) => {
2886+ if ( scenario === 'update' ) {
2887+ expect (
2888+ JSON . parse ( readFileSync ( join ( root , '.void/cloudflare-candidate.json' ) , 'utf8' ) ) ,
2889+ ) . toMatchObject ( { parentVersionId : current , versionIds : [ next ] } ) ;
2890+ }
2891+ return Response . json ( { ready : true , versionId : next } ) ;
2892+ } ,
2893+ } ) ,
2894+ } ) ;
2895+
2896+ await runCloudflareDeploy ( root , { platform : 'cloudflare' } , silentCliLog , deps ) ;
2897+
2898+ expect ( exitCalls ) . toEqual ( [ ] ) ;
2899+ expect ( active ) . toBe ( next ) ;
2900+ const operationTypes = operations . map ( ( operation ) => operation . type ) ;
2901+ expect ( operationTypes . indexOf ( 'versions.list' ) ) . toBeLessThan (
2902+ operationTypes . indexOf ( 'versions.upload' ) ,
2903+ ) ;
2904+ if ( scenario === 'update' ) {
2905+ expect ( operationTypes . lastIndexOf ( 'versions.list' ) ) . toBeGreaterThan (
2906+ operationTypes . indexOf ( 'versions.upload' ) ,
2907+ ) ;
2908+ }
2909+ expect ( existsSync ( join ( root , '.void/cloudflare-candidate.json' ) ) ) . toBe ( false ) ;
2910+ } ,
2911+ ) ;
2912+
28092913 it ( 'keeps an output:"static" app with a dynamic page on the full Worker path' , async ( ) => {
28102914 const root = makeProject ( {
28112915 'package.json' : JSON . stringify ( { name : 'hybrid-ssg' } ) ,
0 commit comments