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

Open
github-bot wants to merge 1 commit from github-bot/gh-1567 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 04:45 UTC · original
IlyassRS3:fix/ptr-truncation-census-guards-and-io → main · +163 −10 · 2 files · 1 commits · open

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)).
**@⁠IlyassRS3** on GitHub · 2026-11-25 04:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1567) `IlyassRS3:fix/ptr-truncation-census-guards-and-io` → `main` · +163 −10 · 2 files · 1 commits · open 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)`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:53 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:45 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 04:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1567#pullrequestreview-6051988781) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1567/head:github-bot/gh-1567'
git switch 'github-bot/gh-1567'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1567'
git switch 'github-bot/gh-1567'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1567'
git switch 'github-bot/gh-1567'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1567'
git switch 'main'
git merge --squash 'github-bot/gh-1567'
git switch 'main'
git merge --ff-only 'github-bot/gh-1567'
git switch 'main'
git merge 'github-bot/gh-1567'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.