regen_fixtures: guard flags/paths, strip UTF-8 BOM, and write atomically #2265

Merged
kirigayakazima merged 1 commit from upstream-pr/2265 into main 2026-11-28 11:53:44 +00:00
kirigayakazima commented 2026-11-26 11:47:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T11:47:19Z.


Claimed in the coordination issue as: REGEN-FIXTURES-UNKNOWN-FLAGS-BOM-TRAVERSAL-AND-ATOMIC-IO (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191130679)

What and why

tests/semantic/regen_fixtures.py previously:

  • Silently ignored unknown -... CLI options and --help, treating unrecognized flags as ignored rather than usage errors.
  • Accepted path-traversal or separator-containing shader names (like ../escape or sub/name) without checking single-segment basename safety.
  • Opened .asm and .s files with "utf-8" instead of "utf-8-sig", leaving a UTF-8 BOM attached to line 1 in marked_names(), generated_names(), render(), mark(), and --check.
  • Overwrote .asm marks and .s fixtures in place via direct open(..., "w").

This rejects unknown flags (-h/--help return 0, -- ends options), validates plain shader stems upfront, opens files with utf-8-sig, stages and publishes writes atomically via tempfile + file_mode.published_mode + replace_retry.replace, handles OSError/UnicodeDecodeError cleanly, and adds unit coverage in tests/test_regen_fixtures.py.

Tested

  • python -I tests/test_regen_fixtures.py -v (11 passed)
  • python -I tests/semantic/regen_fixtures.py --check
  • Detached upstream/main baseline negative control: failed with the new tests before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5509456080 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2265). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T11:47:19Z. --- Claimed in the coordination issue as: REGEN-FIXTURES-UNKNOWN-FLAGS-BOM-TRAVERSAL-AND-ATOMIC-IO (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191130679) ### What and why `tests/semantic/regen_fixtures.py` previously: - Silently ignored unknown `-...` CLI options and `--help`, treating unrecognized flags as ignored rather than usage errors. - Accepted path-traversal or separator-containing shader names (like `../escape` or `sub/name`) without checking single-segment basename safety. - Opened `.asm` and `.s` files with `"utf-8"` instead of `"utf-8-sig"`, leaving a UTF-8 BOM attached to line 1 in `marked_names()`, `generated_names()`, `render()`, `mark()`, and `--check`. - Overwrote `.asm` marks and `.s` fixtures in place via direct `open(..., "w")`. This rejects unknown flags (`-h`/`--help` return 0, `--` ends options), validates plain shader stems upfront, opens files with `utf-8-sig`, stages and publishes writes atomically via `tempfile` + `file_mode.published_mode` + `replace_retry.replace`, handles `OSError`/`UnicodeDecodeError` cleanly, and adds unit coverage in `tests/test_regen_fixtures.py`. ### Tested - `python -I tests/test_regen_fixtures.py -v` (11 passed) - `python -I tests/semantic/regen_fixtures.py --check` - Detached `upstream/main` baseline negative control: failed with the new tests before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
real-rusher commented 2026-11-26 12:23:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:32Z.


Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_regen_fixtures.py: 11 tests OK. The PR's test file against main's tool: 3 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191941265 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2265#issuecomment-7191941265). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:23:32Z. --- Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_regen_fixtures.py: 11 tests OK. The PR's test file against main's tool: 3 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean. AI-assisted: yes (Claude Code)
tiguan26 commented 2026-11-27 04:37:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:37:17Z.

Review: APPROVED


Approving 942872e11.

Generated fixtures are written through a temp file and replace_retry with the destination's mode, sources are read BOM-tolerant, and a shader name with a separator or a traversal segment is refused.

Merged onto main d1dff7949 in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_regen_fixtures.py: 11 passed (main: 7). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083543039 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2265#pullrequestreview-6083543039). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:37:17Z. **Review:** APPROVED --- Approving 942872e11. Generated fixtures are written through a temp file and `replace_retry` with the destination's mode, sources are read BOM-tolerant, and a shader name with a separator or a traversal segment is refused. Merged onto `main` `d1dff7949` in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_regen_fixtures.py`: 11 passed (main: 7). AI-assisted (Claude Code, Claude Opus 5.5).
sodove commented 2026-11-28 10:45:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:45:08Z.


#2265 | head 942872e11e73e0786885259af86434c383e45a7e | python3 -I tests/test_regen_fixtures.py -v | red: 11 run, 3 failures, 1 error | green: 11 passed | Red → green

The fixture regenerator being tested lives under tests/semantic/. I copied only test_regen_fixtures.py to clean main. Its flag, path and BOM assertions failed and the atomic-write case raised an error. All 11 passed after the merge.

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238098494 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2265#issuecomment-7238098494). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:45:08Z. --- #2265 | head `942872e11e73e0786885259af86434c383e45a7e` | `python3 -I tests/test_regen_fixtures.py -v` | red: 11 run, 3 failures, 1 error | green: 11 passed | **Red → green** The fixture regenerator being tested lives under tests/semantic/. I copied only test_regen_fixtures.py to clean main. Its flag, path and BOM assertions failed and the atomic-write case raised an error. All 11 passed after the merge. Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
DadaCap commented 2026-11-28 11:53:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:53:46Z.


Merged, thank you @kirigayakazima! This translator PR (regen_fixtures: guard flags/paths, strip UTF-8 BOM, and write atomically) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238853478 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2265#issuecomment-7238853478). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:53:46Z. --- Merged, thank you @kirigayakazima! This translator PR (regen_fixtures: guard flags/paths, strip UTF-8 BOM, and write atomically) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2265
No description provided.