Skip to content

Commit d288e61

Browse files
Fix nested ShouldProcess prompts; harden attachment-delete integration test
- Connect/Disconnect-Confluence: pass -Confirm:$false to the internal Set-ConfluenceConfig call so -Confirm does not raise a second nested confirmation prompt (review threads on Connect L136 / Disconnect L40). - tests: use IsNullOrWhiteSpace for the integration skip guard so a whitespace-only CONFLUENCE_* variable is treated as missing (review thread on L113). - tests: retry Remove-ConfluenceAttachment on transient HTTP 409 (conflict deleting attachment) to absorb Confluence Cloud eventual consistency; fixes the flaky Test-Confluence (Windows) CI failure.
1 parent fb8d9ac commit d288e61

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/functions/public/Auth/Connect-Confluence.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ function Connect-Confluence {
133133
}
134134

135135
$stored = Set-Context -ID $Name -Context $context -Vault $script:Confluence.ContextVault -PassThru
136-
Set-ConfluenceConfig -Name 'DefaultContext' -Value $Name
136+
# The outer cmdlet already confirmed this operation; suppress the inner cmdlet's own
137+
# ShouldProcess prompt so -Confirm does not trigger a second, nested confirmation.
138+
Set-ConfluenceConfig -Name 'DefaultContext' -Value $Name -Confirm:$false
137139

138140
if ($PassThru) {
139141
$stored

src/functions/public/Auth/Disconnect-Confluence.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function Disconnect-Confluence {
3535
if ($PSCmdlet.ShouldProcess($Name, 'Remove Confluence credential context')) {
3636
Remove-Context -ID $Name -Vault $script:Confluence.ContextVault -ErrorAction SilentlyContinue
3737
if ($script:Confluence.Config['DefaultContext'] -eq $Name) {
38-
Set-ConfluenceConfig -Name 'DefaultContext' -Value ''
38+
# The outer cmdlet already confirmed this operation; suppress the inner cmdlet's
39+
# ShouldProcess prompt so -Confirm does not trigger a second, nested confirmation.
40+
Set-ConfluenceConfig -Name 'DefaultContext' -Value '' -Confirm:$false
3941
}
4042
}
4143
}

tests/Confluence.Tests.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Describe 'Confluence' {
110110
$env:CONFLUENCE_SITE
111111
$env:CONFLUENCE_USERNAME
112112
$env:CONFLUENCE_SPACE_KEY
113-
) | Where-Object { [string]::IsNullOrEmpty($_) }
113+
) | Where-Object { [string]::IsNullOrWhiteSpace($_) }
114114

115115
Context 'Integration' -Skip:(@($missingIntegrationVars).Count -gt 0) {
116116
BeforeAll {
@@ -671,7 +671,22 @@ Describe 'Confluence' {
671671
}
672672

673673
It 'Remove-ConfluenceAttachment deletes the attachment' {
674-
{ Remove-ConfluenceAttachment -AttachmentId $script:attachmentId -Context 'ci' } | Should -Not -Throw
674+
# Confluence Cloud can briefly return HTTP 409 ('Encountered conflict deleting
675+
# attachment') when an attachment is removed shortly after it is uploaded, while
676+
# the upload is still being reconciled server-side. Retry the delete so this
677+
# eventual-consistency window does not fail the run; a non-conflict error, or a
678+
# conflict that never clears, still surfaces and fails the test.
679+
{
680+
for ($attempt = 1; $attempt -le 4; $attempt++) {
681+
try {
682+
Remove-ConfluenceAttachment -AttachmentId $script:attachmentId -Context 'ci'
683+
break
684+
} catch {
685+
if ($_.Exception.Message -notmatch 'HTTP 409|conflict' -or $attempt -eq 4) { throw }
686+
Start-Sleep -Seconds 2
687+
}
688+
}
689+
} | Should -Not -Throw
675690
LogGroup 'Attachments after removal' {
676691
$remaining = Get-ConfluenceAttachment -PageId $script:attachPage.id -Context 'ci'
677692
Write-Host ($remaining | Format-List | Out-String)

0 commit comments

Comments
 (0)