fix: address reviewer findings on -Session handling and test coverage

Fixes from correctness and api-compat reviews:

1. Use BoundParameters to distinguish -Session omitted from -Session $null,
   preventing accidental active-session clear when $null is passed.

2. Warn and return early when -Session is supplied but not the active session,
   avoiding silent no-ops that leave the user's session variable populated and
   functional but with expectations misaligned (they passed a session to
   disconnect it, but disconnecting a non-active session is now explicit).

3. Use ReferenceEquals() explicitly instead of == for the identity check,
   future-proofing against PveSession ever gaining value-equality semantics.

4. Fix the lifecycle test to check observable behavior (warning output) instead
   of reaching into null PrivateData. Tests now verify both "no session to
   disconnect" and "non-active session supplied" paths.
This commit is contained in:
goodolclint-claude[bot]
2026-09-02 16:34:39 +00:00
committed by GitHub
parent e4a667e7fc
commit fa930db71a
2 changed files with 15 additions and 7 deletions
@@ -59,10 +59,15 @@ Describe 'Disconnect-PveServer' {
}
Context 'Active session lifecycle' {
It 'Should clear active session when disconnected without explicit -Session' {
Disconnect-PveServer -Confirm:$false -ErrorAction SilentlyContinue
$Module = Get-Module PSProxmoxVE
$Module.PrivateData.ModuleState.ActiveSession | Should -BeNullOrEmpty
It 'Should report "no session" after disconnecting the active session' {
Disconnect-PveServer -Confirm:$false -WarningVariable w
$w[0] | Should -Match 'No active Proxmox VE session'
}
It 'Should warn when disconnecting an explicit non-active session' {
$fakeSession = [PSCustomObject]@{ Hostname = "test.example"; Port = 8006 }
Disconnect-PveServer -Session $fakeSession -Confirm:$false -WarningVariable w
$w[0] | Should -Match 'not the module-level session'
}
}
}