From c694f39c67bdf89c21c1967367dafffc164c01d1 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 23 Nov 2026 23:18:16 +0000 Subject: [PATCH 1/2] BUILD: Say when no staging test ran, and run the staging tests for the files they use pytest exits 5 when it selects no test, so the Cloud Human Confidence step stopped on that exit code with no message, and its check of the junit report for a run with no tests could never be reached. The step now writes "No staging test ran" when pytest exits 5, and the unreachable check is gone. The Pester stand-in for pytest now takes the exit code to give, and gives 5 in the case where no test ran. A new case checks that a failed test fails the step with pytest's own exit code. The workflow's pull_request paths now also cover the files the staging tests import, tests/live_cloud.py and example_utils.py, and the files the install step uses, the examples' pyproject.toml, ci/write-package-versions.ps1 and ci/packages.ps1. A pull request that changes only one of those now runs the staging tests as well. --- .github/workflows/cloud-human-confidence.yml | 16 ++++++++++++---- ci/key-names.Tests.ps1 | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cloud-human-confidence.yml b/.github/workflows/cloud-human-confidence.yml index f13bffa2..9f2a5be4 100644 --- a/.github/workflows/cloud-human-confidence.yml +++ b/.github/workflows/cloud-human-confidence.yml @@ -28,10 +28,17 @@ on: - cron: '50 6 * * *' pull_request: branches: [main, rc] + # The example and its tests, the files they import, and the files the + # install step uses. paths: - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/humanconfidence_web/**' + - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/example_utils.py' - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/conftest.py' + - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py' - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_humanconfidence_web.py' + - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/pyproject.toml' + - 'ci/write-package-versions.ps1' + - 'ci/packages.ps1' - '.github/workflows/cloud-human-confidence.yml' permissions: @@ -110,6 +117,11 @@ jobs: Remove-Item $report -ErrorAction SilentlyContinue python -m pytest -m staging -p no:cacheprovider -v -rs ` "--junit-xml=$report" + # pytest exits 5 when it selects no test. + if ($LASTEXITCODE -eq 5) { + Write-Host '::error::No staging test ran.' + exit 1 + } if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } if (-not (Test-Path $report)) { Write-Host '::error::The staging tests did not run.' @@ -117,10 +129,6 @@ jobs: } $suite = ([xml](Get-Content -Raw $report)).SelectSingleNode( '//testsuite') - if ([int]$suite.tests -eq 0) { - Write-Host '::error::No staging test ran.' - exit 1 - } if ([int]$suite.skipped -gt 0) { foreach ($skipped in $suite.SelectNodes('testcase[skipped]')) { Write-Host ("::error::$($skipped.name) skipped, so it proved " + diff --git a/ci/key-names.Tests.ps1 b/ci/key-names.Tests.ps1 index 2146b363..32dee96b 100644 --- a/ci/key-names.Tests.ps1 +++ b/ci/key-names.Tests.ps1 @@ -105,9 +105,10 @@ foreach ($asset in $Assets) { Set-Content -LiteralPath "assets/$asset" '' } # Runs the Cloud Human Confidence workflow's test step in its own process # and folder, with the names given set and no others, and python replaced - # by a function that writes $Report as the junit report. Gives the exit - # code and the output. - function Invoke-StagingStep([hashtable]$Names, [string]$Report) { + # by a function that writes $Report as the junit report and exits with + # $PytestExitCode. Gives the step's exit code and the output. + function Invoke-StagingStep([hashtable]$Names, [string]$Report, + [int]$PytestExitCode = 0) { $folder = Join-Path $TestDrive ([Guid]::NewGuid().ToString()) $null = New-Item -ItemType Directory $folder $stepFile = Join-Path $folder 'step.ps1' @@ -116,7 +117,7 @@ foreach ($asset in $Assets) { Set-Content -LiteralPath "assets/$asset" '' } ' Write-Output "pytest ran"' ' $path = "$($args | Where-Object { "$_" -like "--junit-xml=*" })" -replace "^--junit-xml=", ""' " if (`$path) { Set-Content `$path '$Report' }" - ' $global:LASTEXITCODE = 0' + " `$global:LASTEXITCODE = $PytestExitCode" '}' ) @($python + @(Get-StepScript 'cloud-human-confidence.yml' 'Human Confidence tests against the staging cloud')) | @@ -527,13 +528,22 @@ Describe 'Keys under their _51DEGREES_ names' { $result.Output | Should -Match 'test_0 skipped' } + # pytest exits 5 when it selects no test, and still writes the report. It 'fail the Cloud Human Confidence step when no staging test ran' { - $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 0 0) + $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 0 0) 5 $result.ExitCode | Should -Not -Be 0 + $result.Output | Should -Match 'pytest ran' $result.Output | Should -Match 'No staging test ran' } + It 'fail the Cloud Human Confidence step with pytest''s exit code when a staging test failed' { + $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 2 0) 1 + + $result.ExitCode | Should -Be 1 + $result.Output | Should -Not -Match 'No staging test ran' + } + It 'pass the Cloud Human Confidence step when every staging test ran' { $result = Invoke-StagingStep $script:StagingNames (New-JunitReport 2 0) From a6d340585fb57bfa9eb42b1e412aa900eec3e01b Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Tue, 24 Nov 2026 01:45:01 +0000 Subject: [PATCH 2/2] TEST: Check each path the staging workflow runs for is a file here cloud-human-confidence.yml runs for a pull request that changes one of its pull_request paths. A new case in ci/key-names.Tests.ps1 reads those paths and checks that each one without a wildcard is a file in the checkout. The paths now include ci/packages.json, which the install step reads through ci/write-package-versions.ps1. --- .github/workflows/cloud-human-confidence.yml | 1 + ci/key-names.Tests.ps1 | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/.github/workflows/cloud-human-confidence.yml b/.github/workflows/cloud-human-confidence.yml index 9f2a5be4..a525beb1 100644 --- a/.github/workflows/cloud-human-confidence.yml +++ b/.github/workflows/cloud-human-confidence.yml @@ -39,6 +39,7 @@ on: - 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/pyproject.toml' - 'ci/write-package-versions.ps1' - 'ci/packages.ps1' + - 'ci/packages.json' - '.github/workflows/cloud-human-confidence.yml' permissions: diff --git a/ci/key-names.Tests.ps1 b/ci/key-names.Tests.ps1 index 32dee96b..8b5b8607 100644 --- a/ci/key-names.Tests.ps1 +++ b/ci/key-names.Tests.ps1 @@ -550,6 +550,33 @@ Describe 'Keys under their _51DEGREES_ names' { $result.ExitCode | Should -Be 0 $result.Output | Should -Match 'pytest ran' } + + # The workflow runs for a pull request that changes one of its + # pull_request paths, so each path it names is a file in this + # repository. + It 'run for a pull request on files that exist, in the Cloud Human Confidence workflow' { + $lines = @(Get-Content (Join-Path $script:Root '.github/workflows/cloud-human-confidence.yml')) + $trigger = ($lines | Select-String -Pattern '^(\s*)pull_request:\s*$' | + Select-Object -First 1) + $trigger | Should -Not -BeNullOrEmpty + $indent = $trigger.Matches[0].Groups[1].Value.Length + $paths = @() + $inPaths = $false + foreach ($line in $lines | Select-Object -Skip $trigger.LineNumber) { + if (-not $line.Trim() -or $line.Trim().StartsWith('#')) { continue } + if ($line -notmatch "^\s{$($indent + 1),}") { break } + if ($line -match '^\s*paths:\s*$') { $inPaths = $true; continue } + if ($inPaths -and $line -match '^\s*-\s*[''"]?(?[^''"]+?)[''"]?\s*$') { + $paths += $Matches['path'] + } elseif ($inPaths) { + break + } + } + $paths | Should -Not -BeNullOrEmpty + $paths | Where-Object { $_ -notmatch '[*?\[!]' } | + Where-Object { -not (Test-Path -LiteralPath (Join-Path $script:Root $_) -PathType Leaf) } | + Should -BeNullOrEmpty + } } Describe 'The live cloud tests' {