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

Merged
leonida/mandy
quietfold merged 1 commit from fix/ptr-truncation-census-guards-and-io into main 2026-11-28 10:52:42 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:45:46 +00:00

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)).
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] reviewed 2026-11-25 04:45:59 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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)

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 description provided.