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

Open
opened 2026-11-26 20:21:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1360
Author: @JesusACD
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/rootsig-census-json-guard


📝 Commits (2)

  • 8270eae rootsig_census: guard --json inputs with same_report_path and catch write OSError (ROOTSIG-CENSUS-JSON-GUARD)
  • 85b44dd rootsig_census: reserve root and disasm index.json paths before first write (ROOTSIG-CENSUS-JSON-GUARD)

📊 Changes

2 files changed (+143 additions, -9 deletions)

View changed files

📝 tests/test_rootsig_census.py (+92 -0)
📝 tools/rootsig_census.py (+51 -9)

📄 Description

Claimed in the coordination issue as: ROOTSIG-CENSUS-JSON-GUARD (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7146264254)

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1360 **Author:** [@JesusACD](https://github.com/JesusACD) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rootsig-census-json-guard` --- ### 📝 Commits (2) - [`8270eae`](https://github.com/ubiquitarianism/leonida/commit/8270eaea3ee0ea807a1abd77d9bca4739106ee47) rootsig_census: guard --json inputs with same_report_path and catch write OSError (ROOTSIG-CENSUS-JSON-GUARD) - [`85b44dd`](https://github.com/ubiquitarianism/leonida/commit/85b44dd1054abc309b981189b62fadbe4691798a) rootsig_census: reserve root and disasm index.json paths before first write (ROOTSIG-CENSUS-JSON-GUARD) ### 📊 Changes **2 files changed** (+143 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_rootsig_census.py` (+92 -0) 📝 `tools/rootsig_census.py` (+51 -9) </details> ### 📄 Description Claimed in the coordination issue as: ROOTSIG-CENSUS-JSON-GUARD (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7146264254) ### 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1390
No description provided.