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

Open
opened 2026-11-26 21:20:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2265
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/regen-fixtures-safety


📝 Commits (1)

  • 942872e regen_fixtures: guard flags/paths, strip UTF-8 BOM, and write atomically

📊 Changes

2 files changed (+142 additions, -31 deletions)

View changed files

📝 tests/semantic/regen_fixtures.py (+92 -31)
📝 tests/test_regen_fixtures.py (+50 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2265 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/regen-fixtures-safety` --- ### 📝 Commits (1) - [`942872e`](https://github.com/ubiquitarianism/leonida/commit/942872e11e73e0786885259af86434c383e45a7e) regen_fixtures: guard flags/paths, strip UTF-8 BOM, and write atomically ### 📊 Changes **2 files changed** (+142 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/regen_fixtures.py` (+92 -31) 📝 `tests/test_regen_fixtures.py` (+50 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2269
No description provided.