Skip to content

Commit 6254d34

Browse files
Reproduce lost release tags during shared publication reservation
Three isolated disappearance/replacement races each reach one Gallery spy write before the guard correction. Two partial-claim controls pass. No live publication is used.
1 parent dc78ee2 commit 6254d34

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

‎.github/actions/Publish-PSModule/tests/Publish-PSModule.Preflight.Tests.ps1‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,88 @@ Describe 'Publish-PSModule source-bound preflight' {
364364
$script:state.GitHubWrites | Should -Be 0
365365
}
366366

367+
It 'rejects an observed tag that <Mutation> during the shared coordinate reservation' -ForEach @(
368+
@{ Mutation = 'disappears' }
369+
@{ Mutation = 'is replaced' }
370+
) {
371+
Set-PSModuleFixtureClaim -State $script:state -Claim $script:state.ExpectedClaim
372+
$script:state.VersionTag = $null
373+
$script:state.VersionTagObject = $null
374+
$script:state.LateTagMutation = $Mutation
375+
$script:state.OnVersionTagCreate = {
376+
param($State)
377+
if ($State.LateTagMutation -ceq 'disappears') {
378+
$State.Tag = $null
379+
} else {
380+
Set-PSModuleFixtureClaim -State $State -Claim $State.ExpectedClaim `
381+
-TagSha '4444444444444444444444444444444444444444'
382+
}
383+
}
384+
385+
$failure = $null
386+
try { & $script:publishScriptPath 1>$null 6>$null } catch { $failure = $_ }
387+
388+
$script:state.GalleryWrites | Should -Be 0
389+
$script:state.GitHubCreationUpload | Should -Be 0
390+
$script:state.Calls | Should -Contain 'module-version-ref-create'
391+
$script:state.Calls | Should -Not -Contain 'tag-ref-create'
392+
$failure.Exception.Message | Should -Match 'tag.*changed|disappeared'
393+
}
394+
395+
It 'rejects losing a tag first observed after preflight during the shared coordinate reservation' {
396+
$script:state.OnTagRead = {
397+
param($State)
398+
if ($State.TagReads -eq 2) {
399+
Set-PSModuleFixtureClaim -State $State -Claim $State.ExpectedClaim
400+
$State.VersionTag = $null
401+
$State.VersionTagObject = $null
402+
}
403+
}
404+
$script:state.OnVersionTagCreate = {
405+
param($State)
406+
$State.Tag = $null
407+
}
408+
409+
$failure = $null
410+
try { & $script:publishScriptPath 1>$null 6>$null } catch { $failure = $_ }
411+
412+
$script:state.GalleryWrites | Should -Be 0
413+
$script:state.GitHubCreationUpload | Should -Be 0
414+
$script:state.Calls | Should -Contain 'module-version-ref-create'
415+
$script:state.Calls | Should -Not -Contain 'tag-ref-create'
416+
$script:state.Tag | Should -BeNullOrEmpty
417+
$failure.Exception.Message | Should -Match 'tag.*changed|disappeared'
418+
}
419+
420+
It 'reserves a missing shared coordinate without replacing an unchanged existing tag' {
421+
Set-PSModuleFixtureClaim -State $script:state -Claim $script:state.ExpectedClaim
422+
$script:state.VersionTag = $null
423+
$script:state.VersionTagObject = $null
424+
425+
{ & $script:publishScriptPath 1>$null 6>$null } | Should -Not -Throw
426+
427+
$script:state.GalleryWrites | Should -Be 1
428+
$script:state.Tag.sha | Should -BeExactly '3333333333333333333333333333333333333333'
429+
$script:state.VersionTag.sha | Should -BeExactly $script:state.Tag.sha
430+
$script:state.Calls | Should -Contain 'module-version-ref-create'
431+
$script:state.Calls | Should -Not -Contain 'tag-ref-create'
432+
$script:state.Calls | Should -Not -Contain 'tag-object-create'
433+
}
434+
435+
It 'completes a partial shared claim when the release tag has never been observed' {
436+
Set-PSModuleFixtureClaim -State $script:state -Claim $script:state.ExpectedClaim
437+
$script:state.Tag = $null
438+
$script:state.TagObject = $null
439+
440+
{ & $script:publishScriptPath 1>$null 6>$null } | Should -Not -Throw
441+
442+
$script:state.GalleryWrites | Should -Be 1
443+
$script:state.Tag.sha | Should -BeExactly $script:state.VersionTag.sha
444+
$script:state.Calls | Should -Contain 'tag-ref-create'
445+
$script:state.Calls | Should -Not -Contain 'module-version-ref-create'
446+
$script:state.Calls | Should -Not -Contain 'tag-object-create'
447+
}
448+
367449
It 'rejects supplied PR context without a positive identity before all writes' -ForEach @(
368450
@{ Json = '{}' }
369451
@{ Json = '{"Number":0}' }

0 commit comments

Comments
 (0)