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

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/vs-layout-census-safety into main 2026-11-29 03:37:58 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 10:45:20 +00:00

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.
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.
lixonik reviewed 2026-11-26 10:50:46 +00:00
lixonik left a comment
No description provided.
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.
real-rusher commented 2026-11-26 12:23:40 +00:00

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)

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)
tiguan26 approved these changes 2026-11-27 04:35:51 +00:00
tiguan26 left a comment

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).

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).
sodove commented 2026-11-28 09:15:31 +00:00

#2257 | head 8755879c0d12a8658aace63c28467ff76f4ac761 | python3 -I tests/test_vs_layout_census.py -v, py -3.12 -I tests/test_vs_layout_census.py -v | red: Linux 19 tests, 4 assertion failures, 2 errors, 1 skipped. Windows 19 tests, 5 assertion failures, 1 error | green: Linux 18 passed, 1 skipped. Windows 19 passed | Red → green

Repeated both phases natively on Windows to exercise the case-insensitive path check that skipped on Linux. Windows ran all 19 tests.

Pinned main 4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 and Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2257 | head `8755879c0d12a8658aace63c28467ff76f4ac761` | `python3 -I tests/test_vs_layout_census.py -v`, `py -3.12 -I tests/test_vs_layout_census.py -v` | red: Linux 19 tests, 4 assertion failures, 2 errors, 1 skipped. Windows 19 tests, 5 assertion failures, 1 error | green: Linux 18 passed, 1 skipped. Windows 19 passed | **Red → green** Repeated both phases natively on Windows to exercise the case-insensitive path check that skipped on Linux. Windows ran all 19 tests. Pinned main `4938673668d807bf365b61284bf22b1ff8d02cc4`, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 and Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7236982945).
zmasi commented 2026-11-29 01:19:34 +00:00

Independent verification on Windows 11 (10.0.26200, x64) with 8755879c0d merged onto origin/main (5825b02ff8, 0 merge conflicts), tested under both Python 3.12.10 and Python 3.14.5:

  • Red (origin/main scripts/vs_layout_census.py + #2257 tests/test_vs_layout_census.py):
    • python -I tests/test_vs_layout_census.py: Ran 19 tests, FAILED (failures=5, errors=1, skipped=1) on both Python 3.12.10 and Python 3.14.5.
  • Green (8755879c0d merged onto origin/main):
    • python -I tests/test_vs_layout_census.py: Ran 19 tests, OK (skipped=1) on both Python 3.12.10 (0.58 s) and Python 3.14.5 (0.68 s; the 1 skip is the existing WinError 1314 symlink privilege check).
    • Unmocked NTFS read-only --json target check: writing out.json from a UTF-8 BOM index.json (rc=0), marking out.json 0o444, and re-running vs_layout_census.main([dx, "--json", out]) returns rc=2 (Access is denied), preserves out.json byte-for-byte, and leaves 0 .vs-layout-*.tmp staging files behind.
  • Hygiene: git diff --check, python -I -m compileall -q, python -I scripts/check_no_game_data.py, python -I tests/test_ci_registration.py (18/18), and python -I tests/test_text_write_line_endings.py (3/3) all exited 0.

AI-assisted.

Independent verification on Windows 11 (`10.0.26200`, x64) with `8755879c0d` merged onto `origin/main` (`5825b02ff8`, `0` merge conflicts), tested under both `Python 3.12.10` and `Python 3.14.5`: - **Red (`origin/main` `scripts/vs_layout_census.py` + `#2257` `tests/test_vs_layout_census.py`)**: - `python -I tests/test_vs_layout_census.py`: `Ran 19 tests`, `FAILED (failures=5, errors=1, skipped=1)` on both `Python 3.12.10` and `Python 3.14.5`. - **Green (`8755879c0d` merged onto `origin/main`)**: - `python -I tests/test_vs_layout_census.py`: `Ran 19 tests`, `OK (skipped=1)` on both `Python 3.12.10` (`0.58 s`) and `Python 3.14.5` (`0.68 s`; the 1 skip is the existing `WinError 1314` symlink privilege check). - Unmocked NTFS read-only `--json` target check: writing `out.json` from a UTF-8 BOM `index.json` (`rc=0`), marking `out.json` `0o444`, and re-running `vs_layout_census.main([dx, "--json", out])` returns `rc=2` (`Access is denied`), preserves `out.json` byte-for-byte, and leaves `0` `.vs-layout-*.tmp` staging files behind. - **Hygiene**: `git diff --check`, `python -I -m compileall -q`, `python -I scripts/check_no_game_data.py`, `python -I tests/test_ci_registration.py` (`18/18`), and `python -I tests/test_text_write_line_endings.py` (`3/3`) all exited `0`. AI-assisted.
OreoFR commented 2026-11-29 03:19:46 +00:00

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head 8755879c0 : red 4 failures + 2 errors / green 19 OK

python3.12 -I tests/test_vs_layout_census.py (19 tests):

  • Merge: clean (git merge-tree).
  • Red (main + only this PR's test file): 4 failures + 2 errors in test_atomic_json_creates_parent_ends_with_lf_and_cleans_on_failure, test_limit_validation_and_trailing_separator_json_guard (limit 0 / -1, trailing / and \), test_utf8_bom_index_and_recursion_error.
  • Green (main + git merge --no-ff): 19/19 OK, skipped 0.
  • (MEASURED n=3) red stable.
  • Neighbours: only this test imports the script; test_tool_startup has the same psin_dialogue failure on main and merge, unrelated.
  • Diff: BOM accepted (utf-8-sig), RecursionError → ValueError, --limit >= 1, --json ending in a separator refused; JSON write is atomic (temp file, fsync, published_mode, replace_retry, cleanup on failure), helpers exist in tools/. Clean. No game data.

Verdict: READY

AI-assisted: Claude Code

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head 8755879c0 : red 4 failures + 2 errors / green 19 OK `python3.12 -I tests/test_vs_layout_census.py` (19 tests): - Merge: clean (`git merge-tree`). - **Red** (main + only this PR's test file): 4 failures + 2 errors in `test_atomic_json_creates_parent_ends_with_lf_and_cleans_on_failure`, `test_limit_validation_and_trailing_separator_json_guard` (limit 0 / -1, trailing `/` and `\`), `test_utf8_bom_index_and_recursion_error`. - **Green** (main + `git merge --no-ff`): 19/19 OK, skipped 0. - (MEASURED n=3) red stable. - Neighbours: only this test imports the script; `test_tool_startup` has the same `psin_dialogue` failure on main and merge, unrelated. - Diff: BOM accepted (`utf-8-sig`), RecursionError → ValueError, `--limit` >= 1, `--json` ending in a separator refused; JSON write is atomic (temp file, fsync, `published_mode`, `replace_retry`, cleanup on failure), helpers exist in `tools/`. Clean. No game data. **Verdict: READY** AI-assisted: Claude Code
DadaCap commented 2026-11-29 03:37:54 +00:00

Merging, thank you @kirigayakazima! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2257#issuecomment-7249981238), and it still merges cleanly.

AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.

Merging, thank you @kirigayakazima! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2257#issuecomment-7249981238), and it still merges cleanly. AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.
Sign in to join this conversation.
No description provided.