[GH-ISSUE #1935] 8 tests in tools/test_setup_*.py depend on the host: unmocked HEAD to GitHub (2) and unmocked /proc/cpuinfo read (6) #767

Closed
opened 2026-11-04 01:45:42 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @gputier on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1935

Context

On v0.1.42 (61b3fb5d), pytest tools/test_setup_amd.py tools/test_setup_choices.py tools/test_setup_engine_hash.py in a clean python:3.12-slim container (pip install -r requirements.txt pytest jsonschema) gives 8 failed, 107 passed, with or without network. On a Windows machine with internet, the same tests are green. They lean on the host: the WIN branch of cpu_info() never reads /proc/cpuinfo, and the published release only ships the Windows asset. Same family as #414 (host state leaking into test_setup_choices).

I checked this by replacing setup.cpu_info (6 tests) and urllib.request.urlopen (2 tests) in a container with no network. All 8 turn green, so nothing else is missing (cmake and ninja come from requirements.txt, and the tests already mock cmake_build and install_build_tools).

The 2 tests that call the real network

  • tools/test_setup_engine_hash.py:309 WhatARefusalDoesToTheCaller::test_updating_keeps_the_installed_engine_instead_of_stopping (fails at :316)
  • tools/test_setup_engine_hash.py:325 WhatARefusalDoesToTheCaller::test_a_first_install_stops_because_there_is_nothing_to_fall_back_to (SystemExit not raised at :327)

Cause: the tests mock download and engine_digest, but get_prebuilt() first sends a real HEAD (setup.py:2997, urllib.request.urlopen(req, timeout=60)) to releases/download/v<version>/, then releases/latest/download/. On any non-Windows host the asset is strata-linux-x64.zip (setup.py:180), which no release publishes (404). Offline, it is a DNS error. Either way, setup.py:3003 returns None ("compiling instead") before download is reached, so the path under test (verify_engine_archive, engine_refused) never runs.

Proposed fix: patch urllib.request.urlopen in the test helper (:304) and in the :325 test, for example mock.patch.object(setup.urllib.request, "urlopen", return_value=mock.MagicMock()), next to the existing patches of download and engine_digest.

The 6 that read the real /proc/cpuinfo

  • tools/test_setup_amd.py:156 GpuLists::test_build_for_every_arch
  • tools/test_setup_choices.py:354 HipVision::test_the_cpu_encoder_is_built_once
  • tools/test_setup_choices.py:365 HipVision::test_without_images_nothing_changes
  • tools/test_setup_choices.py:527 CudaVision::test_the_encoder_is_built_native (gpu and cpu subtests)
  • tools/test_setup_choices.py:588 HostCompilers::test_the_defs_reach_cmake

Cause: build_engine() (setup.py:3401) and build_engine_hip() (setup.py:2643) call cpu_floor(cpu_info()[1]), and none of these tests mock cpu_info. On Linux, cpu_info() runs re.search(r"^flags\s*:\s*(.*)$", txt, re.M).group(1) (setup.py:720). On aarch64, the file has a Features line instead of flags, and some x86 containers under emulation have neither. re.search then returns None, and the AttributeError is not caught: the try only catches OSError (setup.py:725). Result: AttributeError: 'NoneType' object has no attribute 'group'.

Proposed fix, two parts:

  • Tests: mock.patch.object(setup, "cpu_info", lambda: ("test CPU", True, False)) in the shared setup of these classes, so the result does not depend on the machine.
  • Product (separate from the tests, and it matters on its own): make cpu_info() survive a /proc/cpuinfo without flags (catch AttributeError too, or read Features on ARM). As it is, setup.py raises on any Linux ARM host, which is not just a test problem.
Originally created by @gputier on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1935 ## Context On v0.1.42 (61b3fb5d), `pytest tools/test_setup_amd.py tools/test_setup_choices.py tools/test_setup_engine_hash.py` in a clean `python:3.12-slim` container (`pip install -r requirements.txt pytest jsonschema`) gives 8 failed, 107 passed, with or without network. On a Windows machine with internet, the same tests are green. They lean on the host: the `WIN` branch of `cpu_info()` never reads `/proc/cpuinfo`, and the published release only ships the Windows asset. Same family as #414 (host state leaking into `test_setup_choices`). I checked this by replacing `setup.cpu_info` (6 tests) and `urllib.request.urlopen` (2 tests) in a container with no network. All 8 turn green, so nothing else is missing (cmake and ninja come from requirements.txt, and the tests already mock `cmake_build` and `install_build_tools`). ## The 2 tests that call the real network - `tools/test_setup_engine_hash.py:309` `WhatARefusalDoesToTheCaller::test_updating_keeps_the_installed_engine_instead_of_stopping` (fails at `:316`) - `tools/test_setup_engine_hash.py:325` `WhatARefusalDoesToTheCaller::test_a_first_install_stops_because_there_is_nothing_to_fall_back_to` (`SystemExit` not raised at `:327`) Cause: the tests mock `download` and `engine_digest`, but `get_prebuilt()` first sends a real `HEAD` (`setup.py:2997`, `urllib.request.urlopen(req, timeout=60)`) to `releases/download/v<version>/`, then `releases/latest/download/`. On any non-Windows host the asset is `strata-linux-x64.zip` (`setup.py:180`), which no release publishes (404). Offline, it is a DNS error. Either way, `setup.py:3003` returns `None` ("compiling instead") before `download` is reached, so the path under test (`verify_engine_archive`, `engine_refused`) never runs. Proposed fix: patch `urllib.request.urlopen` in the test helper (`:304`) and in the `:325` test, for example `mock.patch.object(setup.urllib.request, "urlopen", return_value=mock.MagicMock())`, next to the existing patches of `download` and `engine_digest`. ## The 6 that read the real /proc/cpuinfo - `tools/test_setup_amd.py:156` `GpuLists::test_build_for_every_arch` - `tools/test_setup_choices.py:354` `HipVision::test_the_cpu_encoder_is_built_once` - `tools/test_setup_choices.py:365` `HipVision::test_without_images_nothing_changes` - `tools/test_setup_choices.py:527` `CudaVision::test_the_encoder_is_built_native` (gpu and cpu subtests) - `tools/test_setup_choices.py:588` `HostCompilers::test_the_defs_reach_cmake` Cause: `build_engine()` (`setup.py:3401`) and `build_engine_hip()` (`setup.py:2643`) call `cpu_floor(cpu_info()[1])`, and none of these tests mock `cpu_info`. On Linux, `cpu_info()` runs `re.search(r"^flags\s*:\s*(.*)$", txt, re.M).group(1)` (`setup.py:720`). On aarch64, the file has a `Features` line instead of `flags`, and some x86 containers under emulation have neither. `re.search` then returns `None`, and the `AttributeError` is not caught: the `try` only catches `OSError` (`setup.py:725`). Result: `AttributeError: 'NoneType' object has no attribute 'group'`. Proposed fix, two parts: - Tests: `mock.patch.object(setup, "cpu_info", lambda: ("test CPU", True, False))` in the shared setup of these classes, so the result does not depend on the machine. - Product (separate from the tests, and it matters on its own): make `cpu_info()` survive a `/proc/cpuinfo` without `flags` (catch `AttributeError` too, or read `Features` on ARM). As it is, `setup.py` raises on any Linux ARM host, which is not just a test problem.
Author
Owner

@gputier commented on GitHub (Oct 17, 2026):

Still present on v0.1.45: the same 8 tests fail.

git archive v0.1.45 | docker run -i python:3.12-slim (aarch64, Python 3.12.15), pip install -r requirements.txt pytest jsonschema, then pytest tools/test_setup_amd.py tools/test_setup_choices.py tools/test_setup_engine_hash.py:

FAILED tools/test_setup_amd.py::GpuLists::test_build_for_every_arch - Attribu...
FAILED tools/test_setup_choices.py::HipVision::test_the_cpu_encoder_is_built_once
FAILED tools/test_setup_choices.py::HipVision::test_without_images_nothing_changes
SUBFAILED[gpu] tools/test_setup_choices.py::CudaVision::test_the_encoder_is_built_native
SUBFAILED[cpu] tools/test_setup_choices.py::CudaVision::test_the_encoder_is_built_native
FAILED tools/test_setup_choices.py::HostCompilers::test_the_defs_reach_cmake
FAILED tools/test_setup_engine_hash.py::WhatARefusalDoesToTheCaller::test_a_first_install_stops_because_there_is_nothing_to_fall_back_to
FAILED tools/test_setup_engine_hash.py::WhatARefusalDoesToTheCaller::test_updating_keeps_the_installed_engine_instead_of_stopping
8 failed, 114 passed, 1 warning, 4 subtests passed in 2.49s

(114 passed instead of 107 on v0.1.42: tests were added; the failing 8 are the same.)

Same two causes, new line numbers:

  • /proc/cpuinfo (6 tests): cpu_info() still does re.search(r"^flags\s*:\s*(.*)$", txt, re.M).group(1) at setup.py:883 and only catches OSError (setup.py:888). On aarch64: AttributeError: 'NoneType' object has no attribute 'group' at setup.py:883. Callers: build_engine_hip() at setup.py:3084 and build_engine() at setup.py:4046 (cpu_floor(cpu_info()[1])). None of the three test files patches cpu_info (0 occurrences in v0.1.42 and in v0.1.45). The product side is unchanged too: setup.py still raises on a Linux ARM host.
  • Real HEAD to GitHub (2 tests): get_prebuilt() still sends urllib.request.urlopen(req, timeout=60) at setup.py:3624-3625 before download, and returns None at setup.py:3631. The asset is still strata-linux-x64.zip off Windows (setup.py:181). Captured stdout: no ready-made engine at https://github.com/Niko1221/Strata/releases/latest/download/ (HTTP Error 404: Not Found): compiling instead. The helper at tools/test_setup_engine_hash.py:304 and the test at :325 still patch only download and engine_digest.

The proposed fix in the issue still applies as written.

<!-- gh-comment-id:6233818287 --> @gputier commented on GitHub (Oct 17, 2026): Still present on v0.1.45: the same 8 tests fail. `git archive v0.1.45 | docker run -i python:3.12-slim` (aarch64, Python 3.12.15), `pip install -r requirements.txt pytest jsonschema`, then `pytest tools/test_setup_amd.py tools/test_setup_choices.py tools/test_setup_engine_hash.py`: ``` FAILED tools/test_setup_amd.py::GpuLists::test_build_for_every_arch - Attribu... FAILED tools/test_setup_choices.py::HipVision::test_the_cpu_encoder_is_built_once FAILED tools/test_setup_choices.py::HipVision::test_without_images_nothing_changes SUBFAILED[gpu] tools/test_setup_choices.py::CudaVision::test_the_encoder_is_built_native SUBFAILED[cpu] tools/test_setup_choices.py::CudaVision::test_the_encoder_is_built_native FAILED tools/test_setup_choices.py::HostCompilers::test_the_defs_reach_cmake FAILED tools/test_setup_engine_hash.py::WhatARefusalDoesToTheCaller::test_a_first_install_stops_because_there_is_nothing_to_fall_back_to FAILED tools/test_setup_engine_hash.py::WhatARefusalDoesToTheCaller::test_updating_keeps_the_installed_engine_instead_of_stopping 8 failed, 114 passed, 1 warning, 4 subtests passed in 2.49s ``` (114 passed instead of 107 on v0.1.42: tests were added; the failing 8 are the same.) Same two causes, new line numbers: - `/proc/cpuinfo` (6 tests): `cpu_info()` still does `re.search(r"^flags\s*:\s*(.*)$", txt, re.M).group(1)` at `setup.py:883` and only catches `OSError` (`setup.py:888`). On aarch64: `AttributeError: 'NoneType' object has no attribute 'group'` at `setup.py:883`. Callers: `build_engine_hip()` at `setup.py:3084` and `build_engine()` at `setup.py:4046` (`cpu_floor(cpu_info()[1])`). None of the three test files patches `cpu_info` (0 occurrences in v0.1.42 and in v0.1.45). The product side is unchanged too: `setup.py` still raises on a Linux ARM host. - Real `HEAD` to GitHub (2 tests): `get_prebuilt()` still sends `urllib.request.urlopen(req, timeout=60)` at `setup.py:3624-3625` before `download`, and returns `None` at `setup.py:3631`. The asset is still `strata-linux-x64.zip` off Windows (`setup.py:181`). Captured stdout: `no ready-made engine at https://github.com/Niko1221/Strata/releases/latest/download/ (HTTP Error 404: Not Found): compiling instead`. The helper at `tools/test_setup_engine_hash.py:304` and the test at `:325` still patch only `download` and `engine_digest`. The proposed fix in the issue still applies as written.
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6270712550 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#767
No description provided.