Skip to content

BUILD-1336: awc_names, psin_names: read word lists saved by Windows PowerShell 5.1 (BOM, UTF-16) - #4591

Open
rgvxsthi wants to merge 2 commits into
ItsNotRexed:mainfrom
rgvxsthi:fix/word-list-bom
Open

rgvxsthi wants to merge 2 commits into
ItsNotRexed:mainfrom
rgvxsthi:fix/word-list-bom

Conversation

@rgvxsthi

@rgvxsthi rgvxsthi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #4571 (comment) as BUILD-1336

What and why

awc_names.py --words (read_words) and psin_names.py --names (load_names, text lists) read their lists as plain UTF-8. Lists saved by Windows PowerShell 5.1 lose words silently and the run still exits 0:

  • Out-File -Encoding utf8 writes a UTF-8 BOM, which stayed on the first word ('\ufeffzz_rootau_abcd_01'), so that word never matched.
  • > writes UTF-16LE, which matched nothing.

On a synthetic bank with two dialogue streams: plain list → 2 named, BOM list → 1 named, UTF-16 list → 0 named; all exit 0.

Change

  • Text and JSON lists are read as utf-8-sig (as world_names.py, world_build.py and opus_tags.py already do).
  • A UTF-16 text list raises ValueError, which each tool's main() already reports as one stderr line and exit 2 (the message names Out-File -Encoding utf8, like boot_trace.py's).
  • awc_names sniffs JSON after the BOM and leading whitespace (it read one byte before). A UTF-16 .json in awc_names now gets the UTF-16 message instead of a raw UnicodeDecodeError (still exit 2); in psin_names it is still refused as "not JSON", as test_names_file_that_is_not_json_names_the_file expects.

Tested

  • New tests: tests/test_awc_names.py (BOM text list names as many streams as a plain one, BOM hashdict JSON, UTF-16 LE/BE → rc 2 with the message, no traceback) and tests/test_psin_names.py (BOM text + JSON, UTF-16 refused). They fail on main (awc_names: 3 failures, 1 error; psin_names: 1 failure, 1 error) and pass with the change.
  • python -I tests/test_awc_names.py 28 OK, python -I tests/test_psin_names.py 17 OK, python -I tests/test_text_write_line_endings.py OK, python -m compileall -q tools OK.
  • Windows 11 Pro 10.0.26300, Python 3.14.10. CPU only, synthetic inputs, no game files.

AI-assisted (Claude Code), with an independent agent review of the diff.

🤖 Generated with Claude Code

A UTF-8 BOM (`Out-File -Encoding utf8`) stayed on the first word, so that
word never matched; a UTF-16 list (`>`) matched nothing. Both exited 0.
Text and JSON lists are now read as utf-8-sig, and a UTF-16 text list is
refused with one error line and exit 2.

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

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 17dcc7ff on Windows 11: tests/test_awc_names.py -> 28 tests, OK; tests/test_psin_names.py -> 17 tests, OK; git diff --check clean.

read_words/load_names now drop a UTF-8 BOM (both the text and .json paths use utf-8-sig), and a UTF-16LE/BE word list is refused with the "save as UTF-8" message; the call site already catches ValueError and exits 2, and the new tests cover the BOM-equals-plain result and that rc 2. The 64-byte head read still detects { for JSON. No blocking issue.

@rgvxsthi rgvxsthi changed the title awc_names, psin_names: read word lists saved by Windows PowerShell 5.1 (BOM, UTF-16) BUILD-1336: awc_names, psin_names: read word lists saved by Windows PowerShell 5.1 (BOM, UTF-16) Nov 23, 2026
@tupacfan04

Copy link
Copy Markdown
Contributor

PASS. test_awc_names 28 OK, test_psin_names 17 OK, plus the neighbouring awc_manifest/joaat_agreement/opus_tags; compileall, check_no_game_data, docs tests (20) and git diff --check clean, merge clean. Negative control: main's tools fail (awc 3 failures + 1 error, psin 1 + 1).

One gap: tools/awc_names.py:161-165 and tools/psin_names.py:113-116 only detect BOMs, so a BOM-less UTF-16LE list still matches nothing and exits 0 - the same silent-loss class this PR fixes, just via a different encoding. Worth asserting (and handling) that case too.

Minor, acceptable: awc_names.py:163 rejects before the .json branch, so a UTF-16 JSON gets the word-list message.

Approve. AI-assisted review, no game files, no GPU.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 17dcc7f merged with main d0835dd (already up to date) on Linux (WSL2) Python 3.12.16 and native Windows 11 (Windows PowerShell 5.1.26100.9818) Python 3.13.1: pass.

  • tests/test_awc_names.py 28 tests (1 skipped on Linux) and tests/test_psin_names.py 17 tests: OK on both.
  • Negative control: tools/awc_names.py and tools/psin_names.py from main, same tests: 3 failures + 1 error (awc) and 1 failure + 1 error (psin) on Linux.
  • Checked the claim directly on Windows: I wrote a list with 'alpha','beta' | Out-File -Encoding utf8 and another with 'alpha','beta' > file in Windows PowerShell 5.1. With the PR, read_words and load_names return ['alpha', 'beta'] for the first file and raise a ValueError naming UTF-16 for the second. With main's tools the first gives 'alpha' (the BOM stays in the first word) and the second fails with a charmap error instead of a useful message.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted Windows CPU check at 17dcc7ff and d0835dd9, uv CPython 3.12.13. To complement the PowerShell reader check above, I ran both CLIs with synthetic fixtures and actual Out-File -Encoding utf8 and redirection files from PowerShell 5.1.

The parent lost the first UTF-8 BOM entry, reducing AWC matches from 2 to 1 and PSIN references from 4 to 2 (both hash widths for a name containing é). Head matched the BOM-free controls byte for byte in stdout and reports. This also held for UTF-8 BOM JSON, including AWC JSON sniffing after leading whitespace without a .json suffix. Redirected UTF-16LE text returned exit 2 with one diagnostic and preserved existing reports. For redirected .json, AWC gave UTF-16 conversion guidance and PSIN retained its not JSON message.

Seven focused suites passed 152 tests with 3 symlink skips at head. Synthetic inputs only.

@tupacfan04

Copy link
Copy Markdown
Contributor

One extra point from a second check, on top of the BOM-less UTF-16 gap: tools/awc_names.py:167 now treats a text word list whose first non-blank character is { as JSON (previously only when byte 0 was {). Such a list becomes a JSON error instead of a word list. Tightening the sniff (e.g. require a { that parses as an object, or only accept JSON when the whole file parses) would avoid the behaviour change.

Also, for the record on #4588: tools/pe_inspect.py:480, rtti_scan.py:241 and cpu_ref.py:800 check exists rather than isfile, so a directory still exits 1 there, which is inconsistent with the PR's stated "not the expected file/directory type" rule.

AI-assisted review, no game files, no GPU.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested head 17dcc7ff locally (CPU only, synthetic fixtures, no game files).

Environment: Linux, Python 3.10.12. Commands:

python3 -I tests/test_awc_names.py   # 28 tests OK (1 platform skip)
python3 -I tests/test_psin_names.py  # 17 tests OK

45 tests, 0 failures. The new cases cover UTF-8 BOM and UTF-16 word lists as saved by Windows PowerShell 5.1 for both tools/awc_names.py and tools/psin_names.py. Base-tree control not run for this batch.

AI-assisted verification (Devin), no game files, no GPU.

…iff as it was

Review follow-up on ItsNotRexed#4591. A word or name list with a NUL byte anywhere is
refused as UTF-16 (one error line, exit 2), so UTF-16 without a BOM no longer
names nothing silently, even when its first characters hold no zero byte.
awc_names sniffs hashdict JSON only when the first byte after an optional
UTF-8 BOM is "{", as before the BOM fix. Tests pin both, through the CLI too.

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

Copy link
Copy Markdown
Contributor Author

Thanks all for testing. @tupacfan04, both points addressed in 23bc6b33:

  1. UTF-16 without a BOM: a word or name list with a NUL byte anywhere in the file is now refused as UTF-16 (same one-line error, exit 2) in both tools. It checks the whole file, not just the head, so a BOM-less UTF-16 list whose first characters hold no zero byte (e.g. a long Cyrillic first line) is caught too. The message now says "looks like UTF-16 ... not UTF-8 text", since a UTF-32 or binary file lands there as well.
  2. JSON sniff: awc_names is back to the original rule, JSON only when the first byte is {, now after an optional UTF-8 BOM. A text list starting with { reads as text again, and a JSON file with a leading newline and no .json suffix reads as text, as on main (hashdict.py never writes leading whitespace).

New tests: BOM-less UTF-16 LE/BE through the CLI (rc 2, message, no traceback) and through load_names; a NUL past the first 64 bytes; { list as text; leading-newline JSON pinned as text; BOM + JSON with no suffix.

Tested at 23bc6b33 on Windows 11, Python 3.14.10: test_awc_names 33 OK, test_psin_names 19 OK, plus test_awc_manifest, test_joaat_agreement, test_opus_tags and test_text_write_line_endings OK; compileall and git diff --check clean. Negative control: the new tests fail against 17dcc7ff's tools (awc 4 failures + 1 error, psin 3 failures). Reviewed beforehand by two independent agents (code, and a CLI test matrix over plain/BOM/UTF-16 with and without BOM/PowerShell 5.1 outputs). AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 23bc6b3 merged with main 98fa503 on Linux (Python 3.12.16): pass - tests/test_awc_names.py 35 OK (1 skipped), tests/test_psin_names.py 19 OK; negative control: upstream/main versions of tools/awc_names.py and tools/psin_names.py with the new tests: 7 failures + 1 error and 4 failures + 1 error. I read the diff (BOM dropped via utf-8-sig, UTF-16 BOM or any NUL byte refused with ValueError; awc_names' caller already catches ValueError) and found no issue. Not run on Windows PowerShell 5.1.

@memorypressure

Copy link
Copy Markdown

Merged cleanly with current main: the changed suites and both dictionary regressions pass under python -I (test_awc_names 35 with 1 Windows skip, test_psin_names 19, test_hashdict 33, test_rpf9_names 19), and both tools' --help exits 0. The six test_joaat_agreement failures are the known main-red in the unchanged find_hash_lookup copy, fixed by the pending #4753/#4882 pair — not caused by this PR. One design note: BOM-less UTF-16 detection here is the NUL-presence heuristic, so a NUL-free UTF-16 sequence need not be detected — fine if that ceiling is deliberate. Binary fixtures are generated. No CI checks reported. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted independent review. At 23bc6b3 the reader integrated into #5570 fcebf64 preserved the expected synthetic named stream for UTF-8 and UTF-8 BOM text and JSON. It rejected all three UTF-16 text controls with exit 2. Standalone #5570 silently yielded zero named rows for BOM text and the UTF-16 controls. Separately all 2,098 masked stream IDs across 98 cached banks matched their manifest. None matched a bank stem, and a cached dialogue wave-name list was unavailable. The positive name evidence is synthetic.

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.

8 participants