-
Notifications
You must be signed in to change notification settings - Fork 234
Link Checker: Allow relative links in configurable file path patterns #14400
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cfa297a
Initial plan
Copilot de67078
Allow relative links in configurable file paths via allowRelativeLink…
Copilot deb0b39
Only lift relative-link restriction for matching pages, keep other gu…
Copilot 80df54a
Remove instructions.md special case; add .github/** to allow-relative…
Copilot 49eb8fc
Remove **/specs/** from allow-relative-links.txt (repo-specific); .gi…
Copilot 82b58b3
Move allow-relative-links.txt to eng/common/scripts/ so it syncs to a…
Copilot 8d349b5
Update allow-relative-links.txt
weshaggard 8a3dd5b
Change Write-Host to Write-Verbose for logging
weshaggard 52e74ff
Update eng/common/scripts/Verify-Links.ps1
weshaggard 1359805
Address review feedback: trim comments, precompute regexes, Join-Path…
Copilot 4e126a4
Restore eng/** to allow-relative-links.txt with updated comment
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
eng/common-tests/Verify-Links-AllowRelativeLinks.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| Import-Module Pester | ||
|
|
||
| Describe "Test-PageUriMatchesRelativeLinkPattern" { | ||
| BeforeAll { | ||
| # Set up a temp allow-relative-links file | ||
| $script:tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) | ||
| New-Item -ItemType Directory -Path $script:tempDir | Out-Null | ||
|
|
||
| $script:allowRelativeLinksFile = Join-Path $script:tempDir "allow-relative-links.txt" | ||
| Set-Content -Path $script:allowRelativeLinksFile -Value @" | ||
| # Allow relative links in specs directories | ||
| **/specs/** | ||
| # Also allow in internal-docs | ||
| **/internal-docs/** | ||
| "@ | ||
| # Dot-source the script passing the config file so $allowRelativeLinkPatterns is populated | ||
| . $PSScriptRoot/../common/scripts/Verify-Links.ps1 -allowRelativeLinksFile $script:allowRelativeLinksFile | ||
| } | ||
|
|
||
| AfterAll { | ||
| if (Test-Path $script:tempDir) { | ||
| Remove-Item -Recurse -Force $script:tempDir | ||
| } | ||
| } | ||
|
|
||
| Context "When page URI matches a specs/ pattern" { | ||
| It "Should return true for a file inside specs/ directory" { | ||
| $uri = [System.Uri]("file:///home/user/repo/tools/myapp/specs/design.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeTrue | ||
| } | ||
|
|
||
| It "Should return true for a file in a nested specs/ directory" { | ||
| $uri = [System.Uri]("file:///home/user/repo/tools/myapp/specs/sub/nested-spec.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeTrue | ||
| } | ||
|
|
||
| It "Should return true for a file in a deeply nested specs/ directory" { | ||
| $uri = [System.Uri]("file:///home/user/repo/a/b/c/specs/d/e/doc.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeTrue | ||
| } | ||
| } | ||
|
|
||
| Context "When page URI matches the internal-docs/ pattern" { | ||
| It "Should return true for a file inside internal-docs/ directory" { | ||
| $uri = [System.Uri]("file:///home/user/repo/internal-docs/guide.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeTrue | ||
| } | ||
| } | ||
|
|
||
| Context "When page URI does not match any pattern" { | ||
| It "Should return false for a regular README file" { | ||
| $uri = [System.Uri]("file:///home/user/repo/README.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeFalse | ||
| } | ||
|
|
||
| It "Should return false for a file in a non-matching directory" { | ||
| $uri = [System.Uri]("file:///home/user/repo/docs/guide.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeFalse | ||
| } | ||
|
|
||
| It "Should return false for a file whose name contains 'specs' but is not in a specs/ directory" { | ||
| $uri = [System.Uri]("file:///home/user/repo/docs/my-specs-overview.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeFalse | ||
| } | ||
| } | ||
|
|
||
| Context "When no allow-relative-links patterns are loaded" { | ||
| BeforeAll { | ||
| $script:savedRegexes = $allowRelativeLinkRegexes | ||
| $allowRelativeLinkRegexes = @() | ||
| } | ||
| AfterAll { | ||
| $allowRelativeLinkRegexes = $script:savedRegexes | ||
| } | ||
| It "Should return false for any URI when pattern list is empty" { | ||
| $uri = [System.Uri]("file:///home/user/repo/specs/design.md") | ||
| Test-PageUriMatchesRelativeLinkPattern $uri | Should -BeFalse | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Files matching patterns listed here are permitted to use relative links even when checkLinkGuidance is enabled. | ||
| # Relative links in matching files are still verified for correctness. | ||
| # One glob pattern per line. Lines beginning with '#' are ignored. | ||
| # Patterns support wildcards: * matches within a path segment, ** matches across segments. | ||
| # | ||
| # Allow relative links for all files under the .github folder (e.g. copilot instructions). | ||
| .github/** | ||
| # Allow relative links for all files under the eng folder (e.g. engineering system scripts and templates). | ||
| eng/** | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.