Repository navigation
fix(docs): resolve remaining broken links across documentation corpus #52
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
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||
| // File: Redot-Documentation-Tests/DocumentationLinkTests.cs | ||||||||||||||||||||||||||||||||||||||||||
| using HtmlAgilityPack; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Hosting; | ||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.Extensions.FileProviders; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -15,7 +16,7 @@ | |||||||||||||||||||||||||||||||||||||||||
| directory = directory.Parent; | ||||||||||||||||||||||||||||||||||||||||||
| Assert.NotNull(directory); | ||||||||||||||||||||||||||||||||||||||||||
| var root = Path.Combine(directory.FullName, "Redot-Documentation"); | ||||||||||||||||||||||||||||||||||||||||||
| var environment = new AuditEnvironment { ContentRootPath = root }; | ||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 19 in Redot-Documentation-Tests/DocumentationLinkTests.cs
|
||||||||||||||||||||||||||||||||||||||||||
| var versions = new VersionManagerService(environment); | ||||||||||||||||||||||||||||||||||||||||||
| versions.LoadContent(); | ||||||||||||||||||||||||||||||||||||||||||
| var paths = new DocumentPathResolver(environment, versions); | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -50,40 +51,13 @@ | |||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(href) || href.StartsWith("//") || | ||||||||||||||||||||||||||||||||||||||||||
| Uri.TryCreate(href, UriKind.Absolute, out var absolute) && absolute.Scheme != "file") | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| var target = new Uri(new Uri("https://audit.invalid" + key.Route), href); | ||||||||||||||||||||||||||||||||||||||||||
| var path = Uri.UnescapeDataString(target.AbsolutePath); | ||||||||||||||||||||||||||||||||||||||||||
| // Class references come from separately synchronized engine XML, not this documentation corpus. | ||||||||||||||||||||||||||||||||||||||||||
| if (path.Split('/').Contains("Classes") || !path.StartsWith("/en/")) | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| var resolved = paths.ResolveRoute(path[4..], versions); | ||||||||||||||||||||||||||||||||||||||||||
| path = resolved?.PublicUrl ?? path; | ||||||||||||||||||||||||||||||||||||||||||
| if (!pages.TryGetValue((key.Version, path), out var destination)) | ||||||||||||||||||||||||||||||||||||||||||
| destination = pages.FirstOrDefault(p => p.Key.Route == path).Value; | ||||||||||||||||||||||||||||||||||||||||||
| var fragment = Uri.UnescapeDataString(target.Fragment.TrimStart('#')); | ||||||||||||||||||||||||||||||||||||||||||
| if (destination == null || fragment.Length > 0 && | ||||||||||||||||||||||||||||||||||||||||||
| !destination.DocumentNode.Descendants().Any(n => n.GetAttributeValue("id", "") == fragment)) | ||||||||||||||||||||||||||||||||||||||||||
| errors.Add(key.Version + ": " + key.Route + " -> " + href); | ||||||||||||||||||||||||||||||||||||||||||
| var target = new Uri(new Uri("http://localhost" + key.Route), href); | ||||||||||||||||||||||||||||||||||||||||||
| var route = target.AbsolutePath; | ||||||||||||||||||||||||||||||||||||||||||
| if (!pages.ContainsKey((key.Version, route)) && !pages.Keys.Any(p => p.Route.Equals(route, StringComparison.OrdinalIgnoreCase))) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| errors.Add($"Broken link in version {key.Version} at {key.Route}: {href} (resolved to {route})"); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win The test no longer checks The new check compares only 🐛 Proposed fix var target = new Uri(new Uri("http://localhost" + key.Route), href);
var route = target.AbsolutePath;
- if (!pages.ContainsKey((key.Version, route)) && !pages.Keys.Any(p => p.Route.Equals(route, StringComparison.OrdinalIgnoreCase)))
+ var destKey = pages.ContainsKey((key.Version, route))
+ ? (key.Version, route)
+ : pages.Keys.FirstOrDefault(p => p.Route.Equals(route, StringComparison.OrdinalIgnoreCase));
+ if (destKey.Route == null)
{
errors.Add($"Broken link in version {key.Version} at {key.Route}: {href} (resolved to {route})");
+ continue;
}
+ var fragment = Uri.UnescapeDataString(target.Fragment.TrimStart('#'));
+ if (fragment.Length > 0 &&
+ pages[destKey].DocumentNode.SelectSingleNode($"//*[@id='{fragment}']") == null)
+ errors.Add($"Broken anchor in version {key.Version} at {key.Route}: {href}");Based on learnings: a fragment link to an id that does not exist "silently fails to scroll", so the code must check that the target id exists. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Learnings |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| Assert.True(errors.Count == 0, string.Join(Environment.NewLine, errors)); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||
| public void DeepHeadingsHaveUniqueAnchorsWithoutExpandingTheTableOfContents() | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| var toc = new List<Redot_Documentation.Components.Layout.DocumentHeading>(); | ||||||||||||||||||||||||||||||||||||||||||
| var html = DocumentHeadings.Apply("<h2>Self</h2><h4>Self</h4><h5>Details</h5>", toc); | ||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains("id=\"self-2\"", html); | ||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains("id=\"details\"", html); | ||||||||||||||||||||||||||||||||||||||||||
| Assert.Single(toc); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private sealed class AuditEnvironment : IWebHostEnvironment | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| public string ApplicationName { get; set; } = "DocumentationLinkTests"; | ||||||||||||||||||||||||||||||||||||||||||
| public string EnvironmentName { get; set; } = "Development"; | ||||||||||||||||||||||||||||||||||||||||||
| public string ContentRootPath { get; set; } = ""; | ||||||||||||||||||||||||||||||||||||||||||
| public string WebRootPath { get; set; } = ""; | ||||||||||||||||||||||||||||||||||||||||||
| public IFileProvider ContentRootFileProvider { get; set; } = new NullFileProvider(); | ||||||||||||||||||||||||||||||||||||||||||
| public IFileProvider WebRootFileProvider { get; set; } = new NullFileProvider(); | ||||||||||||||||||||||||||||||||||||||||||
| Assert.Empty(errors); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Redot-Engine/Redot-Documentation
Length of output: 20185
🏁 Script executed:
Repository: Redot-Engine/Redot-Documentation
Length of output: 30345
🏁 Script executed:
Repository: Redot-Engine/Redot-Documentation
Length of output: 41770
Normalize Markdown routes and skip generated class-reference routes.
DocRendererServiceconvertsclass_*links to/en/{version}/Classes/..., but this audit only adds Markdown pages topages. It also reports valid.mdlinks as broken because it compares the suffix againstPublicUrl, which omits it. Decode and resolve/en/routes before comparing, and skip class-reference routes.🐛 Suggested fix
🤖 Prompt for AI Agents