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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2257
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/vs-layout-census-safety


📝 Commits (1)

  • 8755879 Harden vs_layout_census BOM/limit validation and atomic --json writes

📊 Changes

2 files changed (+111 additions, -7 deletions)

View changed files

📝 scripts/vs_layout_census.py (+43 -7)
📝 tests/test_vs_layout_census.py (+68 -0)

📄 Description

Claimed in the coordination issue as: VS-LAYOUT-CENSUS-BOM-LIMIT-AND-ATOMIC-JSON-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189748056)

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.

🔄 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/2257 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/vs-layout-census-safety` --- ### 📝 Commits (1) - [`8755879`](https://github.com/ubiquitarianism/leonida/commit/8755879c0d12a8658aace63c28467ff76f4ac761) Harden vs_layout_census BOM/limit validation and atomic --json writes ### 📊 Changes **2 files changed** (+111 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `scripts/vs_layout_census.py` (+43 -7) 📝 `tests/test_vs_layout_census.py` (+68 -0) </details> ### 📄 Description Claimed in the coordination issue as: VS-LAYOUT-CENSUS-BOM-LIMIT-AND-ATOMIC-JSON-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189748056) ### 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. --- <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#2262
No description provided.