@@ -7,9 +7,10 @@ const repository = "DiscoverBox/gitboost";
77const ref = "main" ;
88const cdnPath = `/gh/${ repository } @${ ref } /nodes.enc.json` ;
99
10- test ( "purges jsDelivr and waits for JSDMirror to match nodes.enc.json " , async ( ) => {
10+ test ( "purges jsDelivr and waits for its content to refresh " , async ( ) => {
1111 const expectedContent = '{"version":1}\n' ;
1212
13+ let jsDelivrChecks = 0 ;
1314 let mirrorChecks = 0 ;
1415 const requestedUrls = [ ] ;
1516 const fetchImpl = async ( url ) => {
@@ -20,11 +21,12 @@ test("purges jsDelivr and waits for JSDMirror to match nodes.enc.json", async ()
2021 paths : { [ cdnPath ] : { providers : { CF : true , FY : true } } } ,
2122 } ) ;
2223 }
23- if ( url . startsWith ( "https://cdn.jsdmirror.cn /" ) ) {
24+ if ( url . startsWith ( "https://cdn.jsdmirror.com /" ) ) {
2425 mirrorChecks += 1 ;
2526 return new Response ( mirrorChecks === 1 ? "stale" : expectedContent ) ;
2627 }
27- return new Response ( expectedContent ) ;
28+ jsDelivrChecks += 1 ;
29+ return new Response ( jsDelivrChecks === 1 ? "stale" : expectedContent ) ;
2830 } ;
2931
3032 await refreshCdnCache ( {
@@ -42,6 +44,61 @@ test("purges jsDelivr and waits for JSDMirror to match nodes.enc.json", async ()
4244 assert . equal ( requestedUrls [ 0 ] , `https://purge.jsdelivr.net${ cdnPath } ` ) ;
4345} ) ;
4446
47+ test ( "warns without failing when only JSDMirror remains stale" , async ( ) => {
48+ const expectedContent = '{"version":1}\n' ;
49+ const logs = [ ] ;
50+
51+ await refreshCdnCache ( {
52+ repository,
53+ ref,
54+ readFileImpl : async ( ) => Buffer . from ( expectedContent ) ,
55+ fetchImpl : async ( url ) => {
56+ if ( url . startsWith ( "https://purge.jsdelivr.net/" ) ) {
57+ return Response . json ( {
58+ status : "finished" ,
59+ paths : { [ cdnPath ] : { providers : { CF : true , FY : true } } } ,
60+ } ) ;
61+ }
62+ if ( url . startsWith ( "https://cdn.jsdmirror.com/" ) ) {
63+ return new Response ( "stale" ) ;
64+ }
65+ return new Response ( expectedContent ) ;
66+ } ,
67+ log : ( message ) => logs . push ( message ) ,
68+ } ) ;
69+
70+ assert . ok ( logs . some ( ( message ) => message . startsWith ( "::warning::" ) ) ) ;
71+ } ) ;
72+
73+ test ( "fails when jsDelivr content remains stale" , async ( ) => {
74+ const expectedContent = '{"version":1}\n' ;
75+
76+ await assert . rejects (
77+ refreshCdnCache ( {
78+ repository,
79+ ref,
80+ readFileImpl : async ( ) => Buffer . from ( expectedContent ) ,
81+ fetchImpl : async ( url ) => {
82+ if ( url . startsWith ( "https://purge.jsdelivr.net/" ) ) {
83+ return Response . json ( {
84+ status : "finished" ,
85+ paths : { [ cdnPath ] : { providers : { CF : true , FY : true } } } ,
86+ } ) ;
87+ }
88+ if ( url . startsWith ( "https://cdn.jsdelivr.net/" ) ) {
89+ return new Response ( "stale" ) ;
90+ }
91+ return new Response ( expectedContent ) ;
92+ } ,
93+ wait : async ( ) => { } ,
94+ maxAttempts : 2 ,
95+ pollIntervalMs : 0 ,
96+ log : ( ) => { } ,
97+ } ) ,
98+ / j s D e l i v r c a c h e d i d n o t r e f r e s h a f t e r 2 c h e c k s / ,
99+ ) ;
100+ } ) ;
101+
45102test ( "fails when a jsDelivr provider does not purge the cache" , async ( ) => {
46103 await assert . rejects (
47104 refreshCdnCache ( {
0 commit comments