SEMANTIC-PACKAGE-TESTS: include package initializers in parallel runner #474

Manually merged
github merged 1 commit from gh-pr/474/head into gh-pr/474/base 2026-11-26 09:02:43 +00:00
Owner

@⁠bobcatchris on GitHub · 2026-11-24 05:59 UTC · original
bobcatchris:semantic-package-tests → main · +55 −7 · 2 files · 1 commits · merged 2026-11-24 06:58 UTC

Claimed in the coordination issue as: SEMANTIC-PACKAGE-TESTS

What and why

The default parallel translator-test runner selected only files matching test*.py, but unittest discover also imports every package below the suite root and runs TestCase classes defined in a package's __init__.py. A failing test in pkg/__init__.py therefore made -j 1 fail while -j 2 returned green with one fewer test.

test_modules now includes package initializers even when no filename matches the pattern, module_path handles their path when sorting by size, and an empty initializer with no tests is not reported as a failure. Two regressions cover a failing initializer and a pattern that matches no test filenames.

No game files, GPU, dependencies, keys or decryption are involved.

Tested

  • python -I tests/test_run_semantic_tests.py — 12 tests OK
  • synthetic reproduction: -j 1 and -j 2 now both fail on a failing package initializer (previously -j 2 returned 0)
  • python -I scripts/run_semantic_tests.py tests/semantic — 465 files, 6104 tests; only test_image_cube_store_glc failed in this environment, also fails on unpatched main
  • python -I tests/test_ci_registration.py — 15 tests OK
  • python -m compileall -q scripts tests — OK
  • git diff --check — clean
  • security sweep of the diff — 0 hits

GPUs tested: n/a (CPU-only runner and tests)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • Regression test added for the false-green case.
**@⁠bobcatchris** on GitHub · 2026-11-24 05:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/474) `bobcatchris:semantic-package-tests` → `main` · +55 −7 · 2 files · 1 commits · merged 2026-11-24 06:58 UTC Claimed in the coordination issue as: SEMANTIC-PACKAGE-TESTS ### What and why The default parallel translator-test runner selected only files matching `test*.py`, but `unittest discover` also imports every package below the suite root and runs TestCase classes defined in a package's `__init__.py`. A failing test in `pkg/__init__.py` therefore made `-j 1` fail while `-j 2` returned green with one fewer test. `test_modules` now includes package initializers even when no filename matches the pattern, `module_path` handles their path when sorting by size, and an empty initializer with no tests is not reported as a failure. Two regressions cover a failing initializer and a pattern that matches no test filenames. No game files, GPU, dependencies, keys or decryption are involved. ### Tested - `python -I tests/test_run_semantic_tests.py` — 12 tests OK - synthetic reproduction: `-j 1` and `-j 2` now both fail on a failing package initializer (previously `-j 2` returned 0) - `python -I scripts/run_semantic_tests.py tests/semantic` — 465 files, 6104 tests; only `test_image_cube_store_glc` failed in this environment, also fails on unpatched `main` - `python -I tests/test_ci_registration.py` — 15 tests OK - `python -m compileall -q scripts tests` — OK - `git diff --check` — clean - security sweep of the diff — 0 hits GPUs tested: n/a (CPU-only runner and tests) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. - [x] Regression test added for the false-green case.
unittest discover loads TestCase classes defined in a package's __init__.py regardless of the filename pattern. The parallel runner only selected test*.py files, so a failing package initializer could be skipped while -j 1 reported it. Include package initializers in the parallel module list; an empty initializer with no tests is not a failure. Add regressions for failing initializers and for a pattern that matches no test filenames.

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:02:41 +00:00
github manually merged commit b45d7c2d14 into gh-pr/474/base 2026-11-26 09:02:43 +00:00
Author
Owner

@⁠Dezmonius on GitHub · 2026-11-24 06:06 UTC · original

Independent Windows check at 27b3223 (CPython 3.14.7). The 12 runner tests pass. I found two serial/parallel discrepancies with synthetic packages.

The initializer executes twice in its own parallel worker. python -m unittest pkg.__init__ first imports pkg, then executes the same file as pkg.__init__. For example, create pkg/helper.py containing registrations = [] and use this pkg/__init__.py:

import unittest
from .helper import registrations

registrations.append(__name__)

class T(unittest.TestCase):
    def test_once(self):
        self.assertEqual(registrations, ["pkg"])

Run python -I scripts/run_semantic_tests.py <fixture-root> -j 1 and repeat with -j 2. Serial passes once. Parallel fails with ['pkg', 'pkg.__init__']. Invoking python -m unittest pkg from the fixture root passed and ran the initializer once. Could the initializer job invoke the package name, while retaining the initializer path for size sorting?

An empty package alone gives a false green. With just an empty pkg/__init__.py, serial exits 5, and parallel exits 0 with 1 files, 0 tests, 0 files failed. Please preserve a nonzero exit for a whole run with zero tests while allowing empty initializer jobs alongside real tests.

CPU-only synthetic fixtures. AI-assisted (Codex).

**@⁠Dezmonius** on GitHub · 2026-11-24 06:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/474#issuecomment-7123592683) Independent Windows check at `27b3223` (CPython 3.14.7). The 12 runner tests pass. I found two serial/parallel discrepancies with synthetic packages. **The initializer executes twice in its own parallel worker.** `python -m unittest pkg.__init__` first imports `pkg`, then executes the same file as `pkg.__init__`. For example, create `pkg/helper.py` containing `registrations = []` and use this `pkg/__init__.py`: ```python import unittest from .helper import registrations registrations.append(__name__) class T(unittest.TestCase): def test_once(self): self.assertEqual(registrations, ["pkg"]) ``` Run `python -I scripts/run_semantic_tests.py <fixture-root> -j 1` and repeat with `-j 2`. Serial passes once. Parallel fails with `['pkg', 'pkg.__init__']`. Invoking `python -m unittest pkg` from the fixture root passed and ran the initializer once. Could the initializer job invoke the package name, while retaining the initializer path for size sorting? **An empty package alone gives a false green.** With just an empty `pkg/__init__.py`, serial exits 5, and parallel exits 0 with `1 files, 0 tests, 0 files failed`. Please preserve a nonzero exit for a whole run with zero tests while allowing empty initializer jobs alongside real tests. CPU-only synthetic fixtures. AI-assisted (Codex).
Author
Owner

@⁠csmith105 on GitHub · 2026-11-24 06:13 UTC · original · reviewed

Reviewed 27b3223edd6d7531fef3c3faaeebd34980ebb913 on Windows/Python 3.12.14. I reproduced two package-discovery problems worth fixing before merging:

  1. Scheduling pkg.__init__ executes the initializer twice in one process: Python initializes pkg, then imports the same file as pkg.__init__. With counter.py containing visits = 0, this initializer passes with -j 1 but fails with -j 2 (2 != 1):
# pkg/__init__.py
import unittest
import counter
counter.visits += 1
class T(unittest.TestCase):
    def test_once(self): self.assertEqual(counter.visits, 1)
  1. The new initializer job calls load_tests with pattern=None, while child modules are still scheduled independently. This can still produce a false green. With a passing pkg/case_child.py and this initializer, -p 'case_*.py' -j 1 fails (one failing test), but -p 'case_*.py' -j 2 succeeds (only the passing child runs):
import unittest
class T(unittest.TestCase):
    def test_dynamic(self): self.fail('hook regression')
def load_tests(loader, tests, pattern):
    return tests if pattern == 'case_*.py' else unittest.TestSuite()

I also confirmed that a nested hook which suppresses discovery still has its excluded child run in parallel, and an empty-package-only suite returns 0 in parallel versus 5 in serial on this Python version.

A possible narrow approach is one discovery subprocess per top-level package subtree: python -m unittest discover -s <suite>/pkg -t <suite> -p <pattern>, keeping root-level module jobs as they are and not separately scheduling package descendants. Small synthetic checks preserved initializer identity, nested hooks, the requested pattern and recursion suppression with that approach. Empty package jobs still need an overall no-tests check.

AI-assisted review with OpenAI Codex; all behavior above was executed against the stated head, with no game files or GPU.

**@⁠csmith105** on GitHub · 2026-11-24 06:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/474#pullrequestreview-6034540650) · **reviewed** Reviewed `27b3223edd6d7531fef3c3faaeebd34980ebb913` on Windows/Python 3.12.14. I reproduced two package-discovery problems worth fixing before merging: 1. Scheduling `pkg.__init__` executes the initializer twice in one process: Python initializes `pkg`, then imports the same file as `pkg.__init__`. With `counter.py` containing `visits = 0`, this initializer passes with `-j 1` but fails with `-j 2` (`2 != 1`): ```python # pkg/__init__.py import unittest import counter counter.visits += 1 class T(unittest.TestCase): def test_once(self): self.assertEqual(counter.visits, 1) ``` 2. The new initializer job calls `load_tests` with `pattern=None`, while child modules are still scheduled independently. This can still produce a false green. With a passing `pkg/case_child.py` and this initializer, `-p 'case_*.py' -j 1` fails (one failing test), but `-p 'case_*.py' -j 2` succeeds (only the passing child runs): ```python import unittest class T(unittest.TestCase): def test_dynamic(self): self.fail('hook regression') def load_tests(loader, tests, pattern): return tests if pattern == 'case_*.py' else unittest.TestSuite() ``` I also confirmed that a nested hook which suppresses discovery still has its excluded child run in parallel, and an empty-package-only suite returns 0 in parallel versus 5 in serial on this Python version. A possible narrow approach is one discovery subprocess per top-level package subtree: `python -m unittest discover -s <suite>/pkg -t <suite> -p <pattern>`, keeping root-level module jobs as they are and not separately scheduling package descendants. Small synthetic checks preserved initializer identity, nested hooks, the requested pattern and recursion suppression with that approach. Empty package jobs still need an overall no-tests check. AI-assisted review with OpenAI Codex; all behavior above was executed against the stated head, with no game files or GPU.
Author
Owner

@⁠milk4sale on GitHub · 2026-11-24 06:28 UTC · original

Two more package cases at 27b3223 (Linux, CPython 3.14.10) where -j 2 differs from -j 1, besides the ones above. In both, discover stops at the package (_find_test_path returns the import error or the skip and does not enter it), but the parallel runner still schedules its modules on their own:

  • pkg/__init__.py fails to import (import no_such_module_anywhere), with two passing modules pkg/test_one.py and pkg/test_two.py: -j 1 reports one import error (1 test). -j 2 reports it three times, for pkg.__init__, pkg.test_one and pkg.test_two (3 files, 3 tests, 3 files failed).
  • pkg/__init__.py raises unittest.SkipTest('skip-pkg'), with a failing pkg/test_child.py: -j 1 exits 0 with OK (skipped=1). -j 2 exits 1: both jobs stop with an uncaught unittest.case.SkipTest (2 files, 0 tests, 2 files failed).

Running a package that discover does not enter as python -m unittest discover -s <suite>/pkg -t <suite> -p <pattern>, as csmith105 suggests, gives the serial result in both cases. I checked that with synthetic -j 1/-j 2 suites comparing exit code, test count and the -v test ids.

CPU-only synthetic fixtures, no game files. AI-assisted (Claude Code).

**@⁠milk4sale** on GitHub · 2026-11-24 06:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/474#issuecomment-7123971627) Two more package cases at `27b3223` (Linux, CPython 3.14.10) where `-j 2` differs from `-j 1`, besides the ones above. In both, discover stops at the package (`_find_test_path` returns the import error or the skip and does not enter it), but the parallel runner still schedules its modules on their own: - `pkg/__init__.py` fails to import (`import no_such_module_anywhere`), with two passing modules `pkg/test_one.py` and `pkg/test_two.py`: `-j 1` reports one import error (1 test). `-j 2` reports it three times, for `pkg.__init__`, `pkg.test_one` and `pkg.test_two` (`3 files, 3 tests, 3 files failed`). - `pkg/__init__.py` raises `unittest.SkipTest('skip-pkg')`, with a failing `pkg/test_child.py`: `-j 1` exits 0 with `OK (skipped=1)`. `-j 2` exits 1: both jobs stop with an uncaught `unittest.case.SkipTest` (`2 files, 0 tests, 2 files failed`). Running a package that discover does not enter as `python -m unittest discover -s <suite>/pkg -t <suite> -p <pattern>`, as csmith105 suggests, gives the serial result in both cases. I checked that with synthetic `-j 1`/`-j 2` suites comparing exit code, test count and the `-v` test ids. CPU-only synthetic fixtures, no game files. AI-assisted (Claude Code).
Author
Owner

@⁠Dezmonius on GitHub · 2026-11-24 06:51 UTC · original

Windows recheck at b45d7c2 with CPython 3.14.7 after the rebase onto the timeout change: all 17 runner tests pass, and both original fixtures still reproduce the serial/parallel discrepancies with --timeout 5.

One interaction to account for if adopting the package-discovery subprocess proposed above: --timeout on main currently applies per module with -j 2. I made a package with two test modules, each containing a single test that sleeps for 2.5 seconds. The current runner passes both under -j 2 --timeout 4. A single python -m unittest discover -s <suite>/pkg -t <suite> -p test*.py subprocess times out at 4 seconds and passes both in 5 seconds when given a longer budget. Applying the same limit to a package discovery job therefore changes the meaning of that flag for packages. If the package-job approach is used, please make that scope explicit in the help and cover it with a regression test.

Synthetic tests only. AI-assisted (Codex).

**@⁠Dezmonius** on GitHub · 2026-11-24 06:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/474#issuecomment-7124364140) Windows recheck at `b45d7c2` with CPython 3.14.7 after the rebase onto the timeout change: all 17 runner tests pass, and both original fixtures still reproduce the serial/parallel discrepancies with `--timeout 5`. One interaction to account for if adopting the package-discovery subprocess proposed above: `--timeout` on main currently applies per module with `-j 2`. I made a package with two test modules, each containing a single test that sleeps for 2.5 seconds. The current runner passes both under `-j 2 --timeout 4`. A single `python -m unittest discover -s <suite>/pkg -t <suite> -p test*.py` subprocess times out at 4 seconds and passes both in 5 seconds when given a longer budget. Applying the same limit to a package discovery job therefore changes the meaning of that flag for packages. If the package-job approach is used, please make that scope explicit in the help and cover it with a regression test. Synthetic tests only. AI-assisted (Codex).
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 06:58 UTC · original

Merging. Why merged: parallel semantic runs now include package init modules, the same as discover.
Why it's good: security-reviewed; tested on Windows 11 merged onto main c023a36: runner tests 15 -> 17 OK (7 failures on main without the fix); the real suite still selects the same 465 files and 6105 tests.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 06:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/474#issuecomment-7124485637) Merging. Why merged: parallel semantic runs now include package __init__ modules, the same as discover. Why it's good: security-reviewed; tested on Windows 11 merged onto main c023a36: runner tests 15 -> 17 OK (7 failures on main without the fix); the real suite still selects the same 465 files and 6105 tests. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.