Skip to content

Rename Pester.ps1 script-scope helper to Pester.ScriptScope.ps1#2832

Merged
nohwnd merged 1 commit into
mainfrom
nohwnd-issue-2826-psresource-install-warning
Jul 1, 2026
Merged

Rename Pester.ps1 script-scope helper to Pester.ScriptScope.ps1#2832
nohwnd merged 1 commit into
mainfrom
nohwnd-issue-2826-psresource-install-warning

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 1, 2026

Copy link
Copy Markdown
Member

Problem

Installing Pester with Install-PSResource Pester prints a spurious warning:

WARNING: The installation path for the script does not currently appear in the CurrentUser path environment variable. To make the script discoverable, add the script installation path, .../Modules, to the environment PATH variable.

Root cause

PSResourceGet decides whether an installed package is a script by checking for a <ModuleName>.ps1 file in the package root (InstallHelper.cs):

var scriptPath = Path.Combine(tempDirNameVersion, pkgName + PSScriptFileExt); // Pester.ps1
bool isScript = File.Exists(scriptPath);                                       // true!

Pester ships a tiny Pester.ps1 (used by Invoke-InNewScriptScope for script-scope isolation), so isScript becomes true and the PATH warning at if (!_savePkg && isScript) fires. The upstream fix in PSResourceGet#1043 wasn't accepted, so the agreed fallback is to rename the file on Pester's side.

Fix

Rename src/Pester.ps1src/Pester.ScriptScope.ps1 so the shipped module no longer contains a file matching the module name, and update its references:

  • src/Pester.Runtime.ps1 — the Invoke-InNewScriptScope path
  • build.ps1 — the copy-to-bin/ step
  • publish/filesToPublish.ps1 — the published-file list

The file must stay a standalone .ps1 on disk (it is invoked as a real script to push a new script scope; it is not inlined into Pester.psm1). A comment in the file and at the call site documents why it must not be named Pester.ps1.

Regression test

Added a StyleRules-tagged test in tst/Pester.Tests.ps1 asserting the built module ships Pester.ScriptScope.ps1 and contains no Pester.ps1.

Verification

  • Clean build succeeds; bin/ ships Pester.ScriptScope.ps1 and no Pester.ps1.
  • New regression tests pass.
  • Running a real test file exercises Invoke-InNewScriptScope and passes (script scope pushed, $PSCommandPath set).
  • RSpec acceptance suite: 116/116 passing.
  • Custom build-analyzer rules on ./src: no new violations (new file is clean).

Fix #2826

PSResourceGet decides whether an installed package is a script by checking
for a <ModuleName>.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>
@nohwnd nohwnd added this to the 6.0.0 milestone Jul 1, 2026
@nohwnd nohwnd enabled auto-merge (squash) July 1, 2026 20:54
@nohwnd nohwnd merged commit bb0269e into main Jul 1, 2026
13 checks passed
@nohwnd nohwnd deleted the nohwnd-issue-2826-psresource-install-warning branch July 1, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install-PSResource Pester shows installation path warning

1 participant