Skip to content

first_light: name the file when a manifest.json or index.json read fails - #2602

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
josevictorp:josevictorp/leonida-first-light-json
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
josevictorp:josevictorp/leonida-first-light-json

Conversation

@josevictorp

@josevictorp josevictorp commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

New BUILD item, claimed here.

What was wrong

tools/first_light.py ended in a traceback when one of the JSON files in the user's folders was broken:

Path File Before
--check without --game <out>/manifest.json truncated json.decoder.JSONDecodeError
--check without --game manifest.json not UTF-8 UnicodeDecodeError
--check without --game manifest.json an array, or without width/height TypeError / KeyError in run_draw
--list carve index.json truncated, not UTF-8, not an array, or an entry without stage/name the same four

What changed

A small load_json helper reads those two files in main and exits with one line naming the file and the reason, like the tool's other exits (--list needs --game, shader not in the carve index). Good input behaves as before.

Overlap

Four open pull requests touch this tool, so the change is kept to the two reads in main:

Tested

Linux 6.8, Python 3.12.3, CPU only; no GPU, no game files, no built harness.

  • python -I tests/test_first_light_bad_json.py: 9 tests pass. They run the CLI in a subprocess over hand-written folders in a temporary directory; one of them checks that a well-formed index still lists its vs/ps entries.
  • Negative control: with tools/first_light.py from main, 8 of the 9 fail.
  • python -I tests/test_first_light.py: unchanged (7 tests: 4 pass, 3 skipped without LEONIDA_FIRST_LIGHT_DIR).

Not covered: the --check success path past the read, which needs the built harness.

AI-assisted: written by Qwen (model qwen3.8-gx10-claude-compatible), reviewed and re-run with Claude Code; the tests were moved to their own file in review.

A truncated manifest.json (--check) or carve index.json (--list) died with a json.decoder traceback, a
non-UTF-8 file with a UnicodeDecodeError, and a well-formed file of the wrong shape with a TypeError or
KeyError, though the tool's other failures are single SystemExit lines. The new load_json guards only the
two reads main opens, naming the file and the reason on one line, and checks index entries just on the keys
--list prints; choose() and translate() keep their plain reads, which ItsNotRexed#2419 rewrites.
tests/test_first_light_bad_json.py drives the CLI over hand-written temp folders, with no package or
harness; 8 of its 9 tests fail without the change. The tests sit in their own file (moved there in review)
so they don't collide with the open pull requests that extend tests/test_first_light.py.

AI-assisted: written by Qwen (model qwen3.8-gx10-claude-compatible).
Co-Authored-By: Qwen qwen3.8-gx10-claude-compatible <noreply@qwen.ai>
@ricarmandoagent

Copy link
Copy Markdown

Checked 86b5823995a47cea8094e4b6addd766dc7f63d2c (Linux 7.3.4, Python 3.15.2, no game files, no harness).

$ python3 -m compileall -q make_game.py tools tests        # exit 0
$ python3 -I tests/test_first_light_bad_json.py -v        # Ran 9 tests ... OK
$ python3 -I tests/test_first_light.py                    # Ran 7 tests ... OK (skipped=3, needs LEONIDA_FIRST_LIGHT_DIR)
$ git diff --check main...HEAD                            # clean

Negative control: with tools/first_light.py from main and this PR's test file,
Ran 9 tests ... FAILED (failures=8) (e.g. the dict-shaped index gives
TypeError: string indices must be integers from main), so the new tests detect the old behaviour.

I checked the required keys are compatible with what the tools write: tools/shader_carve.py:117 always emits
name/file/stage per index entry, and the manifest is written with width/height in
tools/first_light.py (manifest = {... "width": a.width, "height": a.height ...}), so the new entry_keys/
keys checks do not reject output the repo produces. A valid hand-written index still lists only vs/ps
(covered by test_list_prints_the_candidates_from_a_hand_written_index).

No defect found in the claimed cases (truncated / non-UTF-8 / wrong shape / missing keys, both files).

AI-assisted review.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 86b5823 merged onto main 4947579 (clean merge) on Windows 11, Python 3.13: pytest tests/test_first_light_bad_json.py: 9 passed. Negative control: the same tests against main's copies of the changed sources give 8 failed, so the tests really cover the change.

AI-assisted (Claude Code); runs on my machine.

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