rootsig_census: guard --json with same_report_path and catch write OSError (ROOTSIG-CENSUS-JSON-GUARD) #1360

Open
github-bot wants to merge 2 commits from github-bot/gh-1360 into main AGit
Owner

@⁠JesusACD on GitHub · 2026-11-24 22:31 UTC · original
JesusACD:fix/rootsig-census-json-guard → main · +143 −9 · 2 files · 2 commits · open

Claimed in the coordination issue as: ROOTSIG-CENSUS-JSON-GUARD (#14)

What and why

tools/rootsig_census.py previously checked --json only with os.path.samefile(a.root, a.json) (:298-303) and wrote --json without catching OSError (:331-334):

  • Passing --json naming an unpacked input or manifest (<root>/<name>.dxbc, <root>/fspx/<name>.json, <root>/index.json, or <disasm>/<name>.s / <disasm>/index.json when --disasm is given) — directly, via another relative spelling, a link, or a case-folded alias — was not refused and overwrote the file.
  • Passing --json naming --disasm or any existing directory other than root ran the entire census first and then crashed with an unhandled IsADirectoryError / PermissionError traceback.
  • Unwritable --json paths crashed with an unhandled OSError traceback instead of reporting a one-line error with exit code 2.

This switches tools/rootsig_census.py to tools/report_paths.same_report_path (per CONTRIBUTING.md), refuses directory targets and input/manifest collisions before scanning, creates missing parent directories for --json, and catches OSError on write to print error: cannot write <path>: <reason> to stderr and exit 2.

Tested

  • python -m compileall -q make_game.py tools tests: clean.
  • python -I make_game.py --help and python -I tools/rootsig_census.py --help: clean.
  • python -I tests/test_rootsig_census.py -v: 30 passed (added 5 regression tests covering input/manifest preservation, delegation to same_report_path, pre-scan directory refusal, nested parent creation, and clean OSError reporting on Windows 11 / Python 3.13.17).
  • python -I tests/test_report_paths.py, python -I tests/test_report_path_case.py, and python -I tests/test_text_write_line_endings.py: 28 passed, 1 skipped.
  • python -I scripts/check_no_game_data.py tools/rootsig_census.py tests/test_rootsig_census.py: clean.
  • No game files or GPU needed.

GPUs tested: n/a

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: no translator change)
**@⁠JesusACD** on GitHub · 2026-11-24 22:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1360) `JesusACD:fix/rootsig-census-json-guard` → `main` · +143 −9 · 2 files · 2 commits · open Claimed in the coordination issue as: ROOTSIG-CENSUS-JSON-GUARD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why `tools/rootsig_census.py` previously checked `--json` only with `os.path.samefile(a.root, a.json)` (`:298-303`) and wrote `--json` without catching `OSError` (`:331-334`): - Passing `--json` naming an unpacked input or manifest (`<root>/<name>.dxbc`, `<root>/fspx/<name>.json`, `<root>/index.json`, or `<disasm>/<name>.s` / `<disasm>/index.json` when `--disasm` is given) — directly, via another relative spelling, a link, or a case-folded alias — was not refused and overwrote the file. - Passing `--json` naming `--disasm` or any existing directory other than `root` ran the entire census first and then crashed with an unhandled `IsADirectoryError` / `PermissionError` traceback. - Unwritable `--json` paths crashed with an unhandled `OSError` traceback instead of reporting a one-line error with exit code `2`. This switches `tools/rootsig_census.py` to `tools/report_paths.same_report_path` (per `CONTRIBUTING.md`), refuses directory targets and input/manifest collisions before scanning, creates missing parent directories for `--json`, and catches `OSError` on write to print `error: cannot write <path>: <reason>` to `stderr` and exit `2`. ### Tested - `python -m compileall -q make_game.py tools tests`: clean. - `python -I make_game.py --help` and `python -I tools/rootsig_census.py --help`: clean. - `python -I tests/test_rootsig_census.py -v`: **30 passed** (added 5 regression tests covering input/manifest preservation, delegation to `same_report_path`, pre-scan directory refusal, nested parent creation, and clean `OSError` reporting on Windows 11 / Python 3.13.17). - `python -I tests/test_report_paths.py`, `python -I tests/test_report_path_case.py`, and `python -I tests/test_text_write_line_endings.py`: **28 passed, 1 skipped**. - `python -I scripts/check_no_game_data.py tools/rootsig_census.py tests/test_rootsig_census.py`: clean. - No game files or GPU needed. GPUs tested: n/a 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:48:43 +00:00
Author
Owner

@⁠xel1uz on GitHub · 2026-11-24 22:49 UTC · original

I reproduced this on 8270eaea with an empty root/ directory. Running python -I tools/rootsig_census.py root --json root/index.json twice gave exit 0 on the first run (it wrote the census report to the manifest path) and exit 2 on the second. I saw the same behavior with an empty disasm/ directory and --disasm disasm --json disasm/index.json.

Fix and regression test: both paths are now rejected before the first write. All 30 tests passed with python -I tests/test_rootsig_census.py.

**@⁠xel1uz** on GitHub · 2026-11-24 22:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1360#issuecomment-7146694792) I reproduced this on `8270eaea` with an empty `root/` directory. Running `python -I tools/rootsig_census.py root --json root/index.json` twice gave exit 0 on the first run (it wrote the census report to the manifest path) and exit 2 on the second. I saw the same behavior with an empty `disasm/` directory and `--disasm disasm --json disasm/index.json`. [Fix and regression test](https://github.com/xel1uz/mandy/commit/6c85fbaebfca2f739d9d5f1b333a680e4ba42a24): both paths are now rejected before the first write. All 30 tests passed with `python -I tests/test_rootsig_census.py`.
Author
Owner

@⁠JesusACD on GitHub · 2026-11-24 23:01 UTC · original

Thanks for catching this, @⁠xel1uz! Updated in 85b44dd10 so <root>/index.json and <disasm>/index.json are reserved unconditionally before the first write, along with the regression test for empty directories. Re-ran python -I tests/test_rootsig_census.py -v (30 passed), test_report_paths.py, test_report_path_case.py, test_text_write_line_endings.py, compileall, and check_no_game_data.py.

**@⁠JesusACD** on GitHub · 2026-11-24 23:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1360#issuecomment-7146921265) Thanks for catching this, @⁠xel1uz! Updated in 85b44dd10 so `<root>/index.json` and `<disasm>/index.json` are reserved unconditionally before the first write, along with the regression test for empty directories. Re-ran `python -I tests/test_rootsig_census.py -v` (30 passed), `test_report_paths.py`, `test_report_path_case.py`, `test_text_write_line_endings.py`, `compileall`, and `check_no_game_data.py`.
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/1360/head:github-bot/gh-1360'
git switch 'github-bot/gh-1360'

Merge

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