[PR #1580] veh_spawn_intensities: handle empty tables, count MudMin>0, guard carve overwrites/paths, and write JSON atomically (VEH-SPAWN-INTENSITIES-AGG-AND-IO) #1600

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1580
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/veh-spawn-intensities-agg-and-io


📝 Commits (1)

  • bbdd853 veh_spawn_intensities: handle empty tables, count MudMin>0, guard carve overwrites/paths, and write JSON atomically

📊 Changes

2 files changed (+138 additions, -14 deletions)

View changed files

📝 tests/test_veh_spawn_intensities.py (+74 -0)
📝 tools/veh_spawn_intensities.py (+64 -14)

📄 Description

Item ID: VEH-SPAWN-INTENSITIES-AGG-AND-IO (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch tools/veh_spawn_intensities.py)

Summary

  • Handle empty VehSpawnIntensities tables in aggregate(): max(len(sig) for sig in signatures) previously crashed with ValueError: max() iterable argument is empty; using default=0 returns a valid zero-entry aggregate.
  • Count MudMin > 0 as well as MudMax > 0 in bands_with_mud: matches the documented rule (MudMin/MudMax above zero) instead of checking only MudMax.
  • Guard carve directory inputs and validate --json before scanning:
    • When input is a carve directory, guard <input>/index.json and .bin/.bk2 streams (including hardlink/case aliases via same_report_path) so --json can never overwrite carve inputs.
    • Reject empty/whitespace --json paths (previously "" was silently ignored and " " created a literal " " file) and existing directories before reading or printing stdout.
  • Write --json atomically before printing stdout and catch RecursionError: stage via NamedTemporaryFile + file_mode.published_mode + replace_retry.replace with allow_nan=False, cleaning up temp files on failure so existing reports are never truncated and failed runs emit no misleading stdout JSON.

Testing

  • AI-assisted: yes
  • GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files)
  • python3 -W error -I tests/test_veh_spawn_intensities.py -v: 12/12 passed
  • python3 -W error -I tests/test_text_write_line_endings.py -v: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/veh_spawn_intensities.py tests/test_veh_spawn_intensities.py: passed
  • python3 -m compileall -q make_game.py tools tests: passed
  • Mutation check against unpatched main:tools/veh_spawn_intensities.py: all 3 new tests fail (FAILED (failures=4, errors=2)).

🔄 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/1580 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/veh-spawn-intensities-agg-and-io` --- ### 📝 Commits (1) - [`bbdd853`](https://github.com/ubiquitarianism/leonida/commit/bbdd853784350967b786bddacea5df0c57fb7c53) veh_spawn_intensities: handle empty tables, count MudMin>0, guard carve overwrites/paths, and write JSON atomically ### 📊 Changes **2 files changed** (+138 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_veh_spawn_intensities.py` (+74 -0) 📝 `tools/veh_spawn_intensities.py` (+64 -14) </details> ### 📄 Description Item ID: `VEH-SPAWN-INTENSITIES-AGG-AND-IO` (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch `tools/veh_spawn_intensities.py`) ## Summary - **Handle empty `VehSpawnIntensities` tables in `aggregate()`**: `max(len(sig) for sig in signatures)` previously crashed with `ValueError: max() iterable argument is empty`; using `default=0` returns a valid zero-entry aggregate. - **Count `MudMin > 0` as well as `MudMax > 0` in `bands_with_mud`**: matches the documented rule (`MudMin`/`MudMax` above zero) instead of checking only `MudMax`. - **Guard carve directory inputs and validate `--json` before scanning**: - When `input` is a carve directory, guard `<input>/index.json` and `.bin`/`.bk2` streams (including hardlink/case aliases via `same_report_path`) so `--json` can never overwrite carve inputs. - Reject empty/whitespace `--json` paths (previously `""` was silently ignored and `" "` created a literal `" "` file) and existing directories before reading or printing stdout. - **Write `--json` atomically before printing stdout and catch `RecursionError`**: stage via `NamedTemporaryFile` + `file_mode.published_mode` + `replace_retry.replace` with `allow_nan=False`, cleaning up temp files on failure so existing reports are never truncated and failed runs emit no misleading stdout JSON. ## Testing - AI-assisted: yes - GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files) - `python3 -W error -I tests/test_veh_spawn_intensities.py -v`: **12/12 passed** - `python3 -W error -I tests/test_text_write_line_endings.py -v`: **3/3 passed** - `python3 -I scripts/check_no_game_data.py tools/veh_spawn_intensities.py tests/test_veh_spawn_intensities.py`: passed - `python3 -m compileall -q make_game.py tools tests`: passed - Mutation check against unpatched `main:tools/veh_spawn_intensities.py`: all 3 new tests fail (`FAILED (failures=4, errors=2)`). --- <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#1600
No description provided.