From 0ff34664f9d87d76ae9d90dba12df9d3d429f5dd Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 1 Jul 2026 22:40:07 +0200 Subject: [PATCH] Rename Pester.ps1 script-scope helper to Pester.ScriptScope.ps1 PSResourceGet decides whether an installed package is a script by checking for a .ps1 file in the package root. Pester shipped a Pester.ps1 (used by Invoke-InNewScriptScope for script-scope isolation), so installing Pester with Install-PSResource printed a spurious "installation path for the script does not currently appear in PATH" warning. Rename the file to Pester.ScriptScope.ps1 so it no longer matches the module name, update the runtime reference, the build copy step and the published file list, and add a regression test asserting the shipped module never contains a Pester.ps1. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build.ps1 | 2 +- publish/filesToPublish.ps1 | 2 +- src/Pester.Runtime.ps1 | 3 ++- src/Pester.ScriptScope.ps1 | 10 ++++++++++ src/Pester.ps1 | 4 ---- tst/Pester.Tests.ps1 | 18 ++++++++++++++++++ 6 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/Pester.ScriptScope.ps1 delete mode 100644 src/Pester.ps1 diff --git a/build.ps1 b/build.ps1 index ff922bc21..e42e3dc72 100644 --- a/build.ps1 +++ b/build.ps1 @@ -206,7 +206,7 @@ function Copy-Content ($Content) { $content = @( , ("$PSScriptRoot/src/en-US/*.txt", "$PSScriptRoot/bin/en-US/") - , ("$PSScriptRoot/src/Pester.ps1", "$PSScriptRoot/bin/") + , ("$PSScriptRoot/src/Pester.ScriptScope.ps1", "$PSScriptRoot/bin/") , ("$PSScriptRoot/src/Pester.psd1", "$PSScriptRoot/bin/") , ("$PSScriptRoot/src/Pester.Format.ps1xml", "$PSScriptRoot/bin/") ) diff --git a/publish/filesToPublish.ps1 b/publish/filesToPublish.ps1 index ca9f45457..9f655c5cb 100644 --- a/publish/filesToPublish.ps1 +++ b/publish/filesToPublish.ps1 @@ -1,5 +1,5 @@ @( - 'Pester.ps1' + 'Pester.ScriptScope.ps1' 'Pester.psd1' 'Pester.psm1' 'Pester.Format.ps1xml' diff --git a/src/Pester.Runtime.ps1 b/src/Pester.Runtime.ps1 index 5efe09925..33e2ef701 100644 --- a/src/Pester.Runtime.ps1 +++ b/src/Pester.Runtime.ps1 @@ -2693,7 +2693,8 @@ function Invoke-InNewScriptScope ([ScriptBlock] $ScriptBlock, $SessionState) { # correct session state, and then invoke the file. We can also pass a script block tied # to the current module to invoke internal function in the newly pushed script scope. - $Path = "$PSScriptRoot/Pester.ps1" + # Invoked as a standalone script file (not Pester.ps1; see Pester.ScriptScope.ps1 for why). + $Path = "$PSScriptRoot/Pester.ScriptScope.ps1" $Data = @{ ScriptBlock = $ScriptBlock } $wrapper = { diff --git a/src/Pester.ScriptScope.ps1 b/src/Pester.ScriptScope.ps1 new file mode 100644 index 000000000..ccafcf768 --- /dev/null +++ b/src/Pester.ScriptScope.ps1 @@ -0,0 +1,10 @@ +# This file is invoked as a real script file by Invoke-InNewScriptScope to push a new +# script scope into the caller's session state (see src/Pester.Runtime.ps1). +# +# Do NOT rename it to Pester.ps1. PSResourceGet treats a '.ps1' file in the +# package (i.e. Pester.ps1) as a script and prints a spurious installation-path warning +# on Install-PSResource Pester. See https://github.com/pester/Pester/issues/2826. +param ($ScriptBlock) + +. $ScriptBlock + diff --git a/src/Pester.ps1 b/src/Pester.ps1 deleted file mode 100644 index b09620420..000000000 --- a/src/Pester.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -param ($ScriptBlock) - -. $ScriptBlock - diff --git a/tst/Pester.Tests.ps1 b/tst/Pester.Tests.ps1 index 9d2493c22..a01ff5aa9 100644 --- a/tst/Pester.Tests.ps1 +++ b/tst/Pester.Tests.ps1 @@ -208,6 +208,24 @@ Describe 'Style rules' -Tag StyleRules { } } +Describe 'Module packaging' -Tag StyleRules { + # Issue #2826: PSResourceGet decides a package is a script by looking for a + # '.ps1' file in the package root (i.e. Pester.ps1). When that file is + # present it prints a spurious installation-path warning on Install-PSResource Pester. + # The script-scope helper is therefore shipped as Pester.ScriptScope.ps1 instead. + BeforeAll { + $pesterRoot = (Get-Module Pester).ModuleBase + } + + It 'does not ship a Pester.ps1 that PSResourceGet would treat as a script' { + (Join-Path $pesterRoot 'Pester.ps1') | Should -Not -Exist + } + + It 'ships the script-scope helper as Pester.ScriptScope.ps1' { + (Join-Path $pesterRoot 'Pester.ScriptScope.ps1') | Should -Exist + } +} + InPesterModuleScope { Describe 'Find-File' { BeforeAll {