|
| 1 | +BeforeAll { |
| 2 | + $projectRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) |
| 3 | + . (Join-Path $projectRoot 'src/private/release/GetGitCommitMessagesForVersionBump.ps1') |
| 4 | + |
| 5 | + function Test-GitRepositoryIsAvailable {param($ProjectRoot) return $true} |
| 6 | + function Invoke-NovaGitCommand {param($ProjectRoot, $Arguments) return [pscustomobject]@{ExitCode=0; Output=@()}} |
| 7 | + function Get-NovaGitCommandOutputText {param($Result) return ($Result.Output -join "`n")} |
| 8 | +} |
| 9 | + |
| 10 | +Describe 'Get-GitCommitMessageForVersionBump' { |
| 11 | + It 'returns an empty array when no git repository is available' { |
| 12 | + Mock Test-GitRepositoryIsAvailable {return $false} |
| 13 | + $messages = Get-GitCommitMessageForVersionBump -ProjectRoot '/proj' |
| 14 | + @($messages).Count | Should -Be 0 |
| 15 | + } |
| 16 | + |
| 17 | + It 'returns parsed commit messages when git is available' { |
| 18 | + Mock Invoke-NovaGitCommand {return [pscustomobject]@{ExitCode=0; Output=@('feat: a','body','--END-COMMIT--','fix: b','--END-COMMIT--')}} |
| 19 | + $messages = Get-GitCommitMessageForVersionBump -ProjectRoot '/proj' |
| 20 | + @($messages).Count | Should -BeGreaterThan 0 |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +Describe 'Get-NovaVersionBumpCommitLogResult' { |
| 25 | + It 'uses lastTag..HEAD range when a last tag was detected' { |
| 26 | + Mock Invoke-NovaGitCommand {return [pscustomobject]@{ExitCode=0; Output=@('out')}} |
| 27 | + $tagResult = [pscustomobject]@{ExitCode=0; Output=@('v1.0.0')} |
| 28 | + $result = Get-NovaVersionBumpCommitLogResult -ProjectRoot '/proj' -Format 'f' -LastTagResult $tagResult |
| 29 | + $result.ExitCode | Should -Be 0 |
| 30 | + Should -Invoke Invoke-NovaGitCommand -ParameterFilter {$Arguments -contains 'v1.0.0..HEAD'} |
| 31 | + } |
| 32 | + |
| 33 | + It 'falls back to plain log when no tag is found' { |
| 34 | + Mock Invoke-NovaGitCommand {return [pscustomobject]@{ExitCode=0; Output=@()}} |
| 35 | + $tagResult = [pscustomobject]@{ExitCode=128; Output=@()} |
| 36 | + Get-NovaVersionBumpCommitLogResult -ProjectRoot '/proj' -Format 'f' -LastTagResult $tagResult | Out-Null |
| 37 | + Should -Invoke Invoke-NovaGitCommand -ParameterFilter {-not ($Arguments -match '\.\.HEAD$')} |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +Describe 'ConvertFrom-NovaVersionBumpCommitLogResult' { |
| 42 | + It 'returns an empty array when the result has a non-zero exit code' { |
| 43 | + $result = [pscustomobject]@{ExitCode=1; Output=@('feat: x')} |
| 44 | + @((ConvertFrom-NovaVersionBumpCommitLogResult -Result $result)).Count | Should -Be 0 |
| 45 | + } |
| 46 | + |
| 47 | + It 'splits commits on the --END-COMMIT-- delimiter and trims them' { |
| 48 | + $result = [pscustomobject]@{ExitCode=0; Output=@('feat: a','body','--END-COMMIT--','fix: b','--END-COMMIT--')} |
| 49 | + $commits = ConvertFrom-NovaVersionBumpCommitLogResult -Result $result |
| 50 | + @($commits).Count | Should -BeGreaterThan 0 |
| 51 | + } |
| 52 | +} |
0 commit comments