-
Notifications
You must be signed in to change notification settings - Fork 582
Fix versioned canonical profile resolution #5503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,18 @@ public void Dispose() | |
|
|
||
| public async Task<Resource> ResolveByCanonicalUriAsync(string uri) | ||
| { | ||
| var summary = (await ListSummariesAsync(CancellationToken.None)).ResolveByCanonicalUri(uri); | ||
| var summaries = (await ListSummariesAsync(CancellationToken.None)).ToList(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the contribution! I have a question on this method: _summaries is built in GetSummariesAsync using result[artifact.ResourceUri] = artifact — keyed on the base canonical URL with no version. When a server holds both v2.0.0 and v3.0.0 of the same SD, only the last one processed survives in _summaries, so url|2.0.0 will silently fail to resolve if v3.0.0 was stored last. I think to fully support multi-version scenarios, GetSummariesAsync needs to key the dictionary by url + version (e.g. $"{artifact.ResourceUri}|{ver}"), and LoadBySummary's cache key needs the same treatment (see separate comment). |
||
| var summary = summaries.ResolveByCanonicalUri(uri); | ||
|
|
||
| if (summary == null && | ||
| TrySplitVersionedCanonicalUri(uri, out string canonicalUri, out string version)) | ||
| { | ||
| summary = summaries.FirstOrDefault(x => | ||
| string.Equals(x.ResourceUri, canonicalUri, StringComparison.OrdinalIgnoreCase) && | ||
| x.TryGetValue(_structureDefinitionVersionKey, out object summaryVersion) && | ||
| string.Equals(summaryVersion?.ToString(), version, StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
|
|
||
| return LoadBySummary(summary); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, if we fix the first comment I made, we will have a new issue: Steps to reproduce (after fixing the deduplication bug above): ResolveByCanonicalUriAsync("url|v2") → loads v2 from JSON → stores in cache under key url |
||
| } | ||
|
|
||
|
|
@@ -175,6 +186,30 @@ private static string GetCanonicalUrl(ArtifactSummary artifact) | |
| return url; | ||
| } | ||
|
|
||
| private static bool TrySplitVersionedCanonicalUri(string uri, out string canonicalUri, out string version) | ||
| { | ||
| canonicalUri = uri; | ||
| version = null; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(uri)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| int fragmentIndex = uri.IndexOf('#'); | ||
| string uriWithoutFragment = fragmentIndex >= 0 ? uri.Substring(0, fragmentIndex) : uri; | ||
| int versionSeparatorIndex = uriWithoutFragment.LastIndexOf('|'); | ||
|
|
||
| if (versionSeparatorIndex <= 0 || versionSeparatorIndex == uriWithoutFragment.Length - 1) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| canonicalUri = uriWithoutFragment.Substring(0, versionSeparatorIndex); | ||
| version = uriWithoutFragment.Substring(versionSeparatorIndex + 1); | ||
| return true; | ||
| } | ||
|
|
||
| private static string GetHashForSupportedProfiles(IReadOnlyCollection<ArtifactSummary> summaries) | ||
| { | ||
| if (summaries == null) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More possible test cases:
Version mismatch returns null — call ResolveByCanonicalUriAsync("url|9.9.9") when only url|3.0.0 exists; assert the result is null. This ensures the fallback doesn't match on URL alone.
Unversioned URI still resolves — regression guard that an unversioned canonical URI resolves correctly after the restructured code path in ResolveByCanonicalUriAsync.
Two versions of the same SD, each resolves correctly — a test with both v2.0.0 and v3.0.0 of the same SD on the server, verifying each versioned URI resolves to the right resource. This will also expose the deduplication/cache bugs noted above.