Skip to content

tools: text reports are written with LF line ends on every platform (BUILD-468) - #1615

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
dev-ewann:build468
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
dev-ewann:build468

Conversation

@dev-ewann

@dev-ewann dev-ewann commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BUILD-468 (claim in #1548). This is the follow-up from @undeadhuman37's review.

State: the first version of this PR (ec9b6cf2) is already on main, merged as 00452cf. 4eb6155 then added newline="\n" to anim_rigs, d16_format_probe and pe_shader_containers. GitHub still shows this PR as open because I had pushed a second commit in the meantime. The branch is now rebuilt on main 4eb6155 and holds only that second commit.

What and why

@undeadhuman37 found three text-mode writes the first version missed. They are atomic report writes through tempfile.NamedTemporaryFile(mode="w", ...), which still get CRLF on Windows:

  • tools/rbf0_tree.py:660
  • tools/rtti_scan.py:202
  • tools/world_build.py:1186

The test on main didn't see them because it reads the mode only at position 1. NamedTemporaryFile(mode) and Path.open(mode) take it at position 0. This PR does three things:

  • The three writes: each now passes newline="\n".
  • The test: tests/test_text_write_line_endings.py now reads the mode where each call takes it:
    • open, io/gzip/bz2/lzma.open and os.fdopen: position 1;
    • Path.open and tempfile.NamedTemporaryFile/TemporaryFile/SpooledTemporaryFile: position 0. The temp-file classes are binary unless their mode says otherwise.
  • What the test leaves alone: it accepts only real mode strings, so a member name like zf.open("words.txt") is not taken for a mode. It skips codecs.open (no newline translation, no newline=), os.open (flags), and the tarfile, zipfile and webbrowser opens.
  • Self-test: the detector's self-test gains every new form and the negative cases.
  • Docs: the CONTRIBUTING.md bullet names Path.open, Path.write_text and NamedTemporaryFile too.

Tested

AI-assisted (Claude), on behalf of dev-ewann. On main 4eb6155. CPU only, Linux (WSL2 Ubuntu, Python 3.14.4, pytest 9.0.2, llvm-mc 18.1, spirv-tools). No game files, no GPU. The Windows CRLF itself is not reproduced; the test is structural.

  • python3 -I -B tests/test_text_write_line_endings.py: OK. It names exactly the three files above on main without the tool changes.
  • Mutations, one at a time, each fails the test:
    • removing newline= from each of the three sites;
    • dropping the tempfile forms, Path.open's mode position, the io/gzip mode position, the not-a-text-file list, the mode-string check or the os.fdopen position;
    • ignoring newline=.
  • test_rbf0_tree.py, test_rtti_scan.py, test_world_build.py: OK.
  • Every tests/test_*.py without import pytest, run as a script: 197 pass. test_cf_ref.py (the exec_hi cases) and test_docs_design_rows.py (duplicate rows in docs/design.md, docs/README.md, docs/testing.md) fail, and fail the same way on an untouched main 4eb6155; this PR touches no docs page.
  • python3 -m pytest tests --ignore=tests/semantic -q: 4330 passed, 132 skipped, 5 failed. The 5 are those same two files.
  • python -m compileall -q make_game.py tools tests scripts runtime/test/shaders: OK.

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 applicable: no translator rule changes.)

🤖 Generated with Claude Code

@Impre-visible

Copy link
Copy Markdown

Tested 844c617 on Arch Linux (Python 3.14.10, pytest 9.2.0, llvm-mc 23.1.5, SPIRV-Tools v2026.4) and on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (Vulkan 1.4.357): pass. This includes the pytest run the description lists as not run.

  • python -m pytest tests (whole tree, tests/semantic included): 5233 passed, 48 skipped, 0 failed
  • tests/test_text_write_line_endings.py: 2 passed
  • python -m unittest discover -s tests/semantic: 1338 OK; compileall OK
  • Native build of runtime/ from this head; build.py: 157 translated, 157 pass spirv-val; check.py: 104 of 137 pass, 33 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 150/150 translated and pass spirv-val; 115/145 passed, 30 skipped (wave64), 0 failed; with LEONIDA_W64_EMULATE=1: 145/145 passed

So the newline="\n" writers in build.py and run_gpu_tests.py still produce files the tools accept on Linux, on a 32-wide GPU. Not covered: Windows, where the CRLF difference would show.

AI-assisted run (Claude). Counts only, no game files involved.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 844c617 merged into main 41f44826 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 145/145 native, 145/145 with LEONIDA_W64_EMULATE=1 (main alone: 145).
  • tests/test_text_write_line_endings.py: 2 passed.

No game files. AI-assisted (Claude Code).

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested ec9b6cf on macOS (Apple Silicon, APFS, Python 3.12.10, pytest 9.2.0, Node 25.6.1, CPU only): pass, with one gap.

  • python -m compileall -q make_game.py tools tests, python -I make_game.py --help, python -m unittest discover -s tests/semantic (OK), node --test tests/test_viewer_streaming.cjs (35/35), python -m pytest tests: everything passes except tests/test_world_names.py, which fails the same way on upstream/main, so it isn't from this PR.

  • Gap: an AST scan of tools/ for text-mode writes without newline= (open, io.open, Path.open, os.fdopen, tempfile.NamedTemporaryFile, Path.write_text) still finds three. They are atomic report writes that are renamed onto the report afterwards, so those reports still get CRLF on Windows:

    • tools/rbf0_tree.py:660 tempfile.NamedTemporaryFile(mode="w", ...)
    • tools/rtti_scan.py:202 tempfile.NamedTemporaryFile("w", ...)
    • tools/world_build.py:1186 tempfile.NamedTemporaryFile(mode="w", ...)

    NamedTemporaryFile takes newline= like open. If it helps, I have a stdlib AST test that fails on any new text-mode write without newline= and checks all six call forms. I wrote it for the same item before I saw this PR, and you're welcome to fold it in: https://github.com/undeadhuman37/Leonida/blob/json-report-lf/tests/test_text_write_newlines.py

I claimed BUILD-468 in #1548 earlier, but this PR got there first, so I'm releasing my claim and won't open a second PR.

AI-assisted (Claude Code), tested on a Mac.

dev-ewann added a commit to dev-ewann/Leonida that referenced this pull request Nov 22, 2026
The first version's detector read the mode only at position 1, so
Path.open(mode) and tempfile.NamedTemporaryFile(mode) were not seen.
Three atomic report writes (rbf0_tree, rtti_scan, world_build) still
got CRLF on Windows, and tools/anim_rigs.py, new on main, had a plain
open(..., "w") without newline=. All four now pass newline="\n".

The test now reads the mode where each call takes it: open, io/gzip/
bz2/lzma.open and os.fdopen at position 1, Path.open and the tempfile
classes at position 0 (binary by default). It accepts only real mode
strings, and skips codecs, os, tarfile, zipfile and webbrowser opens.
Found by @undeadhuman37 in their review of ItsNotRexed#1615.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dev-ewann

Copy link
Copy Markdown
Contributor Author

@undeadhuman37 thanks, you're right. Fixed in e52bbdb, rebased on main 6a6704d:

  • rbf0_tree.py, rtti_scan.py and world_build.py: their NamedTemporaryFile(mode="w", ...) now pass newline="\n".
  • The detector missed them because it read the mode only at position 1. Each form now has its own position: open, io/gzip/bz2/lzma.open and os.fdopen at 1, Path.open and the tempfile classes at 0, the latter binary by default. Only real mode strings count, so zf.open("words.txt") isn't a mode. codecs, os, tarfile, zipfile and webbrowser opens are skipped.
  • The rebase showed one more site: tools/anim_rigs.py:156, new on main since my first version, a plain open(a.out, "w", ...). So the old head, merged into today's main, would have failed its own test. Fixed too.

Your six call forms are all in the self-test now, with the negative cases. I extended the existing test rather than adding a second file, so there's one place to look. 11 mutations (each of the four sites, and each detector rule) all fail the test. CPU only, no GPU, WSL2 Ubuntu, Python 3.14.4. The full runs are in the description.

AI-assisted (Claude), on behalf of dev-ewann.

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…four tools follow the repo rules

- int_hw_probe: VOP3 clamp on the carry-out add/sub ops (#1831) and v_cvt_rpi/flr's exact floor(x+0.5) and NaN
  sign saturation (#1856) now translate as gfx1035 measured, so KNOWN_DIVERGENCES is empty. The known-divergence
  test reports a synthetic entry. shader_validation.md says so, and design.md loses the stale duplicate
  v_cvt_flr/rpi row a "both" merge left that still called them open.
- docs/README.md: one Other languages line (fr, pt-BR, zh-CN, pl-PL, tr, ru, ja); docs/i18n/README.md: one row
  each for pt-BR and zh-CN (the newer).
- anim_rigs, d16_format_probe, pe_shader_containers: text writes name newline="\n" (#1615);
  pe_shader_containers guards stdout (#1428).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#1615's detector read the mode only at position 1, so Path.open(mode)
and tempfile.NamedTemporaryFile(mode) were not seen: three atomic report
writes (rbf0_tree, rtti_scan, world_build) still get CRLF on Windows.
They now pass newline="\n".

The test now reads the mode where each call takes it: open, io/gzip/
bz2/lzma.open and os.fdopen at position 1, Path.open and the tempfile
classes at position 0 (binary by default). It accepts only real mode
strings, and skips codecs, os, tarfile, zipfile and webbrowser opens.
Found by @undeadhuman37 in their review of ItsNotRexed#1615.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dev-ewann

Copy link
Copy Markdown
Contributor Author

@ItsNotRexed, a note on this PR's state. Its first version (ec9b6cf2) is already on main, merged as 00452cf. Your 4eb6155 also covered anim_rigs, d16_format_probe and pe_shader_containers. GitHub still shows the PR as open because I had pushed a second commit before the merge.

I've rebuilt the branch on main 4eb6155, and it now holds only that follow-up (ef6139dd, 5 files). It adds newline="\n" to the three tempfile.NamedTemporaryFile writes @undeadhuman37 found (rbf0_tree, rtti_scan, world_build), and the test now reads the mode where Path.open and the temp-file classes take it. Tests and mutations are in the description. If you'd rather have it as a separate PR, say so and I'll move it.

AI-assisted (Claude), on behalf of dev-ewann. CPU only, no GPU.

@ItsNotRexed
ItsNotRexed merged commit 82cfa38 into ItsNotRexed:main Nov 22, 2026
4 checks passed
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.

5 participants