Repository navigation
Conversation
…OR-CHANGE) A reviewer runs "the pull request's own tests" and a contributor the tests of what they changed, but which ones those are was guesswork: tests are found by their name, and a helper that many tools import has no test of its name. scripts/tests_for.py reads the repository and answers for the paths named, or for the files the current branch changes. For each file it lists the tests under tests/ that import it or name its path, the ones that reach it through the modules they import (with the module they go through), the ones that read its folder, the documentation tests for a Markdown file and the tests beside a fixture that quote its name. For runtime/ it reads runtime/CMakeLists.txt and lists the ctest tests whose program is built from the file: as a source, through a header a source includes, or through a library the program links, with foreach loops and set() lists followed. It then prints the commands, split the way CI splits the tests: python -I, pytest, the semantic runner, node --test and ctest -R. It runs no test. Paths are matched in the case they have on disk, so the answer is the same on Windows and Linux. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2390 (TESTS-FOR-CHANGE). Everything this PR adds runs on macOS, so its own suite and the two big suites were measured here.
Tested head 25a8f9e91 merged onto main bdbc7e923 as merge 98c26ecab (clean; the branch is 108 commits behind but the diff is four added/replaced files).
Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, Apple clang 21.0.0, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.
The new suite passes, and bites
python -I tests/test_tests_for.py: 32/32 OK at the head tree and 32/32 after merging ontobdbc7e923. It is fast (2.8-5.2 s).- Negative control (test kept,
scripts/tests_for.pysabotaged soRepository.reachedstops following imports): 3 failures -test_imports_are_followed_and_say_which_module_they_go_through,test_commands_follow_the_runners,test_tests_are_listed_by_reason_then_by_name. The import graph and the command grouping are pinned. - I also ran the tool by hand on this checkout:
tools/rdna2spirv.py-> 341names it, 273imports(throughtests/semantic/support.py), 11folder;runtime/src/pe_loader.cpp-> 35 ctest;runtime/src/vulkan_replay.h-> 291 ctest;viewer/index.html-> the two viewer tests. The ctest mapping does follow the library/header links, which is the part most likely to be wrong.
No regressions
- Semantic suite: 500 files / 6,367 tests / 0 files failed, both at
mainbdbc7e923and at98c26ecab. Delta 0 (the new file is intests/, nottests/semantic/). - GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, at both
mainand the merge; a line diff of the PASS/FAIL/SKIP output differs only in the per-run temp directory quoted in SKIP reasons. The failures are the pre-existing ones atmain(MV:cs_fma_fused,cs_imgatomic_ext,ps_ssharp; KK:cs_bvh,cs_bvh32,cs_imgatomic_ext,ps_cndmask_sign_mods,ps_valu16_mad_sel). - Runtime build note, unrelated to this PR: a clean
cmake --build runtime/build -j8atmainfails atvk_null_descriptor_testwithglslangValidator: Failed to open file .../build/generated/cs_null_descriptors.spv(runtime/CMakeLists.txt:2266-2273writes intogenerated/without creating it; reproduced on two fresh build dirs).mkdir -p build/generatedthen the build reaches 100%. The GPU binaries (vk_compute_test,vk_store_test,vk_harness) were built before the abort, so the GPU numbers above are from the same tree; I have not counted the aborted build as a pass.
Finding (low, real)
scripts/tests_for.py:344-357 (expand_targets) never checks that a PATH exists. A mistyped path is silently treated as a file nothing names - and because survey's folder reason does not look at the file either, it even lists tests that name the folder. Reproduced on this checkout:
python -I scripts/tests_for.py tools/rdna2spirv.py-> 341names it, 273imports, exit 0.python -I scripts/tests_for.py tools/rdna2spiry.py(one letter wrong) ->folder (11)withtest_alu_frexp.py,test_bad_input_errors.py, ..., aRun:block, and exit 0.
So a reviewer who mistypes a path runs eleven unrelated tests and thinks the change is covered; nothing distinguishes that from a file with genuinely no test. The docstring promises "Exit 0, or 2 on a usage or git error" (line 32). Add an existence check in expand_targets (explicit arguments only, so changed_files can still report a file deleted between --base and --head), e.g. if not os.path.lexists(full): raise GitError(f"{path} does not exist"), and a test beside the others.
Nit
commands() (:422) collapses the ctest list to the whole-suite command whenever there are more than 40, even with --all, although --all's help says "commands for every test found, however many". Running the suite does run every test, so this is wording, not behaviour; either say so in the help or gate the collapse on everything like the other reasons.
No game files. AI-assisted.
Claimed in the coordination issue as: TESTS-FOR-CHANGE (#1608 (comment))
Depends on: none. It merges cleanly with the two open pull requests that also edit
CONTRIBUTING.md(#2151 and #2349, in another section), checked with thescripts/pr_overlap.pyof #2349.What and why
The maintainer guide says to run "the pull request's own tests", and AGENTS.md to run one test file while iterating. Which tests those are was guesswork: tests are found by their name, and a helper that many tools import has no test of its name.
tools/world_build.pyis named by seven test files, only two of them calledtest_world_build*, and six more reach it throughsandbox.py,sandbox_scene.pyand the two drawable tools.python -I scripts/tests_for.py [PATH ...]reads the repository and answers for the files or folders named, or with no argument for what the branch changes (committed against the merge base withorigin/main, plus modified and untracked files). For each file it lists the tests undertests/that reach it, with the reason:names it: the test imports the file as a module or names its path, as a quoted path or joined from quoted segments (os.path.join, pathlib/, Node'sjoin);imports: a module the test imports reaches the file through imports, with the module it goes through;folder: the test names the folder the file is in and nothing in it, so it reads what is there; for a Markdown file these aretests/test_docs_*.pyandtests/test_i18n_index.py, the set CI runs for a documentation change;fixture: the file is under afixturesfolder and a test beside that folder quotes its name;ctest: forruntime/, the ctest tests whose program is built from the file according toruntime/CMakeLists.txt: as a source, through a header a source includes, or through a library the program links.foreachloops andset()lists are followed.Then it prints the commands, split the way CI splits the tests:
python -Ifor a standalone file, pytest for a file with CI's pytest markers or no__main__block, the semantic runner,node --test, andctest -Rwith the names. Tests that name the file and changed tests always get a command; the wider reasons do when there are at most 20 of them, or with--all.--jsongives the whole report. It runs no test and writes nothing.On this repository (1,048 test files, 492
add_testentries):tools/world_build.py: 7 tests name it, 6 reach it through imports, 11 name thetoolsfolder.tools/rdna2spirv.py: 341 name it and 273 reach it through imports; the command list is 38 lines with the semantic suite as one of them.runtime/shims/ws2_offline.cpp: 16 ctest tests,ws2_offlineand 15 whose command runs a program that is built from it too (run_tiny_game,run_argv_modesand others).viewer/index.html:tests/test_viewer_streaming.cjsandtests/test_docs_repo_paths.pyname it, andtests/test_viewer_cdn_integrity.pyis one of the two that name the folder.What it cannot see, also said in its docstring: a path that is built at run time, and a ctest program that a CMake function or a generator expression builds. Of the 492
add_testentries, 15 run something it cannot place (gameinput,run_tiny_asyncand others) and one keeps a${...}in its name and is left out, so the ctest list is the least there is to run. Paths are matched in the case they have on disk, so Windows gives the same answer as Linux.CONTRIBUTING.mdgets one bullet under "Working on the code".Tested
Windows 11, Python 3.14.7, git 2.55.0:
python -I tests/test_tests_for.py: 32 tests. 28 run on a synthetic checkout of 62 small files kept as data intests/fixtures/tests_for_checkout.json(its paths would otherwise read as references of the test file to real files, which one of the tests checks), one on a throwaway git repository for the branch mode, and three on this repository.main, where the script does not exist.python -I scripts/tests_for.py tools/world_build.pytakes 1.8 s here.python -Ion the 13tests/test_docs_*.py,tests/test_i18n_index.py,tests/test_tool_stdout_encoding.py,tests/test_text_write_line_endings.pyandtests/test_ci_registration.py;python -I scripts/check_no_game_data.pyon the new files.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator rule in this change.)🤖 Generated with Claude Code