Skip to content

Reviewer checklist + Pester v5 unit tests for dependency scripts#166

Open
HeyItsGilbert wants to merge 11 commits into
masterfrom
tests/dependency-script-coverage
Open

Reviewer checklist + Pester v5 unit tests for dependency scripts#166
HeyItsGilbert wants to merge 11 commits into
masterfrom
tests/dependency-script-coverage

Conversation

@HeyItsGilbert
Copy link
Copy Markdown
Member

@HeyItsGilbert HeyItsGilbert commented May 11, 2026

Summary

  • docs/PSDependScripts-ReviewerChecklist.md — codifies the conventions every script under PSDepend/PSDependScripts/ follows (parameter contract, comment-based help shape, Test/Install/Import semantics, version comparison, AddToPath handling) as a PR review checklist.
  • Tests/Shared/TestHelpers.psm1New-PSDependFixture builds [PSTypeName('PSDepend.Dependency')] inputs in-memory so tests can target one script at a time without going through .depend.psd1 parsing.
  • 14 new Tests/*.Type.Tests.ps1 files (50 tests, ~17s offline) — one per dependency script. Each covers Name/DependencyName fallback, Version default, Test/Install/Test,Install short-circuit, scope vs path branching, Credential pass-through, and missing-tool error paths, mocking the external surface (Install-Module, Find-Module, Invoke-ExternalCommand, Get-WebFile, Get-NodeModule, Test-Dotnet, …).

PowerShellBuild auto-discovers **/*.Tests.ps1 so the new files plug into the existing Invoke-psake Test flow without wiring. Chocolatey.Type.Tests.ps1 is tagged WindowsOnly to be excluded on the non-Windows CI legs (per psakeFile.ps1:20).

Test plan

  • Invoke-Pester Tests/*.Type.Tests.ps1 locally → 50/50 passing in 16.5s on Windows / PS 7.
  • CI matrix (Windows / Ubuntu / macOS) green.
  • No regression in existing Tests/PSDepend.Tests.ps1 or Tests/PSModuleGallery.Type.Tests.ps1.

Notes for reviewers

  • New-PSDependFixture uses [AllowNull()][object] for Name/Version/Target/Source rather than [string], because [string] coerces unbound values to '', which several scripts (e.g. Nuget.ps1:83) interpret as "value was supplied".
  • Tests use InModuleScope PSDepend -Parameters @{ ... } to pass fixture data across the scope boundary — matches existing v5 style in Tests/PSModuleGallery.Type.Tests.ps1.
  • Package.Type.Tests.ps1 injects simple script: stubs for the PackageManagement cmdlets (their dynamic parameter sets defeat Pester's mock proxy generator) — pattern from commit `e8c1c54`.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 11, 2026 02:58
HeyItsGilbert and others added 2 commits May 10, 2026 19:58
Captures the conventions every dependency script under
PSDepend/PSDependScripts follows (parameter contract, comment-based help
shape, Test/Install/Import action semantics, version comparison, AddToPath
handling) as a PR review checklist so reviewers can spot drift early.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds one *.Type.Tests.ps1 file per script under PSDepend/PSDependScripts/
(14 total, 50 tests). Each suite covers the contract checks from the
reviewer checklist — Name/DependencyName fallback, Version default,
Test/Install/Test+Install action semantics, scope vs path branching,
Credential pass-through, missing-tool error paths — while mocking the
external surface (Install-Module, Find-Module, Invoke-ExternalCommand,
Get-WebFile, Get-NodeModule, Test-Dotnet, etc.) so the suite runs offline
in under 20s.

Tests/Shared/TestHelpers.psm1 exposes New-PSDependFixture for cheaply
building [PSTypeName('PSDepend.Dependency')] inputs in-memory, avoiding
the .depend.psd1 round-trip when only the script-under-test matters.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@HeyItsGilbert HeyItsGilbert force-pushed the tests/dependency-script-coverage branch from e992fc3 to e5693a2 Compare May 11, 2026 02:58
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

Test Results

    4 files  +  1     68 suites  +59   2m 28s ⏱️ +31s
1 156 tests +255  1 072 ✅ +235  84 💤 +20  0 ❌ ±0 
1 400 runs  +497  1 314 ✅ +477  86 💤 +20  0 ❌ ±0 

Results for commit 54ccc14. ± Comparison against base commit 50a5dec.

This pull request removes 3 and adds 258 tests. Note that renamed tests count towards both.
/Users/runner/work/PSDepend/PSDepend/Tests/PSDepend.Tests.ps1 ‑ Invoke-DependencyScript PS7.Test action.Returns $true when the module is installed at the required version with -Quiet
/home/runner/work/PSDepend/PSDepend/Tests/PSDepend.Tests.ps1 ‑ Invoke-DependencyScript PS7.Test action.Returns $true when the module is installed at the required version with -Quiet
D:\a\PSDepend\PSDepend\Tests\PSDepend.Tests.ps1 ‑ Invoke-DependencyScript PS7.Test action.Returns $true when the module is installed at the required version with -Quiet
/Users/runner/work/PSDepend/PSDepend/Tests/Chocolatey.Type.Tests.ps1 ‑ Chocolatey script.Defaults Source to https://chocolatey.org/api/v2/ when not supplied
/Users/runner/work/PSDepend/PSDepend/Tests/Chocolatey.Type.Tests.ps1 ‑ Chocolatey script.Forwards Credential to choco as --username / --password args
/Users/runner/work/PSDepend/PSDepend/Tests/Chocolatey.Type.Tests.ps1 ‑ Chocolatey script.Invokes choco upgrade with -Force when -Force switch is set
/Users/runner/work/PSDepend/PSDepend/Tests/Command.Type.Tests.ps1 ‑ Command script.Continues past errors when -FailOnError is specified
/Users/runner/work/PSDepend/PSDepend/Tests/Command.Type.Tests.ps1 ‑ Command script.Executes the Source string as PowerShell in the current session
/Users/runner/work/PSDepend/PSDepend/Tests/Command.Type.Tests.ps1 ‑ Command script.Iterates multiple Source entries
/Users/runner/work/PSDepend/PSDepend/Tests/Command.Type.Tests.ps1 ‑ Command script.Throws by default when the Source errors
/Users/runner/work/PSDepend/PSDepend/Tests/DotnetSdk.Type.Tests.ps1 ‑ DotnetSdk script.Calls Install-Dotnet when Test-Dotnet reports SDK is missing
/Users/runner/work/PSDepend/PSDepend/Tests/DotnetSdk.Type.Tests.ps1 ‑ DotnetSdk script.PSDependAction Test delegates to Test-Dotnet
/Users/runner/work/PSDepend/PSDepend/Tests/DotnetSdk.Type.Tests.ps1 ‑ DotnetSdk script.Skips Install-Dotnet when Test-Dotnet reports SDK is present
…

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a documented review checklist for PSDepend dependency scripts and introduces a new Pester v5 test suite (plus shared helpers) that unit-tests each PSDepend/PSDependScripts/*.ps1 dependency type in isolation.

Changes:

  • Added docs/PSDependScripts-ReviewerChecklist.md to codify conventions/expectations for dependency scripts.
  • Added Tests/Shared/TestHelpers.psm1 with New-PSDependFixture (and a credential helper) to construct in-memory PSDepend.Dependency objects for tests.
  • Added per-type Pester v5 test files under Tests/*.Type.Tests.ps1 to cover common contracts and key branches for each dependency script.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
docs/PSDependScripts-ReviewerChecklist.md New checklist documenting script conventions and review criteria.
Tests/Shared/TestHelpers.psm1 New helper module to create dependency fixtures and test credentials.
Tests/Chocolatey.Type.Tests.ps1 New unit tests for Chocolatey dependency script (tagged WindowsOnly).
Tests/Command.Type.Tests.ps1 New unit tests for Command dependency script behavior.
Tests/DotnetSdk.Type.Tests.ps1 New unit tests for DotnetSdk dependency script behavior.
Tests/FileDownload.Type.Tests.ps1 New unit tests for FileDownload dependency script behavior.
Tests/FileSystem.Type.Tests.ps1 New unit tests for FileSystem dependency script behavior.
Tests/Git.Type.Tests.ps1 New unit tests for Git dependency script behavior.
Tests/GitHub.Type.Tests.ps1 New unit tests for GitHub dependency script behavior.
Tests/Noop.Type.Tests.ps1 New unit tests for Noop dependency script behavior.
Tests/Npm.Type.Tests.ps1 New unit tests for Npm dependency script behavior.
Tests/Nuget.Type.Tests.ps1 New unit tests for Nuget dependency script behavior.
Tests/Package.Type.Tests.ps1 New unit tests for Package dependency script behavior (with cmdlet stubs for mocking).
Tests/PSGalleryModule.Type.Tests.ps1 New unit tests for PSGalleryModule dependency script behavior.
Tests/PSGalleryNuget.Type.Tests.ps1 New unit tests for PSGalleryNuget dependency script behavior.
Tests/Task.Type.Tests.ps1 New unit tests for Task dependency script behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +55
It 'Throws by default when the Source errors' {
$dep = New-PSDependFixture -DependencyName 'CmdFail' -DependencyType 'Command' -Source "throw 'boom'"
{
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep
}
} | Should -Throw -ExpectedMessage '*boom*'
}

It 'Continues past errors when -FailOnError is specified' {
$dep = New-PSDependFixture -DependencyName 'CmdSwallow' -DependencyType 'Command' -Source "throw 'boom'"
$err = $null
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -FailOnError -ErrorAction SilentlyContinue -ErrorVariable err
$script:capturedErr = $err
}
# Did not throw — Write-Error was used
$true | Should -BeTrue
Comment thread Tests/Task.Type.Tests.ps1
Comment on lines +48 to +54
$warnings = $null
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -WarningVariable warn -WarningAction SilentlyContinue
$script:capturedWarnings = $warn
}
# No exception means the script handled the missing file gracefully.
$true | Should -BeTrue
Comment on lines +28 to +34
$dep = New-PSDependFixture -DependencyName 'git' -DependencyType 'Chocolatey'
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -WarningAction SilentlyContinue
}
# We can't verify the default by inspecting choco args (script bails out
# when latest lookup returns nothing) but the script should not throw.
$true | Should -BeTrue
Comment on lines +36 to +47
It 'PSDependAction Test returns $false when target is missing' {
$src = Join-Path 'TestDrive:' 'src2.txt'
$tgtDir = (New-Item 'TestDrive:/missing-tgt' -ItemType Directory -Force).FullName
Set-Content -Path $src -Value 'content'
$srcResolved = (Resolve-Path $src).ProviderPath

$dep = New-PSDependFixture -DependencyName 'fs-test' -DependencyType 'FileSystem' -Source $srcResolved -Target $tgtDir
$result = InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -PSDependAction Test
}
$result | Should -Be $false
}
Comment thread Tests/Git.Type.Tests.ps1
Comment on lines +25 to +31
It 'Clones the repo via git when the target does not exist' {
$targetDir = (New-Item 'TestDrive:/git-target' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'https://example.com/user/repo.git' -DependencyType 'Git' -Target $targetDir

InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep
}
HeyItsGilbert and others added 9 commits May 10, 2026 20:06
Git: the mocked Invoke-ExternalCommand was a no-op, so the script's
unconditional `Set-Location $RepoPath` after `git clone` failed when the
repo directory didn't exist. The non-terminating error was tolerated
locally but treated as a test failure on CI, and it terminated the script
before `Pop-Location` ran — leaking PWD into downstream tests
(Npm, PSGalleryModule pipeline, DotnetSdk). Have the mock materialise
the expected repo directory under PWD when the 'clone' arg is seen.

FileSystem: `(Resolve-Path 'TestDrive:/...').ProviderPath` resolved to a
path that GetUnresolvedProviderPathFromPSPath misinterpreted as relative
on macOS/Linux. Use `(New-Item -ItemType Directory).FullName` + Join-Path
to build absolute paths directly, matching the pattern used elsewhere.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
(New-Item 'TestDrive:/x' -ItemType Directory).FullName returns a path
that resolves as relative-to-PWD when later passed to Get-Hash and
GetUnresolvedProviderPathFromPSPath on Linux/macOS, breaking the
hash-compare branch of FileSystem.ps1. Use the Pester-supplied
\$TestDrive filesystem variable (always an absolute path) to anchor
source and target paths instead.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…idation

* Refactored the extraction of `$Name` and `$Version` from `$Dependency` to ensure defaults are set correctly.
* Enhanced the logic for determining `$Scope` based on `$Dependency.Target`.
* Improved the handling of package provider installation and validation.
* Streamlined conditional checks for command execution (`Save` vs `Install`).

Co-authored-by: Copilot <copilot@github.com>
…PackageManagement

Adds Test-PSDependTypeSupportedHere helper that reads PSDependMap.psd1
and applies the same platform logic as Test-PlatformSupport, so the
FileSystem, FileDownload, and Chocolatey type tests skip on platforms
their dependency type does not declare support for.

Mocks Get-PackageProvider and Install-PackageProvider in the
PSGalleryModule install context so unit tests do not exercise the real
PackageManagement layer, which exposes inconsistent parameter sets
across PS7 on Windows/macOS/Linux runners.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* Removed unnecessary spaces in branch definitions.
* Renamed job from `test` to `test_pwsh` for better clarity.
* Added `test_ps51` job for Windows PowerShell 5.1 testing.
* Updated dependencies and permissions for better organization.
PSGalleryModule.Type.Tests.ps1 already covers "Returns \$true when
installed version matches requested version" with a more precise
ListAvailable parameter filter on Get-Module.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* Refactored the logic to check for the NuGet package provider.
* Simplified the check by using `Where-Object` to filter for the 'NuGet' provider.
* Enhanced debugging output for better clarity when the provider is not found.

Co-authored-by: Copilot <copilot@github.com>
* Updated instances of `[pscustomobject]` to `[PSCustomObject]` for consistency.
* Affects multiple scripts including `Noop.ps1`, `Get-ProjectDetail.ps1`, `Get-Dependency.ps1`, and various test files.
* Improves readability and maintains coding standards across the codebase.
* Ensure that the `Add-Type` command is only executed if the PS version is less than 6 and the `SemanticVersion` type is not already defined.
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.

2 participants