Skip to content

tests: a semantic test must reach tools/rdna2spirv.py - #2992

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
tupacfan04:test/semantic-translator-use
Nov 22, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
tupacfan04:test/semantic-translator-use

Conversation

@tupacfan04

@tupacfan04 tupacfan04 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new TEST item (claim).

What and why

tests/semantic/ is the translator regression suite, but a file there can reimplement an instruction in Python and never run tools/rdna2spirv.py - so it passes whatever the translator does and cannot catch a regression. CI cannot tell such a file from a real test. 19 open PRs (~24.7k added lines) and three files on main are in that state (details in the coordination-issue finding).

  • New tests/test_semantic_translator_use.py parses each tests/semantic/test_*.py with ast (it does not import them) and requires one of: a direct import rdna2spirv / from rdna2spirv import ...; an import of a helper in tests/semantic that reaches it (support.py, regen_fixtures.py, ...), followed transitively and at any nesting depth; or a subprocess/runpy file whose own string names rdna2spirv.py.
  • An explicit ALLOWLIST with a reason per entry: the two interpreter self-tests, the fixtures drift check, and five files whose subject is hand-written SPIR-V. A second test rejects stale entries and any entry that now does reach the translator, so the list cannot rot silently.
  • A separate DEBT table names the three pre-existing model-only files (test_alu_dot2acc_f16.py, test_ballot_votes.py, test_valu_div_fixup.py = TEST-545). It is documentation, not a merge dependency: fixing or deleting one simply removes it from the debt, so tests/semantic: run v_div_fixup_f32 through the translator instead of a mock oracle (TEST-545) #3011/BUILD-880, TEST-614, TEST-605, TEST-603: report writers, non-ASCII GPU-suite paths, multithread timeouts, real ballot tests #3098 can land without rebasing this guard. On main the guard is therefore green by design - it prevents new model-only files rather than fixing those three.
  • A synthetic-tree test proves the detector rejects a file that imports only its own interpreter.
  • tests/semantic/README.md now states the rule in one paragraph.

Tested

  • python -I tests/test_semantic_translator_use.py: 3 tests, OK over all 241 files and 8 allowlist entries.
  • With the three DEBT entries removed, the guard fails with exactly:
tests\semantic\test_alu_dot2acc_f16.py:25
tests\semantic\test_ballot_votes.py:16
tests\semantic\test_valu_div_fixup.py:24
  • python -m compileall -q tests/test_semantic_translator_use.py.
  • Windows 11 (build 26300), Python 3.13.0. No game files, no GPU, no LLVM.

AI-assisted: prototyped and checked by an AI coding agent (OpenCode).

Checklist

  • 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. (Not a translator rule.)

Depends on: nothing.

tests/semantic is the translator regression suite, but a file there can reimplement the instruction in Python and pass whatever the translator does. Add an ast-based guard: direct import, a helper that reaches the translator, or a subprocess naming rdna2spirv.py. The interpreter self-tests, the hand-written-SPIR-V files and the three pre-existing offenders are listed with a reason, and a second test rejects stale entries.
@TheHoracio

Copy link
Copy Markdown
Contributor

Tested 1b509688 on Windows 11 Pro 26300, Python 3.12, CPU only. python -I tests/test_semantic_translator_use.py: 3 tests OK on the PR's tree.

Two controls with a throwaway tests/semantic/test_zz_selfmodel.py (removed afterwards):

file result
unittest plus a local model() it checks (the #2897 shape) rejected: test_zz_selfmodel.py:1: imports no rdna2spirv and no helper that does
import support, then only assertTrue(support): no translate, no run accepted

So the guard catches the 19-PR pattern, which imports nothing from the repo. The second row shows its limit, though: an import counts as use. A file can import support (or rdna2spirv) to satisfy the guard and still test only its own model.

If you want to close that later, the same ast walk could also require a call: an ast.Call whose function resolves to rdna2spirv.translate, a helper that calls it, or spirv_mini_interp.run_workgroup/run. A docstring line in the test that says "import, not use" would be enough for this PR.

The other part of TEST-603, rewriting the two DEBT: files, is the item I offered to take in #2891 if you're passing on it. AI-assisted review.

@tupacfan04

Copy link
Copy Markdown
Contributor Author

Thanks, that is exactly the control I could not build here.

You are right about the limit: import support satisfies the guard without translating. I have documented it in the module docstring, because closing it properly needs call resolution across helpers (support.translate_lines -> rdna2spirv.translate), and a rule that only looked for a direct rdna2spirv.translate call would reject most of the suite, which goes through support.py deliberately. The pattern this guard is meant to stop is the one that imports nothing from the repository at all, and your first control shows it catches that.

On TEST-603: yes, please take it. I am releasing it in #2891; I only kept it because the coordinator gave the finder first refusal, and your test evidence is stronger than anything I have for those two files. The DEBT: entries in ALLOWLIST name them, so remove those entries in the same PR.

AI-assisted, no game files.

@tupacfan04

Copy link
Copy Markdown
Contributor Author

Following your first control, the guard now also requires the import to be used: _imports() keeps the bound name, and a binding that never appears as a loaded ast.Name no longer counts. So import support with no support.* reference is rejected, which is the cheapest version of the gap you showed. It does not attempt call resolution (support.translate_lines -> rdna2spirv.translate), and the docstring now says so explicitly: the guard proves a file reaches the translator, not that every assertion depends on its output.

Evidence: tests/test_semantic_translator_use.py 3/3 with a new synthetic case (import support alone -> offender); the real suite still flags exactly the same three files, so the stricter rule introduced no false positives. Added as commit 6f9cf18b.

AI-assisted, no game files.

@TheHoracio

Copy link
Copy Markdown
Contributor

Rechecked 6f9cf18b the same way (Windows 11, Python 3.12): tests/test_semantic_translator_use.py OK on the tree.

  • A throwaway file with import support and no use of it is now rejected (imports no rdna2spirv and no helper that does).
  • One that reads support.ROOT is still accepted, as you described: any loaded reference counts, not a call into the translator.

That's a fair line for a guard. Thanks for taking it up. AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor Author

Cross-PR interaction found while checking #3011 and #3098: the guard's "every allowlist entry is still needed" test would fail the moment either lands (missing test_alu_dot2acc_f16.py, or test_valu_div_fixup.py starting to reach the translator), forcing a rebase of this PR before they can merge together.

Fixed by separating the two ideas (93023889):

  • ALLOWLIST now holds only the files that legitimately do not translate (interpreter self-tests, fixture drift check, hand-written SPIR-V). Those never disappear, so the rot check stays strict.
  • DEBT holds the three model-only files. An entry is skipped when the file exists; if the file is later fixed or deleted, it simply stops matching and the guard passes. The debt list is documentation, not a merge dependency.
  • offenders() takes both, and the synthetic-tree test passes an empty debt.

Verified: 3/3 at the head; offenders() is empty on the current tree; with the debt names removed from the check it still reports exactly those three files, so nothing was silently loosened.

AI-assisted, no game files.

@tupacfan04

Copy link
Copy Markdown
Contributor Author

CI check-loop cross-check on the merge with current main (16282101), Windows 11 / Python 3.13.0, RPF9DUMP_DLL unset:

tree files ran skipped non-zero
main 254 225 29 1
this PR 255 226 29 1

The only non-zero is the pre-existing tests/test_report_paths.py macOS-volume failure on Windows, which fails on clean main too. No test file present on main is lost by the merge, and the added file runs and passes in the loop.
tests/test_semantic_translator_use.py runs in 5.0 s; it lives outside tests/semantic, so the loop picks it up.
AI-assisted, no game files.

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.

3 participants