gamedata_xml: write CSV/JSON reports atomically and sort walk subdirs #921

Merged
narekshaghoyandev merged 1 commit from upstream-pr/921 into main 2026-11-29 01:35:56 +00:00
narekshaghoyandev commented 2026-11-24 15:11:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:11:53Z.


Summary

  • Write --csv and --json reports in tools/gamedata_xml.py atomically via a staging temp file in the destination folder (file_mode.published_mode + replace_retry.replace), cleaning up staging files (including read-only ones) on failure so an existing report is never clobbered or truncated.
  • Extract write_json() with allow_nan=False and a trailing newline.
  • Sort dirs in place inside xml_files() so recursive directory walks visit subdirectories in deterministic order regardless of filesystem readdir order.
  • Accept an optional argv=None parameter in main(argv=None).

Verification

  • python3 -I tests/test_gamedata_xml.py -v — 18/18 pass (4 new regression tests).
  • Negative control against main: all 4 new tests fail before the patch and pass after.
  • python3 -I -m py_compile tools/gamedata_xml.py tests/test_gamedata_xml.py — pass.
  • python3 -I scripts/check_no_game_data.py tools/gamedata_xml.py tests/test_gamedata_xml.py — clean.

Claimed in the coordination issue as: BUILD-GAMEDATA-XML-ATOMIC-AND-ORDER
AI-assisted: yes (Gemini)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474860767 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/921). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:11:53Z. --- ## Summary - Write `--csv` and `--json` reports in `tools/gamedata_xml.py` atomically via a staging temp file in the destination folder (`file_mode.published_mode` + `replace_retry.replace`), cleaning up staging files (including read-only ones) on failure so an existing report is never clobbered or truncated. - Extract `write_json()` with `allow_nan=False` and a trailing newline. - Sort `dirs` in place inside `xml_files()` so recursive directory walks visit subdirectories in deterministic order regardless of filesystem `readdir` order. - Accept an optional `argv=None` parameter in `main(argv=None)`. ## Verification - `python3 -I tests/test_gamedata_xml.py -v` — 18/18 pass (4 new regression tests). - Negative control against `main`: all 4 new tests fail before the patch and pass after. - `python3 -I -m py_compile tools/gamedata_xml.py tests/test_gamedata_xml.py` — pass. - `python3 -I scripts/check_no_game_data.py tools/gamedata_xml.py tests/test_gamedata_xml.py` — clean. Claimed in the coordination issue as: BUILD-GAMEDATA-XML-ATOMIC-AND-ORDER AI-assisted: yes (Gemini)
PierreEbele commented 2026-11-25 21:25:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T21:25:52Z.


Reviewed 1fef9b9: staged atomic writes match the file_mode/replace_retry pattern of the other report writers, and os.fdopen names newline="" so BUILD-468 passes. I ran tests/test_gamedata_xml.py plus the report-path/line-ending suites on both trees: 18/18 on the PR; the 4 new tests fail on main, so they cover the fix. End-to-end probe: sorted walk and trailing JSON newline on the PR, raw readdir order and no LF on main; no .tmp leftovers, report mode preserved on both. No findings. AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7175066464 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/921#issuecomment-7175066464). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T21:25:52Z. --- Reviewed 1fef9b9: staged atomic writes match the file_mode/replace_retry pattern of the other report writers, and os.fdopen names newline="" so BUILD-468 passes. I ran tests/test_gamedata_xml.py plus the report-path/line-ending suites on both trees: 18/18 on the PR; the 4 new tests fail on main, so they cover the fix. End-to-end probe: sorted walk and trailing JSON newline on the PR, raw readdir order and no LF on main; no .tmp leftovers, report mode preserved on both. No findings. AI-assisted review. **Recommendation:** Merge
zmasi commented 2026-11-28 22:08:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:08:33Z.


Native Windows 11 NTFS Verification (1fef9b9f5c)

Verified 1fef9b9f5c85d3dc702b83d09a24961c5dff1d30 merged cleanly onto origin/main (c7753ed98a56677f10e34078b37eab0540e190ec, git merge-tree --write-tree rc=0) on native Windows 11 (26200) + NTFS:

  • Red (origin/main c7753ed98a): python -I tests/test_gamedata_xml.py failed (FAILED (failures=1, errors=3, skipped=1) out of 18).
  • Green (origin/main + 1fef9b9f5c):
    • python -I tests/test_gamedata_xml.py: 18 ran, OK (skipped=1) (atomic CSV/JSON writes, allow_nan=False rejection, trailing LF, in-place dirs.sort(), and explicit argv support).
    • Live unmocked Windows 11 NTFS stat.S_IREAD probe: Ran gamedata_xml.main targeting read-only out.csv and out.json (stat.S_IREAD on NTFS): both returned rc=2 with zero secondary unlink errors (os.chmod(tmp_path, 0o600) cleared FILE_ATTRIBUTE_READONLY first), left 0 .gamedata_xml-*.tmp staged files, and preserved both read-only files byte-for-byte.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246525302 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/921#issuecomment-7246525302). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:08:33Z. --- ### Native Windows 11 NTFS Verification (`1fef9b9f5c`) Verified `1fef9b9f5c85d3dc702b83d09a24961c5dff1d30` merged cleanly onto `origin/main` (`c7753ed98a56677f10e34078b37eab0540e190ec`, `git merge-tree --write-tree` `rc=0`) on native **Windows 11 (`26200`) + NTFS**: - **Red (`origin/main` `c7753ed98a`)**: `python -I tests/test_gamedata_xml.py` failed (`FAILED (failures=1, errors=3, skipped=1)` out of `18`). - **Green (`origin/main + 1fef9b9f5c`)**: - `python -I tests/test_gamedata_xml.py`: **`18 ran, OK (skipped=1)`** (atomic CSV/JSON writes, `allow_nan=False` rejection, trailing LF, in-place `dirs.sort()`, and explicit `argv` support). - **Live unmocked Windows 11 NTFS `stat.S_IREAD` probe**: Ran `gamedata_xml.main` targeting read-only `out.csv` and `out.json` (`stat.S_IREAD` on NTFS): both returned `rc=2` with zero secondary `unlink` errors (`os.chmod(tmp_path, 0o600)` cleared `FILE_ATTRIBUTE_READONLY` first), left **`0` `.gamedata_xml-*.tmp` staged files**, and preserved both read-only files byte-for-byte. AI-assisted.
OreoFR commented 2026-11-29 01:31:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:31:27Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure + 3 errors (test_main_accepts_explicit_argv, test_write_csv_and_json_preserve_existing_on_replace_failure, test_write_json_rejects_nan_and_ends_with_newline, test_xml_files_sorts_subdirectories_in_place) / green 18 OK.

  • PR head 1fef9b9f5, python -I tests/test_gamedata_xml.py from the repository root.
  • Red (main + only this PR's test files): 18 run, 1 failure, 3 errors, 0 skips. test_main_accepts_explicit_argv: TypeError: main() takes 0 positional arguments but 1 was given; test_write_csv_and_json_preserve_existing_on_replace_failure: AttributeError: ... no attribute 'replace_retry'; test_write_json_rejects_nan_and_ends_with_newline: AttributeError: ... no attribute 'write_json'; test_xml_files_sorts_subdirectories_in_place: AssertionError: Lists differ (subdirectories left unsorted). MEASURED, failing test(s) alone 3 runs, 3/3 fail.
  • Green (main + git merge --no-ff of this PR, no conflict): 18 run, OK, 0 skips. MEASURED, the same test(s) alone 3/3 pass.
  • Skips: none. POSIX-only parts ran here: test_a_real_unlistable_folder_fails_the_scan (POSIX, non-root) runs and passes on both sides, and the PR's POSIX chmod 0o444 blocks run on macOS.
  • Verdict: READY.

Red = main + only the test files from this PR (git checkout pr-921 -- tests/test_gamedata_xml.py); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248837944 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/921#issuecomment-7248837944). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:31:27Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure + 3 errors (`test_main_accepts_explicit_argv`, `test_write_csv_and_json_preserve_existing_on_replace_failure`, `test_write_json_rejects_nan_and_ends_with_newline`, `test_xml_files_sorts_subdirectories_in_place`) / green 18 OK. - PR head 1fef9b9f5, `python -I tests/test_gamedata_xml.py` from the repository root. - Red (main + only this PR's test files): 18 run, 1 failure, 3 errors, 0 skips. `test_main_accepts_explicit_argv`: `TypeError: main() takes 0 positional arguments but 1 was given`; `test_write_csv_and_json_preserve_existing_on_replace_failure`: `AttributeError: ... no attribute 'replace_retry'`; `test_write_json_rejects_nan_and_ends_with_newline`: `AttributeError: ... no attribute 'write_json'`; `test_xml_files_sorts_subdirectories_in_place`: `AssertionError: Lists differ` (subdirectories left unsorted). MEASURED, failing test(s) alone 3 runs, 3/3 fail. - Green (main + `git merge --no-ff` of this PR, no conflict): 18 run, OK, 0 skips. MEASURED, the same test(s) alone 3/3 pass. - Skips: none. POSIX-only parts ran here: `test_a_real_unlistable_folder_fails_the_scan` (POSIX, non-root) runs and passes on both sides, and the PR's POSIX `chmod 0o444` blocks run on macOS. - Verdict: READY. Red = main + only the test files from this PR (`git checkout pr-921 -- tests/test_gamedata_xml.py`); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched. AI-assisted: Claude Code (Claude Opus 5.5).
MoonEyes commented 2026-11-29 01:35:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:35:58Z.


Merged after OreoFR's red/green check (check) (macOS 27.2.1, Apple M5, Python 3.12) and a local re-check here. Merged after local re-verification: this PR merged onto main ecb0a4a49 without conflict, and its test file(s) (tests/test_gamedata_xml.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248889248 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/921#issuecomment-7248889248). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T01:35:58Z. --- Merged after **OreoFR**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/921#issuecomment-7248837944)) (macOS 27.2.1, Apple M5, Python 3.12) and a local re-check here. Merged after local re-verification: this PR merged onto `main` ecb0a4a49 without conflict, and its test file(s) (`tests/test_gamedata_xml.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!921
No description provided.