tests: test_mutations copies tools/ once and runs only the test each mutation must break (TEST-MUTATIONS-COST) #1516

Open
github-bot wants to merge 1 commit from github-bot/gh-1516 into main AGit
Owner

@⁠milk4sale on GitHub · 2026-11-25 03:03 UTC · original
milk4sale:tests/mutations-one-copy → main · +26 −12 · 1 files · 1 commits · open

Claimed in the coordination issue as: TEST-MUTATIONS-COST (#14)

What and why

tests/semantic/test_mutations.py was the last file still running in all 23 semantic-tests (windows-latest) runs measured for #1462, and in the 14 of them that were cancelled at the 10-minute limit it was the only file still running. For each of its 14 runs of test_ps_semantics.py (the baseline and 13 mutations) it copied tools/ (332 files, 8.6 MB) into a new temporary folder, deleted it afterwards, and ran the whole file.

Now test_each_mutation_is_caught makes one copy for all 13 mutations. Each mutation starts from the original translator and writes it back in a finally, so with test_baseline_copy_passes's own copy, 14 copies of tools/ become 2: about 660 files written and deleted instead of about 4,650. Each mutation runs only the test it must break, test_ps_semantics.TranslatorSemantics.<test>, so the 13 mutation runs translate 13 shaders instead of 78.

failed_tests now counts only failures reported for TranslatorSemantics. A test name the class does not have fails too, as ERROR: test_x (unittest.loader._FailedTest.test_x), so with one test per run the old pattern would have counted a misspelled expected test as caught (checked below).

What the file checks stays the same: the whole of test_ps_semantics.py passes on an unmutated copy, each anchor must match exactly once, each mutation must make its test fail, test_anchors_match_crlf_translator_copies is untouched, and the repository's own tools/ is never written. The children keep PYTHONDONTWRITEBYTECODE=1. Now that the translator is rewritten in place, that also stops a .pyc of one mutant being run for a later mutant of the same size written in the same second. A comment says so.

Why I expect it to help on Windows (a hypothesis, not measured there)

Per-file times of the two legs of the same run, from the job logs of the 9 runs in #1462's table that ran to their end (the Ran N tests in X s of each file):

Run (fork) test_mutations Windows Linux Windows / Linux All other files, Windows / Linux
45335997425 340 s 33.2 s 10.2x 911 s / 565 s = 1.61x
45360123747 269 s 33.9 s 7.9x 792 s / 682 s = 1.16x
45398596589 264 s 45.2 s 5.8x 804 s / 961 s = 0.84x
45420340290 250 s 41.3 s 6.1x 705 s / 928 s = 0.76x
45432144669 316 s 46.0 s 6.9x 798 s / 970 s = 0.82x
45455214398 297 s 45.4 s 6.5x 913 s / 983 s = 0.93x
45466210143 381 s 34.2 s 11.1x 940 s / 757 s = 1.24x
45504536550 288 s 36.5 s 7.9x 1012 s / 682 s = 1.48x
45514815352 352 s 42.9 s 8.2x 976 s / 1027 s = 0.95x

The rest of the suite took 0.76-1.61 times as long on Windows as on Linux; test_mutations took 5.8-11.1 times as long. Most of what its children do is the same CPU work the other files do (compiling and running the translator), so I expect most of the difference to come from what only this file does: writing and deleting about 330 files 14 times, and starting 14 Python processes that each import the translator from a folder created just before. This change removes 12 of the 14 copies. It keeps the 14 processes and their 14 compiles of the 1.1 MB translator, which are the main cost on Linux. Only a Windows run can confirm it. The Windows leg runs on the first push to main after this merges; GitHub blocked my fork's Actions on 25 November, so I could not dispatch one.

Tested

On Linux (Ryzen 9 7900X, 24 threads, Python 3.14.10; CI uses 3.12), with main at f78385646 and this change on top of it, each exported to its own folder, alternating between the two in every round:

main this branch
run_semantic_tests.py tests/semantic -p test_mutations.py, median of 8 (load average 6-12) 6.93 s wall, 6.86 s CPU 6.43 s wall, 6.35 s CPU
the same, median of 6, while another job loaded the machine (load average 27-29) 11.40 s wall, 10.68 s CPU 10.19 s wall, 9.58 s CPU
test_each_mutation_is_caught (unittest --durations), median of 6 4.42 s 3.84 s
test_anchors_match_crlf_translator_copies (unchanged) 2.21 s 2.20 s
test_baseline_copy_passes (unchanged) 0.32 s 0.33 s

The gain on Linux is small: copying tools/ takes about 16 ms here, and a child spends about 0.19 s of its 0.25 s import compiling rdna2spirv.py (-X importtime). Most of the time the file still takes goes into 27 compiles of the translator, 14 in the children and 13 in the CRLF test.

  • Sabotage checks. Each is a copy of the file with its first mutation (SDWA sext()) changed, run against this branch's file and main's: a misspelled expected test (test_ps_sdwz), a real test that mutation does not break (test_ps_ops), a replacement that changes nothing, and an anchor that no longer matches. Every one fails on both, with only that subtest failing and the other 12 mutations passing. With the old failed_tests pattern put back, the misspelled name passes on this branch; that is why the pattern now names the class.
  • An instrumented run of test_each_mutation_is_caught. Each of the 13 children saw the original translator with only its own mutation applied (13 different texts), and the copy's translator was byte-identical to tools/rdna2spirv.py before each mutation and at the end.
  • python -I scripts/run_semantic_tests.py tests/semantic on this branch (on main at b07b9ecb0): 487 files, 6,279 tests, 0 files failed in 69 s with 24 jobs.
  • python -I scripts/check_no_game_data.py tests/semantic/test_mutations.py: clean. python -I tests/test_text_write_line_endings.py: passes.

GPUs tested: n/a (one test file)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase). No open pull request changes tests/semantic/test_mutations.py.
  • 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 change.)

🤖 Generated with Claude Code

**@⁠milk4sale** on GitHub · 2026-11-25 03:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1516) `milk4sale:tests/mutations-one-copy` → `main` · +26 −12 · 1 files · 1 commits · open Claimed in the coordination issue as: TEST-MUTATIONS-COST (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why `tests/semantic/test_mutations.py` was the last file still running in all 23 `semantic-tests (windows-latest)` runs measured for #1462, and in the 14 of them that were cancelled at the 10-minute limit it was the only file still running. For each of its 14 runs of `test_ps_semantics.py` (the baseline and 13 mutations) it copied `tools/` (332 files, 8.6 MB) into a new temporary folder, deleted it afterwards, and ran the whole file. Now `test_each_mutation_is_caught` makes one copy for all 13 mutations. Each mutation starts from the original translator and writes it back in a `finally`, so with `test_baseline_copy_passes`'s own copy, 14 copies of `tools/` become 2: about 660 files written and deleted instead of about 4,650. Each mutation runs only the test it must break, `test_ps_semantics.TranslatorSemantics.<test>`, so the 13 mutation runs translate 13 shaders instead of 78. `failed_tests` now counts only failures reported for `TranslatorSemantics`. A test name the class does not have fails too, as `ERROR: test_x (unittest.loader._FailedTest.test_x)`, so with one test per run the old pattern would have counted a misspelled expected test as caught (checked below). What the file checks stays the same: the whole of `test_ps_semantics.py` passes on an unmutated copy, each anchor must match exactly once, each mutation must make its test fail, `test_anchors_match_crlf_translator_copies` is untouched, and the repository's own `tools/` is never written. The children keep `PYTHONDONTWRITEBYTECODE=1`. Now that the translator is rewritten in place, that also stops a `.pyc` of one mutant being run for a later mutant of the same size written in the same second. A comment says so. ### Why I expect it to help on Windows (a hypothesis, not measured there) Per-file times of the two legs of the same run, from the job logs of the 9 runs in #1462's table that ran to their end (the `Ran N tests in X s` of each file): | Run (fork) | `test_mutations` Windows | Linux | Windows / Linux | All other files, Windows / Linux | |---|---|---|---|---| | [45335997425](https://github.com/milk4sale/leonida/actions/runs/45335997425) | 340 s | 33.2 s | 10.2x | 911 s / 565 s = 1.61x | | [45360123747](https://github.com/milk4sale/leonida/actions/runs/45360123747) | 269 s | 33.9 s | 7.9x | 792 s / 682 s = 1.16x | | [45398596589](https://github.com/milk4sale/leonida/actions/runs/45398596589) | 264 s | 45.2 s | 5.8x | 804 s / 961 s = 0.84x | | [45420340290](https://github.com/milk4sale/leonida/actions/runs/45420340290) | 250 s | 41.3 s | 6.1x | 705 s / 928 s = 0.76x | | [45432144669](https://github.com/milk4sale/leonida/actions/runs/45432144669) | 316 s | 46.0 s | 6.9x | 798 s / 970 s = 0.82x | | [45455214398](https://github.com/milk4sale/leonida/actions/runs/45455214398) | 297 s | 45.4 s | 6.5x | 913 s / 983 s = 0.93x | | [45466210143](https://github.com/milk4sale/leonida/actions/runs/45466210143) | 381 s | 34.2 s | 11.1x | 940 s / 757 s = 1.24x | | [45504536550](https://github.com/milk4sale/leonida/actions/runs/45504536550) | 288 s | 36.5 s | 7.9x | 1012 s / 682 s = 1.48x | | [45514815352](https://github.com/milk4sale/leonida/actions/runs/45514815352) | 352 s | 42.9 s | 8.2x | 976 s / 1027 s = 0.95x | The rest of the suite took 0.76-1.61 times as long on Windows as on Linux; `test_mutations` took 5.8-11.1 times as long. Most of what its children do is the same CPU work the other files do (compiling and running the translator), so I expect most of the difference to come from what only this file does: writing and deleting about 330 files 14 times, and starting 14 Python processes that each import the translator from a folder created just before. This change removes 12 of the 14 copies. It keeps the 14 processes and their 14 compiles of the 1.1 MB translator, which are the main cost on Linux. Only a Windows run can confirm it. The Windows leg runs on the first push to `main` after this merges; GitHub blocked my fork's Actions on 25 November, so I could not dispatch one. ### Tested On Linux (Ryzen 9 7900X, 24 threads, Python 3.14.10; CI uses 3.12), with `main` at f78385646 and this change on top of it, each exported to its own folder, alternating between the two in every round: | | `main` | this branch | |---|---|---| | `run_semantic_tests.py tests/semantic -p test_mutations.py`, median of 8 (load average 6-12) | 6.93 s wall, 6.86 s CPU | 6.43 s wall, 6.35 s CPU | | the same, median of 6, while another job loaded the machine (load average 27-29) | 11.40 s wall, 10.68 s CPU | 10.19 s wall, 9.58 s CPU | | `test_each_mutation_is_caught` (`unittest --durations`), median of 6 | 4.42 s | 3.84 s | | `test_anchors_match_crlf_translator_copies` (unchanged) | 2.21 s | 2.20 s | | `test_baseline_copy_passes` (unchanged) | 0.32 s | 0.33 s | The gain on Linux is small: copying `tools/` takes about 16 ms here, and a child spends about 0.19 s of its 0.25 s import compiling `rdna2spirv.py` (`-X importtime`). Most of the time the file still takes goes into 27 compiles of the translator, 14 in the children and 13 in the CRLF test. - Sabotage checks. Each is a copy of the file with its first mutation (SDWA `sext()`) changed, run against this branch's file and `main`'s: a misspelled expected test (`test_ps_sdwz`), a real test that mutation does not break (`test_ps_ops`), a replacement that changes nothing, and an anchor that no longer matches. Every one fails on both, with only that subtest failing and the other 12 mutations passing. With the old `failed_tests` pattern put back, the misspelled name passes on this branch; that is why the pattern now names the class. - An instrumented run of `test_each_mutation_is_caught`. Each of the 13 children saw the original translator with only its own mutation applied (13 different texts), and the copy's translator was byte-identical to `tools/rdna2spirv.py` before each mutation and at the end. - `python -I scripts/run_semantic_tests.py tests/semantic` on this branch (on `main` at b07b9ecb0): 487 files, 6,279 tests, 0 files failed in 69 s with 24 jobs. - `python -I scripts/check_no_game_data.py tests/semantic/test_mutations.py`: clean. `python -I tests/test_text_write_line_endings.py`: passes. GPUs tested: n/a (one test file) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). No open pull request changes `tests/semantic/test_mutations.py`. - [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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator change.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test_mutations.py is the last file still running in every semantic-tests (windows-latest) run measured for #1462,
250-381 s there against 33-46 s on the Linux leg of the same runs, while the rest of the suite took 0.76-1.61 times
as long on Windows as on Linux. For each of its 14 runs of test_ps_semantics.py (the baseline and 13 mutations) it
copied tools/ (about 330 files) into a new temporary folder, deleted it afterwards, and ran the whole file.

test_each_mutation_is_caught now makes one copy for all 13 mutations: each starts from the original translator and
writes it back in a finally, so 14 copies become 2. Each mutation runs only the test it must break
(test_ps_semantics.TranslatorSemantics.<test>), so its child translates one shader instead of six. failed_tests
counts only failures reported for TranslatorSemantics: a name the class does not have fails too, as
"ERROR: test_x (unittest.loader._FailedTest.test_x)", and with one test per run the old pattern would have counted
a misspelled expected test as caught.

What the file checks is unchanged: the whole of test_ps_semantics.py passes on an unmutated copy, each anchor
matches exactly once, each mutation makes its test fail, the CRLF anchor test is untouched and the repository's
tools/ is never written. The children keep PYTHONDONTWRITEBYTECODE=1, which now also keeps a .pyc of an earlier
mutant from being run for a later one of the same size written in the same second; a comment says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:04 +00:00
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:34 UTC · original · edited 2026-11-25 03:45 UTC

[KEEP]

  • Change looks sound and tightly scoped: only tests/semantic/test_mutations.py; one shared tools/ copy, original restored in a finally, and the failed_tests regex now requires TranslatorSemantics, so a misspelled expected test can no longer count as caught.
  • CI has not finished: change-scope and no-game-data are still pending, and the Windows semantic-tests leg this targets has not reported yet.
  • The PR states the Windows speedup is a hypothesis, not measured. Hold until a green Windows run shows the file completes well inside the limit.
  • No duplicate open PR; #1462 (Windows time limit) is related but complementary.
  • Re-triage once CI is green; this should then be mergeable.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1516#issuecomment-7152034278) · edited 2026-11-25 03:45 UTC **[KEEP]** - Change looks sound and tightly scoped: only `tests/semantic/test_mutations.py`; one shared `tools/` copy, original restored in a `finally`, and the `failed_tests` regex now requires `TranslatorSemantics`, so a misspelled expected test can no longer count as caught. - CI has not finished: `change-scope` and `no-game-data` are still pending, and the Windows `semantic-tests` leg this targets has not reported yet. - The PR states the Windows speedup is a hypothesis, not measured. Hold until a green Windows run shows the file completes well inside the limit. - No duplicate open PR; #1462 (Windows time limit) is related but complementary. - Re-triage once CI is green; this should then be mergeable.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1516/head:github-bot/gh-1516'
git switch 'github-bot/gh-1516'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1516'
git switch 'github-bot/gh-1516'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1516'
git switch 'github-bot/gh-1516'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1516'
git switch 'main'
git merge --squash 'github-bot/gh-1516'
git switch 'main'
git merge --ff-only 'github-bot/gh-1516'
git switch 'main'
git merge 'github-bot/gh-1516'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.