From 7962a549f02e49a7ef5a196e9a9c76e899a90d17 Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Thu, 19 Mar 2026 08:45:23 -0500 Subject: [PATCH] fix(test): load module via .psd1 manifest instead of raw DLL Loading via the module manifest (.psd1) ensures PowerShell sets up proper assembly resolution context. Loading via raw DLL path bypasses PS's module loading infrastructure and fails on CI runners where the .NET SDK's assembly resolution conflicts with PS's bundled runtime. Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/PSProxmoxVE.Tests/_TestHelper.ps1 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/PSProxmoxVE.Tests/_TestHelper.ps1 b/tests/PSProxmoxVE.Tests/_TestHelper.ps1 index 4696613..a249604 100644 --- a/tests/PSProxmoxVE.Tests/_TestHelper.ps1 +++ b/tests/PSProxmoxVE.Tests/_TestHelper.ps1 @@ -10,15 +10,14 @@ if (Get-Module -Name PSProxmoxVE) { return } # 1. Try importing by module name (works in CI where the module is # installed to a PSModulePath location via dotnet publish + copy). -try { +$available = Get-Module PSProxmoxVE -ListAvailable -ErrorAction SilentlyContinue +if ($available) { Import-Module PSProxmoxVE -Force -ErrorAction Stop return } -catch { - # Module not on PSModulePath — fall through to local-path discovery. -} -# 2. Discover the built DLL from the local source tree. +# 2. Discover the module manifest (.psd1) from the local source tree. +# Loading via manifest ensures PS handles assembly resolution correctly. # Prefer the framework that matches the running PowerShell edition. $repoRoot = Resolve-Path (Join-Path $PSScriptRoot '../..') $moduleRoot = Join-Path $repoRoot 'src/PSProxmoxVE' @@ -32,21 +31,21 @@ else { $searchPaths = foreach ($fw in $frameworks) { # Publish output (has all dependencies co-located) - Join-Path $repoRoot "publish/$fw/PSProxmoxVE.dll" + Join-Path $repoRoot "publish/$fw/PSProxmoxVE.psd1" # Build output - Join-Path $moduleRoot "bin/Debug/$fw/PSProxmoxVE.dll" - Join-Path $moduleRoot "bin/Release/$fw/PSProxmoxVE.dll" + Join-Path $moduleRoot "bin/Debug/$fw/PSProxmoxVE.psd1" + Join-Path $moduleRoot "bin/Release/$fw/PSProxmoxVE.psd1" } -$moduleDll = $searchPaths | Where-Object { Test-Path $_ } | Select-Object -First 1 +$moduleManifest = $searchPaths | Where-Object { Test-Path $_ } | Select-Object -First 1 -if ($null -eq $moduleDll) { - throw "PSProxmoxVE.dll not found. Build the project before running Pester tests." +if ($null -eq $moduleManifest) { + throw "PSProxmoxVE module not found. Build the project before running Pester tests." } # Remove deps.json if present — it causes assembly resolution conflicts # when loading a binary module inside PowerShell's own .NET runtime. -$depsJson = Join-Path (Split-Path $moduleDll) 'PSProxmoxVE.deps.json' +$depsJson = Join-Path (Split-Path $moduleManifest) 'PSProxmoxVE.deps.json' if (Test-Path $depsJson) { Remove-Item $depsJson -Force } -Import-Module $moduleDll -Force -ErrorAction Stop +Import-Module $moduleManifest -Force -ErrorAction Stop