Skip to content

fix(tools): pin the TUI log newline and set stdout errors on world_drawable_verify - #7182

Closed
vA7md wants to merge 1 commit into
ProjectLeonida:mainfrom
vA7md:fix/tui-log-newline-and-verify-stdout
Closed

vA7md wants to merge 1 commit into
ProjectLeonida:mainfrom
vA7md:fix/tui-log-newline-and-verify-stdout

Conversation

@vA7md

@vA7md vA7md commented Nov 23, 2026

Copy link
Copy Markdown

Two files on main break the two repository-wide rules in CONTRIBUTING.md and AGENTS.md, so tests/test_text_write_line_endings.py and tests/test_tool_stdout_encoding.py both fail before and after any change.

What

tools/leonida_tui.py:753 opens its stage log in text append mode without pinning the line ending:

self._file = open(log_path, "a", encoding="utf-8", errors="replace")

Under open()'s default translation, every \n the console writes becomes \r\n on Windows, so the same session log differs between platforms. CONTRIBUTING.md requires a text file a tool writes to name its ending, and the sibling writers do; this one now passes newline="\n".

tools/world_drawable_verify.py starts with if __name__ == "__main__": main(), with no stdout reconfiguration. Every other CLI tool sets errors="replace" first, because a redirected stdout under python -I is the strict ANSI code page and a path or name outside it ends the run with UnicodeEncodeError (#1406 fixed make_game.py the same way). It now uses the same block the rest of the tools use, and returns main()'s value.

Neither change alters program output on a UTF-8-capable console.

Tested

CPU only, no GPU, no game files, Windows 11 / Python 3.14.3.

Before, on main:

python -I tests/test_text_write_line_endings.py
  AssertionError: ['tools\f64_omod_probe.py:268', 'tools\leonida_tui.py:753'] != []
python -I tests/test_tool_stdout_encoding.py
  ['tools/awc_cue_labels.py', 'tools/bvh_slot_check.py', 'tools/import_call_sites.py',
   'tools/op_reach.py', 'tools/world_drawable_lookup.py', 'tools/world_drawable_verify.py'] != []

After, each list no longer contains the file this PR fixes (the remaining entries are other people's files, several with open PRs):

python -I tests/test_text_write_line_endings.py   -> ['tools\f64_omod_probe.py:268'] only
python -I tests/test_tool_stdout_encoding.py      -> world_drawable_verify.py gone

Mutation-checked: reverting these two edits puts both names back in the failing lists, so the tests do cover them.

Their own tests still pass, and compileall is clean:

python -I tests/test_leonida_tui.py                 # Ran 24 tests, OK
python -I tests/test_world_drawable_verify.py       # Ran 2 tests, OK
python -I tests/test_world_drawable_lookup.py       # Ran 1 test, OK
python -m compileall -q tools/leonida_tui.py tools/world_drawable_verify.py   # exit 0

Scope

Two one-line-ish edits in two files nobody else has an open PR for. I deliberately left the other six names in those lists alone: tools/f64_omod_probe.py, tools/awc_cue_labels.py, tools/bvh_slot_check.py (already fixed by #6513, same line), tools/import_call_sites.py, tools/op_reach.py and tools/world_drawable_lookup.py are all under other people's open PRs, and fixing them here would collide.

AI-assisted.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech 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.

Independent review on Windows 11 x64, Python 3.12.

  • Red-first verification on Windows:
    • tools/leonida_tui.py:753 previously opened log in text append mode without newline="\n", causing CRLF on Windows and flagging test_every_text_write_pins_its_newline. Passing newline="\n" fixes this.
    • tools/world_drawable_verify.py now reconfigures sys.stdout with errors="replace" before running main(), matching the repository CLI pattern and preventing UnicodeEncodeError under ANSI code page redirections.
  • python -I -m compileall -q tools/leonida_tui.py tools/world_drawable_verify.py (exit 0)
  • python -I tests/test_leonida_tui.py (24/24 passed)
  • python -I tests/test_world_drawable_verify.py (2/2 passed)
  • python -I tests/test_world_drawable_lookup.py (1/1 passed)
  • python -I scripts/check_no_game_data.py (exit 0)
  • git diff --check clean (0).

LGTM. AI-assisted; synthetic tests only, no game files or GPU used.

@vA7md

vA7md commented Nov 23, 2026

Copy link
Copy Markdown
Author

Superseded by #7589 (and #7176 for the world_drawable_verify half). Both fix exactly what this PR does:

#7589 sweeps the whole list of violations rather than these two files, which is the right shape for this: the linters enumerate every offender, so one PR clearing all of them beats a queue of two-file fixes. Thanks to @LAKSHYA-cmd-tech for the red-first review — the finding was right and is being carried by the sweep.

Nothing here was wrong, it was just narrower than what landed first.

@vA7md vA7md closed this Nov 23, 2026
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.

2 participants