Skip to content

Commit d4d2c9c

Browse files
committed
feat(#97): enhance CLI output and result contracts for structured data
- Add tests for formatted CLI command results - Implement tests for version update handling with WhatIf scenarios - Ensure release notes URI is correctly resolved in update messages
1 parent bc8bb00 commit d4d2c9c

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

tests/CoverageGaps.Cli.Tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ Describe 'Coverage gaps for CLI and installed-version internals' {
140140
}
141141
}
142142

143+
It 'Format-NovaCliCommandResult renders applied bump results as a completed CLI summary' {
144+
InModuleScope $script:moduleName {
145+
$versionUpdateResult = [pscustomobject]@{
146+
PreviousVersion = '1.0.0'
147+
NewVersion = '1.1.0'
148+
Label = 'Minor'
149+
CommitCount = 2
150+
Applied = $true
151+
}
152+
153+
$result = Format-NovaCliCommandResult -Command 'bump' -Result $versionUpdateResult
154+
155+
$result | Should -Be 'Version bump completed: 1.0.0 -> 1.1.0 | Label: Minor | Commits: 2'
156+
}
157+
}
158+
143159
It 'Invoke-NovaCliCommandRoute formats bump results through the shared CLI formatter' {
144160
InModuleScope $script:moduleName {
145161
$invocationContext = [pscustomobject]@{

tests/CoverageGaps.ReleaseInternals.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,32 @@ Describe 'Coverage gaps for release and git internals' {
254254
}
255255
}
256256

257+
It 'Set-NovaModuleVersion returns a non-applied write result when WhatIf declines project.json persistence' {
258+
InModuleScope $script:moduleName {
259+
Mock Get-NovaVersionUpdatePlan {
260+
[pscustomobject]@{
261+
ProjectFile = '/tmp/project.json'
262+
NewVersion = [semver]'1.3.0-preview'
263+
}
264+
}
265+
Mock Read-ProjectJsonData {
266+
[ordered]@{
267+
Version = '1.2.3'
268+
}
269+
}
270+
Mock Write-ProjectJsonData {throw 'should not persist during WhatIf'}
271+
272+
$result = Set-NovaModuleVersion -Label Minor -PreviewRelease -WhatIf
273+
274+
$result.ProjectFile | Should -Be '/tmp/project.json'
275+
$result.PreviousVersion | Should -Be '1.2.3'
276+
$result.NewVersion | Should -Be '1.3.0-preview'
277+
$result.Applied | Should -BeFalse
278+
Assert-MockCalled Read-ProjectJsonData -Times 1 -ParameterFilter {$ProjectJsonPath -eq '/tmp/project.json'}
279+
Assert-MockCalled Write-ProjectJsonData -Times 0
280+
}
281+
}
282+
257283
It 'Publish-NovaBuiltModuleToRepository uses the PSGallery fallback api key without forcing verbose output' {
258284
InModuleScope $script:moduleName {
259285
$originalApiKey = $env:PSGALLERY_API

tests/UpdateNotification.Tests.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ Describe 'Update notification behavior' {
308308
}
309309
}
310310

311+
It 'Complete-NovaModuleSelfUpdateResult overwrites an existing release-notes property in place' {
312+
InModuleScope $script:moduleName {
313+
$plan = [pscustomobject]@{
314+
ModuleName = 'NovaModuleTools'
315+
UpdateAvailable = $true
316+
ReleaseNotesUri = 'https://old.example/release-notes'
317+
}
318+
319+
$result = Complete-NovaModuleSelfUpdateResult -Plan $plan -ReleaseNotesUri 'https://www.novamoduletools.com/release-notes.html'
320+
321+
$result.ReleaseNotesUri | Should -Be 'https://www.novamoduletools.com/release-notes.html'
322+
@($result.PSObject.Properties.Name | Where-Object {$_ -eq 'ReleaseNotesUri'}).Count | Should -Be 1
323+
}
324+
}
325+
311326
It 'Update-NovaModuleTool delegates workflow context resolution and execution to private helpers' {
312327
InModuleScope $script:moduleName {
313328
Mock Get-NovaModuleSelfUpdateWorkflowContext {
@@ -348,6 +363,38 @@ Describe 'Update notification behavior' {
348363
}
349364
}
350365

366+
It 'Update-NovaModuleTool returns the unchanged plan and skips update execution when WhatIf declines the update action' {
367+
InModuleScope $script:moduleName {
368+
Mock Get-NovaModuleSelfUpdateWorkflowContext {
369+
[pscustomobject]@{
370+
Plan = [pscustomobject]@{
371+
ModuleName = 'NovaModuleTools'
372+
CurrentVersion = '1.0.0'
373+
TargetVersion = '1.1.0'
374+
PrereleaseNotificationsEnabled = $true
375+
UpdateAvailable = $true
376+
Updated = $false
377+
Cancelled = $false
378+
IsPrereleaseTarget = $false
379+
UsedAllowPrerelease = $false
380+
}
381+
Action = 'Update NovaModuleTools to version 1.1.0'
382+
}
383+
}
384+
Mock Invoke-NovaModuleSelfUpdateWorkflow {throw 'should not update during WhatIf'}
385+
Mock Write-NovaModuleReleaseNotesLink {throw 'should not write release notes during WhatIf'}
386+
387+
$result = Update-NovaModuleTool -WhatIf
388+
389+
$result.UpdateAvailable | Should -BeTrue
390+
$result.Updated | Should -BeFalse
391+
$result.ReleaseNotesUri | Should -BeNullOrEmpty
392+
Assert-MockCalled Get-NovaModuleSelfUpdateWorkflowContext -Times 1
393+
Assert-MockCalled Invoke-NovaModuleSelfUpdateWorkflow -Times 0
394+
Assert-MockCalled Write-NovaModuleReleaseNotesLink -Times 0
395+
}
396+
}
397+
351398
It 'Get-NovaUpdateNotificationPreference defaults prerelease notifications to enabled when no settings file exists' {
352399
$configRoot = Join-Path $TestDrive 'config-default'
353400
$originalConfigHome = $env:XDG_CONFIG_HOME
@@ -625,6 +672,17 @@ throw 'offline'
625672
}
626673
}
627674

675+
It 'Get-NovaModuleReleaseNotesMessage resolves the URI from the module parameter set' {
676+
InModuleScope $script:moduleName {
677+
Mock Get-NovaModuleReleaseNotesUri {'https://www.novamoduletools.com/release-notes.html'}
678+
679+
$message = Get-NovaModuleReleaseNotesMessage -Module ([pscustomobject]@{Name = 'NovaModuleTools'})
680+
681+
$message | Should -Be 'Release notes: https://www.novamoduletools.com/release-notes.html'
682+
Assert-MockCalled Get-NovaModuleReleaseNotesUri -Times 1
683+
}
684+
}
685+
628686
It 'Update-NovaModuleTool applies a stable update without prerelease confirmation' {
629687
$result = Invoke-TestNovaSelfUpdate -Options ([pscustomobject]@{
630688
PrereleaseNotificationsEnabled = $true

0 commit comments

Comments
 (0)