Repository navigation
first_light, sandbox, shader_library: read a carve index.json saved with a UTF-8 BOM - #6450
etcetera-yt wants to merge 2 commits into
Conversation
…ith a UTF-8 BOM Three tools still opened their shader index.json as strict utf-8, so a copy saved by Windows PowerShell 5.1 or a Windows editor (which add a BOM) failed (found by @GiacomoSignorile): - first_light.py choose() and the translated spirv/index.json: "Unexpected UTF-8 BOM"; - sandbox.py pick_pair(): the ValueError is caught, so it silently picks no pair; - shader_library.py carve_digests() (--carve): "Unexpected UTF-8 BOM". They now read utf-8-sig, as ItsNotRexed#6267/ItsNotRexed#6269/ItsNotRexed#6271/ItsNotRexed#6277 do for the other readers. A BOM test per tool; each fails on the old reader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GZEZyXGTTXs4V33hrBw1tD
|
Code read + CPU tests, bb723cb: pass ( Four tools sharing one |
thiefyzheng
left a comment
There was a problem hiding this comment.
Code read + local run (AI-assisted review, per AGENTS.md). This is the fix for the item's own list (BUILD-2182), so I checked it against all three named sites and swept for stragglers.
Verified at this head, applied to 561b65a8:
python -I tests/test_first_light.py-> OK (skipped=4, the pre-existing skips)python -I tests/test_sandbox_pick.py-> OKpython -I tests/test_shader_library.py-> OK- The premise holds:
json.load(open(path, encoding="utf-8"))on a BOM'd file raisesJSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig), and the same file loads withutf-8-sig. So this is a real failure with a real fix, not a style change. - All three sites the item names are converted (
tools/first_light.py:195,tools/sandbox.py:53,tools/shader_library.py:196), each with a BOM case in its test — including theutf-8-sig if bom else "utf-8"switch intest_sandbox_pick.py, which is the right shape: it proves the reader tolerates a BOM without pretending the writer emits one.
Completeness sweep, in case the item's list was partial (every index.json reader in tools/ on main):
still opens plain utf-8 |
status |
|---|---|
tools/gamedata_index.py:183, :214 |
open PR #6220 |
tools/gamedata_maps.py:322 |
open PR #6388 |
tools/ps_sweep.py:35 |
open PR #6440 |
tools/restofworld_index.py:375 |
open PR #6042 |
So the item closes with this PR and nothing is left over; the other encoding="utf-8" hits around index.json are writers (first_light.py:173, :1019, fspx_unpack.py:258, shader_library.py:358), which should stay utf-8 — emitting a BOM is exactly what breaks the next tool in the chain.
One nit, not blocking: only first_light.py:145 carries the explanatory comment (# -sig: a copy re-saved by a Windows editor has a BOM); the other two hunks are bare. Repeating it once at sandbox.py:53 would tell the next reader why -sig is there in a repo where plain utf-8 is the norm elsewhere.
GiacomoSignorile
left a comment
There was a problem hiding this comment.
Review (CPU only, no game files): the change is one word per reader (utf-8 to utf-8-sig) in first_light.py, sandbox.py and shader_library.py, plus a test for each. I checked it at bb723cbf:
python -I tests/test_first_light.py: 47 tests, OK (4 skipped)python -I tests/test_sandbox_pick.py: 7 tests, OKpython -I tests/test_shader_library.py: 10 tests, OK- Negative control: with the three tool files set back to
mainand the new tests kept, all three test files fail (sandboxa failure,shader_libraryandfirst_lighterrors), so the tests cover the fix.
sandbox.py is the important one: before this, the BOM's ValueError was swallowed by the except and the tool reported "no pair" without saying why.
Overlap noted by the author with #4987 (sandbox.pick_pair) still applies; either order should merge with a one-line rebase.
Approve, from the CPU side.
|
Thanks @GiacomoSignorile for the approval and the negative control, @thiefyzheng for the sweep (good to know the rest are writers or in open PRs), and @dcastell1 for the run. On the comment nit: |
|
Comparison for BUILD-2182, as the coordinator asked (#6603):
As far as I can see, #6467 leaves the |
LuvAbyss
left a comment
There was a problem hiding this comment.
Tested bb723cbf on Windows 11, Python 3.12.10: the three test files pass, and with the tools from main all three fail.
One reader of the same carve index is still strict: first_light.py --list reads shaders/dxbc/index.json through load_json (tools/first_light.py:869, encoding="utf-8"), not choose(). With an index.json written by Windows PowerShell 5.1 Out-File -Encoding utf8 (starts EF BB BF), load_json(p, "carve index", list, ...) exits with "not valid JSON (Unexpected UTF-8 BOM (decode using utf-8-sig) at line 1 column 1)". So a normal run reads the file and --list refuses it. The same helper reads manifest.json for --check.
Suggest utf-8-sig there too, in this PR since it is the same file and the same change. Otherwise LGTM. AI-assisted.
…iew) From @LuvAbyss's review of ItsNotRexed#6450: load_json(), which --list uses for the carve's shaders/dxbc/index.json and --check for manifest.json, still opened them as strict utf-8, so --list refused an index a normal run accepts. test_first_light_bad_json.py gets a --list case with a BOM index; it fails without this change with 'not valid JSON (Unexpected UTF-8 BOM ...)'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GZEZyXGTTXs4V33hrBw1tD
|
Thanks @LuvAbyss, good catch. Second commit
Re-run on Windows 10, Python 3.14.7: |
|
Tested d919801 merged with main cd51a43 on Linux/Python 3.12.16: pass Merge was clean (tools/first_light.py, tools/sandbox.py, tools/shader_library.py and their tests).
Diff read: the five Overlap: #6521 (open) makes the same one-line change to |
|
Thanks @kapitche for the merged run and the negative control. AI-assisted (Claude Code). |
|
Tested
#6467 makes the same one-line change in three of these places; this PR also covers 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. |
Claimed in the coordination issue as: new BUILD item (claim), from @GiacomoSignorile's finding.
Depends on: none. #4987 (@kacper-serewis) changes
sandbox.pick_pairjust below the line this touches; either order should merge, or need a one-line rebase.What and why
Three tools still open a shader
index.jsonas strictutf-8, so a copy saved by Windows PowerShell 5.1 (Set-Content/Out-File -Encoding utf8) or by Notepad's default "UTF-8", both of which write a BOM, is refused:tools/first_light.pychoose()(shaders/dxbc/index.json) and the translatedspirv/index.jsonJSONDecodeError: Unexpected UTF-8 BOMtracebacktools/sandbox.pypick_pair()(spirv/index.json)ValueErroris caught, so it silently reports no pairtools/shader_library.pycarve_digests()(--carve <folder>/index.json)JSONDecodeError: Unexpected UTF-8 BOMtracebackEach now reads with
utf-8-sig, the same one-word change as #6267, #6269, #6271 and #6277 for the other readers.first_light.py:148(the dxbc indexchoose()reads) is in the same file and the same class, so it's included. Plain UTF-8 files read exactly as before.Tested
Windows 10 19045, Python 3.14.7, no GPU (these are CPU-only paths), branch on
mainf6c6d11e.New tests, one per tool, each writing its
index.jsonwithencoding="utf-8-sig":tests/test_sandbox_pick.pytest_an_index_saved_with_a_bom_is_read(the pair is still picked);tests/test_shader_library.pytest_carve_index_saved_with_a_bom_is_read(carve_digestsmaps the digest);tests/test_first_light.pytest_indexes_saved_with_a_bom_are_read. This runs the existing two-stagemain()case through a shared helper with both indexes BOM-encoded, so it covers bothfirst_lightreads.Negative control, the three
tools/files reverted tomainwith the new tests kept:FAIL ... AssertionError: unexpectedly None;ERROR ... json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig);JSONDecodeError.With the fix, all three pass.
python -I tests/<file>.py, all exit 0:test_first_light.py(OK, 8 skipped as onmain: they need the draw harness),test_first_light_bad_json.py,test_first_light_harness_paths.py,test_first_light_mesh_draw.py,test_first_light_stale_mesh.py,test_sandbox_pick.py,test_sandbox_scene.py,test_sandbox_scene_build.py,test_shader_library.py,test_tool_startup.py.python -m compileall -q make_game.py tools tests: clean.Not tested: Linux and macOS (the change is encoding-only and platform-independent).
AI-assisted: yes (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (not a translator change)🤖 Generated with Claude Code
https://claude.ai/code/session_01GZEZyXGTTXs4V33hrBw1tD