ptr_truncation_census: guard output paths/overwrites, handle scan/listing OSError, and write JSON atomically (PTR-TRUNCATION-CENSUS-GUARDS-AND-IO) #1567

Merged
IlyassRS3 merged 1 commit from upstream-pr/1567 into main 2026-11-28 10:52:42 +00:00
IlyassRS3 commented 2026-11-25 04:45:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T04:45:46Z.


Item ID: PTR-TRUNCATION-CENSUS-GUARDS-AND-IO (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch tools/ptr_truncation_census.py)

Summary

  • Validate --json and --index-out before scanning: reject empty/whitespace paths (previously "" was silently ignored and " " created a literal " " file in cwd), existing directories, missing parent directories, and any output path that aliases src, a scanned .s listing, <root>/index.json, <root>/<name>.dxbc, or adjacent native_paths (.fssm/.code/.json).
  • Write --json and --index-out atomically: stage via NamedTemporaryFile + file_mode.published_mode + replace_retry.replace, enforce allow_nan=False and trailing LF \n, and clean up temp files on failure so existing outputs are never truncated.
  • Handle OSError cleanly in scan_one() and main(): record unreadable listings as cannot read listing: <ExcType> (never leaking the filename or path into aggregate counts) instead of aborting the pool, and exit 2 cleanly when listings(src) raises OSError.
  • Deterministic tie-breaking in summarise()["not_reached"]: sort by (-count, error) instead of insertion-order-dependent Counter.most_common().

Testing

  • AI-assisted: yes
  • GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files)
  • python3 -W error -I tests/test_ptr_truncation_census.py -v: 16/16 passed
  • python3 -W error -I tests/test_text_write_line_endings.py -v: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/ptr_truncation_census.py tests/test_ptr_truncation_census.py: passed
  • python3 -m compileall -q make_game.py tools tests: passed
  • Mutation check against unpatched main:tools/ptr_truncation_census.py: all 5 new/updated tests fail (FAILED (failures=19, errors=2)).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485339803 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1567). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:45:46Z. --- Item ID: `PTR-TRUNCATION-CENSUS-GUARDS-AND-IO` (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch `tools/ptr_truncation_census.py`) ## Summary - **Validate `--json` and `--index-out` before scanning**: reject empty/whitespace paths (previously `""` was silently ignored and `" "` created a literal `" "` file in cwd), existing directories, missing parent directories, and any output path that aliases `src`, a scanned `.s` listing, `<root>/index.json`, `<root>/<name>.dxbc`, or adjacent `native_paths` (`.fssm`/`.code`/`.json`). - **Write `--json` and `--index-out` atomically**: stage via `NamedTemporaryFile` + `file_mode.published_mode` + `replace_retry.replace`, enforce `allow_nan=False` and trailing LF `\n`, and clean up temp files on failure so existing outputs are never truncated. - **Handle `OSError` cleanly in `scan_one()` and `main()`**: record unreadable listings as `cannot read listing: <ExcType>` (never leaking the filename or path into aggregate counts) instead of aborting the pool, and exit 2 cleanly when `listings(src)` raises `OSError`. - **Deterministic tie-breaking in `summarise()["not_reached"]`**: sort by `(-count, error)` instead of insertion-order-dependent `Counter.most_common()`. ## Testing - AI-assisted: yes - GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files) - `python3 -W error -I tests/test_ptr_truncation_census.py -v`: **16/16 passed** - `python3 -W error -I tests/test_text_write_line_endings.py -v`: **3/3 passed** - `python3 -I scripts/check_no_game_data.py tools/ptr_truncation_census.py tests/test_ptr_truncation_census.py`: passed - `python3 -m compileall -q make_game.py tools tests`: passed - Mutation check against unpatched `main:tools/ptr_truncation_census.py`: all 5 new/updated tests fail (`FAILED (failures=19, errors=2)`).
copilot-pull-request-reviewer[bot] commented 2026-11-25 04:45:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T04:45:59Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051988781 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1567#pullrequestreview-6051988781). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T04:45:59Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:52:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:52:37Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238179640 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1567#issuecomment-7238179640). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:52:37Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. 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!1567
No description provided.