scripts/vs_layout_census: support BOM index, validate limit/paths, write --json atomically #2257

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

@⁠kirigayakazima on GitHub · 2026-11-26 10:45 UTC · original
kirigayakazima:fix/vs-layout-census-safety → main · +111 −7 · 2 files · 1 commits · open

Claimed in the coordination issue as: VS-LAYOUT-CENSUS-BOM-LIMIT-AND-ATOMIC-JSON-SAFETY (#1608)

What and why

  • Read <dxbc>/index.json with encoding="utf-8-sig" and convert RecursionError from json.load() into ValueError across load_index(), input_paths(), and main() (scripts/vs_layout_census.py) so single-line error reporting holds without tracebacks.
  • Reject non-positive limit / --limit (< 1) in survey() and main() as well as trailing-separator --json directory paths (/ or \) before calling survey().
  • Write --json output atomically via _write_json_atomic() (creating missing parent directories cleanly, writing trailing LF \n, fsyncing, preserving permissions with published_mode(), publishing via replace_retry.replace(), and cleaning .vs-layout-*.tmp files on failure).
  • Expand tests/test_vs_layout_census.py covering UTF-8 BOM index parsing, RecursionError CLI handling, --limit validation, trailing-separator --json refusal, and atomic JSON write/failure rollback.

Tested

  • Patched: python -I tests/test_vs_layout_census.py -v -> Ran 19 tests in 0.629s (OK).
  • Baseline check (upstream/main a73a57e1 with updated tests/test_vs_layout_census.py copied into detached worktree): Ran 19 tests in 0.690s (FAILED (failures=5, errors=1)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 5.365s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 13.271s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (synthetic containers/listings and atomic JSON output tests)

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.
**@⁠kirigayakazima** on GitHub · 2026-11-26 10:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2257) `kirigayakazima:fix/vs-layout-census-safety` → `main` · +111 −7 · 2 files · 1 commits · open Claimed in the coordination issue as: VS-LAYOUT-CENSUS-BOM-LIMIT-AND-ATOMIC-JSON-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Read `<dxbc>/index.json` with `encoding="utf-8-sig"` and convert `RecursionError` from `json.load()` into `ValueError` across `load_index()`, `input_paths()`, and `main()` (`scripts/vs_layout_census.py`) so single-line error reporting holds without tracebacks. - Reject non-positive `limit` / `--limit` (`< 1`) in `survey()` and `main()` as well as trailing-separator `--json` directory paths (`/` or `\`) before calling `survey()`. - Write `--json` output atomically via `_write_json_atomic()` (creating missing parent directories cleanly, writing trailing LF `\n`, fsyncing, preserving permissions with `published_mode()`, publishing via `replace_retry.replace()`, and cleaning `.vs-layout-*.tmp` files on failure). - Expand `tests/test_vs_layout_census.py` covering UTF-8 BOM index parsing, `RecursionError` CLI handling, `--limit` validation, trailing-separator `--json` refusal, and atomic JSON write/failure rollback. ### Tested - Patched: `python -I tests/test_vs_layout_census.py -v` -> `Ran 19 tests in 0.629s` (`OK`). - Baseline check (`upstream/main` `a73a57e1` with updated `tests/test_vs_layout_census.py` copied into detached worktree): `Ran 19 tests in 0.690s` (`FAILED (failures=5, errors=1)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.365s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 13.271s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (synthetic containers/listings and atomic JSON output tests) 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:24:40 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:50 UTC · original · reviewed

Windows 11: 19/19 Python tests passed. I also held an existing JSON output open without FILE_SHARE_DELETE. The actual Win32 sharing restriction made the replacement fail, the original stayed byte-for-byte intact, and the temporary file was cleaned up. After closing the handle, a second write succeeded with valid UTF-8 JSON and LF endings. No findings from these checks.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 10:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2257#pullrequestreview-6072804287) · **reviewed** Windows 11: 19/19 Python tests passed. I also held an existing JSON output open without `FILE_SHARE_DELETE`. The actual Win32 sharing restriction made the replacement fail, the original stayed byte-for-byte intact, and the temporary file was cleaned up. After closing the handle, a second write succeeded with valid UTF-8 JSON and LF endings. No findings from these checks. AI-assisted.
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 12:23 UTC · original

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_vs_layout_census.py: 19 tests OK (1 skipped). The PR's test file against main's script: 4 failures and 2 errors, so the new tests fail on main and pass with the change. compileall clean.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2257#issuecomment-7191944203) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_vs_layout_census.py: 19 tests OK (1 skipped). The PR's test file against main's script: 4 failures and 2 errors, so the new tests fail on main and pass with the change. compileall clean. AI-assisted: yes (Claude Code)
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:35 UTC · original · approved these changes

Approving 8755879c0.

The index is read BOM-tolerant with a deep-JSON guard, --limit must be at least 1, and --json is written through a temp file and replace_retry.

Merged onto main d1dff7949 in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_vs_layout_census.py: 18 passed, 1 skipped (main: 15). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2257#pullrequestreview-6083535300) · **approved these changes** Approving 8755879c0. The index is read BOM-tolerant with a deep-JSON guard, `--limit` must be at least 1, and `--json` is written through a temp file and `replace_retry`. Merged onto `main` `d1dff7949` in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_vs_layout_census.py`: 18 passed, 1 skipped (main: 15). AI-assisted (Claude Code, Claude Opus 5.5).
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/2257/head:github-bot/gh-2257'
git switch 'github-bot/gh-2257'

Merge

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