feat(1004): add OutputPath parameter to Invoke-LinkLanguageCheck.ps1#1229
feat(1004): add OutputPath parameter to Invoke-LinkLanguageCheck.ps1#1229PratikWayase wants to merge 4 commits intomicrosoft:mainfrom
Conversation
katriendg
left a comment
There was a problem hiding this comment.
Thanks @PratikWayase for your contribution.
Two small comments I believe we could update before merging?
| } | ||
| } | ||
|
|
||
| #endregion |
There was a problem hiding this comment.
Could you add the trailing empty newline back? It may have been removed by a VS code tool by accident.
| $logsDir = Join-Path $script:RepoRoot "logs" | ||
| if (Test-Path $logsDir) { Remove-Item $logsDir -Recurse -Force } | ||
|
|
||
| Invoke-LinkLanguageCheckCore -ExcludePaths @() -OutputPath $script:DefaultOutputPath | Out-Null |
There was a problem hiding this comment.
nit: this adds the -OutputPath paramater to the test call, but if the test is intended to test the default output path matches, even when the argument is not passed in then it should not pass and still validate the output is where you're expecting
katriendg
left a comment
There was a problem hiding this comment.
Four issues found — one is a broken test that needs to be fixed before merging:
- High (tests):
-OutputPathis commented out in the "writes to custom path" test — it never exercises the custom path and the assertion will fail. - Medium (script):
git rev-parse --show-toplevelis called twice — first with output discarded, then again to capture the value. Consolidate to a single call. - Low (script): Duplicate
$OutputPathdefault in the inner function param block — single source of truth violated. - Low (script): No guard for an empty
$outputDirwhen$OutputPathis a bare filename —New-Item -Path ""will throw.
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Error "Not in a git repository" | ||
| return 1 | ||
| } | ||
|
|
||
| $logsDir = Join-Path $repoRoot "logs" | ||
| if (-not (Test-Path $logsDir)) { | ||
| New-Item -ItemType Directory -Path $logsDir -Force | Out-Null | ||
| $repoRoot = git rev-parse --show-toplevel | ||
| if (-not [System.IO.Path]::IsPathRooted($OutputPath)) { |
There was a problem hiding this comment.
Bug (Medium) — git rev-parse called twice, discarding output the first time
git rev-parse --show-toplevel > $null 2>&1 # output thrown away
if ($LASTEXITCODE -ne 0) { ... }
$repoRoot = git rev-parse --show-toplevel # called again to capturegit is invoked twice unnecessarily — the first call discards its output, then it's called a second time just to capture the value. The original pattern was correct. Consolidate back to a single call:
$repoRoot = git rev-parse --show-toplevel 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Error "Not in a git repository"
return 1
}| [string[]]$ExcludePaths = @() | ||
| [string[]]$ExcludePaths = @(), | ||
| [string]$OutputPath = "logs/link-lang-check-results.json" | ||
| ) |
There was a problem hiding this comment.
Low — Duplicate default for $OutputPath creates a maintenance liability
The inner function repeats the exact same default value "logs/link-lang-check-results.json" that the outer script param already declares. If the default ever changes, it needs to be updated in two places and it's easy for them to drift out of sync.
Since the outer script param always passes the resolved value through to Invoke-LinkLanguageCheckCore, the inner function should not carry its own default:
[string]$OutputPath # no default; outer script always supplies the value| $outputDir = Split-Path -Parent $OutputPath | ||
| if (-not (Test-Path $outputDir)) { | ||
| New-Item -ItemType Directory -Path $outputDir -Force | Out-Null |
There was a problem hiding this comment.
Low — Split-Path -Parent on a bare filename returns "", causing New-Item to throw
When $OutputPath has no directory component (e.g. "results.json"), Split-Path -Parent returns an empty string. Test-Path "" returns $false, so execution reaches New-Item -Path "" which throws an error.
Add a guard before the Test-Path check:
$outputDir = Split-Path -Parent $OutputPath
if ($outputDir -and -not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
}(Same issue exists in the second write block at the bottom of the function — fix both.)
| } | ||
|
|
||
| It 'writes to custom path when OutputPath is specified' { | ||
| $customDir = Split-Path $script:CustomOutputPath -Parent |
There was a problem hiding this comment.
Bug (High) — -OutputPath is commented out, so this test never exercises the custom path
Invoke-LinkLanguageCheckCore -ExcludePaths @() #-OutputPath $script:CustomOutputPath | Out-NullThe -OutputPath $script:CustomOutputPath argument is accidentally commented out. The function runs with the default path (logs/link-lang-check-results.json), not the custom one. The assertion Test-Path $script:CustomOutputPath | Should -BeTrue will then always fail (or give a false positive if the default-path file happens to exist from a prior test run). Uncomment the argument:
Invoke-LinkLanguageCheckCore -ExcludePaths @() -OutputPath $script:CustomOutputPath | Out-Null
Description
This PR adds an
-OutputPathparameter toInvoke-LinkLanguageCheck.ps1to enable callers to redirect the JSON results file without modifying the script.Changes:
-OutputPathparameter with default value"logs/link-lang-check-results.json"(maintains backward compatibility)$OutputPathparameterlogs/link-lang-check-results.json)$repoRootvariable assignmentImpact: Improves script reusability, testability, and flexibility for CI/CD pipelines without breaking existing invocations.
Related Issue(s)
Closes #1004
Type of Change
Select all that apply:
Code & Documentation:
Infrastructure & Configuration:
AI Artifacts:
prompt-builderagent and addressed all feedback.github/instructions/*.instructions.md).github/prompts/*.prompt.md).github/agents/*.agent.md).github/skills/*/SKILL.md)Other:
.ps1,.sh,.py)Testing
Unit Tests:
Invoke-Pester -Path "scripts/tests/linting/Invoke-LinkLanguageCheck.Tests.ps1"— 32/32 tests passlogs/link-lang-check-results.jsonwhen-OutputPathomitted-OutputPathprovidedtimestamp,script,summary, andissuesfieldsLinting:
npm run lint:ps— PSScriptAnalyzer passes with no warnings