scripts: harden meta_to_xml.ps1 null head, limit guard and atomic XML write #1801

Merged
kirigayakazima merged 1 commit from upstream-pr/1801 into main 2026-11-28 20:17:29 +00:00
kirigayakazima commented 2026-11-25 12:18:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T12:18:41Z.


Claimed in the coordination issue as: META-TO-XML-NULL-HEAD-CASE-AND-LIMIT-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162168340)

What and why

  • Guard scripts/meta_to_xml.ps1 against bink2 or malformed index.json entries whose head is null/absent ($_.head -is [string]) instead of throwing InvokeMethodOnNull on .StartsWith(...).
  • Compare 5053494e / 52424630 hex prefixes case-insensitively (OrdinalIgnoreCase) in both filtering and $kind classification.
  • Reject negative -Limit values upfront (throw "-Limit must be 0 or greater.") instead of writing an empty failures.txt and exiting 0.
  • Stage XML outputs to a unique .tmp file beside the destination and publish via Move-Item -LiteralPath ... -Force with finally cleanup.
  • Add synthetic Windows PowerShell 5.1 regression tests in tests/test_meta_to_xml_paths.py.

Tested

  • python -I tests/test_meta_to_xml_paths.py -v (live Windows PowerShell 5.1) -> Ran 3 tests in 4.548s, OK (verified in a detached upstream/main worktree that both new tests fail before the fix: FAILED (failures=2)).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.507s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.931s, OK.
  • python -I scripts/check_no_game_data.py scripts/meta_to_xml.ps1 tests/test_meta_to_xml_paths.py -> exit 0.
  • python -I -m compileall -q tests/test_meta_to_xml_paths.py and git diff --check -> clean.

GPUs tested: n/a (Windows PowerShell 5.1 + stdlib Python tests on Windows 11 x64)

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. (n/a)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5491182566 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1801). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T12:18:41Z. --- Claimed in the coordination issue as: META-TO-XML-NULL-HEAD-CASE-AND-LIMIT-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162168340) ### What and why - Guard `scripts/meta_to_xml.ps1` against `bink2` or malformed `index.json` entries whose `head` is null/absent (`$_.head -is [string]`) instead of throwing `InvokeMethodOnNull` on `.StartsWith(...)`. - Compare `5053494e` / `52424630` hex prefixes case-insensitively (`OrdinalIgnoreCase`) in both filtering and `$kind` classification. - Reject negative `-Limit` values upfront (`throw "-Limit must be 0 or greater."`) instead of writing an empty `failures.txt` and exiting `0`. - Stage XML outputs to a unique `.tmp` file beside the destination and publish via `Move-Item -LiteralPath ... -Force` with `finally` cleanup. - Add synthetic Windows PowerShell 5.1 regression tests in `tests/test_meta_to_xml_paths.py`. ### Tested - `python -I tests/test_meta_to_xml_paths.py -v` (live Windows PowerShell 5.1) -> `Ran 3 tests in 4.548s`, `OK` (verified in a detached `upstream/main` worktree that both new tests fail before the fix: `FAILED (failures=2)`). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.507s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.931s`, `OK`. - `python -I scripts/check_no_game_data.py scripts/meta_to_xml.ps1 tests/test_meta_to_xml_paths.py` -> exit `0`. - `python -I -m compileall -q tests/test_meta_to_xml_paths.py` and `git diff --check` -> clean. GPUs tested: n/a (Windows PowerShell 5.1 + stdlib Python tests on Windows 11 x64) 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. (n/a)
PierreEbele commented 2026-11-25 19:37:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T19:37:00Z.


Reviewed 4ef1614: compileall is clean on PR and main; the PowerShell tests are Windows-only and skip on this Linux host, so I reviewed the script change by reading it. All three hardenings look right (null-head rows skipped, case-insensitive head match, negative -Limit throws before creating Out, tmp+Move write with finally cleanup), and both new tests would fail on main by analysis. One thing to watch in CI: the bracket-path test now exercises Move-Item with brackets in the destination path - worth confirming that job stays green. Nothing was run dynamically.

AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7172541460 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1801#issuecomment-7172541460). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T19:37:00Z. --- Reviewed 4ef1614: compileall is clean on PR and main; the PowerShell tests are Windows-only and skip on this Linux host, so I reviewed the script change by reading it. All three hardenings look right (null-head rows skipped, case-insensitive head match, negative -Limit throws before creating Out, tmp+Move write with finally cleanup), and both new tests would fail on main by analysis. One thing to watch in CI: the bracket-path test now exercises Move-Item with brackets in the destination path - worth confirming that job stays green. Nothing was run dynamically. AI-assisted review. **Recommendation:** Merge
MoonEyes commented 2026-11-28 20:17:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:17:26Z.


Red/green: On main test_meta_to_xml_paths.py has 2 failures (a null head row crashes Where-Object, a negative limit is accepted), and with the PR all 3 tests pass on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245177241 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1801#issuecomment-7245177241). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T20:17:26Z. --- Red/green: On main test_meta_to_xml_paths.py has 2 failures (a null head row crashes Where-Object, a negative limit is accepted), and with the PR all 3 tests pass on Windows 11 at OreoFR's (RTX 4070). Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:54:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:54:06Z.


Verified by OreoFR

  • Base: main 3408969a7 + PR head 4ef161444
  • Test: python -I tests/test_meta_to_xml_paths.py
  • Red on main: 2 FAIL ("cannot call a method on a null-valued expression" in Where-Object; negative limit accepted)
  • Green with the PR: 3 OK
  • Verdict: READY (Windows PowerShell 5.1-specific defect)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246355338 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1801#issuecomment-7246355338). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:54:06Z. --- **Verified by OreoFR** - Base: main `3408969a7` + PR head `4ef161444` - Test: `python -I tests/test_meta_to_xml_paths.py` - Red on main: 2 FAIL ("cannot call a method on a null-valued expression" in Where-Object; negative limit accepted) - Green with the PR: 3 OK - Verdict: READY (Windows PowerShell 5.1-specific defect) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
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!1801
No description provided.