@@ -25,7 +25,6 @@ public sealed class PackageLinkTests
2525 Backoff . DecorrelatedJitterBackoffV2 ( TimeSpan . FromMilliseconds ( 200 ) , 3 ) ,
2626 onRetry : ( outcome , timespan , retryAttempt , context ) =>
2727 {
28- // Log retry attempt if needed
2928 Console . WriteLine ( $ "Retry attempt { retryAttempt } , waiting { timespan . TotalSeconds } seconds") ;
3029 }
3130 ) ;
@@ -36,27 +35,24 @@ public async Task TestPreviewImageUri(BasePackage package)
3635 {
3736 var imageUri = package . PreviewImageUri ;
3837
39- // If is GitHub Uri , use jsdelivr instead due to rate limiting
38+ // If GitHub URL , use jsDelivr to avoid rate limiting
4039 imageUri = GitHubToJsDelivr ( imageUri ) ;
4140
42- // Test http head is successful with retry policy
4341 var response = await RetryPolicy . ExecuteAsync ( async ( ) =>
4442 await HttpClient . SendAsync ( new HttpRequestMessage ( HttpMethod . Head , imageUri ) )
4543 ) ;
4644
47- if ( response . StatusCode == System . Net . HttpStatusCode . Forbidden )
48- {
49- Assert . Inconclusive (
50- $ "PreviewImageUri blocked by host (403): { imageUri } "
51- ) ;
52- }
45+ // 403 should fail — URL is invalid or blocked
46+ Assert . AreNotEqual (
47+ System . Net . HttpStatusCode . Forbidden ,
48+ response . StatusCode ,
49+ $ "PreviewImageUri returned 403 Forbidden: { imageUri } "
50+ ) ;
5351
54- Assert . IsTrue (
55- response . IsSuccessStatusCode ,
56- "Failed to get PreviewImageUri at {0}: {1}" ,
57- imageUri ,
58- response
59- ) ;
52+ Assert . IsTrue (
53+ response . IsSuccessStatusCode ,
54+ $ "Failed to get PreviewImageUri at { imageUri } : { response } "
55+ ) ;
6056 }
6157
6258 [ TestMethod ]
@@ -70,34 +66,32 @@ public async Task TestLicenseUrl(BasePackage package)
7066
7167 var licenseUri = new Uri ( package . LicenseUrl ) ;
7268
73- // If is GitHub Uri , use jsdelivr instead due to rate limiting
69+ // If GitHub URL , use jsDelivr to avoid rate limiting
7470 licenseUri = GitHubToJsDelivr ( licenseUri ) ;
7571
76- // Test http head is successful with retry policy
7772 var response = await RetryPolicy . ExecuteAsync ( async ( ) =>
7873 await HttpClient . SendAsync ( new HttpRequestMessage ( HttpMethod . Head , licenseUri ) )
7974 ) ;
8075
81- Assert . IsTrue (
82- response . IsSuccessStatusCode ,
83- "Failed to get LicenseUrl at {0}: {1}" ,
84- licenseUri ,
85- response
86- ) ;
76+ Assert . IsTrue ( response . IsSuccessStatusCode , $ "Failed to get LicenseUrl at { licenseUri } : { response } ") ;
8777 }
8878
8979 private static Uri GitHubToJsDelivr ( Uri uri )
9080 {
91- // Like https://github.com/user/Repo/blob/main/LICENSE
92- // becomes: https://cdn.jsdelivr.net/gh/user/Repo@main/LICENSE
93- if ( uri . Host . Equals ( "github.com" , StringComparison . OrdinalIgnoreCase ) )
81+ // Example:
82+ // https://github.com/user/Repo/blob/main/LICENSE
83+ // becomes:
84+ // https://cdn.jsdelivr.net/gh/user/Repo@main/LICENSE
85+
86+ if ( ! uri . Host . Equals ( "github.com" , StringComparison . OrdinalIgnoreCase ) )
87+ return uri ;
88+
89+ var segments = uri . AbsolutePath . Split ( '/' , StringSplitOptions . RemoveEmptyEntries ) ;
90+
91+ if ( segments is [ var user , var repo , "blob" , var branch , ..] )
9492 {
95- var segments = uri . AbsolutePath . Split ( '/' , StringSplitOptions . RemoveEmptyEntries ) ;
96- if ( segments is [ var user , var repo , "blob" , var branch , ..] )
97- {
98- var path = string . Join ( "/" , segments . Skip ( 4 ) ) ;
99- return new Uri ( $ "https://cdn.jsdelivr.net/gh/{ user } /{ repo } @{ branch } /{ path } ") ;
100- }
93+ var path = string . Join ( "/" , segments . Skip ( 4 ) ) ;
94+ return new Uri ( $ "https://cdn.jsdelivr.net/gh/{ user } /{ repo } @{ branch } /{ path } ") ;
10195 }
10296
10397 return uri ;
0 commit comments