Skip to content

tests: fail on functions defined twice and repeated dict keys (TEST-893) - #4070

Open
skipper-hack wants to merge 1 commit into
ItsNotRexed:mainfrom
skipper-hack:test-893
Open

skipper-hack wants to merge 1 commit into
ItsNotRexed:mainfrom
skipper-hack:test-893

Conversation

@skipper-hack

Copy link
Copy Markdown

TEST-893

A merge that keeps both sides of a hunk leaves a second definition that silently replaces the first; in a test class, the first test method then never runs and nothing reports it.

  • New tests/test_no_duplicate_definitions.py (standard library only): parses every tracked .py file (third_party/ skipped) and fails on a function defined twice directly in one module or class body, or a constant key repeated in one dict literal. Definitions in different if/try branches, property setters/getters/deleters, typing.overload and singledispatch registrations are allowed. A self-check on a synthetic source covers each case.
  • Removes the two leftovers it finds on main: the repeated header block in tests/semantic/test_salu_and_saveexec_b64.py (lines 558-624, identical to 36-102) and the first of two identical FORMATS entries for key 5 in tools/rdna2spirv.py.

Tested on macOS (no GPU needed): the new test passes with the change and, on unmodified main, reports exactly the five duplicates (four functions, one dict key). FORMATS maps the same 41 entries before and after. python -m unittest discover -s tests/semantic -p test_salu_and_saveexec_b64.py passes 54 of 54 before and after.

A merge that keeps both sides of a hunk leaves a second definition that
silently replaces the first; in a test class the first test then never
runs. tests/test_no_duplicate_definitions.py parses every tracked .py file
and reports a function defined twice in one module or class body, or a
constant key repeated in one dict literal.

It finds two leftovers on main, removed here: the repeated header block in
tests/semantic/test_salu_and_saveexec_b64.py (lines 558-624, identical to
36-102) and the first of two identical FORMATS entries for key 5 in
tools/rdna2spirv.py.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Second check on Windows at 04df728. The exact CLI rejected a synthetic duplicate class method and a repeated integer key, and accepted a property setter and distinct integer/string keys. The two changed source files had five findings on the base and zero on this head, and FORMATS retained all 41 key/value mappings.

The checker still misses real collisions between numeric constants with different types. A fixture with {1: 'x', True: 'y', 1.0: 'z'} exited 0 even though Python retained one entry and overwrote the first two values. The type tag in the lint key makes those values look distinct. Using Python dictionary key equality would catch this case while still keeping 1 and '1' distinct.

AI-assisted.

@Atlonsky

Copy link
Copy Markdown

Confirmed the gap Vonsek reported, at 04df7283 on Windows (Python 3.15.2, python -I): with a tracked tools/zz_dup_probe2.py holding

VALUES = {1: "x", True: "y", 1.0: "z"}

plus a duplicated probe(), the run reports only the function (tools/zz_dup_probe2.py:8 module defines probe() again (first at line 4)) and says nothing about the dict, so the three keys Python collapses into one entry pass silently.

Positive side, same run: a plain repeated integer key ({5: "a", 5: "b"}) is caught with both line numbers, and the function check reports the first definition's line — so only the cross-type collision is blind, exactly where the type tag in the lint key hides it.

AI-assisted (Claude). No game files.

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

At 04df7283, the new tests/test_no_duplicate_definitions.py passes on this head (56 passed), but on a clean merge with current main (aa2988cc) it fails:

1 failed, 55 passed
tests/test_skinned_glb.py:405 class SkinnedGlbTest defines test_full_export_without_numpy() again (first at line 357)

The duplicate came into main after this PR's base was cut (git show origin/main:tests/test_skinned_glb.py has both definitions, at lines 357 and 405), so CI on this branch can't catch it, but the job goes red once this merges. The two bodies are identical as ASTs. Removing one (for example the copy at line 405) in this PR, or in a small PR ahead of it, clears the failure; I checked by removing it in memory on the merged tree. The gate itself is right to flag it.

AI-assisted (Devin); Linux, Python 3.12.16, no GPU or game files.

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested 04df728 on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 185/199 passed, 14 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base f847748 on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 7322 run, OK (expected failures=1)
  • tests/test_no_duplicate_definitions.py: 2 run, OK

No game files. AI-assisted.

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of 04df7283. Ran on Windows 11, Python 3.14. On the head itself tests/test_no_duplicate_definitions.py passes (2 tests). On a local merge of this head with current main (aa2988cc) it fails with tests/test_skinned_glb.py:405 class SkinnedGlbTest defines test_full_export_without_numpy() again (first at line 357), which confirms @ray3242's report: the duplicate arrived on main after this branch's base (f847748c), so the branch CI cannot see it and the job goes red on merge. Removing one of the two identical copies in this PR (or a PR before it) fixes it.
Negative control: a tracked file with a duplicated module-level def and {5: 'a', 5: 'b'} makes the test fail with the file, both line numbers and the kind of duplicate.
One small thing: a tracked .py file with a UTF-8 BOM is valid Python, but tests/test_no_duplicate_definitions.py:99 reads it with encoding="utf-8" and ast.parse then raises SyntaxError: invalid non-printable character U+FEFF, so the test errors instead of checking the file. No tracked file has a BOM today; encoding="utf-8-sig" would avoid it.
AI-assisted code read (Claude).

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Follow-up to my earlier comment: the test_skinned_glb.py:405 duplicate already has a fix in flight. TreXito's #3857 (446432ad, open and mergeable) removes that second test_full_export_without_numpy.

Linux, CPython 3.12.16, python -I tests/test_no_duplicate_definitions.py:

So Depends on: #3857 in the description, with this PR landing after it, avoids the red job, and this PR doesn't need to remove the copy itself.

AI-assisted.

@chpeu

chpeu commented Nov 22, 2026

Copy link
Copy Markdown

Tested 04df7283 on Linux (Linux Mint 22 / Ubuntu 24.04 base, Python 3.12.3, llvm-mc 20.1.2, no game files).
main aa2988cc is not in this branch's history, so the comparable numbers below come from a test merge of your
head into current main (git merge --no-ff --no-commit: clean, no conflicts).

On your head: python -I tests/test_no_duplicate_definitions.py → 2 tests OK; python -m compileall -q make_game.py tools tests clean.

Merged on current main: the checker fails, with exactly one hit —

tests/test_skinned_glb.py:405  class SkinnedGlbTest defines test_full_export_without_numpy() again (first at line 357)

so it needs that third leftover removed to be green on today's main (matches what another tester reported on
Windows). One detail that may change how you fix it: I compared the two bodies here — they are identical
(16 lines each), so nothing is being silently lost on main today; the second definition just shadows an exact
copy of the first. Deleting either copy works, and grep -n "def test_full_export_without_numpy" on the file
gives 357 and 405.

Your deletion of the repeated block in tests/semantic/test_salu_and_saveexec_b64.py costs nothing: with your
change merged on main, python -m unittest discover -s tests/semantic gives 7456 tests, 8 failures, 2 errors
in 295 s — the same totals and the same failing names as main alone on this machine (the repeated block shadows
helper classes, it does not add test methods: the file still declares 54). python -m compileall clean in both
states.

Out of scope for you, so my numbers stay readable: main already fails one pytest case here
(test_u16_high_half::test_d16_buffer_store_no_redundant_extract_after_shr16, fixed by #3902) and one semantic case
because this box's Ubuntu spirv-as (SPIRV-Tools 2025.1~rc1) does not know the FMAKHR capability. AI-assisted
testing, output read through by hand.

@tedin7

tedin7 commented Nov 22, 2026

Copy link
Copy Markdown

Tested 04df728 on NVIDIA GeForce RTX 5080, driver 580.65.06, Ubuntu 22.04 (Linux): the PR passes on its own branch, but it fails once merged into current main (aa2988c)

This PR needs no GPU, so only Python tests were run.

  • On the PR branch (base f847748): python -I tests/test_no_duplicate_definitions.py 2 tests OK; pytest tests/test_no_duplicate_definitions.py 2 passed; python -m unittest discover -s tests/semantic -p test_salu_and_saveexec_b64.py 54 OK.
  • On main aa2988c plus only the new test file: it fails with 6 duplicates, not the 5 in the description: the 4 helper functions at tests/semantic/test_salu_and_saveexec_b64.py:587-602, the dict key 5 at tools/rdna2spirv.py:1732, and tests/test_skinned_glb.py:405 (SkinnedGlbTest.test_full_export_without_numpy defined again, first at line 357).
  • I merged the PR into main aa2988c (clean merge, no conflicts) and ran the new test: still FAILS, with the one remaining duplicate tests/test_skinned_glb.py:405. That file on main comes from a merge (skinned_glb: compare uppercase prefix tokens and mask zero-weight joints before mapping #3178) that is not in the PR's base. As it stands, merging this PR makes the new test fail on main. Fix: remove one of the two identical test_full_export_without_numpy methods (or rebase and drop the first), and check which one is meant to run.

Not tested: macOS; the FORMATS 41-entry equality was not re-checked.

No game data was used.

AI-assisted run.

@slopradish slopradish left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CPU verification: checked out pull/4070/head in an isolated worktree.

  • pytest -q tests/test_cfg_structure.py: 4 passed
  • pytest -q tests/test_no_duplicate_definitions.py: 2 passed

The test is correctly written against the repository's own parser (tools/rdna2spirv.py) rather than a private model — it walks the real source and fails on duplicate function definitions and repeated dict keys, which are exactly the mistakes that silently shadow earlier definitions in Python. The translator change it pairs with removes an actual duplicate definition, so the new lint passes on the head rather than merely being added.

This is a useful guard for a codebase being edited by many contributors at once; it catches a class of bug that unit tests of individual instructions won't. No game files or GPU needed.

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.

9 participants