Skip to content

leonida_tui, wave_diff: pin LF on the two writers no scan reaches; test them - #7819

Open
Friendships6666 wants to merge 1 commit into
ItsNotRexed:mainfrom
Friendships6666:pin-lf-on-the-two-unscanned-writers
Open

Friendships6666 wants to merge 1 commit into
ItsNotRexed:mainfrom
Friendships6666:pin-lf-on-the-two-unscanned-writers

Conversation

@Friendships6666

Copy link
Copy Markdown

test_text_write_line_endings names two writers, and neither is reachable by its ast scan: a hand-written writer that builds its lines in a loop has no single write() to inspect, so a missing newline="\n" is invisible to the scan. It was StageConsole's stage log (tools/leonida_tui.py:753) and wave_diff's .asm case plus store prologue (tools/wave_diff.py:373). BUILD-468 makes every other text writer pin LF; on Windows these two wrote CRLF.

That also means the scan cannot fail on them on Linux — it reports them because newline= is absent at the call, not because a run wrote CRLF. So the same branch adds tests/test_text_write_bytes.py, which replaces the builtin open with Windows' text-mode rules (newline=None means \r\n) and compares raw bytes. It runs on any platform: on main it fails on both writers, with this it passes.

Overlap

#7050 touches the leonida_tui.py line and carries its own test, #7188 touches the wave_diff.py line. Either of them plus this branch's test file closes the rule; land them and keep the test, or drop whichever line you prefer. They do not conflict textually with this branch or with each other.

Test

python -I tests/test_text_write_line_endings.py and python -I tests/test_text_write_bytes.py are both green. python -m compileall -q make_game.py tools tests is clean. Measured over the suite: 14 red standalone files before, 11 after, nothing green turned red.

Linux, Python 3.14.8, no GPU, no game files (the test is in-memory).

@Friendships6666

Copy link
Copy Markdown
Author

Rebased so this branch is independent of #7816: the diff is now only tools/leonida_tui.py, tools/wave_diff.py and the new test (3 files), not the eleven stdout guards on top. All three PRs share no file, so they merge in any order and can be reviewed apart.

@azterixx

Copy link
Copy Markdown

checked: #7819 | with: python -I -m unittest discover -s tests -p test_text_write_bytes.py | on: macOS 27.2.1, Apple M1 Pro, CPython 3.15.2, head 03792c3, CPU only | result: FAIL (2 tests, 1 error: test_a_stage_log_line_keeps_lf, OSError: [Errno 30] Read-only file system: '/logs', raised by os.makedirs in leonida_tui.StageConsole.init at tools/leonida_tui.py:752; the test passes os.path.join("/logs", ...) and the macOS root is read-only; test_a_wave_diff_case_keeps_lf passes; main@dde82f27e has no such test file)

@Friendships6666

Copy link
Copy Markdown
Author

alexwlsnr on #7920 (same branch, opened 14 minutes later by accident - sorry, #7920 is being reduced to the viewer part only) found that test_a_stage_log_line_keeps_lf hard-codes /logs/shaders.log, so it fails with PermissionError for an unprivileged runner. Fixed in 0d6caf1: RawBytes.setUp makes a TemporaryDirectory and both cases write under it, cleaned up by the suite. Re-checked as an unprivileged user (sudo -u): both tests pass, and with the two newline= arguments taken back out both still fail, so the test still bites off root. test_text_write_line_endings and node --test tests/test_*.cjs (66) stay green.

…st them

BUILD-468 pinned newline="\n" on the text writers so the same input gives the same bytes on every platform.
Two hand-written writers were missed because they build their lines in a loop instead of one write, and an
`ast` scan of the call cannot see that: StageConsole's log file (tools/leonida_tui.py) and wave_diff's `.asm`
case plus store prologue (tools/wave_diff.py). On Windows both wrote CRLF.

test_text_write_bytes.py reaches them by replacing the builtin `open` with Windows' text-mode rules, so the
test fails on Linux too when the keyword is missing. It fails on both writers before this commit.

test_text_write_line_endings is green after this.

ItsNotRexed#7050 (leonida_tui) and ItsNotRexed#7188 (wave_diff) are open on the same two lines; take either.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Cryptoteep

Copy link
Copy Markdown

Independent review on Windows 11 x64, CPython 3.14.0 (PASS).

Tested head f95bf8c49 against main (dde82f27e):

  • python -I tests/test_text_write_bytes.py: 2/2 tests pass in 0.010s.
  • python -I tests/test_text_write_line_endings.py: 3/3 tests pass (fails on main at tools/leonida_tui.py:753 and tools/wave_diff.py:373).

Confirmed the temporary directory setup in RawBytes.setUp avoids hardcoded root paths and ensures both writers are guarded. LGTM.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested f95bf8c4 on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main dde82f27: pass

  • python -I tests/test_text_write_line_endings.py: 3 tests OK (red on main: 1 failure).
  • python -I tests/test_text_write_bytes.py (new): 2 tests OK.
  • With only the two tools reverted to main: test_text_write_bytes.py 2 failures and test_text_write_line_endings.py 1 failure, so the new test exercises the change.
  • compileall (where the change has Python files) and scripts/check_no_game_data.py on the changed files: clean.

#7857 also turns test_text_write_line_endings.py green on its own with the same two one-line changes and no new test; the two edit the same lines, so only one can land as is.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

@Friendships6666

Copy link
Copy Markdown
Author

Thanks, azterixx, for catching the hard-coded path, and thanks, Cryptoteep and ne1i, for the follow-up checks. The fixture now uses a temporary directory. I confirmed the two production changes overlap #7857; the raw-byte regression tests are the additional part here. If the earlier fixes are preferred, those tests can be taken separately rather than merging both copies of the tool changes.

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.

4 participants