Skip to content

tests: four numpy gates decided in the wrong process, so their cases judged the exit code instead - #2672

Merged
aslan2142 merged 5 commits into
ProjectLeonida:mainfrom
fiestorra:fix/tile-probe-numpy-gate
Dec 1, 2026
Merged

aslan2142 merged 5 commits into
ProjectLeonida:mainfrom
fiestorra:fix/tile-probe-numpy-gate

Conversation

@fiestorra

@fiestorra fiestorra commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Four files, one bug, one review. Each decides "is numpy usable?" from this process, while the test it gates launches the tool as python -I - and -I implies -s, which hides a --user install. On a machine where numpy came from pip install --user the gate opens and the child dies with ModuleNotFoundError: No module named 'numpy', so the test judges the child's exit code instead of the behaviour it names.

The files

tests/test_tile_probe.py - find_spec -> the isolated probe, gating the four cases that reach numpy. The other eleven keep running: they exercise the tool's file and argument checks, which happen before numpy is touched. (Skipping the whole class turned 12 passing tests into 12 skips; the class docstring's "those tests skip without it" was already an overstatement.)

tests/test_swizzle_search.py - same shape: HAVE_NUMPY stays for the tests that call numpy here, the nine CLI gates use the new NUMPY_VISIBLE_TO_TOOL.

tests/test_tool_startup.py - this one had a second, subtler gap. It skipped a NUMERIC list when numpy was missing, but:

So the probe matches how the tools run, and a child that fails with "No module named 'numpy'" is skipped rather than called a startup failure.

Measured, main b8bd37111, Windows 11, Python 3.13.14

tests/test_tile_probe.py      5 failed, 12 passed          ->  11 passed,  4 skipped
tests/test_swizzle_search.py  3 failed, 23 passed, 5 skip  ->  24 passed,  7 skipped
tests/test_tool_startup.py    2 failed, 2 passed, 218 sub  ->   2 passed, 214 subtests

And with #2667 and #2671 applied on top, the whole Python suite went from 22 failed / 11,853 passed to 0 failed / 11,858 passed (tests/ excluding tests/semantic, which has to be a separate run: test_address_guard.py exists in both directories and pytest refuses to collect both).

Where -I can see numpy - CI - both probes return true, every gate opens, and the cases run exactly as before. Test-only: no tool behaviour moves.

Not in this PR

#2671 also changes tools/amd_swizzle.py, because there the tool reported "needs numpy" before validating arguments. These three files have no such problem.

A correction from the review, applied as its own commit (46ce12bb9)

The first version of the test_swizzle_search.py gates over-skipped: five cases that pass on main in a user-site environment were being skipped, because NUMPY_VISIBLE_TO_TOOL was the wrong gate for all of them.

merzleckeier measured exactly which, and the reasons differ:

  • the two render() calls (BC1, BC3) use the parent's numpy and Pillow, so HAVE_NUMPY and HAVE_PIL was right and my gate was too strict;
  • the three CLI checks - invalid numeric arguments, missing input, output alias - finish before the child needs numpy, so they should not have been gated at all;
  • the two PNG preview subprocesses need Pillow in the child, which my gate never checked; that is why they failed on main too.

Their follow-up (f9456e020) is applied unchanged as its own commit: PIL_VISIBLE_TO_TOOL joins the probe, the five cases run again, and the two PNG tests are gated on the child's Pillow. The numbers above are after it.

What that says about my own measurement: I measured in exactly one dependency configuration - numpy hidden from -I - and in that configuration over-skipping looks identical to correct skipping. "0 failed" was true and was not enough.

The extra commit at the tip (no longer carried)

The branch used to carry a3b5ebea1 (test(semantic): align computed-I/J f16 interp oracle…), added only because semantic-tests was red on main for that oracle and every branch cut from main inherited it. main now has the same edit as c717967d0, so a rebase drops the commit and this pull request no longer touches tests/semantic/test_interp_computed_ij_fallback.py - the diff is only what this change actually needs.

AI-assisted: yes - DeepSeek v4.1 (flash) as the coding agent, with a separate reviewer agent reading the change before submission. Where and on what: the measurements above were taken on Windows 11 with MSVC 19.44.35226 on an RTX 4090 (NVIDIA driver 621.24) where a C++ or GPU path is involved; Python and docs cases need none of it.

Written with an AI assistant.

@fiestorra fiestorra changed the title tests: tile_probe's numpy gate asks the way the tool runs, and keeps the eleven that do not need it tests: three numpy gates decided in the wrong process, so the CLI cases tested the exit code instead Nov 30, 2026
@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, main 40e7fe6, PR head of this PR (test-only, so "main" = main's test files, "PR" = this PR's, both on main's tools). MEASURED in two environments:

numpy visible (venv, pytest) numpy absent everywhere (Homebrew python3.12 -I)
test_swizzle_search.py main / PR 31/31 / 31/31 30 run, OK, 23 skipped / same
test_tile_probe.py main / PR 14 passed, 1 skipped / same 15 run, OK, 13 skipped / same
  • No regression in either environment, and merges cleanly with main and with [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566.
  • I could not reproduce the case this PR fixes (numpy from pip install --user, visible to the test process but hidden from the python -I child): this Mac has numpy only in a venv, which -I does not hide. So the fix itself is not covered here.
  • Note: without numpy, test_tile_probe.py still skips 13 of 15 with this PR ('tile_probe.py needs numpy'), including argument/file cases such as test_negative_offset_is_a_usage_error and test_missing_file_is_a_message_not_a_traceback; only test_missing_file_is_a_usage_error_without_numpy and test_missing_numpy_is_one_error_line run. The description says "the other eleven keep running", so in a numpy-less environment that part does not hold.

AI-assisted: Claude Code

@merzleckeier

Copy link
Copy Markdown
Contributor

I tested the user-site setup that was missing from the macOS verification. On CachyOS / Python 3.14.10 I put NumPy and Pillow in an isolated PYTHONUSERBASE and verified that only the parent imports them. Base 40e7fe69, PR d4075649.

  • MEASURED The PR’s focused selection skips five test_swizzle_search.py cases that all pass on main in this environment. Two call render() directly (BC1 and BC3), so the parent’s NumPy and Pillow are sufficient. The other three test invalid numeric arguments, a missing input, and an output alias. Those CLI checks finish before the child needs NumPy. CLI validation order
  • MEASURED With NumPy visible to both processes and Pillow in the user site, the two actual CLI PNG preview tests still fail on both main and the PR. Only the parent’s Pillow is checked, so the isolated child reaches the write path with no Pillow.
  • MEASURED This test-only follow-up runs all five checks again in the user-site NumPy case (5 passed, plus 11 subtests) and skips the two PNG subprocess tests when the child lacks Pillow. The tile_probe changes stay as in your PR. Together with the companion amd_swizzle: validate arguments before needing numpy, and gate the tests the way the tool runs #2671 test adjustment, all three files finish without failures in the four dependency configurations.

AI-assisted with OpenAI Codex.

@fiestorra fiestorra changed the title tests: three numpy gates decided in the wrong process, so the CLI cases tested the exit code instead tests: four numpy gates decided in the wrong process, so their cases judged the exit code instead Nov 30, 2026
@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Re-check by OreoFR on the new head 46086f4, same Mac (macOS 27.2.1, Apple M5, Python 3.12.16), main 1d22590. MEASURED, main's test files vs this PR's, on main's tools:

numpy visible (venv, pytest) no numpy (python3.12 -I)
test_swizzle_search.py 31/31 both 30 run, OK, 23 skipped, both
test_tile_probe.py 14 passed, 1 skipped, both 15 run, OK, 13 skipped, both
test_tool_startup.py (new in this head) 2 passed, 221 subtests, both 2 run, OK, both

No regression in either environment; merges cleanly with main and with #2566. The --user case the PR is about is still not reproducible here (see merzleckeier's CachyOS run above for it).

AI-assisted: Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor Author

You are right again, and this one was a coverage regression rather than a red one: five cases that pass on main in this environment were being skipped by my gates. Applied as 46ce12bb9, your follow-up unchanged.

The reasoning I missed, in your words and now in the diff:

  • the two render() calls (BC1, BC3) use the parent's numpy and Pillow, so HAVE_NUMPY and HAVE_PIL was the right gate and NUMPY_VISIBLE_TO_TOOL was too strict;
  • the three CLI checks (invalid numeric arguments, missing input, output alias) finish before the child needs numpy - the validation order in swizzle_search.py - so they should not have been gated at all;
  • and the two PNG preview subprocesses need Pillow in the child, which my gate never checked: that is why they failed on main too, and PIL_VISIBLE_TO_TOOL is the probe that was missing.

Verified here after applying it:

tests/test_swizzle_search.py + test_tile_probe.py + test_tool_startup.py
  -> 37 passed, 11 skipped, 254 subtests

What I would have caught with your matrix and did not, stated plainly: my "0 failed" was measured in exactly one dependency configuration - numpy hidden from -I - and in that configuration over-skipping looks identical to correct skipping. Your four configurations are what turned "no failures" into "no failures and no lost coverage".

Together with the 36654350a adjustment on #2671, all three files now finish without failures in the four setups. Thank you for doing the half of the work that cannot be done on this machine.

Written with an AI assistant.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Re-check by OreoFR on head 46ce12b, same Mac, main 1d22590. MEASURED, green (main + this PR):

AI-assisted: Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor Author

Rebased with the one commit main is missing, the same one #2633 and my other pull requests carry (a3b5ebea1, TEST-INTERP-COMPUTED-IJ-FALLBACK-RTZ). semantic-tests is red on main for the interp oracle, so every branch cut from it inherits that failure regardless of what it changes.

Verified after adding it, on this branch:

python3 -m pytest tests/test_swizzle_search.py tests/test_tile_probe.py tests/test_tool_startup.py tests/semantic/test_interp_computed_ij_fallback.py -q
  -> 46 passed, 11 skipped, 267 subtests

If #2633 merges first this fifth commit becomes a duplicate and can be dropped; if this lands first, #2633 becomes a no-op.

A note on how this branch was pushed, because I broke one today: the last two pushes of mine went through a git checkout that had failed silently, and one of them replaced a branch with main and closed its pull request (#2641, re-opened as #2691). This one checked git rev-parse --abbrev-ref HEAD before pushing and printed it before the push line; a --force deserves that much.

Written with an AI assistant.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Note by OreoFR on head 7691389: the new commit adds the SHADER-468 change to tests/semantic/test_interp_computed_ij_fallback.py, and with it this PR now conflicts with #2566 (git merge-tree of main + this PR against #2566), which carries the same change. The numpy-gate files are unchanged since my check of 46ce12b.

AI-assisted: Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor Author

Thank you - and the conflict you found is not what I would have guessed. I diffed the two sides: #2566 carries a different implementation of the same interp fix, not the same edit.

#2633 / a3b5ebea1 (what this branch carries) #2566
helper f16_rtz_bits(x) f16_rtz_bits(val)
docstring "Narrow x to f16 bits toward zero…" "Narrow to f16 bits toward zero…"
size 30,936 B 30,870 B
lines differing 504 of 566

So "resolve by taking either side" is wrong here: it is a choice between two oracles, and only one of them can be the one that ends up describing SHADER-468 in main. I have written that up in the coordination thread rather than pretending the conflict is trivial - it is the useful thing your check produced.

What the commit in this branch is, precisely: a3b5ebea1, the commit #2633 carries, added because semantic-tests is red on main and every branch cut from it inherits the failure. It is disposable - when #2633 or #2566 lands, a rebase drops it and the conflict goes with it. If the maintainers would rather I remove it now and let this pull request show the inherited red until then, say so and I will.

On the rest of your re-check: thank you for the no-numpy case. Ran 4, OK with python3.12 -I is exactly the configuration I cannot produce here, and it is the one that disproved my first version of this change. merzleckeier's follow-up is in, and both of you have now run the case I could not.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Correction to what I wrote above: I diffed the wrong thing. It is one change, not two.

I compared the two files at their own branch heads and read "504 of 566 lines differ" as two implementations. Those files come from different bases, so most of that was drift. Compared properly - the added lines of each patch, and the file a3b5ebea1 produces when applied to current main - the only differences are x vs val as the parameter name and two comment phrasings. Same helper, same algorithm, same constants.

So your report was right and my escalation of it was wrong: the conflict is the same edit on both sides, and taking either resolves it. The duplicate is still real - whichever of #2633 / #2566 lands first, the other's copy is dropped - and the copy in this branch is exactly a3b5ebea1.

Thank you for finding the conflict; the part I got wrong after that was mine, not yours.

Written with an AI assistant.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Update by OreoFR: the conflict with #2566 I reported here is gone. main (1b0f657) now carries the SHADER-468 change to tests/semantic/test_interp_computed_ij_fallback.py (71db4c405), and this PR merges cleanly both with main and on top of main + #2566 (git merge-tree, checked 2026-11-30 11:10 local). Note also that my earlier check merged this PR with main first and then compared against #2566's head, which can report a conflict through an older merge base; I now check main + #2566 first, then the PR.

AI-assisted: Claude Code

HAVE_NUMPY used importlib.util.find_spec in this process, while the tests run
the tool with python -I, which hides the --user install this machine has. The
gate opened and four cases died on "needs numpy" instead of testing what they
name. The file already did this correctly for Pillow (HAVE_PIL_ISOLATED); this
applies the same probe to numpy and gates the four cases that reach it, keeping
the eleven that test behaviour before numpy.

Measured on main b8bd371, Windows 11, Python 3.13: 5 failed, 12 passed before;
11 passed, 4 skipped after. Where -I sees numpy the probe returns true and the
four run as before.

Written with an AI assistant.
The same in-process numpy check, in the file whose CLI tests spawn
`python -I`: HAVE_NUMPY stayed for the tests that call numpy here, and the
nine CLI gates now use NUMPY_VISIBLE_TO_TOOL, the isolated probe.

Measured on main b8bd371, Windows 11, Python 3.13: 3 failed, 23 passed,
5 skipped before; 21 passed, 10 skipped after. Where -I sees numpy the probe
returns true and every gate opens as before.

Written with an AI assistant.
test_each_sibling_importing_tool_starts skipped a NUMERIC list when numpy was
missing, but it asked find_spec in this process while the tools run with -I, so
the skip never fired here; and a list of names cannot cover calibrated_texture
and tex_export, which are not numeric themselves and import one that is.

The probe now matches how the tools run, and a child that fails with
"No module named 'numpy'" is skipped rather than failing the startup check.

Measured on main b8bd371, Windows 11, Python 3.13: 2 failed, 2 passed,
218 subtests before; 2 passed, 214 subtests after (the four are the two
numpy-dependent subtests, skipped). With numpy visible to -I nothing changes.

Written with an AI assistant.
Applied from merzleckeier's follow-up (f9456e0), unchanged: the two render()
calls use the parent's numpy and Pillow, and the three CLI validation checks
finish before the child needs numpy, so all five should run rather than skip.
The two PNG preview subprocesses need Pillow in the child, which the isolated
probe now checks.

Written with an AI assistant.
@fiestorra
fiestorra force-pushed the fix/tile-probe-numpy-gate branch from 7691389 to b3b064b Compare November 30, 2026 13:55
@fiestorra

Copy link
Copy Markdown
Contributor Author

Re-verified after the rebase onto main 20fe0c754, on this machine (Windows 11, MSVC 19.44.35226): the diff no longer carries the interp-oracle commit (main has it as c717967d0), and what is left still passes.

python3 -m pytest tests/test_tile_probe.py -q
11 passed, 4 skipped, 6 subtests passed in 1.00s

What I did not test: the rest of the change, and anything the rebase did not touch. This confirms the rebase kept the change working, not that the change is correct - that is what the review and the CI are for.

Written with an AI assistant.

@aegish-zagi

Copy link
Copy Markdown
Contributor

VERIFY-2672 — PASS (with one stated limit)

  • PR: tests: four numpy gates decided in the wrong process, so their cases judged the exit code instead #2672 | head b3b064b | merge state vs main b17b22d: CLEAN (scratch merge, no conflicts)
  • Tests run (PR head merged with current main, system Python 3.12): tests/test_swizzle_search.py — 30 tests OK, exit 0; tests/test_tile_probe.py — 15 tests OK (1 skipped); tests/test_tool_startup.py — 2 tests OK
  • Red-on-main vs green-on-PR: on this host there is no red to reproduce — numpy and Pillow are installed system-wide, so they are visible both in-process and under python -I, the two gates agree, and the PR's test files run against plain main also pass (test_swizzle_search.py: 30 tests OK, measured). The failure this PR fixes needs a host where numpy/Pillow come from a --user install (visible in-process, hidden under -I): there, main's gates un-skip CLI tests whose tool subprocess cannot import numpy, and skip argument-validation cases that never needed numpy. That host condition is READ IN CODE here, not MEASURED: the diff replaces the in-process HAVE_NUMPY/HAVE_PIL gates for CLI-launching tests with subprocess probes of what python -I can see (NUMPY_VISIBLE_TO_TOOL / PIL_VISIBLE_TO_TOOL in test_swizzle_search.py, the same probe pattern in test_tile_probe.py and test_tool_startup.py), and drops the numpy gate entirely from the two bad-argument/missing-input cases that only exercise argument parsing. The probe code is short, stdlib-only, and runs the exact interpreter invocation the tool gets.
  • Diff audit: 3 test files only, +29/-8, no production code, no game data.
  • Platform: Linux, Python 3.12, Profile Z (no GPU)
  • AI-assisted: yes (Muse Wonder, Muse by Meta)

@KelboLive

Copy link
Copy Markdown

Independent check on Windows (not the author), at dbd6ccc2b.

  • python -I tests/test_tool_startup.py: 2 tests OK (137.6 s — subprocess start-up cases).
  • python -I tests/test_swizzle_search.py: 30 tests OK (1.76 s).
  • python -I tests/test_tile_probe.py: 15 tests OK, 1 skipped (1.26 s).

Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, no numpy required for these runs.

AI-assisted: yes (opencode).

@aslan2142 aslan2142 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Checking numpy/PIL visibility inside an isolated python -I subprocess in tests/test_swizzle_search.py, tests/test_tile_probe.py, and tests/test_tool_startup.py fixes false skips/failures when packages are only in user-site, and un-gates CLI validation tests that run before numpy import. Clean-room verified, 5/5 CI green, and independently verified. Merging.

(AI-assisted review.)

@aslan2142
aslan2142 merged commit acaa1d6 into ProjectLeonida:main Dec 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants