From 3664753c7821ffdb131ab5926dea5034bc569656 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Tue, 24 Nov 2026 18:38:43 +0000 Subject: [PATCH 1/2] BUILD: Name each fetched data file before the Python tests run ip-intelligence/ci/fetch-assets.ps1 sets _51DEGREES_IPI_PATH to the Enterprise data file it fetched, with $env:, so the tests that common-ci runs in the same process read it. device-detection/ci/fetch-assets.ps1 sets _51DEGREES_DD_PATH to the Lite data file it fetched. The IP Intelligence fetch script also fetches the device detection Lite file, which the mixed examples use, and names it in _51DEGREES_DD_PATH, so it is there when only IP Intelligence is tested. The free-threaded test step sets both variables to the Lite files it restores from its cache. The key names and free-threaded Pester tests check each of these. What a person running the examples gets is unchanged. --- .github/workflows/free-threaded-python.yml | 4 +++ ci/free-threaded-python.Tests.ps1 | 16 +++++++++ ci/key-names.Tests.ps1 | 39 ++++++++++++++++++++-- device-detection/ci/fetch-assets.ps1 | 5 +++ ip-intelligence/ci/fetch-assets.ps1 | 12 ++++--- 5 files changed, 68 insertions(+), 8 deletions(-) diff --git a/.github/workflows/free-threaded-python.yml b/.github/workflows/free-threaded-python.yml index be4a347e..d5d1532e 100644 --- a/.github/workflows/free-threaded-python.yml +++ b/.github/workflows/free-threaded-python.yml @@ -195,6 +195,10 @@ jobs: - name: Run the tests run: | + # The data file variables name the files restored above, before + # any test changes folder. + $env:_51DEGREES_DD_PATH = (Resolve-Path cxx/data/device-detection/51Degrees-LiteV4.1.hash).Path + $env:_51DEGREES_IPI_PATH = (Resolve-Path cxx/data/ip-intelligence/51Degrees-LiteV41.ipi).Path $failed = $false foreach ($package in 'device-detection/fiftyone_devicedetection_onpremise', 'ip-intelligence/fiftyone_ipintelligence_onpremise') { Write-Host "::group::$package" diff --git a/ci/free-threaded-python.Tests.ps1 b/ci/free-threaded-python.Tests.ps1 index 8f95fe3f..5f73fb7a 100644 --- a/ci/free-threaded-python.Tests.ps1 +++ b/ci/free-threaded-python.Tests.ps1 @@ -163,6 +163,22 @@ Describe 'free-threaded-python.yml' { } } + It 'sets to the restored before the tests run' -ForEach @( + @{ Variable = '_51DEGREES_DD_PATH'; File = '51Degrees-LiteV4.1.hash' } + @{ Variable = '_51DEGREES_IPI_PATH'; File = '51Degrees-LiteV41.ipi' } + ) { + $paths = Get-Paths (@(Get-Step $script:Fetching[0] 'actions/cache')[0]) + $paths | Should -Contain "cxx/data/**/$File" + foreach ($testing in $script:Testing) { + $text = $script:Jobs[$testing] -join "`n" + $set = [regex]::Match($text, ('(?m)^\s+\$env:' + $Variable + + '\s*=\s*\(Resolve-Path cxx/data/[\w-]+/' + + [regex]::Escape($File) + '\)\.Path\s*$')) + $set.Success | Should -BeTrue + $set.Index | Should -BeLessThan $text.IndexOf('python -m pytest') + } + } + It 'caches each of the free data files the tests use' { $paths = Get-Paths (@(Get-Step $script:Fetching[0] 'actions/cache')[0]) foreach ($file in '51Degrees-LiteV4.1.hash', '51Degrees-LiteV41.ipi', diff --git a/ci/key-names.Tests.ps1 b/ci/key-names.Tests.ps1 index 8b5b8607..12c6540d 100644 --- a/ci/key-names.Tests.ps1 +++ b/ci/key-names.Tests.ps1 @@ -31,7 +31,8 @@ BeforeAll { $script:Saved = @( '_51DEGREES_RESOURCE_KEY', '_51DEGREES_RESOURCE_KEY_BESPOKE', '_51DEGREES_LICENSE_KEY', 'TEMP', 'GITHUB_ENV', - 'GITHUB_JOB', 'PYTEST_ADDOPTS') + 'GITHUB_JOB', 'PYTEST_ADDOPTS', '_51DEGREES_IPI_PATH', + '_51DEGREES_DD_PATH') function New-TempFolder { $path = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString()) @@ -301,9 +302,23 @@ Describe 'Keys under their _51DEGREES_ names' { @($calls.Others | Where-Object { $_ }) | Should -BeNullOrEmpty } + It 'points the examples at the Lite data file it fetched, in device-detection' { + $repoName = New-ProductRepo 'device-detection' 'fetch-assets.ps1' + Push-Location $script:CommonCi + try { + & (Join-Path $repoName 'ci' 'fetch-assets.ps1') + } finally { + Pop-Location + } + + # common-ci runs the tests in the same process as the script, so + # the variable is set in this process. + $env:_51DEGREES_DD_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-LiteV4.1.hash') + $env:_51DEGREES_DD_PATH | Should -Exist + } + It 'asks common-ci for the Enterprise data file with no key or address, and points the tests at it, in ip-intelligence' { $repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1' - $env:GITHUB_ENV = Join-Path $script:CommonCi 'github.env' Push-Location $script:CommonCi try { & (Join-Path $repoName 'ci' 'fetch-assets.ps1') @@ -314,7 +329,25 @@ Describe 'Keys under their _51DEGREES_ names' { $calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json) $calls.Assets | Should -Contain '51Degrees-EnterpriseIpiV41.ipi' @($calls.Others | Where-Object { $_ }) | Should -BeNullOrEmpty - Get-Content $env:GITHUB_ENV | Should -Match '^_51DEGREES_IPI_PATH=.*51Degrees-EnterpriseIpiV41\.ipi$' + # common-ci runs the tests in the same process as the script, so + # the variable is set in this process, to the file it fetched. + $env:_51DEGREES_IPI_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-EnterpriseIpiV41.ipi') + $env:_51DEGREES_IPI_PATH | Should -Exist + } + + It 'fetches the device detection Lite data file for the mixed examples, and points them at it, in ip-intelligence' { + $repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1' + Push-Location $script:CommonCi + try { + & (Join-Path $repoName 'ci' 'fetch-assets.ps1') + } finally { + Pop-Location + } + + $calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json) + $calls.Assets | Should -Contain '51Degrees-LiteV4.1.hash' + $env:_51DEGREES_DD_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-LiteV4.1.hash') + $env:_51DEGREES_DD_PATH | Should -Exist } } diff --git a/device-detection/ci/fetch-assets.ps1 b/device-detection/ci/fetch-assets.ps1 index 5118bcef..7a786598 100644 --- a/device-detection/ci/fetch-assets.ps1 +++ b/device-detection/ci/fetch-assets.ps1 @@ -24,3 +24,8 @@ foreach ($asset in $assets) { default {New-Item -ItemType SymbolicLink -Force -Target "$PWD/assets/$_" -Path "$deviceDetectionData/$_"} } } + +# The examples read their data file from this variable. common-ci runs the +# tests in the same process as this script, so the variable is set in this +# process, to the Lite file fetched above. +$env:_51DEGREES_DD_PATH = (Resolve-Path "assets/51Degrees-LiteV4.1.hash").Path diff --git a/ip-intelligence/ci/fetch-assets.ps1 b/ip-intelligence/ci/fetch-assets.ps1 index 13d9410f..34f2d607 100644 --- a/ip-intelligence/ci/fetch-assets.ps1 +++ b/ip-intelligence/ci/fetch-assets.ps1 @@ -12,8 +12,10 @@ if ($env:GITHUB_JOB -eq "PreBuild") { $assetsDir = "$PSScriptRoot/../assets" New-Item -ItemType Directory -Force -Path $assetsDir | Out-Null +# The mixed examples use the device detection Lite data file as well, so it +# is fetched here too, for a run that tests IP Intelligence alone. $assets = '51Degrees-LiteIpiV41.ipi', 'ip-intelligence-evidence.yml', - '51Degrees-EnterpriseIpiV41.ipi' + '51Degrees-EnterpriseIpiV41.ipi', '51Degrees-LiteV4.1.hash' ./steps/fetch-assets.ps1 -Assets $assets @@ -35,7 +37,7 @@ $asn = '51Degrees-IPIV4AsnIpiV41.ipi' Copy-Item "assets/$asn" $ipIntelligenceData # The tests prefer the Enterprise file, which they find through the -# environment variable the test suites read. -if ($env:GITHUB_ENV) { - Write-Output "_51DEGREES_IPI_PATH=$assetsDir/51Degrees-EnterpriseIpiV41.ipi" | Out-File -Append -FilePath $env:GITHUB_ENV -ErrorAction SilentlyContinue -} +# environment variable the test suites read. common-ci runs the tests in the +# same process as this script, so the variable is set in this process. +$env:_51DEGREES_IPI_PATH = (Resolve-Path "assets/51Degrees-EnterpriseIpiV41.ipi").Path +$env:_51DEGREES_DD_PATH = (Resolve-Path "assets/51Degrees-LiteV4.1.hash").Path From 874d8e902c05bc6f859f20804b559697159b0e8a Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Tue, 24 Nov 2026 23:31:58 +0000 Subject: [PATCH 2/2] BUILD: Point the IP Intelligence tests at the Lite file they fetch ip-intelligence/ci/fetch-assets.ps1 named the Enterprise data file in _51DEGREES_IPI_PATH, and the tests and examples accept the free Lite file, which the script already fetches. It now names the Lite file, and a new test in ci/key-names.Tests.ps1 checks that it does. The test that the script still asks common-ci for the Enterprise file stays, although nothing reads that file now, and an example test comment that said CI names the Enterprise file is corrected. --- ci/key-names.Tests.ps1 | 18 ++++++++++++++++-- ip-intelligence/ci/fetch-assets.ps1 | 9 +++++---- .../test_package_gettingstarted_from_root.py | 5 ++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ci/key-names.Tests.ps1 b/ci/key-names.Tests.ps1 index 12c6540d..68fedb4f 100644 --- a/ci/key-names.Tests.ps1 +++ b/ci/key-names.Tests.ps1 @@ -317,7 +317,7 @@ Describe 'Keys under their _51DEGREES_ names' { $env:_51DEGREES_DD_PATH | Should -Exist } - It 'asks common-ci for the Enterprise data file with no key or address, and points the tests at it, in ip-intelligence' { + It 'asks common-ci for the Enterprise data file with no key or address, in ip-intelligence' { $repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1' Push-Location $script:CommonCi try { @@ -329,9 +329,23 @@ Describe 'Keys under their _51DEGREES_ names' { $calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json) $calls.Assets | Should -Contain '51Degrees-EnterpriseIpiV41.ipi' @($calls.Others | Where-Object { $_ }) | Should -BeNullOrEmpty + } + + It 'points the tests at the Lite data file it fetched, in ip-intelligence' { + $repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1' + Push-Location $script:CommonCi + try { + & (Join-Path $repoName 'ci' 'fetch-assets.ps1') + } finally { + Pop-Location + } + + # The tests and examples accept the Lite file, so they use it. # common-ci runs the tests in the same process as the script, so # the variable is set in this process, to the file it fetched. - $env:_51DEGREES_IPI_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-EnterpriseIpiV41.ipi') + $calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json) + $calls.Assets | Should -Contain '51Degrees-LiteIpiV41.ipi' + $env:_51DEGREES_IPI_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-LiteIpiV41.ipi') $env:_51DEGREES_IPI_PATH | Should -Exist } diff --git a/ip-intelligence/ci/fetch-assets.ps1 b/ip-intelligence/ci/fetch-assets.ps1 index 34f2d607..65cd0fd1 100644 --- a/ip-intelligence/ci/fetch-assets.ps1 +++ b/ip-intelligence/ci/fetch-assets.ps1 @@ -36,8 +36,9 @@ $asn = '51Degrees-IPIV4AsnIpiV41.ipi' ./steps/fetch-assets.ps1 -Assets $asn Copy-Item "assets/$asn" $ipIntelligenceData -# The tests prefer the Enterprise file, which they find through the -# environment variable the test suites read. common-ci runs the tests in the -# same process as this script, so the variable is set in this process. -$env:_51DEGREES_IPI_PATH = (Resolve-Path "assets/51Degrees-EnterpriseIpiV41.ipi").Path +# The tests and examples find their data file through the environment +# variable the test suites read. They accept the Lite file, so it is the one +# named. common-ci runs the tests in the same process as this script, so the +# variable is set in this process. +$env:_51DEGREES_IPI_PATH = (Resolve-Path "assets/51Degrees-LiteIpiV41.ipi").Path $env:_51DEGREES_DD_PATH = (Resolve-Path "assets/51Degrees-LiteV4.1.hash").Path diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_package_gettingstarted_from_root.py b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_package_gettingstarted_from_root.py index bb364299..f0b0d4ae 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_package_gettingstarted_from_root.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_package_gettingstarted_from_root.py @@ -55,9 +55,8 @@ def test_runs_from_the_repository_root(self): folder = os.getcwd() os.chdir(ROOT) try: - # The free file is the one under test, so a data file named in - # the environment, as CI names the Enterprise file, is set - # aside. + # The free file the example finds itself is the one under test, + # so a data file named in the environment is set aside. with mock.patch.dict(os.environ): for name in (ExampleUtils.IPI_PATH_ENV_VAR,): os.environ.pop(name, None)