From 9e74b9be4af9b0ac6ab3a46877544b823c096198 Mon Sep 17 00:00:00 2001 From: Julian Lechner Date: Fri, 18 Sep 2026 12:22:51 +0200 Subject: [PATCH] fix(capabilities): read Python exit code directly --- scripts/commands/check-capabilities.ps1 | 5 +++-- scripts/tests/test-capabilities.ps1 | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 scripts/tests/test-capabilities.ps1 diff --git a/scripts/commands/check-capabilities.ps1 b/scripts/commands/check-capabilities.ps1 index a9e0075..d46c031 100644 --- a/scripts/commands/check-capabilities.ps1 +++ b/scripts/commands/check-capabilities.ps1 @@ -13,8 +13,9 @@ Require-Command jq $pythonVersion = $null foreach ($python in @('python', 'python3')) { if (-not (Get-Command $python -ErrorAction SilentlyContinue)) { continue } - $candidate = (& $python --version 2>$null | Select-Object -First 1) -replace '^Python\s+', '' - if ($LASTEXITCODE -eq 0) { $pythonVersion = $candidate; break } + $candidate = & $python --version 2>$null + $pythonExitCode = $LASTEXITCODE + if ($pythonExitCode -eq 0) { $pythonVersion = $candidate -replace '^Python\s+', ''; break } } if ($null -ne $pythonVersion) { Check-Version 'Python' $pythonVersion ([version]'3.11') } else { Fail 'Python 3.11 or newer is required' } diff --git a/scripts/tests/test-capabilities.ps1 b/scripts/tests/test-capabilities.ps1 new file mode 100644 index 0000000..9c440e1 --- /dev/null +++ b/scripts/tests/test-capabilities.ps1 @@ -0,0 +1,11 @@ +[CmdletBinding()] +param([switch]$Summary) +$ErrorActionPreference = 'Stop' +$root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent +$content = Get-Content (Join-Path $root 'scripts/commands/check-capabilities.ps1') -Raw + +if ($content -match '(?s)\(& \$python --version.*?Select-Object.*?\).*?\$LASTEXITCODE') { + throw 'Python capability detection must not read $LASTEXITCODE after a pipeline.' +} + +if ($Summary) { Write-Output 'Tests: PASS | capabilities' } else { Write-Output 'PASS capabilities: Python exit code is read without a pipeline' }