xml_files walked a directory of XML documents with os.walk and no onerror, so
an unlistable sub-folder was silently skipped: the scan printed its summary and
exited 0 with fewer documents, and the report-collision check could not see
those files either. Raise the listing error; main already prints one
`ERROR: cannot read ...` line and exits 2 for an OSError.
The new test on main's tool fails (os.walk receives no onerror); with the fix,
tests/test_gamedata_xml.py runs 12 tests, OK. CPU only, synthetic XML, no game
files.
AI-assisted.
An existing regular report with one link and a non-input basename cannot alias a scanned XML, index.json or carve stream. Skip the per-file same_report_path loop for it; missing paths, links, input-like names, explicit file targets and symlinked inputs are still compared.
Since 93211578 comments are counted from iterparse "comment" events, which is right for a well-formed
document (comment-like text in CDATA is not a comment). But a truncated or tail-only document stops the
parser at the error, and the comments after it were never counted. When parsing fails, the comment starts
are now counted in the bytes, skipping CDATA sections (an unclosed one runs to the end).
Real data (counts only), the common.rpf carve: --check reports 507 comment starts (412 in 257
declaration-bearing documents), as docs/gamedata.md:471 says; main reported 412 (412). The 95 missing
ones were in 2 truncated tail-only documents.
Tests: test_comments_in_a_document_that_does_not_parse_are_counted (unclosed root, tail-only document,
CDATA closed and cut off; main: the tail-only case gives 0).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
same_report_path was copied into ten tools, and each new "refuse an output that overwrites an input" change added
another copy or a variant. Four copies (anim_index, gamedata_index, gamedata_xml, navmesh_decode) also folded case and
accents on a case-insensitive macOS volume (through _path_key), the other six did not, so the same report pair was
refused by one tool and written by another.
tools/report_paths.py holds one version (the stricter one: realpath, normcase, case-folded NFD on a case-insensitive
volume, then os.path.samefile) and awc_manifest, gamedata_index, gamedata_xml, navmesh_index, rpf_probe, tile_probe
and world_names import it. The tools keep exposing the name same_report_path. On Windows and Linux nothing changes;
on macOS the five tools that lacked the case/accent step now refuse a case-only alias of a report that doesn't exist
yet, as the other five already did.
anim_index, navmesh_decode and world_lights_paths keep their copy for now because open pull requests edit them
(#2051, #2050, #2052, #2107); tests/test_report_paths.py fails if any other tool adds a copy.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAjLH2L6R72dBvVaRG8hka
open(path, "w") without newline= turns each \n into \r\n on Windows, so the same JSON report, manifest or assembly
listing was CRLF there and LF elsewhere. 91 text-mode writes (open, os.fdopen, Path.write_text) under tools/, scripts/,
make_game.py and runtime/test/shaders/ now pass newline="\n". tests/test_text_write_line_endings.py reads the source
with ast and fails for a writer that forgets it; CONTRIBUTING.md names the convention.
AI-assisted (Claude), on behalf of dev-ewann.
csv.writer and csv.DictWriter default to lineterminator="\r\n", and every
one of these tools opens its report with newline="", which turns that into
CRLF on Windows and LF elsewhere: the same archive gave different report
bytes depending on the machine that exported it. awc_manifest and awc_shorts
already pin "\n" and bink_index documents why its stdout writer needs it, so
this brings the remaining 16 writers onto the same convention. A structural
test keeps new writers on it, and three tools are run end to end to check the
bytes.
Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
bvh_index, anim_index, gamedata_xml, gamedata_index and navmesh_decode compare
two report paths with os.path.normcase, which folds case only on Windows. On
macOS's case-insensitive APFS volume `--out o/B.json --csv o/b.json` passed and
the CSV replaced the JSON. The comparison now folds case and Unicode
normalization when the volume that will hold the path is case-insensitive
(pathconf _PC_CASE_SENSITIVE); case-sensitive volumes keep two reports.
Same fix as world_index in #1576.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").
tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--csv and --json are opened after the scan, so a missing folder lost the
result to a FileNotFoundError, a path that resolved to a carve index (or
to an XML target) replaced the input, and an existing directory ended in
a PermissionError traceback. Port navmesh_decode.py's pattern: create the
report parent, reject a directory report path, and reject report paths
that same_report_path() matches against every target (or
<dir>/index.json); also refuse identical --csv/--json paths.
New tests/test_gamedata_xml_report_paths.py covers all of it; main's
tool fails seven of the eight cases as the negative control.
scan_xml() read each element's tail at its "end" event and then cleared the
element, but iterparse can deliver the end event before the parser has read
the tail, so a $(...) reference after a close tag at a 16 KiB boundary was
lost. The tail is now read at the next event (or after the loop), before the
element is cleared.
An encoding declaration Python doesn't know raised LookupError out of
scan_xml() and ended --check in a traceback. It is now recorded as the
document's error, so the file counts as malformed like any other parse error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>