Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/security/Install-PSModules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Resolve-ConfigPath {
if ($env:PS_MODULE_CONFIG_PATH) { return $env:PS_MODULE_CONFIG_PATH }

$repoRoot = git rev-parse --show-toplevel 2>$null
if (-not $repoRoot) { $repoRoot = Split-Path $PSScriptRoot }
if (-not $repoRoot) { $repoRoot = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent }
return Join-Path $repoRoot 'scripts/security/ps-module-versions.json'
}

Expand Down
23 changes: 23 additions & 0 deletions scripts/tests/security/Install-PSModules.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ Describe 'Resolve-ConfigPath' -Tag 'Unit' {
}
}

Context 'when git rev-parse cannot determine the repository root' {
BeforeEach {
$script:OrigEnv = $env:PS_MODULE_CONFIG_PATH
$env:PS_MODULE_CONFIG_PATH = $null
# Simulates git being unavailable, a non-clone checkout, or a linked
# worktree whose main .git is unreachable, forcing the path fallback.
Mock git { }
}
AfterEach {
$env:PS_MODULE_CONFIG_PATH = $script:OrigEnv
}

It 'Does not duplicate the scripts path segment' {
$result = Resolve-ConfigPath -Explicit ''
$result | Should -Not -Match 'scripts[\\/]scripts'
}

It 'Resolves to the existing manifest at the repository root' {
$result = Resolve-ConfigPath -Explicit ''
Test-Path -LiteralPath $result | Should -BeTrue
}
}

Context 'when explicit param takes precedence over env var' {
BeforeEach {
$script:OrigEnv = $env:PS_MODULE_CONFIG_PATH
Expand Down
Loading