[PR #2390] scripts: tests_for.py names the tests that exercise a change (TESTS-FOR-CHANGE) #2393

Open
opened 2026-11-26 21:21:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2390
Author: @syfyra
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: feat/tests-for-change


📝 Commits (1)

  • 25a8f9e scripts: tests_for.py names the tests that exercise a change (TESTS-FOR-CHANGE)

📊 Changes

4 files changed (+912 additions, -0 deletions)

View changed files

📝 CONTRIBUTING.md (+4 -0)
➕ scripts/tests_for.py (+489 -0)
➕ tests/fixtures/tests_for_checkout.json (+64 -0)
➕ tests/test_tests_for.py (+355 -0)

📄 Description

Claimed in the coordination issue as: TESTS-FOR-CHANGE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7197929842)

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 the scripts/pr_overlap.py of #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.py is named by seven test files, only two of them called test_world_build*, and six more reach it through sandbox.py, sandbox_scene.py and 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 with origin/main, plus modified and untracked files). For each file it lists the tests under tests/ 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's join);
  • 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 are tests/test_docs_*.py and tests/test_i18n_index.py, the set CI runs for a documentation change;
  • fixture: the file is under a fixtures folder and a test beside that folder quotes its name;
  • ctest: for runtime/, the ctest tests whose program is built from the file according to runtime/CMakeLists.txt: as a source, through a header a source includes, or through a library the program links. foreach loops and set() lists are followed.

Then it prints the commands, split the way CI splits the tests: python -I for a standalone file, pytest for a file with CI's pytest markers or no __main__ block, the semantic runner, node --test, and ctest -R with 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. --json gives the whole report. It runs no test and writes nothing.

On this repository (1,048 test files, 492 add_test entries):

  • tools/world_build.py: 7 tests name it, 6 reach it through imports, 11 name the tools folder.
  • 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_offline and 15 whose command runs a program that is built from it too (run_tiny_game, run_argv_modes and others).
  • viewer/index.html: tests/test_viewer_streaming.cjs and tests/test_docs_repo_paths.py name it, and tests/test_viewer_cdn_integrity.py is 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_test entries, 15 run something it cannot place (gameinput, run_tiny_async and 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.md gets 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 in tests/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.
  • The test file fails on main, where the script does not exist.
  • 65 small changes to the script (a join that takes any two quoted words, imports not followed, the folder rule widened to subfolders, loops not expanded, libraries linked the wrong way round, the pytest markers shortened, and so on) each make at least one test fail; an unchanged copy passes in the same harness.
  • python -I scripts/tests_for.py tools/world_build.py takes 1.8 s here.
  • python -I on the 13 tests/test_docs_*.py, tests/test_i18n_index.py, tests/test_tool_stdout_encoding.py, tests/test_text_write_line_endings.py and tests/test_ci_registration.py; python -I scripts/check_no_game_data.py on the new files.
  • Not tested: Linux and macOS, Python 3.12, and I did not run the commands it prints for the four examples above; the lists were read, not executed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule in this change.)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2390 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/tests-for-change` --- ### 📝 Commits (1) - [`25a8f9e`](https://github.com/ubiquitarianism/leonida/commit/25a8f9e916663d5b80b5715eaef5c06b79e97275) scripts: tests_for.py names the tests that exercise a change (TESTS-FOR-CHANGE) ### 📊 Changes **4 files changed** (+912 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CONTRIBUTING.md` (+4 -0) ➕ `scripts/tests_for.py` (+489 -0) ➕ `tests/fixtures/tests_for_checkout.json` (+64 -0) ➕ `tests/test_tests_for.py` (+355 -0) </details> ### 📄 Description Claimed in the coordination issue as: TESTS-FOR-CHANGE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7197929842) 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 the `scripts/pr_overlap.py` of #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.py` is named by seven test files, only two of them called `test_world_build*`, and six more reach it through `sandbox.py`, `sandbox_scene.py` and 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 with `origin/main`, plus modified and untracked files). For each file it lists the tests under `tests/` 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's `join`); - `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 are `tests/test_docs_*.py` and `tests/test_i18n_index.py`, the set CI runs for a documentation change; - `fixture`: the file is under a `fixtures` folder and a test beside that folder quotes its name; - `ctest`: for `runtime/`, the ctest tests whose program is built from the file according to `runtime/CMakeLists.txt`: as a source, through a header a source includes, or through a library the program links. `foreach` loops and `set()` lists are followed. Then it prints the commands, split the way CI splits the tests: `python -I` for a standalone file, pytest for a file with CI's pytest markers or no `__main__` block, the semantic runner, `node --test`, and `ctest -R` with 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`. `--json` gives the whole report. It runs no test and writes nothing. On this repository (1,048 test files, 492 `add_test` entries): - `tools/world_build.py`: 7 tests name it, 6 reach it through imports, 11 name the `tools` folder. - `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_offline` and 15 whose command runs a program that is built from it too (`run_tiny_game`, `run_argv_modes` and others). - `viewer/index.html`: `tests/test_viewer_streaming.cjs` and `tests/test_docs_repo_paths.py` name it, and `tests/test_viewer_cdn_integrity.py` is 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_test` entries, 15 run something it cannot place (`gameinput`, `run_tiny_async` and 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.md` gets 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 in `tests/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. - The test file fails on `main`, where the script does not exist. - 65 small changes to the script (a join that takes any two quoted words, imports not followed, the folder rule widened to subfolders, loops not expanded, libraries linked the wrong way round, the pytest markers shortened, and so on) each make at least one test fail; an unchanged copy passes in the same harness. - `python -I scripts/tests_for.py tools/world_build.py` takes 1.8 s here. - `python -I` on the 13 `tests/test_docs_*.py`, `tests/test_i18n_index.py`, `tests/test_tool_stdout_encoding.py`, `tests/test_text_write_line_endings.py` and `tests/test_ci_registration.py`; `python -I scripts/check_no_game_data.py` on the new files. - Not tested: Linux and macOS, Python 3.12, and I did not run the commands it prints for the four examples above; the lists were read, not executed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator rule in this change.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
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
starred/leonida#2393
No description provided.